/* Theme: "Mission control" — retro-NASA instrument panel. Flat, outlined, no glow.
   Space Mono for labels and controls, Instrument Sans for reading text. */
:root {
  --ink: #0b1120;        /* page */
  --panel: #121a2b;      /* raised panels */
  --line: #2a3550;       /* hairlines */
  --line-2: #3a4766;     /* control outlines */
  --cream: #f3ead8;      /* text and primary outline */
  --muted: #9fb0c8;
  --orange: #ff6b35;     /* the one signal accent */
  --teal: #3fc1c9;       /* the horizon */
  --mono: "Space Mono", ui-monospace, Menlo, monospace;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
  --t: 220ms;                                   /* one duration for every transition… */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);       /* …and one curve */
}

/* Every element that appears or disappears uses these two (see setShown in main.js):
   fade + small slide in, and the same in reverse on the way out. */
.fx-in { animation: fxIn var(--t) var(--ease) both; }
.fx-out { animation: fxOut var(--t) var(--ease) both; pointer-events: none; }
@keyframes fxIn { from { opacity: 0; translate: 0 var(--fx-dy, -6px); } to { opacity: 1; translate: 0 0; } }
@keyframes fxOut { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 var(--fx-dy, -6px); } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--cream); overflow: hidden; }
body { font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; display: block; }

#shell {
  position: relative; height: 100dvh; display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 10px; max-width: 1800px; margin: 0 auto;
}

/* "glass" is kept as the class name for raised panels; in this theme they are solid. */
.glass { background: var(--panel); border: 1.5px solid var(--line-2); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.logo { width: 32px; height: 32px; flex: none; }
.brand h1 {
  margin: 0; font: 700 16px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand .tag {
  margin: 2px 0 0; font: 400 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.actions { display: flex; gap: 8px; flex: none; }

/* ---------- buttons ---------- */
.icon, .tool {
  cursor: pointer; color: var(--cream); background: transparent;
  border: 1.5px solid var(--line-2); border-radius: var(--r);
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease), color var(--t) var(--ease), transform 0.1s;
}
.icon:hover, .tool:hover { border-color: var(--cream); }
.icon:active, .tool:active { transform: scale(0.96); }
.icon { width: 42px; height: 42px; display: grid; place-items: center; }
.icon[aria-pressed="true"], .icon[aria-expanded="true"] { background: var(--cream); border-color: var(--cream); color: var(--ink); }
.icon.sm { width: 34px; height: 34px; border-radius: 8px; }
.icon.sm svg { width: 16px; height: 16px; }
.icon.q { font: 700 18px var(--mono); line-height: 1; }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.credit {
  position: absolute; right: 4px; bottom: 18px; margin: 0;
  font: 400 11px var(--mono); letter-spacing: 0.06em; color: var(--muted); opacity: 0.7; pointer-events: none;
}
@media (max-width: 700px) { .credit { position: static; text-align: center; font-size: 10px; margin-top: -4px; } }
#view { position: relative; flex: 1; min-height: 0; }
#view canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; --fx-dy: 0px;   /* views crossfade */
  transition: width var(--t) var(--ease), left var(--t) var(--ease), right var(--t) var(--ease);
}
#sky, #penrose { cursor: crosshair; touch-action: manipulation; }
#view canvas[hidden] { display: none; }

#hud {
  position: absolute; top: 4px; left: 4px; border-radius: 12px; padding: 10px 12px;
  display: grid; gap: 2px; font: 400 12.5px var(--mono); pointer-events: none;
}
#hud[hidden] { display: none; }
#hud div { display: grid; grid-template-columns: 58px 62px auto; align-items: baseline; gap: 8px; }
#hud .k { color: var(--muted); font-size: 12px; }   /* no uppercasing: τ and r꜀ are symbols */
#hud .v { color: var(--orange); font-weight: 700; text-align: right; }
#hud .u { color: var(--muted); font-size: 11px; }

#hint {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%);
  border-radius: var(--r); padding: 8px 14px; pointer-events: none;
  width: max-content; max-width: min(520px, calc(100% - 32px)); text-align: center; line-height: 1.45;
  font: 400 12px var(--mono); letter-spacing: 0.04em;
}
#hint[hidden] { display: none; }
#irBtn {
  position: absolute; right: 6px; bottom: 6px; width: auto; height: 38px; padding: 0 11px; gap: 6px;
  display: flex; align-items: center; font: 700 11.5px var(--mono); letter-spacing: 0.08em; --fx-dy: 6px;
}
#irBtn[hidden] { display: none; }
#irBtn svg { width: 19px; height: 19px; }
#hud:not([hidden]) ~ #hint { top: 140px; }   /* sit below the readouts when they are open */

#spectrum { flex: none; width: 100%; height: 66px; display: block; border-radius: var(--r); }
#spectrum[hidden] { display: none; }

.legend {
  position: absolute; left: 0; right: 0; bottom: 46px; pointer-events: none;
  list-style: none; margin: 0; padding: 2px 8px; display: flex; flex-wrap: wrap; gap: 4px 16px; --fx-dy: 6px;
  font: 400 11.5px var(--mono); color: var(--muted); justify-content: center; letter-spacing: 0.03em;
}
.legend[hidden] { display: none; }
.legend i { display: inline-block; width: 16px; height: 3px; margin-right: 7px; vertical-align: middle; border-radius: 2px; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); }
.legend i.dot { position: relative; width: 20px; }
.legend i.dot::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; translate: -50% -50%;
  border-radius: 50%; background: currentColor; box-shadow: 0 0 0 1.5px #0b1120;
}

/* ---------- toolbar ---------- */
.toolbar { flex: none; display: flex; align-items: center; gap: 8px; padding: 7px; border-radius: 14px; align-self: center; max-width: 100%; }
.tool {
  height: 44px; min-width: 44px; padding: 0 14px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border-color: var(--cream); font: 700 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
}
.tool[aria-pressed="true"] { background: var(--cream); color: var(--ink); }
#play { background: var(--orange); border-color: var(--orange); color: var(--ink); }
#play:hover { filter: brightness(1.08); }

/* Option groups: a cream selector slides to the chosen option (positioned by syncSeg in main.js). */
.seg { position: relative; display: flex; border: 1.5px solid var(--line-2); border-radius: var(--r); overflow: hidden; margin-left: 2px; }
.seg-thumb {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--cream); pointer-events: none;
  transition: transform var(--t) var(--ease), width var(--t) var(--ease);
}
.seg button {
  position: relative; z-index: 1; height: 41px; padding: 0 13px; border: 0; background: transparent; cursor: pointer;
  font: 700 11.5px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  transition: color var(--t) var(--ease);
}
.seg button:hover { color: var(--cream); }
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { color: var(--ink); }

#penZoom { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); white-space: nowrap; margin: 0; --fx-dy: 6px; }
#penZoom[hidden] { display: none; }
#penZoom button { height: 34px; padding: 0 16px; }

/* ---------- sheets (dropdowns) ---------- */
.sheet {
  position: absolute; z-index: 20; border-radius: 14px; padding: 14px 16px 16px;
  top: calc(max(10px, env(safe-area-inset-top)) + 56px);
  right: max(12px, env(safe-area-inset-right));
  width: min(400px, calc(100vw - 24px));
  max-height: calc(100dvh - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain;
}
.sheet[hidden] { display: none; }
.sheet > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet h2 { margin: 0; font: 700 12px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--teal); }

.field { display: block; margin: 0 0 14px; }
.field > span { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font: 400 11.5px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field output { color: var(--orange); font: 700 12px var(--mono); text-transform: none; letter-spacing: 0; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 4px 0 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--orange); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--cream); border: 0; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--cream); border: 0; }

.switches { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 6px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 38px; font: 400 11.5px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { flex: none; width: 36px; height: 20px; border-radius: 10px; border: 1.5px solid var(--line-2); position: relative; transition: border-color var(--t) var(--ease); }
.switch span::after { content: ""; position: absolute; top: 2.5px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--line-2); transition: transform var(--t) var(--ease), background var(--t) var(--ease); }
.switch input:checked + span { border-color: var(--cream); }
.switch input:checked + span::after { transform: translateX(15px); background: var(--orange); }
.switch input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }

#beacons { font: 400 12px var(--mono); display: grid; gap: 6px; }
#beacons .b { display: flex; flex-wrap: wrap; gap: 3px 12px; align-items: center; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); }
#beacons .b b { color: var(--cream); }
#beacons .sw { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
#beacons .gone { color: var(--muted); }
.muted { color: var(--muted); margin: 0; }

.notes p, .notes li { margin: 0 0 11px; color: #d9d2c3; font-size: 15px; line-height: 1.6; }
.notes ul { margin: 0; padding-left: 20px; }
.notes h3 { margin: 18px 0 6px; font: 700 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--orange); }
.notes h3:first-of-type { margin-top: 0; }
.notes b { color: var(--cream); }
.notes .katex { font-size: 1.06em; color: var(--cream); }
.notes .katex-display { margin: 10px 0 14px; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

@media (max-width: 560px) { .brand .tag { display: none; } }
@media (max-width: 420px) {
  .brand { gap: 8px; }
  .logo { width: 26px; height: 26px; }
  .brand h1 { font-size: 14px; letter-spacing: 0.03em; }
  .actions { gap: 6px; }
  .icon { width: 40px; height: 40px; }
  .toolbar { gap: 6px; padding: 6px; }
  .tool { padding: 0 11px; height: 44px; min-width: 44px; }
  .seg button { padding: 0 10px; }
  #spectrum { height: 58px; }
}
@media (max-width: 370px) { .actions { gap: 4px; } .icon { width: 37px; height: 37px; } }
@media (max-width: 360px) { .tool span { display: none; } }

.wide-only { display: none; }
@media (min-width: 1000px) {
  .seg .wide-only { display: block; }
  #view.both #sky { right: 50%; width: 50%; }
  #view.both #penrose { left: 50%; width: 50%; }
  #view.both #hint { left: 25%; }
  #view.both #legend { left: 50%; }
  #view.both #irBtn { right: calc(50% + 6px); }
  #view.both #penZoom { left: 75%; }
  #view.both::after { content: ""; position: absolute; top: 8%; bottom: 8%; left: 50%; width: 1.5px; background: var(--line); }
  #aboutSheet { width: min(580px, calc(100vw - 24px)); }
}
@media (prefers-reduced-motion: reduce) { .fx-in, .fx-out { animation-duration: 0.01s; } }
