:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #E6E9ED;
  --panel: #F4F5F7;
  --ink: #1C2733;
  --muted: #5A6776;
  --rule: #C7CED6;
  --accent: #27588A;
  --accent-ink: #FFFFFF;
  --plate: #0E1A2A;
  --warn: #9A4A12;
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111821; --panel: #18212C; --ink: #E3E8EE; --muted: #8B98A7;
    --rule: #2B3746; --accent: #7EA6D4; --accent-ink: #0F1822; --plate: #050A12; --warn: #E0A06A;
  }
}
:root[data-theme="dark"] {
  --bg: #111821; --panel: #18212C; --ink: #E3E8EE; --muted: #8B98A7;
  --rule: #2B3746; --accent: #7EA6D4; --accent-ink: #0F1822; --plate: #050A12; --warn: #E0A06A;
}
*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.app {
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh; max-width: 1400px; margin: 0 auto;
}
aside {
  background: var(--panel); border-right: 1px solid var(--rule);
  padding: 20px 20px 24px; display: flex; flex-direction: column; gap: 14px;
}
h1 {
  margin: 0; font-size: 28px; line-height: 1.05; font-weight: 780;
  font-stretch: 118%; letter-spacing: -0.01em;
}
.lede { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }
.rule-eq { font-style: italic; color: var(--ink); white-space: nowrap; }
label, .lbl { font-size: 13px; color: var(--muted); font-stretch: 90%; }
select, input[type="text"] {
  width: 100%; font: inherit; font-size: 14.5px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--rule); border-radius: 3px;
  padding: 6px 8px;
}
select { padding-right: 4px; }
input.adjusted { border-color: var(--warn); }
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; align-items: start;
}
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field .hint { font-size: 11.5px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
button {
  font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer;
  border-radius: 3px; padding: 8px 12px; border: 1px solid var(--rule);
  background: var(--bg); color: var(--ink);
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 8px; }
.actions .primary { flex: 1; }
.progress { display: flex; flex-direction: column; gap: 5px; }
.bar { height: 6px; background: var(--rule); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); }
.status { font-size: 12.5px; color: var(--muted); min-height: 1.4em; }
.status.warn { color: var(--warn); }

main { padding: 22px 26px 28px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage {
  position: relative; background: var(--plate); border-radius: 4px;
  width: min(100%, calc(100vh - 150px)); min-width: 260px; aspect-ratio: 1 / 1;
  align-self: center; overflow: hidden;
}
#view, #gl { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.stage.torus { background: #000; }
.stage.pair { aspect-ratio: 2 / 1; width: min(100%, var(--pair-w, 560px)); }
#gl { cursor: grab; touch-action: none; }
#gl.dragging { cursor: grabbing; }
.view3d { width: min(100%, calc(100vh - 150px)); min-width: 260px; align-self: center;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; align-items: end; }
.view3d .field input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; }
.view3d .val { color: var(--ink); }
.view3d .checks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 22px; }
.view3d .note { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); margin: 0; }
.stamp {
  position: absolute; left: 10px; top: 8px; color: #fff; font-size: 13px;
  text-shadow: 0 1px 2px rgba(0,0,0,.7); pointer-events: none; font-stretch: 90%;
}
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #C9D6E6; font-size: 15px; text-align: center; padding: 20px;
}
.transport {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  width: min(100%, calc(100vh - 150px)); min-width: 260px; align-self: center;
}
.transport input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.transport select { width: auto; }
.readout { font-size: 13px; color: var(--muted); min-width: 9ch; text-align: right; }
.meta { font-size: 12.5px; color: var(--muted); width: min(100%, calc(100vh - 150px)); align-self: center; }
.hunt { width: min(100%, calc(100vh - 150px)); min-width: 260px; align-self: center; border-top: 1px solid var(--rule); padding-top: 16px; margin-top: 6px; display: flex; flex-direction: column; gap: 10px; }
.hunt h2 { margin: 0; font-size: 19px; font-weight: 720; font-stretch: 112%; }
.hunt p { margin: 0; font-size: 13px; color: var(--muted); max-width: 70ch; }
.hunt-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.hunt-controls .field { width: 110px; }
.hunt-controls .check { padding-bottom: 7px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.thumb { padding: 0; border: 1px solid var(--rule); background: var(--panel); border-radius: 3px; overflow: hidden; text-align: left; font-weight: 400; }
.thumb canvas { display: block; width: 100%; aspect-ratio: 1 / 1; image-rendering: pixelated; }
.thumb span { display: block; padding: 5px 7px 6px; font-size: 12px; line-height: 1.3; color: var(--ink); }
.thumb span b { font-weight: 650; }
.thumb.hit { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  aside { border-right: 0; border-top: 1px solid var(--rule); order: 2; }
  main { order: 1; }
  main { padding: 16px 14px 24px; }
  .stage, .transport, .meta { width: 100%; }
}
