/* Dither Studio - the console stylesheet.
 *
 * House style (DESIGN.md): a dark instrument panel. The chrome is a compact
 * rail of collapsible stations - Source, Press, Tone, Ink, Detail, Effects,
 * Motion, Type, Presets - and the proof sheet is the hero. Density and
 * grouping follow how professional dithering tools organise themselves
 * (arrow-stepped algorithm browsing, an additive reorderable effects stack,
 * a viewport-bottom Full/Live/Still update control); the tokens, the mono
 * face and the hairlines are the house's own.
 */

:root {
  --bg: #0e0f13;        /* page ground            */
  --panel: #15171d;     /* rails, headers          */
  --panel-2: #1b1e26;   /* controls, raised chips  */
  --line: #262a34;      /* hairlines and borders   */
  --text: #e8eaf0;      /* primary text            */
  --muted: #8b91a3;     /* labels, secondary text  */
  --accent: #7aa2ff;    /* the single accent       */
  --radius: 8px;
  --font: "SF Mono", "Cascadia Code", Consolas, "JetBrains Mono", Menlo, monospace;

  /* Local, non-forked refinements: the well the artifact sits in, and the
     measured heights that keep every control on the same rhythm. */
  --well: #0b0c10;
  --row: 26px;
  --gap: 7px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

/* Mobile Safari collapses its own toolbar, which makes 100% of the *short*
   viewport clip the bottom bar on the way out. Ask for the dynamic viewport
   where it exists; on a desktop the two are the same number. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  margin: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--font);
  overflow: hidden;
}

/* An author `display` must never defeat the `hidden` attribute. */
[hidden] { display: none !important; }

/* ---------- the rail ---------- */

.panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.rail-head { padding: 14px 14px 8px; }

.brand {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.01em;
}

.brand span { color: var(--accent); }

.tagline {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* The console bar. On a phone the rail collapses to this one row, so it is off
   by default and the phone layer below turns it on. Its note carries the open
   station's own summary, which is what makes a collapsed bar worth reading. */
.console-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.console-toggle-label {
  flex: 0 0 auto;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.console-toggle-note {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--accent);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel[data-console="closed"] .console-toggle .caret { transform: rotate(-90deg); }

/* Section jump strip: the rail is long, so the stations are also a row of
   chips. Click scrolls the station open; the visible one is marked. */
/* Chips wrap rather than hide: ten stations, all reachable, none truncated. */
.jump {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 10px 9px;
  border-bottom: 1px solid var(--line);
}

.jump-chip {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 11px/1.4 var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: color 140ms ease, border-color 140ms ease;
}

.jump-chip:hover { color: var(--text); border-color: var(--line); }

.jump-chip[aria-current="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.rail-scroll {
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
  scroll-behavior: smooth;
}

.rail-hint {
  margin: 0;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

.rail-hint b { color: var(--text); }

/* ---------- stations (collapsible groups) ---------- */

.group { border-bottom: 1px solid var(--line); }

.group:last-child { border-bottom: none; }

.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 2px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.group-head:hover .group-name { color: var(--accent); }

.group-name {
  flex: 0 0 auto;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: color 140ms ease;
}

.group-note {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--muted);
}

.caret {
  flex: 0 0 auto;
  width: 9px;
  font-size: 9px;
  color: var(--muted);
  transition: transform 160ms ease;
}

.group[data-open="false"] .caret { transform: rotate(-90deg); }

.group-body {
  display: grid;
  gap: var(--gap);
  padding: 2px 2px 12px;
}

.group[data-open="false"] .group-body { display: none; }

.group-body > .hint { margin: 1px 0 0; }

/* ---------- rows ---------- */

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.buttons-1 { grid-template-columns: 1fr; }

.field {
  display: grid;
  gap: 2px;
}

.field > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.field > span > em {
  font-style: normal;
  font-weight: 600;
  color: var(--text);
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.check input { accent-color: var(--accent); }

.hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.hint b { color: var(--text); font-weight: 600; }

/* stepper rows: select + ◀ ▶, the way pro tools let you browse a list */
.row-stepper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px 24px;
  gap: 4px;
}

.btn-step {
  padding: 0;
  height: var(--row);
  font-size: 9px;
  line-height: 1;
}

.seed-row { display: grid; grid-template-columns: minmax(0, 1fr) 34px; gap: 6px; }

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 2px 0 1px;
}

.swatch {
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
}

/* ---------- controls ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  margin: 0;
  background: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

select,
input[type="number"],
input[type="text"] {
  width: 100%;
  height: var(--row);
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

select { cursor: pointer; }

input[type="color"] {
  width: 26px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-2);
  cursor: pointer;
}

.ink-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.btn {
  height: var(--row);
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}

.btn:hover { border-color: var(--accent); }

.btn:active { filter: brightness(0.94); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn:disabled:hover { border-color: var(--line); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0c10;
  font-weight: 700;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-mini { height: 24px; padding: 0 8px; font-size: 11.5px; }

/* segmented control: one choice out of three, no dropdown round-trip */
.seg {
  display: inline-flex;
  height: var(--row);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.seg-btn {
  padding: 0 9px;
  border: none;
  border-left: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.seg-btn:first-child { border-left: none; }

.seg-btn:hover { color: var(--text); }

.seg-btn.is-on { background: var(--panel-2); color: var(--accent); font-weight: 600; }

/* ---------- effects stack ---------- */

.stack { display: grid; gap: 5px; }

.stack-row {
  display: grid;
  gap: 3px;
  padding: 6px 7px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.stack-top {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.stack-index {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}

.stack-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.stack-tools { display: flex; gap: 3px; }

.icon-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}

.icon-btn:hover { color: var(--text); border-color: var(--line); }

.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.stack-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.stack-row select { width: auto; min-width: 84px; height: 21px; font-size: 11px; }

.stack-empty {
  padding: 6px 2px;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- stage ---------- */

.stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-size: 11px;
  color: var(--muted);
}

.statusbar b { color: var(--text); font-weight: 600; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
}

.grow { flex: 1 1 auto; }

.readout { font-size: 11px; }

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: var(--well);
}

.canvas-frame {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
}

#canvas {
  image-rendering: pixelated;
  background:
    repeating-conic-gradient(#141519 0% 25%, #0f1014 0% 50%) 50% / 16px 16px;
  box-shadow: 0 0 0 1px var(--line);
  cursor: grab;
}

#canvas.alpha-on {
  background:
    repeating-conic-gradient(#1b1e26 0% 25%, #14161c 0% 50%) 50% / 16px 16px;
}

#canvas.panning { cursor: grabbing; }

.canvas-wrap.drag-over { outline: 1px dashed var(--accent); outline-offset: -6px; }

/* viewport bar: update mode on the left, playback in the middle, state right */
.viewport-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 11px;
  color: var(--muted);
}

.transport { display: flex; align-items: center; gap: 6px; }

/* ---------- states ---------- */

:focus-visible,
.btn:focus-visible,
.seg-btn:focus-visible,
.jump-chip:focus-visible,
.icon-btn:focus-visible,
.group-head:focus-visible,
.check input:focus-visible,
.field select:focus-visible,
.field input:focus-visible,
.inline select:focus-visible,
.stack-row select:focus-visible,
input[type="color"]:focus-visible,
#canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection { background: var(--accent); color: #0b0c10; }

/* keep the bar honest on short windows */
@media (max-height: 620px) {
  .tagline { display: none; }
}

/* -------------------------------------------------------------------- */
/* responsive: the same console, contracted (DESIGN.md)                   */
/*                                                                        */
/* Three layers, in the order they overlap:                               */
/*   - pointer: coarse: bigger targets and thumbs (the iPad/phone layer). */
/*   - the tablet range: the rail takes the width touch labels need.      */
/*   - under 720px: the console collapses to its bar and the proof leads.  */
/* -------------------------------------------------------------------- */

@media (pointer: coarse) {
  /* Every control a finger has to hit, at a size a finger can hit. */
  .btn,
  select,
  input[type="number"],
  input[type="text"] { min-height: 38px; }

  .btn { font-size: 13px; }
  .btn-mini { min-height: 34px; }
  .btn-step { height: 38px; font-size: 11px; }
  .seg { height: 38px; }
  .seg-btn { padding: 0 12px; }
  input[type="color"] { width: 34px; height: 30px; }

  .group-head { padding: 12px 2px; }
  .jump-chip { padding: 6px 10px; font-size: 12px; }

  /* A slider is a control, not a hairline: thicken the track and grow the
     thumb, or it cannot be caught and dragged. */
  input[type="range"] { height: 28px; }
  input[type="range"]::-webkit-slider-runnable-track { height: 4px; }
  input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7px; }
  input[type="range"]::-moz-range-track { height: 4px; }
  input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }

  .check { min-height: 34px; font-size: 12.5px; }
  .check input { width: 17px; height: 17px; }

  .icon-btn { width: 30px; height: 30px; font-size: 12px; }
  .stack-row { padding: 8px 9px 7px; }
  .stack-row select { height: 32px; min-width: 96px; }

  /* Double-tap is the browser's zoom, not ours. */
  button, select, input, label, .jump-chip, .group-head { touch-action: manipulation; }

  /* The keyboard hints are a lie on a device with no keyboard; the Compare
     button and the toolbar carry the same verbs. */
  .rail-hint { display: none; }

  /* Installed to the home screen, the console runs full-bleed on a notched
     iPad: keep the bottom bar clear of the home indicator. */
  .viewport-bar { padding-bottom: calc(7px + env(safe-area-inset-bottom)); }

  /* The canvas owns its gestures: one finger pans, two fingers pinch the
     zoom ladder. Letting the browser have them instead would scroll the page
     under the proof and zoom the whole console mid-gesture. */
  #canvas { touch-action: none; }
}

/* iPad, both ways up: the rail carries touch labels, so it takes a little
   more width than the desktop rail and the bars breathe. A short window is
   excluded: it belongs to the phone layer above, whatever its width. */
@media (min-width: 721px) and (max-width: 1180px) and (min-height: 521px) and (pointer: coarse) {
  body { grid-template-columns: 272px minmax(0, 1fr); }
  .rail-head { padding: 16px 16px 10px; }
  .statusbar,
  .toolbar,
  .viewport-bar { padding-left: 16px; padding-right: 16px; }
}

/* Phones: the console collapses to its bar. The proof keeps the lead, and a
         tap on the bar grows the rail in place - the stage shrinks, nothing is
         covered up and nothing is a modal. A phone on its side is wider than
         this but has no height to spare, so a short coarse-pointer window
         takes the same treatment rather than sitting in the tablet layout. */
@media (max-width: 720px), (pointer: coarse) and (max-height: 520px) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

  .panel {
    order: 1;
    grid-template-rows: auto auto auto auto;
    padding-top: env(safe-area-inset-top);
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .stage { order: 2; }

  .rail-head { padding: 11px 12px 10px; }
  .brand { font-size: 17px; }
  .tagline { display: none; }
  .console-toggle { display: flex; }

  /* Closed: the bar is all that is left. Open: the rail scrolls inside a
     capped sheet, so the proof never disappears off the bottom. */
  .panel[data-console="closed"] .jump,
  .panel[data-console="closed"] .rail-scroll,
  .panel[data-console="closed"] .rail-hint { display: none; }

  .panel[data-console="open"] .rail-scroll { max-height: 46dvh; }

  /* Ten stations in one row: the strip scrolls sideways instead of wrapping. */
  .jump { flex-wrap: nowrap; overflow-x: auto; padding: 0 12px 10px; scrollbar-width: none; }
  .jump::-webkit-scrollbar { display: none; }

  /* The statusbar is the house signature, so it stays: as one scrollable
     line rather than four stacked ones. */
  .statusbar {
    flex-wrap: nowrap;
    gap: 12px;
    padding: 7px 12px;
    overflow-x: auto;
    font-size: 10.5px;
    scrollbar-width: none;
  }
  .statusbar::-webkit-scrollbar { display: none; }
  .statusbar > span { flex: 0 0 auto; }

  .toolbar { flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
  .viewport-bar { flex-wrap: wrap; row-gap: 6px; padding: 7px 12px; }
  .canvas-frame { padding: 12px; }
}

/* A short viewport gives the sheet more of itself, takes the last of the
   padding out of the proof, and keeps the bar itself thin: on a landscape
   phone every row of chrome is a row the proof does not get. */
@media (max-height: 520px) {
  .panel[data-console="open"] .rail-scroll { max-height: 62dvh; }
  .canvas-frame { padding: 6px; }
}

@media (pointer: coarse) and (max-height: 520px) {
  .rail-head { padding: 9px 12px 8px; }
  .brand { font-size: 15px; }
  .console-toggle { margin-top: 7px; padding: 7px 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .caret,
  .console-toggle .caret,
  .jump-chip,
  .group-name,
  .btn,
  .seg-btn,
  .icon-btn { transition: none; }
  .rail-scroll { scroll-behavior: auto; }
}
