/* reese-forge browser instrument. Tokens = docs/design/kit.css (Croky's colour key on warm
   near-black). Mobile first: one column on a phone, the plugin-like grid from 1100 px. */
:root {
  --bg: #11100e; --panel: #191815; --panel-2: #201f1b; --raise: #2a2823;
  --line: #34312b; --line-soft: #26241f;
  --ink: #efe8d6; --muted: #a39c8d; --dim: #8a8376;
  --green: #6fb534; --green-hi: #a3d94a; --green-lo: #2f5a1e;
  --yellow: #edca36; --red: #d4404a; --blue: #4f7fd0; --brown: #7d5c42; --cream: #f2e8cc;
  --r: 6px; --r-s: 3px;
  --label: "Nimbus Sans Narrow", "Arial Narrow", "Roboto Condensed", "Liberation Sans Narrow", "Helvetica Neue", Arial, sans-serif;
  --num: "JetBrains Mono", "JetBrainsMono NF", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --kb-h: 140px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); }
body { font-family: var(--label); color: var(--ink); -webkit-font-smoothing: antialiased; font-size: 14px; }
a { color: var(--ink); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green-hi); outline-offset: 2px; }
kbd { font: 11px var(--num); color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 3px; padding: 0 4px; background: var(--panel-2); }
[hidden] { display: none !important; }

.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- top bar ------------------------------------------------------------------------------ */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; }
.tab { white-space: nowrap; font: 600 12px var(--label); letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  padding: 0 12px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; border-radius: var(--r-s);
  border: 1px solid transparent; text-decoration: none; }
.tab.on { color: var(--ink); background: var(--raise); border-color: var(--line); }
.tab small { font: 10px var(--num); letter-spacing: 0; color: var(--dim); }
.tab.later:hover { color: var(--ink); }
.transport { display: flex; align-items: center; gap: 6px; }
.btn { font: 600 12px var(--label); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--r-s); padding: 0 12px; min-height: 44px; min-width: 44px; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; touch-action: manipulation; }
.btn:hover { color: var(--ink); }
.btn[aria-pressed="true"] { color: #12110f; background: var(--green-hi); border-color: var(--green-hi); }
.btn[aria-pressed="true"] kbd { color: #12110f; background: transparent; border-color: #12110f55; }
.btn svg { fill: currentColor; }
.btn.play .i-stop, .btn.play[aria-pressed="true"] .i-play { display: none; }
.btn.play[aria-pressed="true"] .i-stop { display: inline; }
.btn.step { padding: 0; width: 44px; font: 600 18px var(--num); }
.tempo { display: flex; align-items: center; gap: 4px; }
.tempo label { display: inline-flex; align-items: center; gap: 4px; }
.tempo input { width: 5ch; min-height: 44px; font: 15px var(--num); font-variant-numeric: tabular-nums; text-align: center; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-s); -moz-appearance: textfield; appearance: textfield; }
.tempo input::-webkit-inner-spin-button, .tempo input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.readout { font: 12px var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.readout b { color: var(--ink); font-weight: 500; display: inline-block; text-align: right; }
.readout .lbl { font: 600 11px var(--label); letter-spacing: .1em; }
.w3 { width: 3ch; }
.spacer { flex: 1; }
.state { font: 11px var(--num); color: var(--dim); white-space: nowrap; min-width: 9ch; }
.state.on { color: var(--green-hi); }
.state.err { color: var(--red); }

/* ---- panels ------------------------------------------------------------------------------- */
.grid { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 8px; flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r); position: relative; min-width: 0; padding-bottom: 10px; }
.ph { display: flex; align-items: baseline; gap: 10px; margin: 0; padding: 9px 12px 4px;
  font: 700 12px var(--label); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.ph .sub { font: 400 12px var(--label); letter-spacing: .02em; text-transform: none; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pnote { margin: 4px 12px 0; font-size: 12px; line-height: 1.35; color: var(--dim); }
.knobs { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 6px 4px; padding: 4px 6px 0; min-height: 92px; }

/* knob (svg drawn by app.js) */
.knob { display: inline-flex; flex-direction: column; align-items: center; width: 76px; gap: 1px; cursor: ns-resize; touch-action: none;
  user-select: none; -webkit-user-select: none; border-radius: var(--r); padding: 4px 0; }
.knob svg { display: block; overflow: visible; }
.knob .kl { font: 600 11px var(--label); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.knob .kv { font: 11px var(--num); font-variant-numeric: tabular-nums; color: var(--ink); width: 9ch; text-align: center; white-space: nowrap; }
.knob:focus-visible { outline-offset: 0; }

/* wobble rate: segmented */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; margin: 6px 12px 4px; min-height: 90px; }
.seg button { min-height: 44px; font: 12px var(--num); color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-s); cursor: pointer; touch-action: manipulation; }
.seg button[aria-checked="true"] { color: #12110f; background: var(--green-hi); border-color: var(--green-hi); }
.wob-row, .out-row { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.wob-row .knobs, .out-row .knobs { flex: 1; }
.lfo { width: 160px; height: 56px; flex: 0 1 160px; min-width: 0; }
.meter { width: 10px; height: 96px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; position: relative; overflow: hidden; flex: none; }
.meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(to top, var(--green-lo), var(--green-hi) 70%, var(--yellow) 92%, var(--red)); }

.viz { display: block; width: calc(100% - 16px); height: 170px; margin: 4px 8px 0; background: var(--bg); border-radius: var(--r-s); }

.perch { display: flex; justify-content: center; align-items: flex-end; height: 92px; margin: 4px 12px 0;
  border-bottom: 3px solid var(--brown); border-radius: 0 0 2px 2px; }
.perch canvas { width: 96px; height: 72px; image-rendering: pixelated; image-rendering: crisp-edges; }

/* coming-later previews: honest mockups, not controls */
.soon { display: block; text-decoration: none; color: inherit; }
.soon img { display: block; width: calc(100% - 24px); height: auto; max-height: 150px; object-fit: cover; object-position: top left;
  margin: 4px 12px 0; border-radius: var(--r-s); border: 1px dashed var(--line); opacity: .55; filter: saturate(.6); }
.soon:hover img, .soon:focus-visible img { opacity: .85; }
.badge { font: 600 10px var(--num); letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-s); padding: 1px 5px; }
.badge.hot { color: #12110f; background: var(--yellow); border-color: var(--yellow); }

/* ---- keyboard ----------------------------------------------------------------------------- */
.keys { position: sticky; bottom: 0; z-index: 4; display: flex; gap: 8px; align-items: stretch; padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.kb-ctl { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 2px; }
.kb-ctl .btn.step { min-height: 44px; height: 44px; }
.piano { position: relative; flex: 1; height: var(--kb-h); display: flex; touch-action: none; user-select: none; -webkit-user-select: none; }
.k { position: relative; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px;
  padding-bottom: 6px; background: #e9e1cd; color: #3a352c; border: 1px solid #0b0a09; border-radius: 0 0 4px 4px;
  font: 10px var(--num); cursor: pointer; }
.k.b { position: absolute; top: 0; height: 60%; z-index: 2; background: #23211d; color: var(--muted); border-color: #0b0a09; }
.k.down { background: var(--green-hi); color: #12110f; }
.k.b.down { background: var(--green); color: #12110f; }
.k .kc { font-size: 9px; opacity: .65; }
.k.root::after { content: ""; position: absolute; left: 25%; right: 25%; bottom: 2px; height: 2px; background: var(--green); border-radius: 1px; }

/* ---- footer, start, dialog ---------------------------------------------------------------- */
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 8px 10px; font-size: 12px; color: var(--dim);
  border-top: 1px solid var(--line); background: var(--panel); }
.foot .hint { color: var(--muted); }
.foot a { color: var(--muted); }

.start { position: fixed; left: 0; right: 0; bottom: calc(var(--kb-h) + 28px + env(safe-area-inset-bottom)); z-index: 10;
  display: flex; justify-content: center; pointer-events: none; transition: opacity .35s ease, transform .35s ease; }
.start button { pointer-events: auto; display: inline-flex; align-items: center; gap: 12px; min-height: 64px; padding: 0 30px;
  font: 600 16px var(--label); letter-spacing: .08em; text-transform: uppercase; color: #12110f; background: var(--green-hi);
  border: 0; border-radius: 32px; box-shadow: 0 10px 30px #0009; cursor: pointer; }
.start button svg { fill: currentColor; }
.start.gone { opacity: 0; transform: translateY(12px); }
.start.gone button { pointer-events: none; }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 14px 14px; max-width: min(560px, 94vw); }
dialog::backdrop { background: #000a; }
dialog table { border-collapse: collapse; font-size: 13px; margin: 6px 0 12px; }
dialog td { padding: 5px 10px 5px 0; vertical-align: top; color: var(--muted); }
dialog td:first-child { color: var(--ink); }
.noscript { padding: 20px; color: var(--muted); }

.d-only { display: none; }

/* ---- tablet: two columns ------------------------------------------------------------------ */
@media (min-width: 700px) {
  :root { --kb-h: 140px; }
  .grid { grid-template-columns: repeat(6, 1fr); }
  .p-osc, .p-filt, .p-amp { grid-column: span 2; }
  .p-wob, .p-out { grid-column: span 3; }
  .p-scope, .p-spec { grid-column: span 3; }
  .p-croky { grid-column: span 6; }
  .soon { grid-column: span 3; }
  .d-only { display: initial; }
}

/* ---- desktop: the plugin-like layout ------------------------------------------------------ */
@media (min-width: 1100px) {
  :root { --kb-h: 150px; }
  .grid { grid-template-columns: repeat(12, 1fr); }
  .p-osc { grid-column: span 2; } .p-wob { grid-column: span 3; } .p-filt { grid-column: span 2; }
  .p-amp { grid-column: span 2; } .p-out { grid-column: span 3; }
  .p-scope { grid-column: span 4; } .p-spec { grid-column: span 5; } .p-croky { grid-column: span 3; }
  .soon { grid-column: span 3; }
  .perch { height: 120px; }
  .perch canvas { width: 128px; height: 96px; }
  .viz { height: 210px; }
}

/* phone: the start pill sits above the sticky keyboard; bigger keys */
@media (max-width: 699px) {
  /* one real view on a phone: no tab row; the bar scrolls away, the keyboard stays */
  .top { position: static; gap: 6px; }
  .tabs { display: none; }
  .soon img { max-height: 110px; }
  .knob { width: 82px; }
  .k.b { min-width: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .start { transition: none; }
}
