/* ============================================================
   MarketPulse — Mobile terminal + Advertisement view
   ============================================================ */

.stage {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #0C1119 0%, #05070B 70%);
  z-index: 5;
}
.stage.on { display: flex; }

/* ---------------- MOBILE ---------------- */
.phone-wrap { display: flex; align-items: center; gap: 44px; }
.phone {
  width: 390px; height: 800px; border-radius: 38px;
  background: var(--bg-void); border: 8px solid #14181F;
  box-shadow: 0 50px 100px -30px rgba(0,0,0,.9), 0 0 0 1px rgba(255,255,255,.06);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}
.phone-notch {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 128px; height: 26px; background: #14181F; border-radius: 0 0 14px 14px; z-index: 60;
}
.m-status {
  height: 34px; flex: 0 0 34px; display: flex; align-items: flex-end;
  justify-content: space-between; padding: 0 20px 4px;
  font-size: 11px; color: var(--t2); font-family: var(--font-mono);
}
.m-top {
  height: 46px; flex: 0 0 46px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; border-bottom: 1px solid var(--line);
}
.m-brand { display: flex; align-items: center; gap: 7px; }
.m-brand .bn { font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.m-top .sp { flex: 1; }
.m-chip {
  font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700;
  padding: 3px 6px; border-radius: 3px; background: var(--bg-input);
  border: 1px solid var(--line); color: var(--t3);
  display: flex; align-items: center; gap: 5px;
}
.m-chip .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--bull); animation: pulse-dot 2s infinite; }

.m-body { flex: 1 1 auto; overflow-y: auto; position: relative; }
.m-view { display: none; }
.m-view.on { display: block; }

/* PULSE card */
.m-card {
  margin: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-panel); overflow: hidden;
}
.m-card-head { padding: 12px 14px 8px; display: flex; align-items: baseline; justify-content: space-between; }
.m-pair { font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.m-tf { font-family: var(--font-mono); font-size: 10px; color: var(--t3); margin-left: 7px; }
.m-price { font-family: var(--font-mono); font-size: 16px; font-weight: 600; }
.m-chg { font-family: var(--font-mono); font-size: 11px; }
.m-chart { height: 210px; position: relative; margin: 0 2px; }
.m-chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.m-agr {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center;
  padding: 12px 14px; border-top: 1px solid var(--line);
}
.m-agr-n { font-family: var(--font-mono); font-size: 30px; font-weight: 700; line-height: 1; }
.m-agr-k { font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--t4); font-weight: 700; margin-top: 4px; }
.m-fams { display: flex; flex-direction: column; gap: 3px; }
.m-fam { display: grid; grid-template-columns: 62px 1fr 30px; gap: 7px; align-items: center; font-size: 9px; }
.m-fam .k { letter-spacing: .08em; text-transform: uppercase; color: var(--t4); font-weight: 700; }
.m-fam .t { height: 4px; background: var(--bg-input); border-radius: 2px; overflow: hidden; }
.m-fam .t i { display: block; height: 100%; }
.m-fam .v { font-family: var(--font-mono); color: var(--t3); text-align: right; }
.m-actions { display: flex; gap: 8px; padding: 0 14px 14px; }
.m-btn {
  flex: 1; height: 42px; border-radius: 7px; background: var(--blue); color: #fff;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; letter-spacing: .14em;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 0 22px -8px var(--blue-glow);
}
.m-btn.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--t2); flex: 0 0 48px; letter-spacing: 0; }
.m-hint { text-align: center; font-size: 10px; color: var(--t4); padding: 2px 0 16px; }

/* mobile monitor rows */
.m-mon-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.m-mon-l .p { font-size: 13px; font-weight: 700; }
.m-mon-l .e { font-size: 10.5px; color: var(--t3); margin-top: 2px; }
.m-mon-spark { width: 62px; height: 24px; }
.m-mon-b { font-family: var(--font-mono); font-size: 13px; font-weight: 700; min-width: 34px; text-align: right; }

/* mobile analysis fullscreen */
.m-analysis {
  position: absolute; inset: 0; background: var(--bg-void); z-index: 50;
  display: none; flex-direction: column;
}
.m-analysis.on { display: flex; }
.m-a-head {
  flex: 0 0 52px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding-top: 8px;
}
.m-a-head .p { font-family: var(--font-mono); font-size: 15px; font-weight: 700; letter-spacing: .1em; }
.m-a-head .s { font-family: var(--font-mono); font-size: 9px; color: var(--t4); letter-spacing: .1em; }
.m-a-chart { flex: 0 0 36%; position: relative; }
.m-a-chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.m-a-matrix {
  flex: 1 1 auto; overflow: hidden; padding: 10px 16px 0;
  display: flex; flex-direction: column; gap: 0; justify-content: flex-end;
}
.m-a-row {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 9px; align-items: center;
  height: 22px; font-size: 11px; opacity: 0; transform: translateY(8px);
  transition: opacity 160ms, transform 160ms;
}
.m-a-row.in { opacity: 1; transform: none; }
.m-a-row .d { width: 5px; height: 5px; border-radius: 50%; background: var(--t4); justify-self: center; }
.m-a-row.analyzing .d { background: var(--amber); animation: mxpulse 620ms ease-in-out infinite; }
.m-a-row .n { color: var(--t3); font-size: 10.5px; letter-spacing: .04em; }
.m-a-row .r { font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: .05em; color: var(--t4); }
.m-a-row.done .n { color: var(--t1); }
.m-a-row.r-bull .d { background: var(--bull); box-shadow: 0 0 6px var(--bull-glow); } .m-a-row.r-bull .r { color: var(--bull); }
.m-a-row.r-bear .d { background: var(--bear); box-shadow: 0 0 6px var(--bear-glow); } .m-a-row.r-bear .r { color: var(--bear); }
.m-a-row.r-flat .d { background: var(--gray); } .m-a-row.r-flat .r { color: var(--gray); }

.m-a-consensus { flex: 0 0 auto; padding: 12px 16px 6px; opacity: 0; transition: opacity 240ms; }
.m-a-consensus.on { opacity: 1; }
.m-a-verdict {
  flex: 0 0 auto; padding: 4px 16px 22px; text-align: center;
  opacity: 0; transform: scale(.94); transition: opacity 280ms, transform 280ms var(--e-enter);
}
.m-a-verdict.on { opacity: 1; transform: none; }
.m-a-verdict .g { font-size: 34px; line-height: 1; margin-bottom: 4px; }
.m-a-verdict .w { font-size: 27px; font-weight: 700; letter-spacing: -.01em; }
.m-a-verdict .n { font-family: var(--font-mono); font-size: 15px; color: var(--t2); margin-top: 4px; }
.m-a-verdict .share {
  margin-top: 14px; height: 40px; border-radius: 7px; width: 100%;
  border: 1px solid var(--line-2); color: var(--t1); font-size: 11px;
  letter-spacing: .12em; font-weight: 700; text-transform: uppercase;
}

/* mobile tabbar */
.m-tabs {
  flex: 0 0 62px; display: grid; grid-template-columns: repeat(4,1fr);
  border-top: 1px solid var(--line); background: var(--bg-panel); padding-bottom: 8px;
}
.m-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--t4); font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700;
}
.m-tab.active { color: var(--blue); }

/* mobile annotation column */
.phone-notes { width: 330px; display: flex; flex-direction: column; gap: 14px; }
.pn-item { border-left: 2px solid var(--line-2); padding-left: 12px; }
.pn-k { font-size: 9px; letter-spacing: .14em; text-transform: uppercase; color: var(--blue); font-weight: 700; margin-bottom: 4px; }
.pn-v { font-size: 11.5px; color: var(--t2); line-height: 1.6; }
.pn-v b { color: var(--t1); font-weight: 600; }

/* ---------------- AD VIEW ---------------- */
.ad-wrap { display: flex; gap: 40px; align-items: center; }
.ad-frame-outer { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.ad-frame {
  width: 372px; height: 662px; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line-2); position: relative; background: var(--bg-void);
  box-shadow: 0 40px 90px -30px rgba(0,0,0,.9);
}
.ad-frame.landscape { width: 720px; height: 405px; }
.ad-frame iframe { display: none; }
.ad-rec {
  position: absolute; top: 12px; left: 12px; z-index: 90;
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .16em; color: var(--bear);
  text-transform: uppercase;
}
.ad-rec .rd { width: 7px; height: 7px; border-radius: 50%; background: var(--bear); animation: pulse-dot 1.2s infinite; }
.ad-timecode {
  position: absolute; top: 12px; right: 12px; z-index: 90;
  font-family: var(--font-mono); font-size: 10px; color: var(--t2); letter-spacing: .06em;
}
.ad-caption {
  position: absolute; left: 0; right: 0; bottom: 46px; z-index: 90;
  text-align: center; padding: 0 24px;
  font-size: 20px; font-weight: 700; line-height: 1.25; letter-spacing: -.01em;
  text-shadow: 0 3px 20px rgba(0,0,0,.9);
  opacity: 0; transform: translateY(8px);
  transition: opacity 260ms, transform 260ms var(--e-enter);
}
.ad-caption.on { opacity: 1; transform: none; }
.ad-caption .sm { display: block; font-size: 11px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--t3); margin-top: 8px; }
.ad-endcard {
  position: absolute; inset: 0; z-index: 95; background: var(--bg-void);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  opacity: 0; pointer-events: none; transition: opacity 300ms;
}
.ad-endcard.on { opacity: 1; }
.ad-endcard .l { font-size: 22px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.ad-endcard .u { font-family: var(--font-mono); font-size: 12px; color: var(--t3); letter-spacing: .2em; }
.ad-endcard .d { font-size: 10px; color: var(--t4); margin-top: 6px; }

.ad-timeline { width: 372px; }
.ad-tl-track { height: 5px; background: var(--bg-elev); border-radius: 3px; position: relative; overflow: hidden; }
.ad-tl-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--bear); }
.ad-tl-marks { display: flex; justify-content: space-between; margin-top: 5px; font-family: var(--font-mono); font-size: 9px; color: var(--t4); }

.ad-notes { width: 380px; display: flex; flex-direction: column; gap: 12px; }
.ad-shot {
  border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; background: var(--bg-panel);
  transition: border-color var(--d-fast), background var(--d-fast);
}
.ad-shot.active { border-color: rgba(255,77,98,.45); background: rgba(255,77,98,.05); }
.ad-shot .t { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.ad-shot .tc { font-family: var(--font-mono); font-size: 10px; color: var(--bear); font-weight: 700; }
.ad-shot .nm { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ad-shot .ds { font-size: 11px; color: var(--t3); line-height: 1.5; }

.ctl-row { display: flex; gap: 8px; align-items: center; }
.ctl-btn {
  height: 32px; padding: 0 14px; border-radius: 5px; border: 1px solid var(--line-2);
  color: var(--t2); font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
}
.ctl-btn:hover { border-color: var(--line-3); color: var(--t1); background: var(--bg-elev); }
.ctl-btn.primary { background: var(--bear); border-color: transparent; color: #fff; }
.ctl-btn.primary:hover { background: #FF6274; color: #fff; }

/* narrow screens */
@media (max-width: 1500px) {
  :root { --w-right: 312px; --w-left: 224px; }
}
@media (max-width: 1280px) {
  :root { --w-right: 292px; --w-left: 0px; }
  .left-panel { display: none; }
}


/* ad frame: verdict phase clears room for the caption */
#adAnalysis .m-a-verdict { padding-bottom: 96px; }
.m-analysis.verdict-phase .m-a-matrix { opacity: .10; transition: opacity 260ms; }
.m-analysis.verdict-phase .m-a-consensus { opacity: .45; }


/* hero facts: duration + entry time, mobile and ad */
.m-hero-facts {
  display: flex; justify-content: center; gap: 26px; margin-top: 12px;
}
.m-hero-facts span { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.m-hero-facts i {
  font-style: normal; font-size: 8px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--t4); font-weight: 700;
}
.m-hero-facts b {
  font-family: var(--font-mono); font-size: 21px; font-weight: 700; color: var(--t1);
  letter-spacing: -.02em;
}
.m-hero-facts.big b { font-size: 25px; }

.ad-phase {
  position: absolute; top: 34px; left: 0; right: 0; z-index: 90; text-align: center;
  font-family: var(--font-mono); font-size: 8.5px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--amber); opacity: .85;
}
.m-analysis.verdict-phase .m-a-head { opacity: .35; transition: opacity 260ms; }


/* ============================================================================
   ============================================================================
   RESPONSIVE SHELL — tablet, mobile, small mobile
   ----------------------------------------------------------------------------
   Everything below is additive and lives behind a media query. The desktop
   terminal at >= 1200px is untouched.

   Breakpoints
     >= 1200px   desktop terminal (approved design, unchanged)
     768–1199px  tablet: chart + right panel, watchlist as a section
     <= 767px    mobile: single column, chart-first, collapsible sections
     <= 390px    small mobile: tighter type and spacing
   ============================================================================
   ============================================================================ */


/* ============================================================
   TABLET — 768 to 1199
   Keep the two-pane feel but drop the fixed left column.
   ============================================================ */
@media (min-width: 768px) and (max-width: 1199px) and (min-height: 521px) {
  :root { --w-right: 300px; --w-left: 0px; }
  .left-panel { display: none; }
  .verdict-card { width: min(420px, 56vw); margin-right: min(120px, 10vw); }
  .trend-hud { width: 260px; }
  .matrix-rail { width: 300px; }
  .phase-caption { left: 286px; max-width: 40%; }
  .speed-flag { left: 286px; }
}


/* ============================================================
   MOBILE — <= 767px
   ============================================================ */
@media (max-width: 767px), (orientation: landscape) and (max-height: 520px) and (max-width: 1199px) {

  /* ---- the page must scroll. tokens.css locks the desktop terminal
     to the viewport with overflow:hidden; a phone needs the opposite. ---- */
  html, body {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: rgba(61,125,255,.18); }

  /* ---- app shell ---- */
  .stage { position: static; display: none; }
  .stage.full, .stage.full.on { display: block; position: static; }
  /* the in-page phone mockup and ad cut are desktop showcases */
  #stageMobile, #stageAd { display: none !important; }

  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* ============ HEADER ============ */
  /* one row, <= 64px. The wordmark gives way to the mark so the live price,
     the feed/allowance chips and the plan badge all fit a single strip. */
  .topbar {
    height: auto;
    min-height: 56px;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: calc(env(safe-area-inset-top, 0px)) 10px 0 0;
    row-gap: 0;
  }
  .brand-full { padding-left: 12px; gap: 8px; flex: 0 0 auto; }
  .brand-name { display: none; }
  .brand-mark svg { width: 20px; height: 20px; }

  /* proxied by the mobile control row */
  .topbar .pair-select,
  .topbar .tf-group { display: none; }

  /* the price block takes the slack instead, so spread/close never ellipsise */
  .top-spacer { display: none; }

  .chipbar { gap: 6px; }
  .chip { height: 28px; padding: 0 8px; font-size: 9.5px; }
  /* the full DEMO-data disclosure lives in the status bar on mobile */
  .chip.demo, .chip.session { display: none; }
  .chip.live .val { display: none; }
  .chip.quota .qlbl { display: none; }

  .account { gap: 6px; padding: 0 2px 0 6px; }
  .account .avatar { display: none; }
  .plan-badge { font-size: 8.5px; padding: 4px 7px; }

  /* price — two compact lines inside the single header row, so spread and
     close time survive on mobile instead of being dropped */
  .price-block {
    order: 0;
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    border-top: 0;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas: "price chg" "meta meta";
    align-items: baseline;
    column-gap: 7px;
    row-gap: 1px;
  }
  .price-main {
    grid-area: price;
    font-size: clamp(16px, 4.6vw, 19px);
    line-height: 1.05;
    padding: 0;
  }
  .price-chg { grid-area: chg; font-size: 11px; }
  .price-meta {
    grid-area: meta;
    font-size: 9.5px;
    margin-left: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chipbar, .account { flex: 0 0 auto; }

  /* ============ MOBILE CONTROL ROW (built by mobile-shell.js) ============ */
  .m-controls {
    position: sticky;
    top: 0;
    z-index: 70;
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 18px -14px rgba(0,0,0,.9);
  }
  .m-ctl {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    min-height: 46px;
    min-width: 44px;
    padding: 0 11px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background: var(--bg-input);
    text-align: left;
    flex: 0 0 auto;
  }
  .m-ctl:active { background: var(--bg-elev); }
  .m-ctl .k {
    font-size: 8px; letter-spacing: .12em; text-transform: uppercase;
    color: var(--t4); font-weight: 700;
  }
  .m-ctl .v {
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
    color: var(--t1); letter-spacing: .02em; white-space: nowrap;
  }
  .m-ctl.m-tf .v { font-size: 13px; }

  .m-analyze {
    flex: 1 1 auto;
    min-height: 46px;
    min-width: 44px;
    border-radius: 6px;
    background: var(--blue);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 13px; font-weight: 700; letter-spacing: .16em;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 0 0 1px rgba(61,125,255,.5), 0 0 24px -8px var(--blue-glow);
  }
  .m-analyze .glyph { font-size: 10px; }
  .m-analyze:active { background: #3570E8; }
  .m-analyze.disarmed {
    background: transparent; color: var(--t2);
    box-shadow: inset 0 0 0 1px var(--line-2);
    letter-spacing: .1em;
  }

  /* timeframe bottom sheet */
  .m-sheet {
    position: fixed; inset: 0; z-index: 400;
    background: rgba(3,5,9,.72);
    backdrop-filter: blur(3px);
    display: none;
    align-items: flex-end;
  }
  .m-sheet.on { display: flex; animation: mSheetIn 180ms var(--e-standard); }
  @keyframes mSheetIn { from { opacity: 0; } to { opacity: 1; } }
  .m-sheet-panel {
    width: 100%;
    background: var(--bg-elev);
    border-top: 1px solid var(--line-2);
    border-radius: 12px 12px 0 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    animation: mSheetUp 220ms var(--e-enter);
  }
  @keyframes mSheetUp { from { transform: translateY(14px); } to { transform: none; } }
  .m-sheet-head {
    font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
    color: var(--t3); font-weight: 700; margin-bottom: 11px;
  }
  .m-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .m-tf-opt {
    min-height: 46px;
    border: 1px solid var(--line-2); border-radius: 6px;
    background: var(--bg-input); color: var(--t2);
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
  }
  .m-tf-opt.active { background: var(--blue); color: #fff; border-color: transparent; }
  .m-tf-opt.locked { color: var(--t4); }
  .m-tf-opt .lk { font-size: 9px; }
  .m-sheet-close {
    width: 100%; min-height: 44px; margin-top: 12px;
    border: 1px solid var(--line-2); border-radius: 6px;
    color: var(--t2); font-size: 12px; font-weight: 600; letter-spacing: .06em;
  }

  /* ============ BODY: single column ============ */
  .body {
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }
  .rail { display: none; }
  .draw-tools { display: none; }

  .workspace { order: 1; width: 100%; min-width: 0; }
  .right-panel { order: 2; }
  .left-panel { order: 3; }

  /* ---- chart: the dominant element ---- */
  .chart-stack {
    height: clamp(320px, 46vh, 430px);
    height: clamp(320px, 46dvh, 430px);
    flex: 0 0 auto;
  }
  .chart-area { width: 100%; min-width: 0; }
  .chart-legend { font-size: 9.5px; }
  .snapshot-stamp { font-size: 9px; }

  /* the floating desktop analyze dock is replaced by the control row */
  .analyze-dock { display: none; }

  /* ---- indicator subpanels become a section ---- */
  .subpanels { max-height: none; }
  .subpanel { height: 78px; }

  /* ---- right panel becomes stacked sections ---- */
  .right-panel {
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    border-left: none;
    border-top: 1px solid var(--line);
    position: static;
    height: auto;
    overflow: visible;
  }
  .right-panel .tabs { display: none; }
  .right-panel .tab-panes {
    position: static;
    flex: 0 0 auto;
    min-height: 0;
    height: auto;
    overflow: visible;
  }
  .right-panel .tab-panes .pane {
    position: static;
    display: block;
    overflow: visible;
    inset: auto;
  }

  /* ---- left panel becomes the market-context section ---- */
  .left-panel {
    display: flex;
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    border-right: none;
    border-top: 1px solid var(--line);
    height: auto;
  }
  .watchlist { max-height: 264px; flex: 0 0 auto; }
  .wl-row { height: 44px; }
  .side-block { padding: 10px 12px 12px; }

  /* ============ COLLAPSIBLE SECTIONS ============ */
  /* an injected header is a flex sibling: without an explicit order it would
     default to 0 and jump above the chart */
  .body > .m-sec { order: 3; }

  .m-sec {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 46px;
    padding: 0 14px;
    background: var(--bg-panel);
    border: none;
    border-top: 1px solid var(--line);
    text-align: left;
  }
  .m-sec:active { background: var(--bg-elev); }
  .m-sec-l {
    font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
    color: var(--t1); font-weight: 700;
  }
  .m-sec-h {
    font-family: var(--font-mono); font-size: 9.5px; color: var(--t4);
    letter-spacing: .04em;
  }
  .m-sec-c {
    margin-left: auto; color: var(--t3); font-size: 11px;
    transition: transform var(--d-fast) var(--e-standard);
  }
  .m-sec.closed .m-sec-c { transform: rotate(-90deg); }
  .tab-panes .pane.m-closed,
  .m-body.m-closed { display: none !important; }

  /* ============ READING CARD ============ */
  .rp-hero {
    grid-template-columns: auto 1fr;
    row-gap: 12px;
    column-gap: 12px;
    padding: 14px 14px 15px;
  }
  .rp-hero .g { font-size: clamp(26px, 8vw, 32px); }
  .rp-hero .w { font-size: clamp(27px, 8.6vw, 34px); }
  .rp-hero .sub { grid-column: 1 / -1; font-size: 10.5px; }
  .rp-hero .fact b { font-size: clamp(16px, 5vw, 19px); }
  .rp-hero .fact i { font-size: 8.5px; }

  .verdict-strip { padding: 14px; }
  .score-ring { width: 78px; height: 78px; flex: 0 0 78px; }
  .score-ring .sv .n { font-size: 23px; }
  .bar-row { grid-template-columns: 52px 1fr 22px; }

  .meta-grid { grid-template-columns: 1fr 1fr; }
  .meta-cell { padding: 10px 12px; }
  .meta-cell .mk { font-size: 9px; }
  .meta-cell .mv { font-size: 14px; }

  .family-list { padding: 12px 14px 6px; }
  .fam-row { height: 30px; grid-template-columns: 74px 1fr 50px; }
  .fam-row .fk { font-size: 10.5px; }

  .prem-block { padding: 13px 14px 15px; }
  .prem-v { font-size: 16px; }
  .btn-row { padding: 0 14px 15px; }
  .btn-ghost { min-height: 44px; font-size: 12px; }
  .corr-note { margin: 12px 14px 0; font-size: 11.5px; }
  .paywall-inline { margin: 12px 14px; }
  .pi-item { font-size: 11.5px; min-height: 22px; }

  /* ============ STRATEGY MATRIX ============ */
  .rm-fam-head { padding: 10px 14px 7px; min-height: 40px; }
  .rm-fam-k { font-size: 10.5px; }
  .rm-row {
    height: 42px;
    grid-template-columns: 14px 1fr auto 34px 14px;
    padding: 0 14px;
    font-size: 12.5px;
  }
  .rm-row .n { font-size: 12.5px; }
  .rm-row .r { font-size: 10.5px; }
  .rm-row .s { font-size: 10.5px; }
  .rm-detail { padding: 10px 14px 14px 30px; }
  .rd-v { font-size: 11px; }
  .rd-btn { min-height: 36px; padding: 0 12px; }

  /* ============ ACTIVITY ============ */
  .activity-head { padding: 10px 12px; gap: 6px; }
  .afilter { min-height: 34px; padding: 0 10px; display: flex; align-items: center; }
  .feed-row { padding: 7px 14px 7px 12px; font-size: 11.5px; }
  .feed-row .ts { font-size: 9.5px; }

  /* ============ BOTTOM NAVIGATION ============ */
  .m-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(12,16,23,.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line-2);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .m-nav-b {
    min-height: 54px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 4px;
    color: var(--t4);
    font-size: 9px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700;
  }
  .m-nav-b svg { width: 18px; height: 18px; }
  .m-nav-b.active { color: var(--blue); }
  .m-nav-b:active { background: var(--bg-elev); }

  /* ============ STATUS BAR ============ */
  .statusbar {
    height: auto;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 10px 12px 12px;
    font-size: 10px;
    line-height: 1.5;
  }
  .statusbar .sep,
  .statusbar .right { display: none; }
  .statusbar .demo-note { flex: 1 1 100%; color: var(--amber); opacity: 1; }

  /* ============ PROTOTYPE BAR ============ */
  /* index.html carries an inline <style> for #protoBar that is parsed after
     this file, so the mobile override needs a higher specificity than a bare
     id selector to win. */
  body #protoBar {
    position: static;
    transform: none;
    margin: 12px auto 4px;
    width: max-content;
    max-width: calc(100% - 20px);
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 6px;
  }
  body #protoBar .sep { display: none; }
  body #stageSwitch { display: none; }
  .vs-btn { min-height: 36px; padding: 0 12px; }

  /* ============ OVERLAYS ============ */
  .cmdk { padding-top: 0; align-items: flex-start; }
  .cmdk-box {
    width: calc(100% - 20px);
    margin: calc(env(safe-area-inset-top, 0px) + 14px) 10px 0;
    max-height: 82dvh;
  }
  /* 16px stops iOS from zooming the page when the field is focused */
  .cmdk-input { height: 52px; font-size: 16px; }
  .cmdk-list { max-height: 62dvh; }
  .cmdk-item { min-height: 46px; font-size: 13px; }

  /* Off-canvas panels: the desktop version parks them at translateX(100%),
     which on a full-width mobile panel pushes 390px past the viewport and is
     the real cause of page-level horizontal scroll. Take them out of layout
     entirely when closed rather than hiding the symptom with overflow-x. */
  .upsell, .math-over {
    display: none;
    transform: none;
    width: 100%;
    max-width: 100%;
    left: 0; right: 0;
  }
  .upsell.on, .math-over.on {
    display: flex;
    animation: mPanelIn 260ms var(--e-enter);
  }
  @keyframes mPanelIn {
    from { opacity: 0; transform: translateX(22px); }
    to   { opacity: 1; transform: none; }
  }
  .upsell-body { padding: 16px 14px calc(16px + env(safe-area-inset-bottom, 0px)); }
  .math-body { padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .math-body pre { font-size: 10px; }

  .toast-layer { left: 8px; right: 8px; top: auto; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  .toast { width: auto; }

  /* rail views (monitor / history / stats / lab / alerts) take the screen */
  .view-overlay { position: fixed; inset: 0; z-index: 300; }
  .view-overlay.on { display: flex; }
  .view-head { padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px; height: auto; min-height: 48px; }
  .view-close { min-height: 40px; display: flex; align-items: center; }
  .view-body {
    padding: 12px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;                 /* intentional: wide tables and the heatmap */
    -webkit-overflow-scrolling: touch;
  }
  .mon-grid { grid-template-columns: 1fr; }
  .lab-grid { grid-template-columns: 1fr; height: auto; }
  .scope-note { max-width: 100%; }
  .plan-card { padding: 14px; }
  .pc-list li { font-size: 12px; }

  /* ============ ANALYSIS MODE ============
     The sequence takes the whole viewport. chart-stack becomes a fixed
     overlay so the animation can never be clipped by page scroll. */
  .app[data-mode="analysis"] .chart-stack {
    position: fixed;
    inset: 0;
    z-index: 200;
    height: auto;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .app[data-mode="analysis"] .m-controls,
  .app[data-mode="analysis"] .m-nav { opacity: 0; pointer-events: none; }
  /* never let the desktop slide-away transforms create horizontal overflow */
  .app[data-mode="analysis"] .left-panel,
  .app[data-mode="analysis"] .right-panel { display: none; }
  .app[data-mode="analysis"] .subpanels { display: none; }
  /* the fixed ticker owns the top strip during analysis; the snapshot stamp
     and legend would collide with it */
  .app[data-mode="analysis"] .snapshot-stamp,
  .app[data-mode="analysis"] .chart-legend { display: none; }

  .analysis-ticker {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    z-index: 210;
    height: 38px;
    font-size: 10.5px;
    letter-spacing: .08em;
    gap: 10px;
  }
  .analysis-ticker .st { font-size: 8.5px; letter-spacing: .14em; }

  .hairline { position: fixed; z-index: 220; }

  /* phase rail: segments only — 9 labels cannot fit on a phone */
  .phase-rail {
    top: calc(env(safe-area-inset-top, 0px) + 42px);
    left: 10px; right: 10px;
    gap: 4px;
    z-index: 205;
  }
  .phase-rail .ph-label { display: none; }
  .phase-rail .ph-track { height: 3px; }

  /* the phase name comes from the caption instead */
  .phase-caption {
    top: calc(env(safe-area-inset-top, 0px) + 54px);
    left: 10px; right: 10px;
    bottom: auto;
    max-width: none;
    z-index: 205;
  }
  .phase-caption .pc-n { font-size: 9.5px; }
  .phase-caption .pc-v { font-size: 10.5px; }

  .trend-hud {
    top: calc(env(safe-area-inset-top, 0px) + 96px);
    left: 10px; right: 10px;
    width: auto;
    grid-template-columns: 1fr auto;
    padding: 9px 11px 10px;
  }
  .th-strength { min-width: 130px; }
  .th-label { font-size: 15px; }
  .th-glyph { font-size: 19px; }
  .th-struct { gap: 3px 14px; }
  .th-struct .sl { font-size: 10.5px; }

  .speed-flag { display: none; }
  .cat-cluster, .cat-cluster.docked { display: none; }

  /* matrix + consensus: a bottom sheet */
  .matrix-rail {
    left: 8px; right: 8px;
    width: auto;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
    max-height: 48%;
    border-radius: 8px;
    padding: 10px 12px 11px;
    transform: translateY(calc(100% + 20px));
  }
  .matrix-rail.on { transform: none; }
  .mr-head { margin-bottom: 6px; padding-bottom: 6px; }
  .mr-title { font-size: 9px; }
  .mr-count { font-size: 9px; }
  .mx-row { height: 19px; }
  .mx-row .mx-name { font-size: 10px; }
  .c-ring { width: 52px; height: 52px; flex: 0 0 52px; }
  .c-ring svg { width: 52px; height: 52px; }
  .c-ring .cv .n { font-size: 17px; }
  .c-qual .qd { display: none; }
  .c-indep { font-size: 8.5px; min-height: 20px; }

  /* ============ FINAL RESULT CARD ============ */
  .verdict-layer { padding: 0 10px; }
  .verdict-card {
    width: min(94vw, 420px);
    margin-right: 0;
    padding: 18px 16px 14px;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .vc-pairline { font-size: 9.5px; margin-bottom: 12px; flex-wrap: wrap; }
  .vc-hero {
    grid-template-columns: 1fr 1fr;
    gap: 14px 14px;
    margin-bottom: 14px;
  }
  .vc-hero .rule { display: none; }
  .vc-dir { grid-column: 1 / -1; }
  .vc-dir .g { font-size: clamp(30px, 9vw, 40px); }
  .vc-dir .w { font-size: clamp(32px, 10.5vw, 44px); }
  .vc-fact .v { font-size: clamp(19px, 6vw, 25px); }
  .vc-fact .k { font-size: 8px; }
  .vc-fact .s { font-size: 9px; white-space: normal; }
  .vc-entrybar { grid-template-columns: 1fr; }
  .vc-entrybar .cell { padding: 10px 12px; }
  .vc-entrybar .cell .v { font-size: 15px; }
  .vc-wait-grid { grid-template-columns: 1fr; }
  .vc-consensus { grid-template-columns: auto 1fr; gap: 12px; }
  .vc-consensus .big { font-size: 24px; }
  .vc-note { font-size: 11px; }
  .vc-actions { flex-wrap: wrap; gap: 8px; }
  .vc-actions .btn-ghost { flex: 1 1 45%; min-height: 44px; }
  .vc-disclaimer { font-size: 9.5px; }

  /* ---- touch targets ---- */
  .tab { min-height: 44px; }
  .dt-btn, .rail-btn { min-width: 44px; min-height: 44px; }
  .speed-item { min-height: 52px; }
}


/* ============================================================
   SMALL MOBILE — <= 390px
   ============================================================ */
@media (max-width: 390px) {
  .m-controls { gap: 6px; padding: 7px 8px; }
  .m-ctl { padding: 0 9px; min-width: 44px; }
  .m-ctl .v { font-size: 12px; }
  .m-analyze { font-size: 12px; letter-spacing: .12em; }
  .chip { padding: 0 7px; }
  .price-meta { font-size: 9px; }
  /* at 360px the strip cannot hold the feed chip and the full spread/close
     line at once. The allowance chip is the more useful of the two, and feed
     liveness is already visible in the ticking price. */
  .chip.live { display: none; }
  .m-sec { padding: 0 12px; }
  .m-sec-h { display: none; }
  .rm-row { grid-template-columns: 12px 1fr auto 30px 10px; padding: 0 12px; font-size: 12px; }
  .verdict-card { padding: 16px 14px 12px; }
  .vc-hero { gap: 12px 10px; }
  .th-strength { min-width: 112px; }
  .ths-row { grid-template-columns: 38px 1fr 48px; }
}


/* ============================================================
   LANDSCAPE PHONES — keep it usable, not redesigned
   ============================================================ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .chart-stack { height: clamp(220px, 62dvh, 320px); }
  .topbar { min-height: 52px; }
  .m-controls { padding: 6px 10px; }
  .m-ctl, .m-analyze { min-height: 44px; }
  .m-nav-b { min-height: 46px; }
  .verdict-card { max-height: calc(100dvh - 20px); }
  .vc-hero { grid-template-columns: auto 1fr 1fr; }
  .vc-dir { grid-column: auto; }
  .matrix-rail { max-height: 58%; }
  .trend-hud { top: calc(env(safe-area-inset-top, 0px) + 84px); }
}
