:root {
  --bg: #070a12;
  --bg-2: #0c1322;
  --card: rgba(20, 27, 45, 0.55);
  --card-border: rgba(120, 140, 190, 0.14);
  --card-hi: rgba(140, 160, 220, 0.22);
  --text: #e8edf7;
  --text-dim: #8b97b4;
  --text-faint: #566079;
  --accent: #4f7cff;
  --accent-2: #21d4fd;
  --btc: #f7931a;
  --eth: #627eea;
  --sol: #14f195;
  --xrp: #00aae4;
  --inset: rgba(255, 255, 255, 0.04);
  --track: rgba(255, 255, 255, 0.06);
  --text-grad: linear-gradient(120deg, #ffffff, #dce6fb);
  --switch-active: rgba(120, 140, 200, 0.22);
  --switch-active-fg: #ffffff;
  --dist-mean: rgba(255, 255, 255, 0.55);
  --radius: 18px;
  --shadow: 0 18px 50px -22px rgba(0, 0, 0, 0.85);
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;
}

:root[data-theme="light"] {
  --bg: #eef1f8;
  --bg-2: #e2e8f4;
  --card: rgba(255, 255, 255, 0.74);
  --card-border: rgba(60, 80, 130, 0.14);
  --card-hi: rgba(60, 80, 130, 0.24);
  --text: #131a2e;
  --text-dim: #5b6886;
  --text-faint: #97a2bd;
  --inset: rgba(60, 80, 130, 0.06);
  --track: rgba(60, 80, 130, 0.10);
  --text-grad: linear-gradient(120deg, #0f1830, #2c47a8);
  --switch-active: rgba(79, 124, 255, 0.16);
  --switch-active-fg: #15203a;
  --dist-mean: rgba(40, 60, 110, 0.45);
  --shadow: 0 18px 50px -24px rgba(40, 60, 110, 0.30);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -8%, rgba(79, 124, 255, 0.16), transparent 60%),
    radial-gradient(1000px 700px at 95% 0%, rgba(33, 212, 253, 0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 55%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

.wrap { max-width: 1320px; margin: 0 auto; padding: 34px 28px 64px; }

/* ── Header ─────────────────────────────────────────────────────── */
header.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 30px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 13px;
  background: conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent));
  display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #061022;
  box-shadow: 0 10px 30px -8px rgba(79, 124, 255, 0.6);
}
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.brand .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

.top-right { display: flex; align-items: center; gap: 16px; }
.live { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2ee6a8; box-shadow: 0 0 0 0 rgba(46, 230, 168, 0.55);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 230, 168, 0.5); }
  70% { box-shadow: 0 0 0 9px rgba(46, 230, 168, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 230, 168, 0); }
}

/* interval toggle */
.toggle { display: inline-flex; background: var(--card); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 4px; backdrop-filter: blur(8px); }
.toggle button {
  border: none; background: transparent; color: var(--text-dim);
  padding: 8px 18px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: color .2s, background .25s; font-family: inherit;
}
.toggle button.active { color: #fff; background: linear-gradient(135deg, var(--accent), #3a63d8);
  box-shadow: 0 6px 18px -6px rgba(79, 124, 255, 0.7); }
.toggle button:not(.active):hover { color: var(--text); }

/* theme toggle */
.theme-btn { width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--card-border);
  background: var(--card); color: var(--text-dim); cursor: pointer; display: grid; place-items: center;
  backdrop-filter: blur(8px); transition: color .2s, border-color .25s, transform .2s; }
.theme-btn:hover { color: var(--text); border-color: var(--card-hi); transform: translateY(-1px); }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .i-moon { display: none; }
:root[data-theme="light"] .theme-btn .i-sun { display: none; }
:root[data-theme="light"] .theme-btn .i-moon { display: block; }

/* ── KPI row ────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 20px 22px; backdrop-filter: blur(10px); position: relative; overflow: hidden;
  transition: transform .3s, border-color .3s, box-shadow .3s;
}
.kpi::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(120, 150, 255, 0.06) 50%, transparent 70%);
  transform: translateX(-100%); transition: transform .7s;
}
.kpi:hover { transform: translateY(-3px); border-color: var(--card-hi); box-shadow: var(--shadow); }
.kpi:hover::after { transform: translateX(100%); }
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 9px; font-family: var(--mono);
  background: var(--text-grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; }
.kpi .meta { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.kpi .bar { height: 3px; border-radius: 3px; margin-top: 14px; background: var(--track); overflow: hidden; }
.kpi .bar > i { display: block; height: 100%; border-radius: 3px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 1.1s cubic-bezier(.2,.8,.2,1); }

/* ── Cards / grid ───────────────────────────────────────────────── */
.grid { display: grid; gap: 18px; }
.row-main { grid-template-columns: 1.85fr 1fr; }
.row-2 { grid-template-columns: 1fr 1fr; margin-top: 18px; }
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .row-main, .row-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 22px 24px 16px; backdrop-filter: blur(10px); box-shadow: var(--shadow);
  transition: border-color .3s;
}
.card:hover { border-color: var(--card-hi); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.card-head .hint { font-size: 11.5px; color: var(--text-dim); }
.chart { width: 100%; }
.chart-tall { height: 360px; }
.chart-mid { height: 320px; }

.legend-mini { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.legend-mini span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; transition: opacity .2s; }
.legend-mini span.off { opacity: 0.32; }
.legend-mini i { width: 10px; height: 10px; border-radius: 3px; }

/* view-mode switch on main chart */
.miniswitch { display: inline-flex; background: var(--inset); border-radius: 9px; padding: 3px; }
.miniswitch button { border: none; background: transparent; color: var(--text-dim); font: 600 11.5px/1 inherit;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; transition: .2s; }
.miniswitch button.active { color: var(--switch-active-fg); background: var(--switch-active); }

/* loading + empty states */
.loading { display: grid; place-items: center; height: 100%; color: var(--text-dim); font-size: 13px; gap: 14px; }
.spinner { width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(120, 140, 200, 0.18); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.note { font-size: 12px; color: var(--text-faint); text-align: center; padding-top: 6px; }

footer { text-align: center; color: var(--text-faint); font-size: 12px; margin-top: 38px; }
footer a { color: var(--text-dim); text-decoration: none; }
footer a:hover { color: var(--text); }

/* ── Volatility view ────────────────────────────────────────────── */
.vol-kpi {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 18px 20px; backdrop-filter: blur(10px); position: relative; overflow: hidden;
  transition: transform .3s, border-color .3s, box-shadow .3s;
}
.vol-kpi:hover { transform: translateY(-2px); border-color: var(--card-hi); box-shadow: var(--shadow); }
.vol-kpi .top-row { display: flex; align-items: center; justify-content: space-between; }
.vol-kpi .asset { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.vol-kpi .asset i { width: 11px; height: 11px; border-radius: 50%; }
.badge { font-size: 11px; font-weight: 700; padding: 4px 11px; border-radius: 20px; letter-spacing: .03em; }
.badge.normal       { background: rgba(46,230,168,.15); color: #2ee6a8; border: 1px solid rgba(46,230,168,.3); }
.badge.high, .badge.low { background: rgba(245,190,64,.15); color: #f5be40; border: 1px solid rgba(245,190,64,.3); }
.badge.anomaly_high, .badge.anomaly_low { background: rgba(255,107,138,.15); color: #ff6b8a; border: 1px solid rgba(255,107,138,.4); }
.vol-kpi .big { font-size: 30px; font-weight: 700; margin-top: 10px; font-family: var(--mono);
  background: var(--text-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.vol-kpi .big .unit { font-size: 15px; color: var(--text-dim); -webkit-text-fill-color: var(--text-dim); margin-left: 3px; }
.vol-kpi .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

/* distribution bar: hist mean ± 2σ with current marker */
.dist { position: relative; height: 8px; border-radius: 5px; margin: 16px 0 6px;
  background: linear-gradient(90deg,
    rgba(255,107,138,.25), rgba(245,190,64,.18) 25%, rgba(46,230,168,.22) 50%,
    rgba(245,190,64,.18) 75%, rgba(255,107,138,.25)); }
.dist .mean { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--dist-mean); }
.dist .marker { position: absolute; top: -4px; width: 4px; height: 16px; border-radius: 2px;
  background: #fff; box-shadow: 0 0 8px rgba(255,255,255,.7); }
.dist-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-faint); font-family: var(--mono); }
.vol-kpi .foot { font-size: 11.5px; color: var(--text-dim); margin-top: 8px; font-family: var(--mono); }

.liq-ex-grid { margin: 0; }
.liq-ex-kpi .badge.normal { background: rgba(79,124,255,.15); color: var(--accent); }

.liq-table-wrap { overflow-x: auto; padding: 4px 2px 8px; }
table.liq-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.liq-table th, table.liq-table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--card-border); }
table.liq-table th:first-child, table.liq-table td:first-child { text-align: left; }
table.liq-table th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
table.liq-table td b { font-family: var(--mono); }
table.liq-table .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
table.liq-table tbody tr:hover { background: var(--inset); }
