/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  /* neutrals (dark default — these are the active values) */
  --bg-0: #0a0a0a;
  --bg-1: #111113;
  --bg-2: #17171a;
  --bg-3: #1f1f23;
  --bg-4: #2a2a2f;
  --border: #2a2a2f;
  --border-strong: #3a3a40;
  --text-0: #f5f5f5;
  --text-1: #d4d4d4;
  --text-2: #a3a3a3;
  --text-3: #737373;
  --text-4: #525252;

  /* market semantic — 红涨绿跌 (CN convention) */
  --up: #dc2626;
  --up-strong: #ef4444;
  --up-soft: #2a1414;
  --up-soft-border: #4a1d1d;

  --down: #16a34a;
  --down-strong: #22c55e;
  --down-soft: #0d1f14;
  --down-soft-border: #1c3a23;

  /* accent — high-score / AI signal */
  --accent: #f59e0b;
  --accent-strong: #fbbf24;
  --accent-soft: #2a1f0a;

  /* three-source palette */
  --src-tech: #3b82f6;
  --src-ai: #a855f7;
  --src-expert: #f59e0b;

  /* status */
  --info: #38bdf8;
  --warn: #f59e0b;
  --danger: #dc2626;
  --ok: #22c55e;

  /* type */
  --font-sans: "Inter", "PingFang SC", "Noto Sans SC", -apple-system, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* radii */
  --r-1: 4px;
  --r-2: 8px;
  --r-3: 12px;
  --r-4: 16px;
  --r-5: 20px;

  /* shadow */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.5);

  color-scheme: dark;
}

/* light theme overrides */
[data-theme="light"] {
  --bg-0: #fafafa;
  --bg-1: #ffffff;
  --bg-2: #f5f5f5;
  --bg-3: #ededed;
  --bg-4: #e5e5e5;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --text-0: #0a0a0a;
  --text-1: #262626;
  --text-2: #525252;
  --text-3: #737373;
  --text-4: #a3a3a3;

  --up-soft: #fef2f2;
  --up-soft-border: #fecaca;
  --down-soft: #f0fdf4;
  --down-soft-border: #bbf7d0;
  --accent-soft: #fffbeb;

  color-scheme: light;
}

/* ─── Base ───────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  background: #0e0e10;
  color: var(--text-0);
  font-feature-settings: "cv11", "ss01", "tnum";
}
body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
button { font-family: inherit; color: inherit; }
.mono, .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.font-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ─── Stage ──────────────────────────────────────────────────── */
.stage {
  display: flex; gap: 32px; align-items: flex-start;
}

/* ─── App screen (lives inside iOS frame) ───────────────────── */
.app {
  background: var(--bg-0);
  color: var(--text-0);
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  font-family: var(--font-sans);
  position: relative;
}
.app-scroll {
  flex: 1;
  overflow-y: auto;
  padding-top: 54px; /* status bar */
  padding-bottom: 92px; /* tab bar */
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.app-scroll::-webkit-scrollbar { width: 4px; }
.app-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* ─── Header ─────────────────────────────────────────────────── */
.hdr {
  padding: 8px 16px 12px;
  background: linear-gradient(to bottom, var(--bg-0) 0%, var(--bg-0) 70%, transparent 100%);
  position: sticky; top: 0;
  z-index: 5;
}
.hdr-top {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.hdr-title {
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--text-0);
  margin: 0;
}
.hdr-sub {
  font-size: 11px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--ok);
  display: inline-block;
}
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }

/* ─── Segmented controls ─────────────────────────────────────── */
.seg {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  gap: 0;
}
.seg-btn {
  flex: 1;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.seg-btn.active {
  background: var(--bg-4);
  color: var(--text-0);
  box-shadow: var(--shadow-1);
}
.seg-btn:not(.active):hover { color: var(--text-1); }

/* ─── Term tabs (smaller, secondary) ─────────────────────────── */
.term-row {
  display: flex; gap: 6px; margin-top: 10px;
  align-items: center;
}
.term-btn {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.term-btn.active {
  background: var(--text-0);
  color: var(--bg-0);
  border-color: var(--text-0);
}
.term-btn .num { font-size: 10px; color: var(--text-3); margin-left: 4px; }
.term-btn.active .num { color: var(--bg-2); }

.refresh-btn {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); cursor: pointer;
}
.refresh-btn:hover { color: var(--text-0); }
.refresh-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Recommendation card ────────────────────────────────────── */
.rec {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  margin: 0 16px 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.rec:hover { border-color: var(--border-strong); }
.rec:active { transform: scale(0.995); }

.rec-row1 {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px 10px;
}
.rec-mkt {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--text-1);
  flex-shrink: 0;
}
.rec-id { flex: 1; min-width: 0; }
.rec-sym {
  display: flex; gap: 8px; align-items: baseline;
}
.rec-sym .symbol {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 600;
  color: var(--text-0);
}
.rec-sym .name {
  font-size: 12px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rec-price {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rec-price .px {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 600;
  color: var(--text-0);
}
.rec-price .ch {
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; gap: 2px; justify-content: flex-end;
}
.ch.up { color: var(--up-strong); }
.ch.down { color: var(--down-strong); }

/* fusion row */
.rec-fusion {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 10px;
  border-top: 1px dashed var(--border);
}
.fusion-bar {
  flex: 1; height: 6px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.fusion-bar > i {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, var(--src-tech), var(--src-ai), var(--src-expert));
  transform-origin: left;
}
.fusion-score {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 700;
  color: var(--accent);
}
.fusion-score .max { color: var(--text-4); font-weight: 500; font-size: 11px; }
.fusion-label { font-size: 11px; color: var(--text-3); }

/* three-source mini */
.three-src-mini {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1px; background: var(--border);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.src-cell {
  background: var(--bg-1);
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 1px;
}
.src-cell .label { font-size: 10px; color: var(--text-3); }
.src-cell .val {
  font-family: var(--font-mono); font-weight: 700; font-size: 16px;
  color: var(--text-0);
  display: flex; align-items: baseline; gap: 3px;
}
.src-cell .val::before {
  content: ""; width: 6px; height: 6px; border-radius: 999px;
  display: inline-block; margin-right: 4px;
  align-self: center;
}
.src-cell.tech .val::before { background: var(--src-tech); }
.src-cell.ai .val::before { background: var(--src-ai); }
.src-cell.expert .val::before { background: var(--src-expert); }

/* rec footer */
.rec-meta {
  padding: 10px 14px 12px;
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 11px;
  color: var(--text-2);
}
.rec-meta .row { display: flex; align-items: center; gap: 5px; }
.rec-meta .lab { color: var(--text-3); }
.rec-meta .v { font-family: var(--font-mono); color: var(--text-1); }

/* risk chip */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  border: 1px solid;
}
.chip.low {
  background: var(--down-soft); border-color: var(--down-soft-border); color: var(--down-strong);
}
.chip.medium {
  background: var(--accent-soft); border-color: rgba(245,158,11,0.3); color: var(--accent-strong);
}
.chip.high {
  background: var(--up-soft); border-color: var(--up-soft-border); color: var(--up-strong);
}

.win-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: 11px;
}
.win-badge .pct { color: var(--text-0); font-weight: 700; }
.win-badge .n { color: var(--text-3); }
.win-badge.warn { color: var(--warn); }

/* ─── Bottom tab bar ─────────────────────────────────────────── */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 80px;
  background: rgba(20,20,22,0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 4px 4px 24px;
  z-index: 10;
}
[data-theme="light"] .tabbar {
  background: rgba(255,255,255,0.85);
}
.tab {
  flex: 1;
  border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px;
  color: var(--text-3);
  font-size: 10px;
  cursor: pointer;
}
.tab.active { color: var(--accent); }
.tab svg { width: 22px; height: 22px; }

/* ─── Detail page ────────────────────────────────────────────── */
.detail-hero {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.detail-back {
  display: inline-flex; align-items: center; gap: 4px;
  background: transparent; border: 0;
  color: var(--text-2); font-size: 14px; padding: 4px 0;
  cursor: pointer; margin-bottom: 8px;
}
.detail-back:hover { color: var(--text-0); }

.detail-symline {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
}
.detail-symline .symbol {
  font-family: var(--font-mono); font-size: 22px; font-weight: 700;
}
.detail-symline .badge {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--bg-3); color: var(--text-2);
  border: 1px solid var(--border);
}
.detail-name { color: var(--text-2); font-size: 13px; margin-bottom: 14px; }

.detail-priceblock {
  display: flex; align-items: baseline; gap: 12px;
}
.detail-priceblock .px {
  font-family: var(--font-mono); font-size: 36px; font-weight: 700;
  letter-spacing: -0.02em;
}
.detail-priceblock .ch {
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 4px;
}

/* fusion ring (big) */
.fusion-ring-wrap {
  display: flex; align-items: center; gap: 16px;
  margin-top: 16px;
  padding: 14px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
}
.fusion-ring-wrap .info { flex: 1; }
.fusion-ring-wrap .info .lab { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.fusion-ring-wrap .info .ttl { font-size: 14px; color: var(--text-0); font-weight: 600; margin-bottom: 6px; }
.fusion-ring-wrap .info .why { font-size: 12px; color: var(--text-2); line-height: 1.5; }

/* sections */
.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 11px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em;
  margin: 0 0 10px;
  display: flex; justify-content: space-between; align-items: center;
}

/* three-source big */
.three-src-big {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.src-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.src-card .head {
  display: flex; justify-content: space-between; align-items: center;
}
.src-card .lab {
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; gap: 4px;
}
.src-card.tech .lab { color: var(--src-tech); }
.src-card.ai .lab { color: var(--src-ai); }
.src-card.expert .lab { color: var(--src-expert); }
.src-card .pct {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 700;
  color: var(--text-0);
  line-height: 1;
}
.src-card .pct .max { font-size: 11px; color: var(--text-4); font-weight: 500; }
.src-card .reason { font-size: 11px; color: var(--text-2); line-height: 1.45; }

/* chart panel */
.chart-panel {
  height: 200px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-2);
  position: relative; overflow: hidden;
}
.chart-controls {
  display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap;
}
.indicator-toggle {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  cursor: pointer;
}
.indicator-toggle.on {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(245,158,11,0.35);
}

/* stat grid */
.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  overflow: hidden;
}
.stat-cell {
  background: var(--bg-1);
  padding: 10px 12px;
}
.stat-cell .lab { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.stat-cell .v {
  font-family: var(--font-mono);
  font-size: 18px; font-weight: 700;
  color: var(--text-0);
}
.stat-cell .v.up { color: var(--up); }
.stat-cell .v.down { color: var(--down); }
.stat-cell .sub { font-size: 10px; color: var(--text-3); margin-top: 2px; }

/* regret panel */
.regret-panel {
  background: linear-gradient(135deg, var(--up-soft), var(--bg-1));
  border: 1px solid var(--up-soft-border);
  border-radius: var(--r-3);
  padding: 14px;
}
.regret-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.regret-head .ttl {
  font-size: 13px; font-weight: 600;
  color: var(--text-0);
}
.regret-icon {
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--up-soft-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--up-strong);
}

/* action bar */
.action-bar {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 6px;
  padding: 12px 16px;
  position: sticky;
  bottom: 80px;
  background: linear-gradient(to top, var(--bg-0) 60%, transparent);
}
.act-btn {
  height: 44px;
  border-radius: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-1);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.act-btn.primary {
  background: var(--up); color: white; border-color: transparent;
}
.act-btn.primary:hover { background: var(--up-strong); }
.act-btn:hover { border-color: var(--border-strong); }

/* expandable AI */
.expand-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-2);
  overflow: hidden;
}
.expand-head {
  padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
  font-size: 13px;
}
.expand-body {
  padding: 0 12px 12px;
  font-size: 12px; line-height: 1.6;
  color: var(--text-2);
}

/* ─── Portfolio ──────────────────────────────────────────────── */
.kpi-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 16px 12px;
}
.kpi {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 10px;
}
.kpi .lab { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi .v { font-family: var(--font-mono); font-size: 18px; font-weight: 700; margin-top: 4px; }
.kpi .v.up { color: var(--up); }
.kpi .v.down { color: var(--down); }
.kpi .delta { font-size: 11px; margin-top: 2px; }

.curve-card {
  margin: 0 16px 12px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: 12px;
}
.curve-card .head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.curve-card .total {
  font-family: var(--font-mono); font-size: 24px; font-weight: 700;
}

/* positions */
.pos-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: 12px;
}
.pos-row.head { color: var(--text-3); font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.pos-row .sym { font-family: var(--font-mono); font-weight: 600; }
.pos-row .right { text-align: right; font-family: var(--font-mono); }
.pos-row .meta { font-size: 10px; color: var(--text-3); margin-top: 2px; }

/* strategies */
.strat-card {
  margin: 0 16px 8px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: 12px;
}
.strat-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.strat-head .name { font-weight: 600; font-size: 14px; }
.strat-stat-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.strat-stat .lab { font-size: 10px; color: var(--text-3); }
.strat-stat .v { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }

.toggle {
  position: relative;
  width: 40px; height: 22px;
  background: var(--bg-4); border-radius: 999px;
  cursor: pointer; transition: background .15s;
  border: 0; padding: 0;
}
.toggle::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: white; border-radius: 999px;
  transition: transform .15s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(18px); }

.status-pill {
  font-size: 11px; padding: 2px 8px;
  border-radius: 999px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.status-pill.on { background: var(--down-soft); color: var(--down-strong); border: 1px solid var(--down-soft-border); }
.status-pill.deg { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid rgba(245,158,11,0.3); }
.status-pill.off { background: var(--bg-3); color: var(--text-3); border: 1px solid var(--border); }

/* banner */
.banner {
  margin: 0 16px 12px;
  padding: 10px 12px;
  background: var(--up-soft); border: 1px solid var(--up-soft-border);
  border-radius: var(--r-2);
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12px;
  color: var(--up-strong);
  line-height: 1.5;
}

/* settings rows */
.set-group {
  margin: 0 16px 16px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
}
.set-group .group-ttl {
  padding: 10px 14px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.set-row {
  display: flex; align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.set-row:last-child { border-bottom: 0; }
.set-row .lab { flex: 1; font-size: 14px; }
.set-row .sub { font-size: 11px; color: var(--text-3); margin-top: 1px; }

/* disclaimer */
.disclaimer {
  font-size: 10px; color: var(--text-4);
  padding: 16px 16px 24px;
  text-align: center;
  line-height: 1.6;
}

/* skeleton */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.skel {
  background: var(--bg-3);
  border-radius: 4px;
  animation: pulse 1.6s ease-in-out infinite;
}

/* misc */
.spacer { height: 12px; }
.h-divider { height: 1px; background: var(--border); margin: 0 16px; }
