:root {
  --bg0: #070b17; --bg1: #101a33;
  --panel: rgba(14, 21, 42, .78); --panel-solid: #0e152a;
  --line: rgba(148, 163, 184, .18);
  --text: #e6ecfa; --muted: #93a1bd;
  --accent: #5eead4; --accent2: #818cf8;
  --c-energy: #fb923c; --c-prog: #5eead4;
  --hydro: #fbbf24; --polar: #5eead4; --pos: #60a5fa; --neg: #f87171;
  --radius: 14px;
  --lw: 296px; --rw: 348px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 50% 35%, #17254a 0%, var(--bg1) 38%, var(--bg0) 100%);
  -webkit-font-smoothing: antialiased;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#c.dragging { cursor: grabbing; }

/* header */
#top { position: fixed; z-index: 5; top: 0; left: 0; right: 0; height: 56px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.brand { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.brand b { font-size: 18px; letter-spacing: .3px; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; pointer-events: auto; }
.mobile-only { display: none; }

/* panels */
.panel {
  position: fixed; z-index: 4; top: 64px; bottom: 14px; padding: 14px;
  background: var(--panel); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
#left { left: 14px; width: var(--lw); }
#right { right: 14px; width: var(--rw); }
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: #334 transparent; }
section + section { margin-top: 18px; }
h2 { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
h3 small { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); } .tiny { font-size: 12px; margin: 6px 0 0; }

/* presets */
.presets { display: grid; gap: 6px; }
.preset { all: unset; box-sizing: border-box; cursor: pointer; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.02); display: flex; justify-content: space-between; align-items: center; gap: 8px; transition: .15s; }
.preset:hover { border-color: rgba(129, 140, 248, .6); background: rgba(129,140,248,.08); }
.preset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.preset[aria-selected="true"] { border-color: var(--accent); background: linear-gradient(90deg, rgba(94,234,212,.14), rgba(129,140,248,.1)); }
.preset b { font-weight: 600; display: block; font-size: 13px; }
.preset span { color: var(--muted); font-size: 12px; }
.preset em { font-style: normal; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; white-space: nowrap; }

/* sliders */
.slider { display: block; margin-bottom: 14px; }
.slider .lab { display: flex; justify-content: space-between; align-items: baseline; }
.slider output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.slider.disabled { opacity: .4; pointer-events: none; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 4px 0 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 4px; background: linear-gradient(90deg, var(--accent2), var(--accent)); opacity: .55; }
input[type=range]::-moz-range-track { height: 5px; border-radius: 4px; background: linear-gradient(90deg, var(--accent2), var(--accent)); opacity: .55; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* buttons & fields */
button { font: inherit; color: var(--text); cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); padding: 7px 12px; transition: .15s; }
button:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.3); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: linear-gradient(135deg, #14b8a6, #6366f1); border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.12); }
button.ghost { background: rgba(14,21,42,.6); }
button.wide { width: 100%; margin-top: 8px; }
.btnrow { display: flex; gap: 6px; margin-bottom: 6px; } .btnrow button { flex: 1; white-space: nowrap; padding: 7px 6px; }
.field { display: grid; grid-template-columns: 1fr; gap: 3px; margin-bottom: 8px; }
.field label { font-size: 12px; color: var(--muted); }
select { font: inherit; color: var(--text); background: #0b1226; border: 1px solid var(--line); border-radius: 9px; padding: 7px 8px; width: 100%; }
select:focus-visible { outline: 2px solid var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend .grad { width: 70px; height: 8px; border-radius: 4px; }

/* right panel */
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.05); padding: 3px; border-radius: 11px; margin-bottom: 12px; position: sticky; top: -14px; z-index: 2; backdrop-filter: blur(10px); }
.tabs button { flex: 1; border: 0; background: transparent; }
.tabs button[aria-selected="true"] { background: rgba(94,234,212,.16); color: var(--accent); font-weight: 600; }
.card { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card + .card { margin-top: 0; }
section.card + section.card { margin-top: 0; }
.statehead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.badge { padding: 3px 11px; border-radius: 99px; font-weight: 600; font-size: 12.5px; background: rgba(148,163,184,.18); color: #cbd5e1; transition: background .3s, color .3s; }
.badge.s1 { background: rgba(251,146,60,.18); color: #fdba74; }
.badge.s2 { background: rgba(250,204,21,.16); color: #fde047; }
.badge.s3 { background: rgba(94,234,212,.18); color: #5eead4; }
.proglabel { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.proglabel b { font-variant-numeric: tabular-nums; }
.bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #fb923c, #facc15 45%, #5eead4); transition: width .25s; }
.energy { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 8px; }
.energy small { display: block; color: var(--muted); font-size: 11.5px; }
.energy .block { display: block; font-size: 12px; }
.energy b { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.2; display: inline-block; margin-right: 5px; }
.stats { margin: 8px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.stats div { border-top: 1px solid var(--line); padding-top: 5px; }
.stats dt { font-size: 11.5px; color: var(--muted); } .stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.ebars { display: grid; gap: 7px; }
.erow { display: grid; grid-template-columns: 96px 1fr 52px; gap: 8px; align-items: center; font-size: 12px; }
.erow .track { position: relative; height: 8px; background: rgba(255,255,255,.07); border-radius: 4px; overflow: hidden; }
.erow .track i { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.erow .track::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.3); }
.erow output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.chart { width: 100%; height: 150px; display: block; border-radius: 8px; background: rgba(0,0,0,.18); }
.chartkey { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.chartkey i { display: inline-block; width: 10px; height: 3px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }

/* learn */
details { border: 1px solid var(--line); border-radius: 11px; padding: 0 12px; margin-bottom: 8px; background: rgba(255,255,255,.025); }
summary { cursor: pointer; padding: 10px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--accent); font-size: 18px; line-height: 1; }
details[open] summary::after { content: "–"; }
details p, details li { color: #c5cfe6; font-size: 13px; } details ul, details ol { padding-left: 18px; margin: 0 0 10px; } details li { margin-bottom: 5px; }
details p { margin: 0 0 10px; }
.lvl { list-style: none; padding: 0 !important; }
.eq { text-align: center; padding: 6px; background: rgba(0,0,0,.2); border-radius: 8px; font-family: ui-serif, Georgia, serif; font-size: 13.5px !important; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 4px 0 2px; vertical-align: baseline; }
#structCard h3 { font-size: 16px; margin-bottom: 2px; }
#structCard .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
#structCard p { margin: 6px 0; font-size: 13px; color: #c5cfe6; }
#structCard .tip { border-left: 3px solid var(--accent); padding-left: 9px; }
.seq { font: 12.5px/1.7 ui-monospace, "SF Mono", Menlo, Consolas, monospace; word-break: break-all; margin-top: 8px; letter-spacing: 1px; }
.seq b { padding: 0 1px; border-radius: 3px; }
.seq .H { color: var(--hydro); } .seq .P { color: #99f6e4; } .seq .K { color: var(--pos); } .seq .D { color: var(--neg); }
.seq b.sel { background: rgba(255,255,255,.25); }

/* overlays */
#tooltip { position: fixed; z-index: 8; pointer-events: none; padding: 7px 10px; font-size: 12px; border-radius: 9px; background: rgba(8,12,26,.92); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.4); white-space: nowrap; }
#tooltip b { font-size: 13px; }
.termlabel { position: fixed; z-index: 3; left: 0; top: 0; pointer-events: none; font-weight: 700; font-size: 12px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(8,12,26,.8); border: 1px solid var(--line); margin: -11px 0 0 -11px; transition: opacity .2s; }
#labelN { color: #93c5fd; border-color: #93c5fd; } #labelC { color: #fca5a5; border-color: #fca5a5; }
#hint { position: fixed; z-index: 3; bottom: 18px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--muted); padding: 5px 12px; border-radius: 99px; background: rgba(8,12,26,.55); border: 1px solid var(--line); pointer-events: none; white-space: nowrap; transition: opacity .6s; }
#fps { position: fixed; right: 18px; top: 18px; font-size: 11px; color: var(--muted); z-index: 3; display: none; }
[hidden] { display: none !important; }

/* narrower screens: panels become drawers */
@media (max-width: 1100px) {
  :root { --lw: 270px; --rw: 300px; }
}
@media (max-width: 860px) {
  .mobile-only { display: inline-block; }
  .brand small { display: none; }
  .top-actions button { white-space: nowrap; padding: 6px 10px; }
  .panel { top: auto; bottom: 0; left: 0 !important; right: 0 !important; width: auto !important; max-height: 58vh; border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .3s; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .panel.open { transform: none; }
  #hint { display: none; }
  .tabs { top: -14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
