/* Dark theme overhaul -- "black background with our active traces/cursors
   being the most vibrant and engaging visual element." Ring hues (given =
   yellow, received = blue, made = green) are law-declared (00-laws.md /
   lexicon) and untouched in identity -- only pushed to saturated/luminous
   variants here so they read as bright, moving foreground against a dark
   field, rather than the pastel washes that worked on white. */
:root {
  --bg: #0b0b0e;
  --bg-panel: #17171d;
  --bg-input: #1c1c24;
  --border: #34343e;
  --border-soft: #262630;
  --text: #d9d9e0;
  --text-dim: #8d8d98;
  --text-faint: #5c5c68;
  --accent-given: #ffcf3d;
  --accent-received: #34b3ff;
  --accent-made: #3ee87a;
  --danger: #ff5b52;
  --warn-bg: #2a1c0d;
  --warn-border: #7a4a12;
  --warn-text: #e3a25a;
  --focus: #34b3ff;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px;
}
h1 { font-size: 20px; margin: 0 0 16px; color: var(--text); }
.sub { font-weight: normal; font-size: 13px; color: var(--text-dim); }

.layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
}

/* position: sticky removed here -- a real bug found while making the
   wheel bigger, not a stylistic choice. .wheel-frame is now tall enough
   (canvas + legend) to exceed a typical viewport height in advanced
   mode, and a sticky element that tall visually overlaps/intercepts
   clicks meant for whatever page content (e.g. the keyboard section
   below .layout) has scrolled into the same screen region -- confirmed
   directly: the on-screen keyboard's own click-to-insert broke under
   Playwright with "canvas#wheel intercepts pointer events" until this
   was removed. Sticky's own remaining benefit was marginal anyway --
   .panel already scrolls WITHIN itself (its own overflow-y:auto), so the
   wheel staying visible while browsing panel content never depended on
   page-level stickiness in the normal (unwrapped) desktop layout this
   sizes for. */
.wheel-frame {
  flex: 0 0 auto;
}

/* "Make the orphograph display itself larger, it's the focal point of our
   whole build." A real CSS size (was previously undefined -- the canvas
   just rendered at its bare width="700" height="700" HTML attributes,
   with nothing to make it bigger or responsive). Floor matches today's
   size exactly (no regression on a small window); ceiling is ~50%
   bigger. Sized off viewport HEIGHT, not width or vmin -- this layout's
   width already has slack (.panel can flex down to 480px, and .layout
   wraps if it doesn't fit), so height is the real constraint on a
   typical wide browser window; vmin would be dominated by that same
   height on any wide-than-tall window anyway, but bottoms out at the
   700px floor far too easily (measured: 60vmin on a 1600x1000 viewport
   is only 600px, already below the floor). aspect-ratio keeps it square
   so main.js's ResizeObserver always reports equal width/height to
   WheelView.resize(). The canvas's own JS-driven backing-store size
   (see view.js's resize()) is what actually determines drawing
   resolution/crispness -- this CSS only sets the on-screen box size. */
#wheel {
  display: block;
  width: clamp(700px, 85vh, 1050px);
  aspect-ratio: 1;
}

/* Capped, not left to fill .wheel-frame's own (now much wider, up to
   1050px) width -- a real regression found while making the wheel
   bigger: an uncapped 8-column grid stretching to match the wheel's new
   width ballooned each of the 39 legend cells to ~95px+ (real
   letterforms don't need to be anywhere near that big for a quick-
   reference key), pushing .wheel-frame's total height (canvas + this
   grid) well past a typical viewport height and causing its own
   position:sticky to visually overlap the keyboard section below. A
   capped column width keeps this a compact reference strip regardless
   of how big the wheel itself gets. */
.legend-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 60px));
  gap: 3px;
  margin-top: 10px;
}
.legend-key {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 13px;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom: 3px solid var(--accent, var(--border));
  border-radius: 3px;
  background: var(--bg-panel);
  cursor: pointer;
  transition: background 120ms, box-shadow 120ms;
}
.legend-key:hover { background: #202028; }
.legend-key.legend-flash {
  background: #4a3f10;
  box-shadow: 0 0 0 2px var(--accent-given), 0 0 10px 1px var(--accent-given);
}

.timbre-panel {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--bg-panel);
}
.timbre-panel + .timbre-panel { margin-top: 8px; }
.timbre-panel summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
}
.timbre-presets {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-soft);
}
.timbre-presets select,
.timbre-presets button { font-size: 11px; padding: 3px 8px; }
.timbre-grid {
  display: grid;
  /* Was a fixed 2 columns regardless of the panel's own actual width --
     squeezed a slider+number row into ~200px inside the old 420px cap.
     auto-fit lets the SAME markup lay out as 2, 3, or 4+ columns
     depending on how much width .panel actually has right now, so widening
     the panel automatically shortens (and un-scrolls) the parameter list
     instead of just adding blank margin. */
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px 14px;
  margin-top: 10px;
}
.timbre-group-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  margin-top: 6px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 2px;
}
.timbre-grid .timbre-group-label:first-child { margin-top: 0; }
.timbre-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--text-dim);
}
.timbre-grid .rw { display: flex; gap: 6px; align-items: center; }
.timbre-grid input:disabled { opacity: 0.4; cursor: not-allowed; }
.timbre-grid input[type="range"] { flex: 1; min-width: 0; }
.timbre-grid input[type="number"] {
  width: 62px;
  font-size: 11px;
  padding: 2px 4px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Mixer meters -- see mixMeterLevels (synth.js) / drawMixMeters (main.js).
   Plain width-scaled fills rather than a canvas, since five small bars
   updated once a frame need nothing heavier. */
.mix-meters {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mix-meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.mix-meter-label {
  width: 66px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 10px;
  color: var(--text-faint);
}
.mix-meter-track {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.mix-meter-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent-received);
  transition: width 0.05s linear;
}
.mix-meter-clip {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  opacity: 0.35;
}
.mix-meter-clip.clipping {
  color: var(--danger);
  opacity: 1;
}

canvas {
  background: #08080b;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 320px;
  /* Was a hard 420px cap regardless of screen size -- "a lot of empty
     screen real estate... before having to scroll horizontally or
     vertically." Grows to use whatever's actually available (up to a
     sane reading-width ceiling so a single label+slider row doesn't
     stretch absurdly wide on an ultrawide monitor) instead of staying
     pinned narrow next to unused black space. */
  flex: 1 1 480px;
  max-width: 1600px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding-right: 4px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

input[type="text"] {
  font-size: 15px;
  padding: 6px 8px;
  font-family: monospace;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Live invalid-character preview: a real, editable input with its own
   text made transparent (only its caret stays visible) sitting in front
   of a backdrop div that renders the SAME text with unrecognized
   characters colored red. Padding/font here must stay byte-identical to
   input[type="text"] above, or the two layers drift out of alignment. */
.input-highlight-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-input);
}
.input-backdrop {
  position: absolute;
  inset: 0;
  padding: 6px 8px;
  font-size: 15px;
  font-family: monospace;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  color: var(--text);
}
/* The phrase input specifically (not every input[type="text"] on the
   page, e.g. the scale-text field elsewhere) -- much larger than a
   normal text field so its own pixel-font glyphs get real resolution.
   Measured, not guessed: at 15px, one monospace character cell is only
   ~8px wide -- nowhere near enough to render a 16-column pixel grid
   without crushing multiple columns into the same screen pixel ("the F
   is illegible"). 36px measures ~20px per cell, comfortably above the
   16px (one real pixel per grid column) floor "at least 1-to-1 pixel
   display" asks for. Both #input AND its backdrop must change together
   -- see the comment above on why they have to stay byte-identical. */
#input, .input-backdrop {
  font-size: 36px;
}
.input-backdrop .invalid-char {
  color: var(--danger);
  font-weight: 700;
}
/* Pixel-font glyph slot -- see main.js's updateInputBackdrop. Width is
   set inline per-token (N ch, matching that token's own character count
   in the real, invisible input beneath) so the backdrop's cumulative
   width never drifts from the real input's -- the one thing this layout
   cannot get wrong, since the real input's caret alignment depends on
   it. display:inline-block/line-height:0 keep the SVG from adding its
   own extra line-box height on top of the surrounding monospace text. */
.pixel-glyph-slot {
  display: inline-block;
  height: 1.1em;
  line-height: 0;
  vertical-align: middle;
  overflow: hidden;
}
/* Fills the slot's exact box (width fixed per-token in ch units by
   main.js, height fixed above) rather than staying square -- see
   pixelGlyphSVGMarkup's own comment on preserveAspectRatio="none" for
   why a single-character token's glyph is deliberately narrow/tall
   instead of getting cropped. */
.pixel-glyph-slot svg {
  display: block;
  width: 100%;
  height: 100%;
}
.input-highlight-wrap input#input {
  position: relative;
  display: block;
  width: 100%;
  box-sizing: border-box;
  border: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
}
.input-highlight-wrap input#input:focus {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
}

input[type="range"] { width: 100%; accent-color: var(--accent-received); }

select,
button {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

select#phrase-select {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  padding: 5px 6px;
  border-radius: 3px;
}

.ring-modes label.inline {
  gap: 6px;
  font-weight: 600;
  color: var(--text-dim);
}
.ring-modes select {
  font-weight: normal;
  padding: 3px 4px;
  border-radius: 3px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* "The most limited UI available... keep the levers to a minimum when I
   let other people test it." Default (no `advanced-mode` class on body):
   every parameter lever/readout/settings row is hidden entirely, not just
   visually de-emphasized -- play, stop, the phrase input, and the wheel's
   own compact key-square grid are the only surviving controls. Revealed
   by a hidden hotkey (see main.js) that adds `advanced-mode` to body;
   `!important` here only to reliably win over `<details>`'s own default
   display regardless of DOM position, not to fight anything else. */
body:not(.advanced-mode) .advanced-only { display: none !important; }

.response-procession { display: flex; flex-direction: column; gap: 6px; }
.response-step-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
}
.response-step-row .step-index { color: var(--text-faint); width: 1.4em; }
.response-step-row select,
.response-step-row input[type="number"] { font-size: 12px; padding: 2px 4px; background: var(--bg-input); color: var(--text); border: 1px solid var(--border); border-radius: 3px; }
.response-step-row input[type="number"] { width: 48px; }
.response-step-row label.inline { font-size: 12px; color: var(--text-dim); }
.response-step-row .step-spacer { flex: 1; }
.response-step-row button { padding: 2px 8px; font-size: 11px; }

button {
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: #24242c; }

.status { font-size: 12px; color: var(--text-dim); }

.unknown-warning {
  margin-top: 6px;
  font-size: 12px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 4px;
  padding: 6px 8px;
}

.readout {
  font-size: 13px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
  color: var(--text-dim);
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 4px;
  width: auto;
}

.loop-log {
  max-height: 120px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Pictographic keyboard -- an "unrolled" wheel: 12 spoke-columns, one row
   per ring plus a 4th for still-open (unassigned) letters. Full-width, its
   own section below the wheel+panel row, since a 12-column grid needs more
   room than the narrow side panel has. */
.keyboard-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.keyboard-section h2 {
  font-size: 15px;
  margin: 0 0 4px;
  color: var(--text);
}
.keyboard-section .sub {
  display: block;
  margin-bottom: 10px;
}
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kbd-row {
  display: grid;
  grid-template-columns: 90px repeat(12, minmax(0, 1fr));
  gap: 3px;
  align-items: stretch;
}
.kbd-row-label {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.kbd-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: stretch;
  justify-content: center;
  min-height: 30px;
  padding: 3px;
  border-radius: 4px;
}
.kbd-row-given .kbd-cell { background: rgba(255, 207, 61, 0.1); }
.kbd-row-received .kbd-cell { background: rgba(52, 179, 255, 0.1); }
.kbd-row-made .kbd-cell { background: rgba(62, 232, 122, 0.1); }
.kbd-row-unassigned .kbd-cell { background: transparent; border: 1px dashed var(--border); }
.kbd-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: background 120ms, box-shadow 120ms;
}
.kbd-key svg, .legend-key svg { display: block; }
.kbd-shorthand {
  position: absolute;
  top: -5px;
  right: -3px;
  font-size: 8px;
  font-weight: 700;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 2px;
  padding: 0 2px;
  line-height: 1.3;
}
.kbd-key:hover { background: #26262f; }
.kbd-key.kbd-flash {
  background: #4a3f10;
  box-shadow: 0 0 0 2px var(--accent-given), 0 0 10px 1px var(--accent-given);
}
.kbd-space-row {
  margin-top: 8px;
}
