/* Studio Demby tokens: light warm ground, Outfit / Crimson Pro / JetBrains Mono,
   coral as the primary accent. */
:root {
  /* Without this the browser hands us dark form controls on a light page. */
  color-scheme: light;

  --bg: #F8F7F5;
  --surface: #FFFFFF;
  --line: #DCD8D3;
  --line-soft: #EFEDEA;
  --ink: #1A1A1A;
  --ink-2: #3D3D3D;
  --ink-3: #737373;
  --ink-4: #A3A3A3;
  --coral: #FF6B6B;
  --violet: #8B5CF6;

  --font-display: 'Outfit', system-ui, sans-serif;
  --font-body: 'Crimson Pro', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-display);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--coral); color: #fff; }

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 72px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* Back to the portfolio. Matches the house .portfolio-back convention but is
   defined locally rather than pulling ../_shared/back-link.css, so the page is
   self-contained and renders identically inside and outside the portfolio. */
.portfolio-back {
  --portfolio-back-color: var(--ink-4);
  --portfolio-back-color-hover: var(--ink);
  display: inline-block;
  align-self: flex-start;
  margin-top: 14px;
  font: 0.75rem/1 var(--font-mono);
  letter-spacing: 0.04em;
  color: var(--portfolio-back-color);
  text-decoration: none;
}
.portfolio-back:hover { color: var(--portfolio-back-color-hover); }
/* The host page has its own navigation, and trims its own top spacing. */
body.embed .portfolio-back { display: none; }
body.embed .page { padding-bottom: 32px; }
body.embed .topbar { position: static; }

/* ── topbar: print is the only filled button on the page ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: -6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.topbar-action { display: flex; align-items: center; gap: 10px; }
.print-summary {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  /* Narrow screens can't hold the wordmark, the count and two buttons; the
     count is the one you can do without, and it reappears at 720px. */
  display: none;
}
button.primary {
  background: var(--coral);
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: 600 15px var(--font-display);
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.06); }

/* Quiet by design: Print stays the only filled button on the page. */
button.quiet {
  background: var(--surface);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px;
  font: 14px var(--font-display);
  cursor: pointer;
  white-space: nowrap;
}
button.quiet:hover { border-color: var(--ink-3); color: var(--ink); }

/* The host page already carries the title; two of them reads as a mistake. */
body.embed .wordmark { display: none; }
body.embed .topbar { justify-content: flex-end; }
button.primary:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* ── intro ─────────────────────────────────────────────── */
.intro p {
  margin: 0;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink-2);
  max-width: 54ch;
}
.intro-flow { margin-top: 6px !important; color: var(--ink-3) !important; font-style: italic; }

/* ── stage ─────────────────────────────────────────────── */
.stage { display: flex; flex-direction: column; gap: 18px; }
.grid { display: flex; flex-direction: column; gap: 18px; }
.system { min-width: 0; }
.bar-number {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-4);
}
/* Setting overflow on one axis makes the other compute to `auto` too, so this
   box clips on all four sides, and the playhead ring extends 2px past a cell.
   The breathing room has to live on the scrolling *content*, not on this
   container: a scroll box's trailing padding is left out of scrollWidth, so
   container padding-right vanishes once you scroll to the end. */
.grid-scroll { overflow-x: auto; padding-bottom: 4px; }
/* min-width lets the lane box grow with its columns; without it the grid
   content overflows the lane's own box and the padding never applies. */
.grid .lane { padding: 3px; min-width: max-content; }
.lane {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(18px, 1fr));
  gap: 3px;
}
.lane-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 5px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}
.lane-label-editable { color: var(--ink-2); }
.lane-action {
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 8px;
  font: 11px var(--font-display);
  color: var(--ink-3);
  cursor: pointer;
}
.lane-action:hover { border-color: var(--ink-3); color: var(--ink); }

.ruler .tick {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-4);
  padding-bottom: 4px;
}
.ruler .tick.beat { color: var(--ink); font-weight: 500; }

/* Two channels, not one: shape (hollow vs solid) carries the distinction and
   survives greyscale; colour is redundant reinforcement. Matches the sheet. */
.cell {
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  padding: 0;
  min-width: 0;
}
.cell.beat { border-color: var(--line); }
button.cell { cursor: pointer; }
button.cell:hover { border-color: var(--ink-3); }
/* The gap sits under whichever lane is on top — sliding hand, now. */
.lane-pattern { margin-bottom: 9px; }
.lane-ostinato .cell.on { border: 2.5px solid var(--ink); background: var(--surface); }
.lane-pattern .cell.on { background: var(--coral); border-color: var(--coral); }
.cell.playing { box-shadow: 0 0 0 2px var(--violet); }

/* ── nudge: the core verb gets its own control ─────────── */
.nudge { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nudge button {
  width: 44px; height: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.nudge button:hover { border-color: var(--ink-3); }
.nudge-readout { margin: 0 0 0 4px; font-size: 14px; color: var(--ink-2); }
.nudge-count { font-family: var(--font-mono); font-size: 11px; color: var(--ink-4); margin-left: 6px; }

/* ── transport ─────────────────────────────────────────── */
.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.transport button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 16px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  min-width: 112px;
}
.transport button:hover { border-color: var(--ink-3); }
.transport label { font-size: 12px; color: var(--ink-3); }
.transport input {
  width: 66px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font: 14px var(--font-mono);
  color: var(--ink);
}
.unit { font-size: 12px; color: var(--ink-4); }

.note:empty { display: none; }
.note p {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink-3);
  max-width: 60ch;
}
.note strong { color: var(--ink); font-family: var(--font-mono); font-size: 14px; }

/* ── library ───────────────────────────────────────────── */
.library h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: -0.01em; }
.library-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 12px;
}
.control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.control label, .control-label, .modes legend { font-size: 12px; color: var(--ink-3); }

/* Segmented control. The whole range is visible and any value is one click
   away, so nothing regenerates at the values you would have dragged through. */
.steps {
  display: inline-flex;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.step {
  min-width: 40px;
  padding: 9px 0;
  background: none;
  border: 0;
  border-left: 1px solid var(--line);
  font: 14px var(--font-mono);
  color: var(--ink-3);
  cursor: pointer;
}
.step:first-child { border-left: 0; }
.step:hover { background: var(--line-soft); color: var(--ink); }
/* Filled with ink, not coral — coral stays the print button's alone. */
.step.current { background: var(--ink); color: var(--bg); }
.step.current:hover { background: var(--ink); color: var(--bg); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: var(--line); border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px; margin-top: -6.5px;
  border-radius: 50%; background: var(--coral);
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line);
}
input[type="range"]::-moz-range-track {
  height: 4px; background: var(--line); border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border: 2px solid var(--surface);
  border-radius: 50%; background: var(--coral);
}
select {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
}

.hint {
  margin: 0 0 10px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink-3);
  max-width: 62ch;
}
.shape-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip.current { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.chip-tag { font-family: var(--font-mono); font-size: 11px; color: var(--ink-4); }
.swatch { display: grid; grid-template-columns: repeat(var(--n), 10px); gap: 2px; }
.dot { height: 10px; border-radius: 2px; background: var(--line-soft); }
.dot.on { background: var(--ink); }

/* ── setup: set once, then get out of the way ──────────── */
.setup {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
/* Reads as a control rather than a line of grey text — it was easy to miss
   sitting at the foot of the page. */
.setup summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px 7px 10px;
  list-style: none;
}
.setup summary::-webkit-details-marker { display: none; }
.setup summary:hover { border-color: var(--ink-3); color: var(--ink); }
.setup-icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: transform 0.25s ease;
}
.setup[open] .setup-icon { transform: rotate(45deg); }
.setup-caret {
  font-size: 15px; line-height: 1; color: var(--ink-4);
  transition: transform 0.2s ease;
}
.setup[open] .setup-caret { transform: rotate(90deg); }
.setup-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px 0 4px;
}
.modes { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.modes legend { padding: 0; margin-bottom: 6px; }
.modes label {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 14px; color: var(--ink-2);
}
.modes input { margin-top: 3px; accent-color: var(--coral); }
.modes strong { color: var(--ink); font-weight: 600; }

@media (min-width: 720px) {
  .print-summary { display: inline; }
  .page { padding: 0 24px 96px; }
  .wordmark { font-size: 22px; }
  .library-controls { grid-template-columns: 1fr 1fr; gap: 24px; }
  .setup-body { grid-template-columns: 1fr 1fr 2fr; }
}

.sheet { display: none; }

/* ── the sheet ─────────────────────────────────────────── */
/* Paper is greyscale, so the two hands are told apart by glyph, not colour:
   hollow = steady hand, solid = sliding hand. Same language as the screen. */
@media print {
  @page { size: A4 portrait; margin: 15mm; }

  body { background: #fff; color: #000; }
  .page { max-width: none; padding: 0; gap: 0; display: block; }
  .page > *:not(.sheet) { display: none !important; }
  .sheet { display: block; }

  .sheet-header { margin: 0 0 6mm; }
  .sheet-header h1 { font-size: 15pt; margin: 0 0 1mm; letter-spacing: -0.01em; }
  .sheet-header p { font-size: 9pt; margin: 0; color: #444; }
  .sheet-header .legend { margin-top: 3mm; display: flex; align-items: center; gap: 3mm; }
  .key { width: 4mm; height: 4mm; display: inline-block; margin-right: 1mm; }
  .key-ostinato { border: 1pt solid #000; background: #fff; }
  .key-pattern { background: #000; }

  .drill { break-inside: avoid; margin: 0 0 4mm; }
  .drill-head {
    display: flex; align-items: baseline; gap: 4mm;
    margin: 0 0 2mm; font-size: 9pt;
  }
  .drill-number { font-weight: 700; font-size: 11pt; }
  .drill-shape { letter-spacing: 0.15em; }
  .drill-gaps { color: #666; }

  .sheet .system { margin: 0 0 2mm; }
  .sheet .bar-number { margin: 0 0 1mm; font-size: 7.5pt; color: #666; }
  .sheet .grid-scroll { overflow: visible; padding: 0; }
  .sheet .lane {
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: 1mm;
  }
  .sheet .lane-pattern { margin-bottom: 1mm; }
  .sheet .ruler .tick {
    font-size: 7.5pt; text-align: center; color: #000;
    padding-bottom: 0.5mm;
  }
  .sheet .ruler .tick:not(.beat) { color: #888; }
  .sheet .cell {
    aspect-ratio: 1;
    border: 0.4pt solid #d5d5d5;
    background: #fff;
    border-radius: 0;
  }
  .sheet .lane-ostinato .cell.on { border: 1.1pt solid #000; background: #fff; }
  .sheet .lane-pattern .cell.on { border: 1.1pt solid #000; background: #000; }
}
