/* Layout: a console deck. The deck (roll, pad, score) on the left, the cartridge shelf on the
   right, the manual below. Under 860px it stacks: deck first, then shelf. */
:root {
  color-scheme: dark;
  --bg: #15132a;
  --panel: #1f1c3c;
  --panel-2: #29254d;
  --line: #3a3566;
  --well: #0e0c1f;
  --fg: #ece9ff;
  --muted: #a39fc9;
  --accent: #f4b860;
  --err: #ff7a7a;
  --ok: #7fd6a4;
  /* Super Famicom face buttons, then the shoulder grays: one color per channel. */
  --ch1: #e5484d; --ch2: #f2c230; --ch3: #3fb27f; --ch4: #4f7fe8; --ch5: #a58cf0; --ch6: #f08fb6; --ch7: #67d2e0;
  --display: "Silkscreen", "Courier New", monospace;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --r: 6px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); }
button, select, input { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

.wrap { max-width: 1240px; margin: 0 auto; padding-inline: 20px; padding-block: 28px 64px; }
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 20px; margin-bottom: 22px; }
h1 { font: 700 34px/1 var(--display); margin: 0; letter-spacing: 0.02em; color: var(--accent); }
header p { margin: 0; color: var(--muted); max-width: 62ch; }
h2 { font: 400 13px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Buttons */
.btn { font: 700 14px/1 var(--body); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .seg:focus-visible, .tab:focus-visible, .cell:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: #241a05; border-color: var(--accent); min-width: 96px; }
.btn.small { font-size: 13px; padding: 7px 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.seg { background: var(--well); border: 1px solid var(--line); padding: 7px 11px; font: 400 11px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); cursor: pointer; }
.seg:first-child { border-radius: var(--r) 0 0 var(--r); }
.seg:last-child { border-radius: 0 var(--r) var(--r) 0; }
.seg + .seg { border-left: 0; }
.seg[aria-pressed="true"] { background: var(--panel-2); color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); }
select { background: var(--well); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; font: 13px var(--mono); }

/* Deck */
.deck { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 16px; min-width: 0; }
.now { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; }
.now .titles { flex: 1 1 260px; min-width: 0; }
.now .game { font: 400 12px/1 var(--display); letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; }
.title { display: block; width: 100%; font: 700 26px/1.15 var(--body); margin: 4px 0 2px; padding: 2px 6px; margin-left: -6px; background: transparent; border: 1px solid transparent; border-radius: var(--r); }
.title:hover { border-color: var(--line); }
.title:focus { outline: none; border-color: var(--accent); background: var(--well); }
.now .mood { margin: 0; color: var(--muted); }
.transport { display: flex; gap: 8px; align-items: center; }
.readout { display: flex; flex-wrap: wrap; gap: 6px 18px; font: 12px/1 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.readout b { color: var(--fg); font-weight: 600; }
.roll { position: relative; background: var(--well); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.roll canvas { display: block; width: 100%; height: 180px; }
.roll .hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font: 12px var(--display); letter-spacing: 0.06em; pointer-events: none; }
.chans { display: flex; flex-wrap: wrap; gap: 8px; }
.chan { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; font: 13px/1 var(--mono); background: var(--panel-2); touch-action: manipulation; }
.chan i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); opacity: 0.35; transition: opacity 60ms; }
.chan.lit i { opacity: 1; box-shadow: 0 0 8px var(--c); }
.chan[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.chan:focus-visible { outline: 2px solid var(--accent); }
.chan small { color: var(--muted); font-size: 11px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { all: unset; cursor: pointer; padding: 8px 14px 9px; font: 400 13px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.panel { display: grid; gap: 14px; min-width: 0; }
#padBody { display: grid; gap: 14px; }
.padonly { background: var(--well); border: 1px dashed var(--line); border-radius: var(--r); padding: 14px; }
.padonly p { margin: 0 0 10px; color: var(--muted); }

/* Pattern + lane pickers */
.pats, .addpats { display: flex; gap: 6px; }
.chip { all: unset; cursor: pointer; display: inline-grid; place-items: center; min-width: 38px; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--well); font: 700 15px/1 var(--display); color: var(--muted); position: relative; touch-action: manipulation; }
.chip[aria-pressed="true"] { background: var(--panel-2); color: var(--fg); border-color: var(--accent); }
.chip.empty { opacity: 0.6; }
.chip.lit::after { content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; background: var(--accent); }
.addpats .chip { min-width: 30px; height: 30px; font-size: 13px; }
.voices { display: flex; flex-wrap: wrap; gap: 6px; }
.voice { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--well); font: 400 12px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); touch-action: manipulation; }
.voice i { width: 10px; height: 10px; background: var(--c); }
.voice[aria-pressed="true"] { color: var(--fg); background: var(--panel-2); border-color: var(--c); }
.voice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lane-opts { gap: 10px 14px; }
.inst { display: inline-flex; gap: 8px; align-items: center; font: 400 11px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tools, .pages { display: inline-flex; }
.pages { display: none; }

/* The pad: label column + one column per step. Squares are pixels. */
.padgrid { --cols: 16; display: grid; grid-template-columns: 52px repeat(var(--cols), minmax(0, 1fr)); gap: 3px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; user-select: none; -webkit-user-select: none; }
.lab { font: 11px/1 var(--mono); color: var(--muted); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; white-space: nowrap; overflow: hidden; }
.lab.root { color: var(--fg); }
.cell { all: unset; cursor: pointer; aspect-ratio: 1; min-height: 18px; max-height: 34px; background: #1a1733; position: relative; touch-action: manipulation; }
.cell.alt { background: #221e40; }
.cell.rootrow { background: #262147; }
.cell.rootrow.alt { background: #2c2752; }
.cell.on { background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.cell.held { background: var(--c); opacity: 0.55; }
.cell.held::before { content: ""; position: absolute; left: -3px; top: 35%; width: 3px; height: 30%; background: var(--c); }
.cell.ghost { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 45%, transparent); }
.cell.play { outline: 1px solid rgba(244, 184, 96, 0.55); outline-offset: 0; }
.cell.on.play { filter: brightness(1.35); }
.sep { grid-column: 1 / -1; height: 4px; }

/* Song chain */
.songbox { display: grid; gap: 10px; }
.chain { list-style: none; margin: 0; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; min-height: 52px; background: var(--well); border: 1px solid var(--line); border-radius: var(--r); }
.chain li { display: contents; }
.chain .chip { min-width: 34px; height: 34px; }
.chain .chip.lit { border-color: var(--accent); color: var(--fg); }

/* Knobs */
.knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 18px; }
.knobs label { display: grid; gap: 6px; font: 400 11px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.knobs output { font: 12px var(--mono); color: var(--fg); text-transform: none; letter-spacing: 0; margin-left: 4px; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }

/* Score */
.editor-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.editor-head p { margin: 0; max-width: 52ch; }
textarea { width: 100%; min-height: 380px; resize: vertical; background: var(--well); color: var(--fg); border: 1px solid var(--line); border-radius: var(--r);
  font: 12.5px/1.6 var(--mono); padding: 12px 14px; white-space: pre; overflow: auto; tab-size: 4; }
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea[readonly] { color: var(--muted); }
.status { font: 13px/1.45 var(--mono); min-height: 1.4em; color: var(--muted); }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }
.status ul { margin: 4px 0 0; padding-left: 18px; }

/* Shelf */
.side { display: grid; gap: 12px; position: sticky; top: 16px; }
.shelf { display: grid; gap: 8px; }
.slot { display: grid; grid-template-columns: 1fr auto; }
.cart { all: unset; cursor: pointer; display: grid; grid-template-columns: 8px 1fr auto; gap: 4px 12px; align-items: center; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r) 0 0 var(--r); padding: 10px 12px 10px 0; overflow: hidden; }
.cart::before { content: ""; grid-row: span 2; align-self: stretch; background: var(--line); }
.cart:hover { background: var(--panel-2); }
.cart:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cart[aria-current="true"] { border-color: var(--accent); background: var(--panel-2); }
.cart[aria-current="true"]::before { background: var(--accent); }
.cart .game { font: 400 11px/1.2 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.cart .name { font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart .meta { grid-row: span 2; font: 12px/1.3 var(--mono); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.del { all: unset; cursor: pointer; width: 34px; display: grid; place-items: center; color: var(--muted); border: 1px solid var(--line); border-left: 0; border-radius: 0 var(--r) var(--r) 0; background: var(--panel); }
.del:hover { color: var(--err); }
.del:focus-visible { outline: 2px solid var(--accent); }
.share { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side p { margin: 0; }

/* Manual */
.manual { margin-top: 36px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.manual section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; min-width: 0; }
.manual h2 { margin-bottom: 12px; }
.manual h3 { font: 700 18px/1.2 var(--body); margin: 0 0 10px; }
.manual p { margin: 0 0 12px; max-width: 66ch; }
.manual p.lede { color: var(--muted); }
.tbl { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 400 11px var(--display); letter-spacing: 0.06em; color: var(--muted); text-transform: uppercase; }
code, td:first-child { font-family: var(--mono); font-size: 13px; color: var(--accent); }
td:first-child { white-space: nowrap; }
pre.sample { margin: 0; background: var(--well); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; font: 12.5px/1.6 var(--mono); overflow-x: auto; }
.drums { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px 14px; font-size: 14px; }
.drums code { display: inline-block; width: 1.4em; }
footer { margin-top: 32px; color: var(--muted); font: 400 11px var(--display); letter-spacing: 0.06em; text-transform: uppercase; }

.fab { display: none; }

@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .manual { grid-template-columns: minmax(0, 1fr); }
}

/* Phone: half a bar at a time, bigger squares, a floating play button. */
@media (max-width: 600px) {
  .wrap { padding-inline: 16px; padding-block: 18px 96px; }
  h1 { font-size: 28px; }
  header p { font-size: 14px; }
  .deck { padding: 12px; gap: 14px; border-radius: 8px; }
  .title { font-size: 22px; }
  .transport .primary { display: none; }
  .roll canvas { height: 130px; }
  .pages { display: inline-flex; }
  .padgrid { --cols: 8; grid-template-columns: 44px repeat(var(--cols), minmax(0, 1fr)); gap: 4px; padding: 6px; }
  .cell { max-height: none; min-height: 30px; }
  .lab { font-size: 10px; padding-right: 4px; }
  textarea { min-height: 300px; font-size: 12px; }
  .fab { display: grid; place-items: center; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 5;
    width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: #241a05; font: 700 22px/1 var(--body);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); cursor: pointer; }
  .fab:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }
}

@media (prefers-reduced-motion: reduce) { .chan i { transition: none; } }
.mt, .manual .mt { margin-top: 16px; }
