:root {
  --bg: #0a0e1a;
  --card: #131a2b;
  --card-2: #182238;
  --border: #232d44;
  --text: #eef1f8;
  --text-dim: #8b93a7;
  --text-faint: #5c6478;
  --accent: #5b6df6;
  --accent-2: #7b8bff;
  --buy: #21c579;
  --buy-bg: rgba(33, 197, 121, 0.14);
  --sell: #f0475a;
  --sell-bg: rgba(240, 71, 90, 0.14);
  --neutral: #8b93a7;
  --neutral-bg: rgba(139, 147, 167, 0.14);
  --warn: #f0a63c;
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.view {
  flex: 1;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(96px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar h1 {
  font-size: 20px;
  margin: 0 0 2px;
  font-weight: 700;
}
.topbar .subtitle {
  font-size: 12.5px;
  color: var(--text-dim);
}
.topbar .icon-btn, .back-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn svg, .back-btn svg, .nav-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
  margin: 0 0 10px;
}

/* ---------- Price header card ---------- */
.price-card { display: flex; align-items: center; justify-content: space-between; }
.price-card .pair-info { display: flex; align-items: center; gap: 10px; }
.pair-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #f7931a, #ffb84d);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #1a1204; font-size: 18px;
}
.pair-info .name { font-weight: 700; font-size: 15px; }
.pair-info .meta { font-size: 12px; color: var(--text-dim); }
.price-card .price-block { text-align: right; }
.price-card .price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-card .change { font-size: 12.5px; font-weight: 600; }
.change.up { color: var(--buy); }
.change.down { color: var(--sell); }

.source-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  padding: 4px 10px; border-radius: 20px;
  background: var(--card-2); color: var(--text-dim); border: 1px solid var(--border);
  margin-bottom: 14px;
}
.source-pill.fallback { color: var(--warn); border-color: rgba(240,166,60,.3); }

/* ---------- Primary CTA ---------- */
.cta-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 15px;
  font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px rgba(91,109,246,0.6);
}
.cta-btn .sub { font-size: 11.5px; font-weight: 500; opacity: 0.85; }
.cta-btn:disabled { opacity: 0.6; }

/* ---------- Model grid (home) ---------- */
.model-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.model-chip {
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 6px; text-align: center; font-size: 11px; color: var(--text-dim); font-weight: 600;
}
.model-chip .glyph {
  width: 30px; height: 30px; border-radius: 50%; margin: 0 auto 6px;
  background: var(--card); display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

/* ---------- Signal badges ---------- */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 800; letter-spacing: 0.03em;
}
.badge.BUY { color: var(--buy); background: var(--buy-bg); }
.badge.SELL { color: var(--sell); background: var(--sell-bg); }
.badge.NO_TRADE { color: var(--neutral); background: var(--neutral-bg); }
.badge.ERROR, .badge.error, .badge.timeout { color: var(--warn); background: rgba(240,166,60,.14); }

/* ---------- Progress / analyzing screen ---------- */
.pulse-ring {
  width: 140px; height: 140px; margin: 30px auto; border-radius: 50%;
  background: var(--card-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.pulse-ring::before, .pulse-ring::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  border: 1px solid rgba(91,109,246,0.35); animation: pulse 2s ease-out infinite;
}
.pulse-ring::after { animation-delay: 1s; }
@keyframes pulse { 0% { transform: scale(0.85); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }
.pulse-ring .coin { width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, #f7931a, #ffb84d); display:flex; align-items:center; justify-content:center; font-weight:800; font-size:26px; color:#1a1204; }

.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--text-faint);
}
.status-list li:last-child { border-bottom: none; }
.status-list li .dot {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.status-list li.done { color: var(--text); }
.status-list li.done .dot { background: var(--buy); border-color: var(--buy); color: #06231a; }
.status-list li.active { color: var(--accent-2); }
.status-list li.active .dot { border-color: var(--accent); }

/* ---------- Vote donut ---------- */
.vote-summary { display: flex; align-items: center; gap: 18px; }
.donut { width: 84px; height: 84px; border-radius: 50%; flex-shrink: 0; position: relative; }
.donut .center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--text-dim); }
.vote-legend { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.vote-legend .row { display: flex; align-items: center; justify-content: space-between; }
.vote-legend .label { display: flex; align-items: center; gap: 7px; }
.vote-legend .swatch { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- Majority recommendation ---------- */
.majority-box {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card-2); border-radius: var(--radius-sm); padding: 14px;
}
.majority-badge {
  font-size: 15px; font-weight: 800; padding: 8px 18px; border-radius: 12px;
}
.majority-badge.BUY { background: var(--buy); color: #06231a; }
.majority-badge.SELL { background: var(--sell); color: #2a0509; }
.majority-badge.NO_TRADE { background: var(--neutral); color: #12161e; }
.majority-note { font-size: 12px; color: var(--text-dim); max-width: 62%; text-align: right; }

/* ---------- kv rows ---------- */
.kv-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--text-dim); }
.kv-row .v { font-weight: 600; }

/* ---------- AI result cards (history feed on result screen) ---------- */
.ai-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.ai-card .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ai-card .model-name { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.ai-card .model-name .glyph { width: 26px; height: 26px; border-radius: 50%; background: var(--card-2); display: flex; align-items: center; justify-content: center; font-size: 12px; }
.ai-card .confidence { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.ai-card .chev { color: var(--text-faint); }

/* ---------- list items (history) ---------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto; }
.filter-chip {
  padding: 7px 14px; border-radius: 20px; background: var(--card-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--text-dim); white-space: nowrap; cursor: pointer;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.history-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.history-item .icon-box { width: 36px; height: 36px; border-radius: 10px; background: var(--card-2); display: flex; align-items: center; justify-content: center; margin-right: 12px; color: var(--text-dim); }
.history-item .main { flex: 1; min-width: 0; }
.history-item .title { font-weight: 700; font-size: 13.5px; }
.history-item .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.history-item .right { text-align: right; }

/* ---------- settings toggles ---------- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 600; }
.toggle-row .glyph { width: 26px; height: 26px; border-radius: 50%; background: var(--card-2); display: flex; align-items: center; justify-content: center; font-size: 12px; }
.switch { width: 42px; height: 24px; border-radius: 20px; background: var(--border); position: relative; cursor: pointer; flex-shrink: 0; border: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

/* ---------- raw response box ---------- */
.raw-box {
  background: #06090f; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
  color: #9fe6b0; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow-y: auto;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: flex; background: rgba(10,14,26,0.92); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--text-faint);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 4px 0; cursor: pointer;
}
.nav-btn.active { color: var(--accent-2); }

/* ---------- misc ---------- */
.empty-state { text-align: center; color: var(--text-dim); font-size: 13px; padding: 40px 10px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-banner { background: var(--sell-bg); color: var(--sell); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; margin-bottom: 14px; }
.section-gap { height: 4px; }
