:root {
  --bg: #070b12;
  --bg2: #0d1420;
  --card: #111a28;
  --card-hover: #152033;
  --border: #1e2d42;
  --border-bright: #2a3f5c;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --dim: #5a6b84;
  --accent: #f0b90b;
  --accent2: #00d4aa;
  --danger: #ff5c7a;
  --warn: #ffb020;
  --info: #4da3ff;
  --s: #f0b90b;
  --a: #00d4aa;
  --b: #4da3ff;
  --c: #9aa8bc;
  --d: #6b5b7a;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0,0,0,.45);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: Inter, system-ui, -apple-system, "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(240,185,11,.12), transparent 50%),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(0,212,170,.08), transparent 45%),
    linear-gradient(rgba(30,45,66,.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,45,66,.35) 1px, transparent 1px);
  background-size: auto, auto, 48px 48px, 48px 48px;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .85rem 1.5rem;
  background: rgba(7,11,18,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .75rem; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #f0b90b, #00d4aa);
  color: #0a0e14; font-weight: 700; font-size: 1.2rem;
}
.brand-title { font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: .75rem; color: var(--muted); }
.nav { display: flex; gap: .35rem; flex: 1; }
.nav-link {
  color: var(--muted); text-decoration: none;
  padding: .45rem .85rem; border-radius: 999px; font-size: .9rem; font-weight: 500;
  transition: .15s;
}
.nav-link:hover { color: var(--text); background: var(--card); }
.nav-link.active {
  color: #0a0e14; background: var(--accent); font-weight: 600;
}
.meta-chip {
  font-family: var(--mono); font-size: .72rem;
  color: var(--muted); border: 1px solid var(--border);
  padding: .35rem .7rem; border-radius: 999px; background: var(--bg2);
}

main { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.section { display: none; animation: fade .25s ease; }
.section.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero h1 { margin: 0 0 .4rem; font-size: 1.75rem; }
.hero-desc { color: var(--muted); margin: 0 0 1.5rem; max-width: 52rem; }
.section-head h1 { margin: 0 0 .35rem; font-size: 1.5rem; }
.section-head p { color: var(--muted); margin: 0 0 1.25rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .85rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-card .value {
  font-family: var(--mono); font-size: 1.65rem; font-weight: 600;
  margin-top: .25rem; color: var(--accent);
}
.stat-card .sub { font-size: .75rem; color: var(--dim); margin-top: .2rem; }

.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: .9rem; gap: .75rem;
}
.card-head h2 { margin: 0; font-size: 1.05rem; }
.hint { font-size: .75rem; color: var(--dim); }
.link-btn { color: var(--accent2); text-decoration: none; font-size: .85rem; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

.grade-bars { display: flex; flex-direction: column; gap: .55rem; }
.gbar {
  display: grid; grid-template-columns: 28px 1fr 36px; align-items: center; gap: .6rem;
  font-size: .85rem;
}
.gbar .bar-track {
  height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.gbar .bar-fill { height: 100%; border-radius: 999px; }
.gbar.S .bar-fill { background: var(--s); }
.gbar.A .bar-fill { background: var(--a); }
.gbar.B .bar-fill { background: var(--b); }
.gbar.C .bar-fill { background: var(--c); }
.gbar.D .bar-fill { background: var(--d); }
.gbar .cnt { font-family: var(--mono); color: var(--muted); text-align: right; }

.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .85rem; }
.chip {
  font-family: var(--mono); font-size: .78rem; font-weight: 600;
  padding: .3rem .65rem; border-radius: 8px;
  background: rgba(240,185,11,.12); color: var(--accent);
  border: 1px solid rgba(240,185,11,.35);
}

.mini-table-wrap { overflow-x: auto; }
.mini-table, .data-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
.mini-table th, .data-table th {
  text-align: left; color: var(--dim); font-weight: 500;
  padding: .5rem .6rem; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.mini-table td, .data-table td {
  padding: .55rem .6rem; border-bottom: 1px solid rgba(30,45,66,.7);
  font-family: var(--mono); white-space: nowrap;
}
.mini-table tr:hover td, .data-table tbody tr:hover td {
  background: var(--card-hover);
}
.data-table tbody tr { cursor: pointer; }

.badge {
  display: inline-block; min-width: 1.6rem; text-align: center;
  padding: .15rem .45rem; border-radius: 6px; font-weight: 700; font-size: .75rem;
}
.badge.S { background: rgba(240,185,11,.2); color: var(--s); }
.badge.A { background: rgba(0,212,170,.18); color: var(--a); }
.badge.B { background: rgba(77,163,255,.18); color: var(--b); }
.badge.C { background: rgba(154,168,188,.15); color: var(--c); }
.badge.D { background: rgba(107,91,122,.25); color: #c4b0d8; }

.pos { color: var(--accent2); }
.neg { color: var(--danger); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: .65rem; align-items: center;
  margin-bottom: 1rem;
}
.toolbar input[type="search"], .toolbar select {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: .55rem .85rem; font-family: var(--sans); font-size: .9rem;
  outline: none; min-width: 180px;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); }
.filter-group { display: flex; gap: .3rem; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--border); background: var(--bg2); color: var(--muted);
  border-radius: 999px; padding: .35rem .7rem; cursor: pointer; font-size: .8rem; font-weight: 600;
}
.pill:hover { border-color: var(--border-bright); color: var(--text); }
.pill.active { background: var(--accent); color: #0a0e14; border-color: var(--accent); }
.pill.grade-S.active { background: var(--s); }
.pill.grade-A.active { background: var(--a); color: #062; }
.pill.grade-B.active { background: var(--b); color: #021; }
.result-count { margin-left: auto; font-size: .8rem; color: var(--muted); font-family: var(--mono); }

.table-wrap {
  overflow: auto; max-height: min(70vh, 720px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
}
.data-table thead th { position: sticky; top: 0; background: #152033; z-index: 2; }
.sym-cell .name { display: block; font-family: var(--sans); font-size: .72rem; color: var(--dim); font-weight: 400; }
.sym-cell .sym { font-weight: 600; color: var(--text); }

.detail-panel {
  position: fixed; right: 1rem; top: 4.5rem; bottom: 1rem; width: min(380px, 92vw);
  background: var(--bg2); border: 1px solid var(--border-bright);
  border-radius: var(--radius); padding: 1.2rem; z-index: 60;
  box-shadow: var(--shadow); overflow: auto;
}
.detail-panel[hidden] { display: none; }
.close-btn {
  position: absolute; top: .6rem; right: .7rem;
  background: transparent; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer;
}
.close-btn:hover { color: var(--text); }
.detail-panel h3 { margin: 0 0 .5rem; }
.detail-panel .kv { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .75rem; margin: .75rem 0; }
.detail-panel .kv div { background: var(--card); border-radius: 8px; padding: .45rem .55rem; font-size: .8rem; }
.detail-panel .kv .k { color: var(--dim); font-size: .7rem; }
.detail-panel .kv .v { font-family: var(--mono); }
.bd-bars { margin-top: .75rem; }
.bd-row { display: grid; grid-template-columns: 7rem 1fr 2.5rem; gap: .4rem; align-items: center; font-size: .75rem; margin-bottom: .35rem; }
.bd-row .t { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bd-row .f { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); }

.watch-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.watch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.watch-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  transition: border-color .15s, transform .15s;
}
.watch-card:hover { border-color: var(--accent2); transform: translateY(-2px); }
.watch-card .wc-top {
  display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem;
  margin-bottom: .65rem;
}
.watch-card .wc-sym { font-size: 1.15rem; font-weight: 700; font-family: var(--mono); }
.watch-card .score {
  font-family: var(--mono); font-weight: 700; color: var(--accent2);
  background: rgba(0,212,170,.12); padding: .25rem .55rem; border-radius: 8px; font-size: .9rem;
}
.reason-list { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .8rem; }
.reason-list li { margin-bottom: .25rem; }
.wc-meta {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem;
}
.tag {
  font-size: .7rem; font-family: var(--mono);
  padding: .2rem .45rem; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.empty-note { color: var(--muted); text-align: center; padding: 2rem; }

.rules-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem; margin-bottom: 1rem;
}
.rule-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.15rem;
  position: relative; overflow: hidden;
}
.rule-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.rule-card h3 { margin: 0 0 .35rem; display: flex; align-items: center; gap: .5rem; }
.lift {
  font-size: .75rem; font-family: var(--mono); color: var(--accent);
  background: rgba(240,185,11,.12); padding: .15rem .45rem; border-radius: 6px;
}
.rule-card ol { margin: .6rem 0; padding-left: 1.2rem; color: var(--muted); font-size: .88rem; }
.rule-card .note { font-size: .8rem; color: var(--dim); }
.signal-levels { display: flex; flex-direction: column; gap: .65rem; margin-top: .5rem; }
.sig {
  display: grid; grid-template-columns: 2rem 1fr; gap: .6rem;
  padding: .55rem .65rem; background: var(--bg); border-radius: 10px;
  border: 1px solid var(--border); font-size: .82rem;
}
.sig .lv { font-weight: 800; font-family: var(--mono); }
.rules-note h3 { margin: 1rem 0 .4rem; font-size: .95rem; }
.rules-note ul { color: var(--muted); font-size: .88rem; margin: 0; padding-left: 1.2rem; }
.rules-note li { margin-bottom: .35rem; }

.footer {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  max-width: 1280px; margin: 0 auto; padding: 1rem 1.25rem 2rem;
  color: var(--dim); font-size: .75rem; border-top: 1px solid var(--border);
}
.footer code { color: var(--muted); font-family: var(--mono); }


/* —— refresh controls —— */
.topbar-right { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.refresh-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--sans); font-size: .85rem; font-weight: 600;
  color: #0a0e14; background: linear-gradient(135deg, #f0b90b, #00d4aa);
  border: none; border-radius: 999px; padding: .45rem .95rem;
  cursor: pointer; box-shadow: 0 2px 12px rgba(240,185,11,.25);
  transition: transform .12s, filter .12s, opacity .12s;
}
.refresh-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.refresh-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; filter: none; }
.refresh-btn.running .refresh-icon { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.refresh-icon { font-size: 1.05rem; line-height: 1; }

.refresh-banner {
  position: sticky; top: 58px; z-index: 45;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1.5rem;
  background: rgba(13,20,32,.95);
  border-bottom: 1px solid var(--border-bright);
  font-size: .85rem; color: var(--muted);
  backdrop-filter: blur(8px);
}
.refresh-banner[hidden] { display: none !important; }
.refresh-banner.running { color: var(--info); }
.refresh-banner.done { color: var(--accent2); }
.refresh-banner.error { color: var(--danger); }
.rb-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--info); box-shadow: 0 0 8px var(--info);
}
.refresh-banner.running .rb-dot { animation: pulse 1.2s ease infinite; }
.refresh-banner.done .rb-dot { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); animation: none; }
.refresh-banner.error .rb-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

@media (max-width: 720px) {
  .refresh-label { display: none; }
  .meta-chip { font-size: .65rem; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* —— detail drawer —— */
.detail-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.detail-backdrop[hidden] { display: none !important; }
.detail-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(440px, 96vw);
  background: var(--bg2); border-left: 1px solid var(--border-bright);
  border-radius: 0; padding: 1.25rem 1.2rem 2rem;
  z-index: 70; box-shadow: -12px 0 40px rgba(0,0,0,.5);
  overflow: auto;
}
.detail-panel[hidden] { display: none !important; }
.detail-sub { color: var(--muted); margin: 0 0 .75rem; font-size: .85rem; }
.link-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .85rem; }
.ext-link {
  font-size: .75rem; font-weight: 600;
  padding: .3rem .65rem; border-radius: 999px;
  background: rgba(77,163,255,.12); color: var(--info);
  border: 1px solid rgba(77,163,255,.35); text-decoration: none;
}
.ext-link:hover { background: rgba(77,163,255,.22); }
.detail-section { margin: 1rem 0; }
.phase-cell { font-size: .72rem; color: var(--muted); max-width: 7rem; white-space: normal; }

/* —— predictions —— */
.pred-highlights {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .65rem;
}
.hl-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: .7rem .8rem;
}
.hl-card .k { font-size: .7rem; color: var(--dim); }
.hl-card .v { font-family: var(--mono); font-weight: 600; margin-top: .25rem; color: var(--accent); }
.disclaimer-inline {
  font-size: .75rem; color: var(--dim); margin: .85rem 0 0; line-height: 1.45;
}
.warn-card {
  border-color: rgba(255,176,32,.45);
  background: linear-gradient(180deg, rgba(255,176,32,.08), var(--card));
}
.warn-card p { color: var(--muted); font-size: .88rem; margin: .4rem 0 0; }

.pred-stack { margin: .85rem 0; }
.pred-stack.compact { margin-top: .75rem; }
.pred-phase { margin-bottom: .5rem; font-size: .8rem; color: var(--muted); }
.phase-pill {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: .15rem .5rem; border-radius: 999px;
  background: rgba(77,163,255,.15); color: var(--info);
  border: 1px solid rgba(77,163,255,.35);
}
.phase-pill.early_breakout { background: rgba(0,212,170,.15); color: var(--accent2); border-color: rgba(0,212,170,.4); }
.phase-pill.near_ath { background: rgba(240,185,11,.15); color: var(--accent); border-color: rgba(240,185,11,.4); }
.phase-pill.post_ath_cold { background: rgba(255,92,122,.12); color: var(--danger); border-color: rgba(255,92,122,.35); }
.phase-pill.mid_drawdown { background: rgba(154,168,188,.12); color: var(--c); }

.pred-box {
  border: 1px solid var(--border); border-radius: 12px;
  padding: .75rem .85rem; margin-bottom: .55rem; background: var(--card);
}
.pred-box.up { border-color: rgba(0,212,170,.35); }
.pred-box.down { border-color: rgba(255,92,122,.3); }
.pred-box.muted { opacity: .85; }
.pred-title { font-weight: 600; font-size: .85rem; margin-bottom: .5rem; }
.pred-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .6rem;
}
.pred-metrics .k { font-size: .68rem; color: var(--dim); }
.pred-metrics .v { font-family: var(--mono); font-size: .9rem; font-weight: 600; }
.pred-note { font-size: .72rem; color: var(--muted); margin: .55rem 0 0; line-height: 1.4; }
.tag.pos { color: var(--accent2); border-color: rgba(0,212,170,.35); }
.tag.neg { color: var(--danger); border-color: rgba(255,92,122,.35); }
.wc-phase { font-size: .75rem; color: var(--accent2); margin-bottom: .4rem; }
.clickable { cursor: pointer; }
.mini-table tr.clickable:hover td { background: var(--card-hover); }

.refresh-btn.public-disabled {
  background: var(--bg2); color: var(--muted);
  box-shadow: none; border: 1px solid var(--border);
}

/* FDV + track pills */
.pred-box.fdv { border-color: rgba(120, 180, 255, 0.35); }
.pred-box.combined { border-color: rgba(180, 140, 255, 0.4); background: rgba(100, 70, 180, 0.08); }
.track-pill {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
}
.track-pill.track-B { color: #5dffa8; border-color: rgba(93,255,168,0.4); }
.track-pill.track-A, .track-pill.track-Ap { color: #7ec8ff; border-color: rgba(126,200,255,0.4); }
.track-pill.track-C { color: #ffd76a; border-color: rgba(255,215,106,0.4); }
.track-pill.track-Cw { color: #c9b6ff; border-color: rgba(201,182,255,0.4); }
.track-pill.track-M { color: #5de0ff; border-color: rgba(93,224,255,0.45); }
.track-pill.track-Mw { color: #8ad4ff; border-color: rgba(138,212,255,0.35); }
.track-pill.track-L { color: #ff8a8a; border-color: rgba(255,138,138,0.5); }
.rule-card.risk-high { border-color: rgba(255,100,100,0.35); }

.rule-card.risk-elevated { border-color: rgba(138,212,255,0.25); }
.ba-list { margin: 0.4rem 0 0; padding-left: 1.1rem; line-height: 1.55; color: var(--muted); }
.ba-list strong { color: var(--text); }

/* ============================================================
   Mobile UX — sticky filters, bottom nav, card list, full drawer
   ============================================================ */

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

:root {
  --topbar-h: 58px;
  --bottom-nav-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Desktop: hide mobile-only pieces */
.bottom-nav { display: none; }
.cand-cards { display: none; }
.detail-back { display: none; }
.detail-header-title { display: none; }

.detail-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  margin: -1.25rem -1.2rem 0.75rem;
  padding: .65rem 1rem;
  background: rgba(13, 20, 32, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.close-btn-desk {
  position: static;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1.35rem;
  cursor: pointer;
}
.close-btn-desk:hover { color: var(--text); border-color: var(--border-bright); }

body.detail-open {
  overflow: hidden;
  touch-action: none;
}

/* Touch-friendlier pills & controls (all sizes) */
.pill {
  min-height: 36px;
  min-width: 40px;
  padding: .45rem .85rem;
  -webkit-tap-highlight-color: transparent;
}
.nav-link, .bn-item, .watch-card, .cand-card, .refresh-btn, .ext-link {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (max-width: 900px) {
  :root { --bottom-nav-h: calc(56px + var(--safe-bottom)); }

  .nav-desktop { display: none !important; }
  .brand-sub { display: none; }
  .brand-title { font-size: .95rem; }
  .logo { width: 34px; height: 34px; font-size: 1rem; border-radius: 10px; }

  .topbar {
    padding: .55rem .85rem;
    padding-top: calc(.55rem + var(--safe-top));
    gap: .6rem;
    flex-wrap: nowrap;
  }
  .topbar-right { gap: .4rem; }
  .refresh-btn {
    min-height: 40px;
    min-width: 40px;
    padding: .4rem .7rem;
    justify-content: center;
  }
  .meta-chip {
    font-size: .62rem;
    max-width: 36vw;
    padding: .3rem .5rem;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 80;
    height: var(--bottom-nav-h);
    padding: 0 .25rem var(--safe-bottom);
    background: rgba(7, 11, 18, .94);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
    align-items: stretch;
  }
  .bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .15rem;
    text-decoration: none;
    color: var(--muted);
    font-size: .65rem;
    font-weight: 600;
    min-height: 48px;
    border-radius: 10px;
    margin: .25rem 0;
    transition: color .15s, background .15s;
  }
  .bn-item .bn-ico { font-size: 1.05rem; line-height: 1; }
  .bn-item.active {
    color: var(--accent);
    background: rgba(240, 185, 11, .1);
  }

  main {
    padding: 1rem .85rem calc(1.5rem + var(--bottom-nav-h));
  }
  .footer {
    padding: 1rem .85rem calc(1.25rem + var(--bottom-nav-h));
    font-size: .7rem;
  }

  .hero h1 { font-size: 1.35rem; }
  .hero-desc { font-size: .88rem; margin-bottom: 1rem; }
  .section-head h1 { font-size: 1.25rem; }
  .section-head p { font-size: .85rem; }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .65rem;
  }
  .stat-card { padding: .85rem .9rem; }
  .stat-card .value { font-size: 1.35rem; }

  .card { padding: .95rem 1rem; border-radius: 12px; }
  .card-head { flex-wrap: wrap; }
  .card-head h2 { font-size: .98rem; }

  .pred-highlights {
    grid-template-columns: repeat(2, 1fr);
  }

  .watch-preview,
  .watch-grid {
    grid-template-columns: 1fr;
  }
  .watch-card {
    padding: .95rem 1rem;
  }
  .watch-card:active {
    border-color: var(--accent2);
    transform: scale(.99);
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  /* Sticky candidate toolbar under topbar */
  .sticky-toolbar {
    position: sticky;
    top: calc(var(--topbar-h) + var(--safe-top) - 4px);
    z-index: 40;
    background: rgba(7, 11, 18, .92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .65rem .7rem;
    margin: 0 -.15rem 1rem;
    gap: .5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
  }
  .toolbar input[type="search"],
  .toolbar select {
    min-width: 0;
    width: 100%;
    flex: 1 1 100%;
    min-height: 44px;
    font-size: 16px; /* avoid iOS zoom */
    border-radius: 10px;
  }
  .filter-group {
    width: 100%;
    flex: 1 1 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .filter-group::-webkit-scrollbar { display: none; }
  .pill {
    flex: 0 0 auto;
    min-height: 40px;
    padding: .45rem 1rem;
  }
  .result-count {
    margin-left: 0;
    width: 100%;
    text-align: right;
  }

  /* Mobile cards instead of wide table */
  .desk-only { display: none !important; }
  .cand-cards {
    display: flex;
    flex-direction: column;
    gap: .65rem;
  }
  .cand-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .9rem 1rem;
    cursor: pointer;
    transition: border-color .12s, background .12s;
  }
  .cand-card:active {
    border-color: var(--accent);
    background: var(--card-hover);
  }
  .cc-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .6rem;
    margin-bottom: .55rem;
  }
  .cc-sym {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 1.05rem;
  }
  .cc-name {
    font-size: .72rem;
    color: var(--dim);
    margin-top: .1rem;
  }
  .cc-score {
    text-align: right;
    flex-shrink: 0;
  }
  .cc-score .num {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent);
  }
  .cc-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .4rem .55rem;
  }
  .cc-metrics .m {
    background: var(--bg);
    border-radius: 8px;
    padding: .4rem .5rem;
    border: 1px solid rgba(30,45,66,.8);
  }
  .cc-metrics .k {
    font-size: .65rem;
    color: var(--dim);
  }
  .cc-metrics .v {
    font-family: var(--mono);
    font-size: .82rem;
    font-weight: 600;
    margin-top: .1rem;
  }
  .cc-phase {
    margin-top: .55rem;
    font-size: .72rem;
    color: var(--muted);
  }
  .cc-chevron {
    color: var(--dim);
    font-size: .9rem;
    margin-left: .25rem;
  }

  /* Full-screen detail drawer */
  .detail-panel {
    left: 0; right: 0; top: 0; bottom: 0;
    width: 100%;
    max-width: none;
    border-left: none;
    border-radius: 0;
    padding: 0 1rem calc(1.25rem + var(--safe-bottom));
    padding-top: 0;
    z-index: 90;
    animation: slideUp .22s ease;
  }
  @keyframes slideUp {
    from { transform: translateY(12%); opacity: .6; }
    to { transform: none; opacity: 1; }
  }
  .detail-backdrop {
    z-index: 85;
    background: rgba(0,0,0,.55);
  }
  .detail-header {
    margin: 0 -1rem .85rem;
    padding: calc(.55rem + var(--safe-top)) 1rem .65rem;
    justify-content: space-between;
  }
  .detail-back {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    min-height: 44px;
    padding: .35rem .75rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-family: var(--sans);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
  }
  .detail-back:active { background: var(--card-hover); }
  .detail-header-title {
    display: block;
    font-weight: 700;
    font-family: var(--mono);
    font-size: .95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 40vw;
  }
  .close-btn-desk { display: none; }

  .detail-panel .kv {
    grid-template-columns: 1fr 1fr;
    gap: .45rem;
  }
  .detail-panel .kv div {
    padding: .55rem .6rem;
    min-height: 52px;
  }
  .pred-metrics {
    grid-template-columns: 1fr 1fr;
  }
  .link-row .ext-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: .45rem .85rem;
    font-size: .8rem;
  }

  .refresh-banner {
    top: auto;
    position: fixed;
    left: .75rem;
    right: .75rem;
    bottom: calc(var(--bottom-nav-h) + .5rem);
    z-index: 75;
    border: 1px solid var(--border-bright);
    border-radius: 12px;
    padding: .65rem .85rem;
    box-shadow: var(--shadow);
  }

  .mini-table-wrap {
    margin: 0 -.25rem;
    padding-bottom: .25rem;
  }
  .mini-table th, .mini-table td {
    padding: .55rem .5rem;
    font-size: .78rem;
  }
}

@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .cc-metrics { grid-template-columns: 1fr 1fr; }
  .bn-label { font-size: .6rem; }
  .pred-highlights { grid-template-columns: 1fr 1fr; }
}

/* Landscape phones: keep bottom nav but shrink a bit */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  :root { --bottom-nav-h: calc(48px + var(--safe-bottom)); }
  .bn-item { min-height: 40px; }
  .bn-label { display: none; }
}


/* Mobile polish v2: compact toolbar, ensure bottom nav visible */
@media (max-width: 900px) {
  .bottom-nav { z-index: 100; }
  .detail-panel { z-index: 110; }
  .detail-backdrop { z-index: 105; }
  .sticky-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: .5rem;
  }
  .sticky-toolbar input[type="search"] {
    grid-column: 1 / -1;
    flex: none;
    width: 100%;
  }
  .sticky-toolbar .filter-group {
    grid-column: 1 / -1;
    width: 100%;
  }
  .sticky-toolbar select {
    grid-column: 1 / 2;
    width: 100%;
    flex: none;
  }
  .sticky-toolbar .result-count {
    grid-column: 2 / 3;
    width: auto;
    align-self: center;
    text-align: right;
    margin: 0;
  }
  .section-head p { display: none; } /* save vertical space on mobile */
  .hero-desc { font-size: .82rem; line-height: 1.45; }
}

/* Risk prompts */
.risk-box {
  margin-top: .75rem;
  padding: .75rem .85rem;
  border-radius: 12px;
  border: 1px solid rgba(255,176,32,.35);
  background: rgba(255,176,32,.06);
}
.risk-box.high {
  border-color: rgba(255,92,122,.45);
  background: rgba(255,92,122,.08);
}
.risk-box.elevated {
  border-color: rgba(138,212,255,.35);
  background: rgba(77,163,255,.06);
}
.risk-box.standard {
  border-color: rgba(255,176,32,.3);
}
.risk-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--warn);
  margin-bottom: .35rem;
}
.risk-box.high .risk-title { color: var(--danger); }
.risk-prompt {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.45;
}
.risk-meta {
  margin-top: .35rem;
  font-size: .72rem;
  color: var(--muted);
}
.risk-stops {
  margin: .45rem 0 0;
  padding-left: 1.1rem;
  font-size: .78rem;
  color: var(--muted);
}
.risk-stops li { margin: .15rem 0; }
.risk-live {
  margin-top: .4rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--danger);
}
.rule-card.risk-high {
  border-color: rgba(255,92,122,.4);
}

/* ===== Live analysis ===== */
.live-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
}
.live-status-left {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .85rem;
  color: var(--muted);
  min-width: 0;
}
.live-status-left #liveStatusText { color: var(--text); word-break: break-word; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--dim);
  box-shadow: 0 0 0 3px rgba(90,107,132,.25);
  flex-shrink: 0;
}
.live-dot.ok { background: var(--accent2); box-shadow: 0 0 0 3px rgba(0,212,170,.2); }
.live-dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(255,176,32,.2); }
.live-dot.err { background: var(--danger); box-shadow: 0 0 0 3px rgba(255,92,122,.2); }
.live-dot.pulse { animation: livePulse 1.2s ease-in-out infinite; }
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .55; transform: scale(.85); }
}
.live-status-right {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.live-stat-grid { margin-bottom: 1rem; }

.live-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.live-card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  padding: .95rem 1rem;
  cursor: pointer;
  transition: border-color .15s, transform .15s, background .15s;
}
.live-card:hover { border-color: var(--accent2); background: var(--card-hover); }
.live-card.pri-P1 { border-left: 3px solid var(--accent); }
.live-card.pri-P2 { border-left: 3px solid var(--accent2); }
.live-card.pri-P3 { border-left: 3px solid var(--info); }
.live-card.pri-OBS { border-left: 3px solid var(--c); }
.live-card.pri-RISK { border-left: 3px solid var(--danger); }
.live-card.pri-NONE { border-left: 3px solid var(--dim); }

.live-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .75rem;
  margin-bottom: .55rem;
}
.live-sym {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.1rem;
}
.live-sub {
  font-size: .72rem;
  color: var(--dim);
  margin-top: .15rem;
}
.live-badges { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.live-score {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.live-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .5rem;
  margin: .55rem 0 .35rem;
}
.live-metric {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .45rem .55rem;
  min-width: 0;
}
.live-metric .lm-label {
  font-size: .65rem;
  color: var(--dim);
  text-transform: none;
}
.live-metric .lm-val {
  font-family: var(--mono);
  font-size: .88rem;
  font-weight: 600;
  margin-top: .1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-metric .lm-val.pos { color: var(--accent2); }
.live-metric .lm-val.neg { color: var(--danger); }

.live-brk-bar {
  margin: .45rem 0 .35rem;
}
.live-brk-bar .bar-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(30,45,66,.9);
  overflow: hidden;
}
.live-brk-bar .bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--danger), var(--warn), var(--accent2));
  max-width: 100%;
}
.live-brk-bar .bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: var(--dim);
  margin-top: .25rem;
}

.live-risk-line {
  font-size: .78rem;
  color: var(--warn);
  margin-top: .35rem;
  line-height: 1.4;
}
.live-risk-line.high { color: var(--danger); font-weight: 600; }
.live-risk-line.elevated { color: var(--info); }

@media (max-width: 900px) {
  .live-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-status-bar { padding: .7rem .8rem; }
  .bn-item { font-size: .58rem; }
  .bn-item .bn-ico { font-size: .95rem; }
  .live-card { padding: .85rem .8rem; }
}
@media (max-width: 420px) {
  .live-metrics { grid-template-columns: 1fr 1fr; }
}

/* ===== Mobile more / research sheet ===== */
.more-backdrop {
  display: none;
}
.more-sheet {
  display: none;
}
.bn-more {
  appearance: none;
  background: transparent;
  border: 0;
  font: inherit;
  cursor: pointer;
  padding: 0;
}
.track-pill.track-none {
  background: rgba(90, 107, 132, .25);
  color: var(--muted);
  border: 1px solid var(--border);
}

@media (max-width: 900px) {
  .more-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, .55);
  }
  .more-backdrop[hidden] { display: none !important; }

  .more-sheet {
    display: block;
    position: fixed;
    left: 0; right: 0;
    bottom: var(--bottom-nav-h);
    z-index: 95;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 18px 18px 0 0;
    padding: .35rem .85rem calc(.85rem + var(--safe-bottom));
    box-shadow: 0 -12px 40px rgba(0,0,0,.45);
    max-height: min(70vh, 420px);
    overflow: auto;
    animation: moreUp .2s ease;
  }
  .more-sheet[hidden] { display: none !important; }
  @keyframes moreUp {
    from { transform: translateY(12px); opacity: .6; }
    to { transform: translateY(0); opacity: 1; }
  }
  .more-sheet-handle {
    width: 36px; height: 4px; border-radius: 999px;
    background: var(--border-bright);
    margin: .35rem auto .55rem;
  }
  .more-sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: .5rem;
  }
  .more-sheet-head h2 {
    margin: 0; font-size: 1rem;
  }
  .more-sheet-list {
    display: flex; flex-direction: column; gap: .45rem;
  }
  .more-item {
    display: flex; align-items: center; gap: .75rem;
    text-decoration: none; color: var(--text);
    padding: .85rem .9rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    min-height: 56px;
  }
  .more-item.active {
    border-color: var(--accent);
    background: rgba(240,185,11,.08);
  }
  .more-item:active { transform: scale(.99); }
  .more-ico {
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 1.05rem;
    flex-shrink: 0;
  }
  .more-text { flex: 1; min-width: 0; }
  .more-text strong { display: block; font-size: .95rem; }
  .more-text small { display: block; color: var(--muted); font-size: .72rem; margin-top: .15rem; }
  .more-chev { color: var(--dim); font-size: 1.25rem; }
  body.more-open { overflow: hidden; }
}
