:root {
  --bg: #060a14; --panel: rgba(11, 17, 31, .76); --line: rgba(255, 255, 255, .1); --text: #e8eefc; --mut: #8d9bb7;
  --p: #35d0ff; --s: #ff4fa3; --l: #ffd24d; --accent: #6ea8ff; --good: #5df2a8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #0d1630, var(--bg) 70%); color: var(--text); }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
canvas#gl.drag { cursor: grabbing; }
canvas#gl.pick { cursor: pointer; }

.panel { background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 16px; }
h3 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--mut); display: flex; justify-content: space-between; align-items: baseline; }
h3 .hint { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 11px; color: var(--accent); }
.note { margin: 6px 0 0; font-size: 12px; line-height: 1.45; color: var(--mut); }
.note.small { font-size: 11px; }

/* top bar */
#top { position: fixed; top: 10px; left: 10px; right: 10px; height: 54px; display: flex; align-items: center; gap: 14px; padding: 6px 12px; z-index: 5;
  background: var(--panel); backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { display: block; font-size: 15px; white-space: nowrap; }
.brand small { color: var(--mut); font-size: 11px; white-space: nowrap; }
.logo { flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, #ff7a3d, #d6336c); box-shadow: 0 4px 16px rgba(255, 90, 60, .35); }
.chips { display: flex; gap: 8px; margin-left: auto; }
.chip { padding: 3px 12px; border-radius: 10px; background: rgba(255, 255, 255, .06); text-align: center; min-width: 74px; }
.chip.wide { min-width: 120px; }
.chip small { display: block; color: var(--mut); font-size: 9.5px; text-transform: uppercase; letter-spacing: .09em; }
.chip b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.clock b { color: var(--good); }
.mbtns { display: none; gap: 6px; }
.ghost { background: rgba(255, 255, 255, .07); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; transition: background .15s; }
.ghost:hover { background: rgba(255, 255, 255, .16); }
.primary { width: 100%; margin-top: 12px; padding: 11px 14px; font-weight: 700; border: 0; border-radius: 12px; color: #fff;
  background: linear-gradient(135deg, #ff7a3d, #d6336c); box-shadow: 0 6px 20px rgba(255, 90, 60, .3); transition: transform .12s, filter .15s; }
.primary:hover { filter: brightness(1.12); } .primary:active { transform: scale(.98); }

/* left controls */
#controls { position: fixed; left: 10px; top: 72px; bottom: 84px; width: 292px; overflow: auto; padding: 14px; z-index: 4; }
#controls section { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
#controls section:last-child { border: 0; margin: 0; padding: 0; }
select { width: 100%; padding: 9px 10px; border-radius: 10px; background: rgba(255, 255, 255, .07); border: 1px solid var(--line); }
select option { background: #101830; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; margin: 8px 0 0; }
.row output { font-weight: 700; font-variant-numeric: tabular-nums; }
.row input { grid-column: 1 / -1; }
.scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--mut); margin-top: 1px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 9px; background: linear-gradient(90deg, var(--accent), #b07bff); opacity: .7; }
input[type=range]::-moz-range-track { height: 5px; border-radius: 9px; background: linear-gradient(90deg, var(--accent), #b07bff); opacity: .7; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6.5px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 4px rgba(110, 168, 255, .3); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 4px rgba(110, 168, 255, .3); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tg { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 8px; border-radius: 9px; background: rgba(255, 255, 255, .05); cursor: pointer; user-select: none; }
.tg input { position: absolute; opacity: 0; pointer-events: none; }
.tg i { flex: none; width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--mut); transition: .15s; }
.tg input:checked + i { background: var(--accent); border-color: var(--accent); }
.tg.p input:checked + i { background: var(--p); border-color: var(--p); }
.tg.s input:checked + i { background: var(--s); border-color: var(--s); }
.tg.l input:checked + i { background: var(--l); border-color: var(--l); }
.tg input:focus-visible + i { outline: 2px solid #fff; outline-offset: 2px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; margin-top: 10px; padding: 3px; gap: 3px; border-radius: 11px; background: rgba(255, 255, 255, .06); }
.seg button { border: 0; border-radius: 8px; padding: 7px; background: transparent; color: var(--mut); font-size: 12.5px; }
.seg button.on { background: rgba(110, 168, 255, .25); color: #fff; }
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 12.5px; }
.facts dt { color: var(--mut); } .facts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* right side */
#side { position: fixed; right: 10px; top: 72px; bottom: 84px; width: 392px; display: flex; flex-direction: column; padding: 10px 12px 12px; z-index: 4; min-height: 0; }
#secWrap { position: relative; flex: none; width: min(100%, 300px, 36vh); aspect-ratio: 1; margin: 0 auto 8px; }
#sec { width: 100%; height: 100%; display: block; }
.legend { position: absolute; left: 0; bottom: 0; display: flex; flex-direction: column; gap: 2px; font-size: 10px; }
.legend span { padding: 1px 6px; border-radius: 6px; background: rgba(0, 0, 0, .45); }
.legend .p { color: var(--p); } .legend .s { color: var(--s); } .legend .l { color: var(--l); } .legend .sh { color: #ff8a80; }
.tabs { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 3px; border-radius: 11px; background: rgba(255, 255, 255, .06); margin-bottom: 8px; }
.tabs button { border: 0; background: transparent; color: var(--mut); border-radius: 8px; padding: 7px 2px; font-size: 12px; }
.tabs button.on { background: rgba(110, 168, 255, .25); color: #fff; }
.tabbody { display: none; flex: 1; min-height: 0; overflow: auto; }
.tabbody.on { display: block; }
#stTable, .mini { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#stTable th, .mini th { position: sticky; top: 0; background: #0e1527; text-align: right; color: var(--mut); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; padding: 5px 6px; }
#stTable th:first-child, .mini th:first-child { text-align: left; }
#stTable th.p { color: var(--p); } #stTable th.s { color: var(--s); } #stTable th.l { color: var(--l); }
#stTable td { padding: 5px 6px; text-align: right; border-top: 1px solid rgba(255, 255, 255, .05); transition: color .3s, background .3s; }
#stTable td:first-child { text-align: left; }
#stTable td small { display: block; color: var(--mut); font-size: 10px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stTable tr { cursor: pointer; } #stTable tr:hover { background: rgba(255, 255, 255, .06); }
#stTable tr.sel { background: rgba(110, 168, 255, .16); }
#stTable td.dim { color: var(--mut); opacity: .6; }
#stTable td.faint { opacity: .5; font-style: italic; }
#stTable td.tp.hit { color: var(--p); font-weight: 700; } #stTable td.ts.hit { color: var(--s); font-weight: 700; } #stTable td.tl.hit { color: var(--l); font-weight: 700; }
i.faint { opacity: .6; }
.mini td, .mini th { padding: 4px 5px; text-align: left; border-top: 1px solid rgba(255, 255, 255, .06); } .mini { margin: 6px 0; font-size: 11.5px; }
.seishead { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; font-size: 13px; } .seishead span { color: var(--mut); font-size: 11.5px; }
#seis, #tt { width: 100%; height: 190px; display: block; border-radius: 10px; background: rgba(0, 0, 0, .28); }
#tt { height: 240px; }
.learn { font-size: 13px; line-height: 1.55; color: #cdd7ee; }
.learn details { border-bottom: 1px solid var(--line); padding: 7px 2px; }
.learn summary { cursor: pointer; font-weight: 700; color: var(--text); padding: 3px 0; }
.learn p { margin: 6px 0; } .learn ul { margin: 6px 0; padding-left: 18px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; } .dot.p { background: var(--p); } .dot.s { background: var(--s); } .dot.l { background: var(--l); }

/* timeline */
#timeline { position: fixed; left: 10px; right: 10px; bottom: 10px; height: 64px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; z-index: 5; }
.round { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: linear-gradient(135deg, #6ea8ff, #8b5cf6); font-weight: 700; box-shadow: 0 4px 16px rgba(110, 120, 255, .4); }
.scrub { position: relative; flex: 1; min-width: 0; }
.scrub input { position: relative; z-index: 1; margin: 0; }
#marks { position: absolute; left: 9px; right: 9px; top: 0; bottom: 0; pointer-events: none; }
#marks i { position: absolute; top: 2px; bottom: 2px; width: 3px; margin-left: -1.5px; border-radius: 2px; opacity: .95; }
#marks i::after { content: attr(data-l); position: absolute; top: -13px; left: 50%; transform: translateX(-50%); font: 700 9.5px system-ui; font-style: normal; }
.speed { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mut); } .speed select { width: auto; padding: 6px 8px; }

/* overlays */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.lbl { position: absolute; left: 0; top: 0; padding: 1px 6px; border-radius: 6px; font-size: 11px; font-weight: 600; background: rgba(8, 12, 24, .72); border: 1px solid var(--line); white-space: nowrap; transform: translate(-50%, -150%); will-change: transform; }
.lbl.sel { border-color: var(--accent); background: rgba(40, 60, 120, .85); }
.lbl.epi { color: #ffb066; border-color: rgba(255, 140, 60, .6); }
#tip { position: fixed; z-index: 7; pointer-events: none; padding: 6px 9px; border-radius: 8px; font-size: 12px; line-height: 1.4; background: rgba(8, 12, 24, .92); border: 1px solid var(--line); opacity: 0; transition: opacity .12s; max-width: 220px; }
#tip.on { opacity: 1; }
#flash { position: fixed; inset: 0; z-index: 3; pointer-events: none; background: radial-gradient(circle, rgba(255, 220, 160, .9), rgba(255, 120, 60, .35) 60%, transparent); opacity: 0; }
#flash.go { animation: flash .9s ease-out; }
@keyframes flash { 0% { opacity: var(--fa, .5); } 100% { opacity: 0; } }
#hint { position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); z-index: 3; padding: 7px 14px; border-radius: 999px; font-size: 12px; color: var(--text); background: rgba(8, 12, 24, .8); border: 1px solid var(--line); transition: opacity .6s; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
#hint.off { opacity: 0; }
#noGL { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 20; text-align: center; padding: 20px; }

/* narrower screens: panels become sheets */
@media (max-width: 1100px) {
  .brand small, .chip.wide { display: none; }
  .mbtns { display: flex; margin-left: auto; }
  .chips { margin-left: 0; } .chip { min-width: 62px; padding: 3px 8px; }
  .sheet { position: fixed; left: 10px !important; right: 10px; top: auto !important; bottom: 84px; width: auto !important; height: min(50vh, 480px); transform: translateY(130%); transition: transform .28s ease; z-index: 6; }
  .sheet.open { transform: none; }
  #secWrap { width: min(100%, 230px, 28vh); }
  #hint { bottom: 86px; }
}
@media (max-width: 640px) {
  .brand b { font-size: 13px; } .logo { width: 30px; height: 30px; } .brand > div { display: none; }
  .chip small { font-size: 8.5px; } .chip b { font-size: 14px; } .chip.clock { display: none; }
  .speed { display: none; } #timeline { gap: 8px; padding: 8px 10px; }
  .mbtns .ghost { padding: 7px 9px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { #flash.go { animation: none; } .sheet { transition: none; } }
@media (max-height: 800px) and (max-width: 1100px) { #secWrap { width: min(100%, 170px, 24vh); margin-bottom: 4px; } }
@media (max-height: 760px) and (min-width: 1101px) { #secWrap { width: min(100%, 240px, 30vh); } }
