:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #15181d;
  --muted: #5d6673;
  --up: #12805c;
  --down: #c8342b;
  --flat: #8a6d00;
  --accent: #2f6fdb;
  --put: #12805c;
  --call: #c8342b;
  --flip: #b26a00;
  --hvl: #7a4fd1;
  --em: #0b8fa8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --panel: #161a21;
    --border: #262c36;
    --text: #e6e9ee;
    --muted: #8e98a6;
    --up: #2fbf8a;
    --down: #ef5a50;
    --flat: #e0b43a;
    --accent: #5b93ff;
    --put: #2fbf8a;
    --call: #ef5a50;
    --flip: #f0a43a;
    --hvl: #a989ff;
    --em: #3cc6dd;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --panel: #161a21; --border: #262c36; --text: #e6e9ee; --muted: #8e98a6;
  --up: #2fbf8a; --down: #ef5a50; --flat: #e0b43a; --accent: #5b93ff;
  --put: #2fbf8a; --call: #ef5a50; --flip: #f0a43a; --hvl: #a989ff; --em: #3cc6dd;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 5px 16px; padding-top: max(5px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 14px; }
.status { color: var(--muted); font-size: 11px; text-align: right; }
.top-right { display: flex; align-items: center; gap: 10px; }
.theme-btn { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text); font: inherit; font-size: 12px; padding: 2px 10px; cursor: pointer; }
.theme-btn:hover { border-color: var(--muted); }

main { max-width: 1400px; margin: 0 auto; padding: 12px 16px; }
html { -webkit-text-size-adjust: 100%; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.card.big { grid-column: span 2; }
.label { color: var(--muted); font-size: 12px; }
.value { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card.big .value { font-size: 26px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--flat); }
.meter { height: 6px; border-radius: 3px; background: var(--border); margin-top: 8px; position: relative; overflow: hidden; }
.meter-fill { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--muted); transition: all .3s; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 14px 0 10px; }
.toggles { border: 1px solid var(--border); border-radius: 10px; background: var(--panel); padding: 6px 12px; margin: 0; display: flex; gap: 14px; flex-wrap: wrap; }
.toggles legend { color: var(--muted); font-size: 11px; padding: 0 4px; }
.toggles label { cursor: pointer; user-select: none; white-space: nowrap; }
.ranges { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel); margin-left: auto; }
.ranges button { background: none; border: 0; color: var(--text); padding: 8px 12px; cursor: pointer; font: inherit; }
.ranges button.on { background: var(--accent); color: #fff; }
.range-select { appearance: none; -webkit-appearance: none; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer;
  padding: 8px 26px 8px 12px; border-right: 1px solid var(--border);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 13px center, right 9px center; background-size: 4px 4px; background-repeat: no-repeat; }
.range-select.on { background-color: var(--accent); color: #fff; }
.range-select option { color: var(--text); background: var(--panel); }

.gex-table { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; overflow-x: auto; }
.gex-table table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.gex-table th, .gex-table td { text-align: right; padding: 4px 10px; white-space: nowrap; }
.gex-table th:first-child, .gex-table td:first-child { text-align: left; }
.gex-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.gex-note { color: var(--muted); font-size: 12px; }
.sw { display: inline-block; width: 10px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(560px, 100%), 1fr)); gap: 10px; }
.chart-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-width: 0; overflow: hidden; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0 4px 6px; }
.chart-title { font-weight: 650; }
.chart-title .nm { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.chart-price { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart-box { height: 340px; width: 100%; }
.chart-right { display: flex; align-items: baseline; gap: 10px; }
.chart-iv { font-size: 12px; font-weight: 600; color: var(--em); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-variant-numeric: tabular-nums; }
.chart-iv:empty { display: none; }
.iv-label { color: var(--muted); font-weight: 700; margin-right: 2px; }
.chart-note { color: var(--muted); font-size: 12px; margin: 6px 4px 0; font-variant-numeric: tabular-nums; }
.expand { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); cursor: pointer;
  line-height: 0; width: 30px; height: 26px; padding: 0; align-self: center; display: inline-flex; align-items: center; justify-content: center; }
.expand + .expand { margin-left: -4px; }
.expand:hover { color: var(--text); border-color: var(--muted); }
.chart-panel.wide { grid-column: 1 / -1; }
.chart-panel:fullscreen, .chart-panel.pseudo-full { display: flex; flex-direction: column; border-radius: 0; border: 0; padding: 12px; background: var(--bg); }
.chart-panel:-webkit-full-screen { display: flex; flex-direction: column; padding: 12px; background: var(--bg); }
.chart-panel.pseudo-full { position: fixed; inset: 0; z-index: 50; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.chart-panel:fullscreen .chart-box, .chart-panel:-webkit-full-screen .chart-box, .chart-panel.pseudo-full .chart-box { flex: 1; height: auto; min-height: 0; }
.chart-panel:fullscreen .expand:not(.fs), .chart-panel.pseudo-full .expand:not(.fs) { display: none; }
body.no-scroll { overflow: hidden; }
.chart-err { color: var(--muted); padding: 40px 10px; text-align: center; }

.foot { color: var(--muted); font-size: 12px; margin: 18px 0 8px; }

/* Phones: two-up compact cards, full-width controls with touch-sized targets, shorter charts. */
@media (max-width: 640px) {
  main { padding: 10px 10px; }
  .top { padding-left: 10px; padding-right: 10px; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 8px 10px; }
  .card.big { grid-column: span 2; }
  .value { font-size: 17px; }
  .card.big .value { font-size: 21px; }
  .hint { font-size: 11px; }
  .controls { gap: 8px; margin: 10px 0 8px; }
  .toggles { gap: 4px 12px; padding: 4px 10px; }
  .status .long { display: none; }
  .toggles label { padding: 4px 0; }
  .toggles input { width: 18px; height: 18px; vertical-align: -4px; }
  .ranges { margin-left: 0; width: 100%; }
  .ranges button { flex: 1; padding: 10px 0; }
  .range-select { padding-top: 10px; padding-bottom: 10px; }
  .chart-panel { padding: 8px 6px; }
  .chart-title .nm { display: none; }
  .chart-box { height: 300px; }
  .expand { width: 34px; height: 30px; }
  .gex-table { padding: 8px 10px; }
}
