:root {
  --bg: #04060c; --ink: #e8eef8; --muted: #93a3bd; --rule: rgba(150, 175, 220, 0.16); --card: rgba(12, 18, 32, 0.82);
  --accent: #5fd4ff; --accent2: #ffb347; --good: #67e8a5; --warn: #ffcf5a; --bad: #ff6b6b;
  --panel-w: 360px; --top-h: 52px; --sheet-h: 44vh;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); overflow: hidden; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#stage { position: fixed; left: 0; top: 0; right: 0; bottom: 0; }
body.in-lab #stage { top: calc(var(--top-h) + var(--sat)); right: calc(var(--panel-w) + var(--sar)); }
#gl { display: block; width: 100%; height: 100%; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; transform: translate(-50%, -130%); padding: 2px 7px; border-radius: 999px; font: 600 11px/1.3 var(--sans); letter-spacing: .02em; background: rgba(5, 9, 18, .62); border: 1px solid var(--rule); color: var(--ink); white-space: nowrap; backdrop-filter: blur(4px); }
.lbl.accent { color: var(--accent); } .lbl.warm { color: var(--accent2); } .lbl.bad { color: var(--bad); border-color: rgba(255,107,107,.5); } .lbl.good { color: var(--good); }

/* top bar */
#topbar { position: fixed; z-index: 20; left: 0; right: 0; top: 0; height: calc(var(--top-h) + var(--sat)); padding: var(--sat) calc(10px + var(--sar)) 0 calc(10px + var(--sal)); display: flex; align-items: center; gap: 10px; background: linear-gradient(180deg, rgba(4,6,12,.96), rgba(4,6,12,.82)); border-bottom: 1px solid var(--rule); }
#topbar[hidden] { display: none; }
.brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.brand span { color: var(--accent); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lab-tabs { display: flex; gap: 4px; margin-left: 12px; overflow-x: auto; scrollbar-width: none; }
#lab-tabs button { border: 1px solid transparent; background: none; padding: 7px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; white-space: nowrap; min-height: 36px; }
#lab-tabs button.on { color: var(--ink); background: rgba(95, 212, 255, .12); border-color: rgba(95,212,255,.3); }
#lab-tabs button i { font-style: normal; font-family: var(--mono); color: var(--accent); margin-right: 5px; font-size: 11px; }
.tb-right { margin-left: auto; display: flex; gap: 6px; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--rule); background: rgba(255,255,255,.03); cursor: pointer; display: grid; place-items: center; font-size: 16px; flex: none; }
.iconbtn:hover { background: rgba(95,212,255,.12); }
.iconbtn.off { color: var(--muted); text-decoration: line-through; }

/* side panel (landscape) / bottom sheet (portrait) */
#panel { position: fixed; z-index: 15; top: calc(var(--top-h) + var(--sat)); right: 0; bottom: 0; width: calc(var(--panel-w) + var(--sar)); padding-right: var(--sar); background: var(--card); border-left: 1px solid var(--rule); backdrop-filter: blur(10px); display: flex; flex-direction: column; }
#panel[hidden] { display: none; }
#sheet-handle { display: none; }
#panel-body { overflow-y: auto; padding: 12px 14px calc(18px + var(--sab)); flex: 1; scrollbar-width: thin; }
.lab-head .kicker { color: var(--accent); }
.lab-head h2 { margin: 2px 0 4px; font-size: 20px; line-height: 1.15; }
.lab-head p { margin: 0 0 6px; color: var(--muted); }
.kicker { font: 600 11px/1.2 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.psec { border-top: 1px solid var(--rule); padding: 10px 0 8px; }
.psec h3 { margin: 0 0 8px; font: 650 11px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.note { color: var(--muted); margin: 4px 0 8px; font-size: 13px; }
.note b, .note strong { color: var(--ink); }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; margin: 6px 0 10px; }
.slider .lab { font-size: 13px; }
.slider output { font: 600 12px var(--mono); color: var(--accent); }
.slider input { grid-column: 1 / -1; width: 100%; height: 28px; accent-color: var(--accent); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip { border: 1px solid var(--rule); background: rgba(255,255,255,.03); border-radius: 999px; padding: 6px 11px; cursor: pointer; font-size: 12.5px; min-height: 34px; }
.chip.on { background: rgba(95,212,255,.16); border-color: rgba(95,212,255,.55); color: #fff; }
.btn { border: 1px solid var(--rule); background: rgba(255,255,255,.05); border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: rgba(95,212,255,.14); }
.btn.primary { background: linear-gradient(180deg, #2bb6ea, #1386c0); border-color: #4cc9f5; color: #031018; font-weight: 700; }
.btn.warm { background: rgba(255,179,71,.14); border-color: rgba(255,179,71,.5); }
.btn.ghost { background: none; }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.btnrow .btn { flex: 1 1 auto; }
.toggle { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; font-size: 13px; min-height: 30px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.rogrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ro { background: rgba(255,255,255,.035); border: 1px solid var(--rule); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; min-width: 0; }
.ro > span:first-child { font-size: 11px; color: var(--muted); line-height: 1.2; }
.ro .rv { font: 650 15px/1.3 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ro .rv small { font-weight: 400; color: var(--muted); font-size: 11px; }
.ro.wide { grid-column: 1 / -1; }
.ro.good .rv strong { color: var(--good); } .ro.bad .rv strong { color: var(--bad); } .ro.warn .rv strong { color: var(--warn); }
.chartwrap { margin: 6px 0; }
.chart { width: 100%; display: block; border-radius: 8px; background: rgba(0,0,0,.25); border: 1px solid var(--rule); touch-action: none; cursor: ew-resize; }
.objectives { list-style: none; margin: 0; padding: 0; counter-reset: o; }
.objectives li { position: relative; padding: 6px 8px 6px 32px; margin: 4px 0; border-radius: 8px; border: 1px solid var(--rule); background: rgba(255,255,255,.025); counter-increment: o; }
.objectives li::before { content: counter(o); position: absolute; left: 8px; top: 7px; width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--muted); font: 600 10px/16px var(--mono); text-align: center; color: var(--muted); }
.objectives li.done { border-color: rgba(103,232,165,.45); background: rgba(103,232,165,.07); }
.objectives li.done::before { content: "✓"; background: var(--good); color: #032; border-color: var(--good); }
.objectives li.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(103,232,165,.8); } 100% { box-shadow: 0 0 0 14px rgba(103,232,165,0); } }
.objectives b { display: block; font-size: 13px; } .objectives span { display: block; font-size: 12px; color: var(--muted); }
.whatif { border: 1px dashed rgba(255,179,71,.45); border-radius: 10px; padding: 8px 10px; background: rgba(255,179,71,.05); margin: 6px 0; }
.whatif h4 { margin: 0 0 4px; font-size: 12px; color: var(--accent2); letter-spacing: .06em; text-transform: uppercase; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 4px 0; }
.legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 13px; margin: 4px 0; }
details.more p { color: var(--muted); font-size: 13px; }

/* screens */
.screen { position: fixed; inset: 0; z-index: 40; display: none; align-items: flex-start; justify-content: center; padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal)); background: radial-gradient(ellipse at 50% 40%, rgba(10,20,40,.55), rgba(2,3,8,.92)); overflow-y: auto; }
.screen.on { display: flex; }
.screen > * { margin: auto 0; }
.lbl.below { transform: translate(-50%, 40%); }
#screen-start, #screen-menu { background: radial-gradient(ellipse at 50% 100%, rgba(4,10,24,.2), rgba(2,3,8,.72)); }
.loadbox, .startbox { text-align: center; max-width: 620px; }
.loadbox h1, .startbox h1 { font-size: clamp(30px, 7vw, 60px); line-height: 1; margin: 10px 0 14px; letter-spacing: -.01em; }
.startbox h1 span { display: block; font-size: .42em; letter-spacing: .32em; text-transform: uppercase; color: var(--accent); margin-top: 10px; font-weight: 600; }
.startbox p { color: #c3cee0; font-size: 16px; }
.startbox .btn { margin: 6px; }
.hint { color: var(--muted) !important; font-size: 13px !important; margin-top: 18px; }
.bar { height: 4px; background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden; margin-top: 18px; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.menu { width: min(1100px, 100%); }
.menu header h2 { font-size: clamp(24px, 4vw, 36px); margin: 4px 0; }
.menu header p { color: var(--muted); max-width: 640px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 16px 0; }
.card { text-align: left; border: 1px solid var(--rule); background: var(--card); border-radius: 14px; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-height: 170px; transition: transform .15s, border-color .15s; }
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: rgba(95,212,255,.6); }
.card .num { font: 700 12px var(--mono); color: var(--accent); }
.card h3 { margin: 0; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; flex: 1; }
.card .prog { font: 600 11px var(--mono); color: var(--good); }
.menu-foot { display: flex; flex-wrap: wrap; gap: 8px; }
.panelbox { width: min(520px, 100%); background: var(--card); border: 1px solid var(--rule); border-radius: 16px; padding: 18px 20px; max-height: 100%; overflow-y: auto; }
.panelbox.wide { width: min(760px, 100%); }
.panelbox h2 { margin-top: 0; }
.setrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.setrow input[type=range] { width: 50%; accent-color: var(--accent); }
.setrow select { background: #0d1424; border: 1px solid var(--rule); border-radius: 8px; padding: 6px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.keys { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys td { border-bottom: 1px solid var(--rule); padding: 6px 4px; vertical-align: top; }
.keys td:first-child { white-space: nowrap; font-weight: 650; padding-right: 12px; }
#about-body p, #help-body p { color: #c3cee0; }
#about-body a { color: var(--accent); }
#about-body li { margin: 4px 0; color: #c3cee0; }

/* cutscene */
#caption { position: fixed; z-index: 30; left: 50%; bottom: calc(9vh + var(--sab)); transform: translateX(-50%); width: min(760px, calc(100% - 32px)); text-align: center; pointer-events: none; opacity: 0; transition: opacity .6s; text-shadow: 0 2px 12px #000, 0 0 2px #000; }
#caption.on { opacity: 1; }
#caption .t { font: 600 12px/1.2 var(--mono); letter-spacing: .18em; color: var(--accent2); text-transform: uppercase; }
#caption .m { font-size: clamp(17px, 2.6vw, 26px); line-height: 1.3; margin-top: 6px; }
#caption .s { color: #b9c6da; font-size: clamp(13px, 1.6vw, 15px); margin-top: 6px; }
#caption.title .m { font-size: clamp(34px, 7vw, 72px); font-weight: 750; letter-spacing: -.01em; }
#skip { position: fixed; z-index: 31; right: calc(14px + var(--sar)); bottom: calc(14px + var(--sab)); border: 1px solid var(--rule); background: rgba(4,6,12,.6); border-radius: 999px; padding: 10px 16px; cursor: pointer; min-height: 44px; }
#skip[hidden] { display: none; }
#toast { position: fixed; z-index: 50; left: 50%; top: calc(var(--top-h) + var(--sat) + 12px); transform: translate(-50%, -20px); opacity: 0; pointer-events: none; transition: all .35s; background: rgba(8, 28, 20, .92); border: 1px solid rgba(103,232,165,.6); color: #dfffee; padding: 10px 16px; border-radius: 12px; max-width: min(520px, calc(100vw - 24px)); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast b { display: block; } #toast span { font-size: 13px; color: #b6e9cf; }
body.in-lab #toast { left: calc((100% - var(--panel-w)) / 2); }

/* ---------- portrait phones & narrow windows: bottom sheet ---------- */
@media (orientation: portrait), (max-width: 720px) and (min-height: 520px) {
  :root { --top-h: 50px; }
  body.in-lab #stage { right: 0; bottom: calc(var(--sheet-h) + var(--sab)); }
  body.in-lab.sheet-min #stage { bottom: calc(64px + var(--sab)); }
  #panel { top: auto; left: 0; right: 0; width: auto; height: calc(var(--sheet-h) + var(--sab)); border-left: 0; border-top: 1px solid var(--rule); border-radius: 16px 16px 0 0; padding-right: 0; }
  body.sheet-min #panel { height: calc(64px + var(--sab)); }
  #sheet-handle { display: block; flex: none; height: 22px; border: 0; background: none; cursor: pointer; padding: 0; }
  #sheet-handle span { display: block; width: 44px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.3); margin: 8px auto; }
  #panel-body { padding-top: 0; }
  #lab-tabs { display: none; }
  body.in-lab #toast { left: 50%; }
  #caption { bottom: calc(14vh + var(--sab)); }
}
/* ---------- landscape phones (short viewport) ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --top-h: 42px; --panel-w: 300px; }
  html, body { font-size: 13px; }
  .iconbtn { width: 34px; height: 34px; font-size: 14px; }
  #lab-tabs button { padding: 4px 8px; min-height: 30px; font-size: 12px; }
  .brand span { display: none; }
  .lab-head h2 { font-size: 16px; }
  .lab-head p { display: none; }
  .slider { margin: 2px 0 6px; } .slider input { height: 24px; }
  .ro .rv { font-size: 13px; }
  .chip { min-height: 30px; padding: 4px 9px; }
  .btn { min-height: 34px; padding: 6px 10px; }
  .startbox h1 { font-size: 34px; } .startbox p { font-size: 14px; }
  .card { min-height: 120px; }
  #caption { bottom: calc(5vh + var(--sab)); } #caption .m { font-size: 16px; } #caption.title .m { font-size: 34px; }
}
@media (max-width: 1680px) { #lab-tabs button span { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* the Sun view overlay */
#sunview { position: fixed; z-index: 35; left: calc(16px + var(--sal, 0px)); bottom: calc(16px + var(--sab)); width: min(380px, calc(100vw - 32px)); background: rgba(10, 8, 6, .78); border: 1px solid rgba(255, 196, 120, .45); border-radius: 14px; padding: 12px 14px; color: #ffe9cf; backdrop-filter: blur(8px); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#sunview[hidden] { display: none; }
#sunview .sv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#sunview .iconbtn.sm { width: 32px; height: 32px; font-size: 13px; }
#sunview .sv-clock { font: 600 13px/1.4 var(--mono, ui-monospace, monospace); color: #ffc98a; margin: 4px 0 8px; min-height: 2.8em; }
#sunview .sv-modes { display: flex; flex-wrap: wrap; gap: 6px; }
#sunview .sv-modes button { border: 1px solid rgba(255, 196, 120, .4); background: rgba(255,255,255,.04); color: inherit; border-radius: 999px; padding: 6px 11px; font-size: 13px; cursor: pointer; min-height: 32px; }
#sunview .sv-modes button[aria-checked="true"] { background: rgba(255, 170, 80, .28); border-color: #ffb46a; }
#sunview .sv-note { font-size: 12.5px; line-height: 1.45; color: #e9cfae; margin: 8px 0 0; }
#btn-sun[aria-pressed="true"] { background: rgba(255, 170, 80, .25); border-color: #ffb46a; }
@media (orientation: portrait) and (max-width: 760px) {
  #sunview { left: 12px; right: 12px; width: auto; top: calc(var(--top-h) + var(--sat) + 10px); bottom: auto; padding: 10px 12px; }
  #sunview .sv-note { display: none; }
}
@media (max-height: 460px) {
  #sunview { width: min(330px, 46vw); padding: 8px 10px; }
  #sunview .sv-note { display: none; }
  #sunview .sv-clock { min-height: 0; margin: 2px 0 6px; }
}
