/* r321: phones. Navbar flush to the bottom edge, full screen chart to the notch, time frame sheet, drawing tools sheet.
   Theme variables only. */
@media (max-width: 767px), (max-width: 1024px) and (max-height: 500px) and (pointer: coarse) {
  /* ---------- bottom navigation: sits on the bottom edge, no floating gap ---------- */
  body:not(.embed), body:not(.embed)[data-desk-density] { --nav-h: 66px; }
  body:not(.embed) .mnav { left: 0 !important; right: 0 !important; bottom: 0 !important; height: calc(66px + env(safe-area-inset-bottom)) !important; padding: 3px 4px env(safe-area-inset-bottom) !important; border: 0 !important; border-top: 1px solid var(--hair) !important; border-radius: 0 !important; box-shadow: none !important; background: var(--card) !important; }
  body:not(.embed) .mnav .mn { min-height: 60px !important; flex-direction: column; justify-content: center; gap: 4px !important; font-size: 11px !important; }
  body:not(.embed) .mnav .mn svg { width: 23px !important; height: 23px !important; }
  body:not(.embed) .mnav .mn span { font-size: 11px !important; font-weight: 600; line-height: 1.1; }
  body:not(.embed) .mnav .mn::before { width: 40px !important; height: 40px !important; top: 2px !important; }
  body:not(.embed) .app { height: calc(var(--mobile-visible-height, 100dvh) - 66px - env(safe-area-inset-bottom)) !important; }
  body.mobile-keyboard:not(.embed) .app { height: var(--mobile-visible-height, 100dvh) !important; }

  /* ---------- symbol row above the navbar ---------- */
  body.mobile-toolbar-mounted:not(.embed) .top { border-top: 1px solid var(--hair); background: var(--card); }
  body.mobile-toolbar-mounted:not(.embed) #mobileToolbarRow > #symBtn { touch-action: pan-x; border-radius: 9px; }
  body.mobile-toolbar-mounted:not(.embed) #mobileToolbarRow > #symBtn::after { content: "⇅"; flex: none; margin-left: 2px; font-size: 11px; color: var(--t3); }
  body.mobile-toolbar-mounted:not(.embed) #mobileToolbarRow > #tfBtn { flex: 0 0 54px !important; width: 54px !important; max-width: 54px !important; height: 34px !important; min-height: 34px !important; border: 1px solid var(--hair) !important; border-radius: 9px !important; background: var(--fill) !important; font-weight: 700 !important; font-size: 12px !important; }

  /* ---------- full screen: chart fills the screen, under the notch ---------- */
  html.sc-full body:not(.embed), html.sc-full body:not(.embed)[data-desk-density] { --mobile-controls-h: calc(48px + env(safe-area-inset-bottom)); }
  html.sc-full body:not(.embed) .app { height: 100dvh !important; padding: 0 !important; }
  html.sc-full body:not(.embed) .stage { padding: 0 !important; }
  html.sc-full body:not(.embed) .card { border-radius: 0 !important; border: 0 !important; margin: 0 !important; }
  html.sc-full body:not(.embed) .legend { top: calc(env(safe-area-inset-top) + 6px) !important; left: calc(env(safe-area-inset-left) + 8px) !important; }
  html.sc-full body:not(.embed) .top { padding-bottom: env(safe-area-inset-bottom) !important; height: calc(48px + env(safe-area-inset-bottom)) !important; }
  html.sc-full, html.sc-full body { background: var(--chart-bg, var(--card)) !important; }
  /* exit button: small, top-right of the chart, clear of the price scale and the bottom tool row */
  html.sc-full .sc-full-exit { top: calc(env(safe-area-inset-top) + 8px) !important; bottom: auto !important; right: calc(env(safe-area-inset-right) + 72px) !important; width: 34px !important; height: 34px !important; border-radius: 10px !important; opacity: .8; }
  html.sc-full .sc-full-exit svg { width: 16px; height: 16px; }

  /* ---------- time frame menu as a tidy sheet ---------- */
  .pop:has(.tf-grid) { left: 8px !important; right: 8px !important; width: auto !important; max-width: none !important; max-height: 70dvh !important; padding: 10px 12px 12px !important; border-radius: 16px !important; overflow-y: auto; }
  .pop:has(.tf-grid) .ph { margin: 8px 2px 6px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--t3); }
  .pop:has(.tf-grid) .tf-grid { display: grid !important; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .pop:has(.tf-grid) .tf-grid .pi { justify-content: center; height: 40px; min-height: 40px; padding: 0; border: 1px solid var(--hair); border-radius: 10px; font-size: 13px; font-weight: 600; }
  .pop:has(.tf-grid) .tf-grid .pi.on { background: var(--t1); border-color: var(--t1); color: var(--card); }
  .pop:has(.tf-grid) .custom-tf { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 6px; }
  .pop:has(.tf-grid) .custom-tf :is(input, select, .btn) { height: 40px; border-radius: 10px; }
  .pop:has(.tf-grid) #favEdit { height: 42px; border-radius: 10px; }
}

/* ---------- drawing tools sheet (phones) ---------- */
.modal-box.dw321-box { width: min(520px, 100%); height: min(640px, 92dvh); padding: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: 16px; }
.dw321-box > .mh { padding: 14px 14px 8px 16px; flex: none; }
.dw321-box .advanced-content { flex: 1; min-height: 0; padding: 0; overflow: hidden; display: flex; }
.dw321 { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dw321-s { padding: 0 14px 8px; flex: none; }
.dw321-s input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--hair); border-radius: 10px; background: var(--fill); color: var(--t1); font: inherit; font-size: 14px; }
.dw321-c { display: flex; gap: 6px; padding: 4px 14px 10px; overflow-x: auto; scrollbar-width: none; flex: none; border-bottom: 1px solid var(--hair); }
.dw321-c::-webkit-scrollbar { display: none; }
.dw321-c button { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--hair); border-radius: 999px; background: transparent; color: var(--t2); font: inherit; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.dw321-c button svg { width: 15px; height: 15px; }
.dw321-c button.on { background: var(--t1); border-color: var(--t1); color: var(--card); }
.dw321-b { flex: 1; min-height: 0; overflow-y: auto; padding: 0 14px 12px; overscroll-behavior: contain; }
.dw321-h { padding: 12px 2px 6px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--t3); }
.dw321 > .dw321-h { padding-left: 16px; }
.dw321-g { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.dw321-rec { padding: 0 14px 10px; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.dw321-t { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 5px; min-height: 74px; padding: 9px 4px 6px; border: 1px solid var(--hair); border-radius: 12px; background: var(--card); color: var(--t1); font: inherit; cursor: pointer; }
.dw321-t:active { background: var(--fill-2); }
.dw321-i { display: grid; place-items: center; width: 30px; height: 30px; color: var(--t1); }
.dw321-i svg { width: 26px; height: 26px; }
.dw321-n { font-size: 10.5px; line-height: 1.2; color: var(--t2); text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dw321-none { padding: 30px 0; text-align: center; color: var(--t3); }
.dw321-f { display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hair); flex: none; }
.dw321-f .btn { flex: 1; height: 40px; justify-content: center; display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 767px) {
  .modal-box.dw321-box { width: 100%; height: 86dvh; margin-top: auto; border-radius: 18px 18px 0 0; }
}
