/* ChordPad — Beats By Moody's dark room and violet accent, sized for a phone
   held in one hand. The whole app fits one screen (100dvh): nothing scrolls
   but the chord grid, sideways. */

@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('../fonts/inter-v20-latin-regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('../fonts/inter-v20-latin-600.woff2') format('woff2'); }
@font-face { font-family: 'Oswald'; font-weight: 500; font-display: swap; src: url('../fonts/oswald-v57-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'Oswald'; font-weight: 600; font-display: swap; src: url('../fonts/oswald-v57-latin-600.woff2') format('woff2'); }

:root {
  /* From the theme's variables.css */
  --bg: #08080f;
  --panel: #0f0f1a;
  --tile: #1a1a2e;
  --tile-hi: #23233c;
  --line: rgba(255, 255, 255, 0.08);
  --line-hi: rgba(255, 255, 255, 0.16);
  --text: #eeeef0;
  --muted: #9898a8; /* 6.6:1 on --tile */
  --accent: #7c5cfc;
  --accent-light: #9b82ff;
  --accent-ink: #000; /* text on violet fills is black (theme rule) */
  --danger: #ff6b6b;
  --radius: 10px;
  --gutter: 16px;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --display: 'Oswald', 'Inter', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.35 var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ── header ── */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 8px;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.wordmark {
  font: 600 20px/1 var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.brand { overflow: hidden; }
.by {
  margin-top: 4px;
  font: 500 9.5px/1 var(--display);
  letter-spacing: 0.14em;
  white-space: nowrap;
  text-transform: uppercase;
  color: var(--muted);
}
.top .sound { margin-left: auto; min-width: 0; width: 41%; }
.top .sound select { font-size: 14px; }

/* The LP switch: same family as the click toggle. */
.lp {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 500 12px/1 var(--display);
  letter-spacing: 0.14em;
  color: var(--muted);
}
.lp .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.35; }
.lp.on { color: var(--text); border-color: var(--accent); }
.lp.on .dot { background: var(--accent-light); opacity: 1; }

/* ── selects ── */

.pick { position: relative; display: block; min-width: 0; }
.pick::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.pick select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  padding: 0 32px 0 12px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  text-overflow: ellipsis;
}
.pick select:disabled { opacity: 0.5; }
.grow { flex: 1; }

/* ── transport ── */

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px var(--gutter) 10px;
}
.bpm {
  display: flex;
  align-items: center;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  height: 44px;
}
.step {
  width: 40px;
  height: 100%;
  background: none;
  border: 0;
  font-size: 22px;
  line-height: 1;
}
.step:active { color: var(--accent-light); }
.bpm-val { display: flex; align-items: baseline; gap: 4px; }
.bpm-val input {
  width: 3ch;
  padding: 0;
  background: none;
  border: 0;
  text-align: right;
  font: 600 20px/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.bpm-val span {
  font: 500 10px/1 var(--display);
  letter-spacing: 0.14em;
  color: var(--muted);
}
.click {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 500 12px/1 var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.click .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
}
.click.on { color: var(--text); border-color: var(--line-hi); }
.click.on .dot { background: var(--accent-light); opacity: 1; }
.click .dot.accent { background: #fff; }
.vol {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  background: none;
  accent-color: var(--accent);
}
.vol:disabled { opacity: 0.35; }

/* ── source ── */

.source {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 var(--gutter) 10px;
}
.tabs {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tabs button {
  height: 32px;
  padding: 0 10px;
  background: none;
  border: 0;
  border-radius: 7px;
  font: 500 12px/1 var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.tabs button[aria-selected='true'] { background: var(--tile-hi); color: var(--text); }
.source-row { display: flex; gap: 8px; align-items: center; }
.pickers { display: flex; gap: 8px; align-items: center; min-width: 0; }
.pickers[hidden], .pick[hidden] { display: none; }
.pick.root { flex: none; width: 76px; }
.nudge {
  flex: none;
  width: 36px;
  height: 40px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 20px;
  line-height: 1;
}

/* ── context row: genre · what the lighting reads · octave ── */

.context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gutter) 8px;
}
.genre-btn {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  background: var(--tile);
  border: 1px solid var(--accent);
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
}
.genre-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-light); }
.ctx-note {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.octave {
  flex: none;
  display: flex;
  align-items: center;
  height: 32px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.oct-step { width: 34px; height: 100%; background: none; border: 0; font-size: 18px; line-height: 1; }
.oct-val {
  min-width: 46px;
  text-align: center;
  font: 500 11px/1 var(--display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.genre-pick { text-align: left; }
.genre-pick.current { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

/* ── chord grid ── */

.grid-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  max-height: 400px;
  display: flex;
}
.grid {
  --cols: 4.3; /* a sliver of the next column shows there is more */
  flex: 1;
  min-width: 0;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(4, minmax(44px, 1fr));
  grid-auto-columns: calc((100% - 3 * 8px) / var(--cols));
  gap: 8px;
  padding: 0 var(--gutter) 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-padding: 0 var(--gutter);
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.grid::-webkit-scrollbar { display: none; }
.grid[hidden] { display: none; }

.tile {
  scroll-snap-align: start;
  /* Sideways is the grid's scroll; up/down is ours (a lift to the dock). */
  touch-action: pan-x;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
  padding: 8px 8px 6px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  text-align: left;
  overflow: hidden;
}
.tile .name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.15;
}
.tile .name.long { font-size: 14px; }
.tile .name.xlong { font-size: 12.5px; }
.tile .tag {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tile.last { border-color: var(--accent-light); border-top-color: var(--accent-light); }
/* Dimmed = less likely next in this genre. Still playable and draggable:
   advice, not a lock. The strip goes grey too, so lit ones read at a glance. */
.tile.dim { opacity: 0.38; border-top-color: var(--line-hi); }
.tile.dim.pressed { opacity: 1; }
.tile.pressed { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.pressed .tag { color: var(--accent-ink); }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  padding: 0 var(--gutter);
  color: var(--muted);
}
.empty[hidden] { display: none; }
.empty p { margin: 0 0 6px; max-width: 32ch; }
.empty-title { color: var(--text); font-weight: 600; }

/* ── patterns ── */

.dock {
  margin-top: auto;
  padding: 10px var(--gutter) calc(env(safe-area-inset-bottom) + 10px);
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.pattern + .pattern { margin-top: 8px; }
.pat-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
}
.pat-label {
  font: 500 12px/1 var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.spacer { flex: 1; }
.txt {
  height: 32px;
  padding: 0 7px;
  background: none;
  border: 0;
  color: var(--accent-light);
  font-weight: 600;
  font-size: 13px;
}
.pat-row { display: flex; gap: 8px; }
.play {
  flex: none;
  width: 48px;
  height: 60px;
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  background: var(--tile);
  position: relative;
}
/* ▶ and ■ drawn in CSS so they never fall back to an emoji glyph */
.play::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  border-style: solid;
  border-width: 9px 0 9px 15px;
  border-color: transparent transparent transparent var(--text);
  transform: translate(-35%, -50%);
}
.play.playing { background: var(--accent); border-color: var(--accent); }
.play.playing::before {
  width: 14px;
  height: 14px;
  border: 0;
  background: var(--accent-ink);
  transform: translate(-50%, -50%);
}
.slots {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  min-width: 0;
}
.slot {
  touch-action: none; /* slots don't scroll; every move is a drag */
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  min-width: 0;
  padding: 4px;
  border: 1px dashed var(--line-hi);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
}
.slot .plus { font-size: 22px; color: var(--muted); }
.slot .name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.15;
}
.slot .name.long { font-size: 13px; }
.slot .name.xlong { font-size: 11.5px; }
.slot.filled {
  background: var(--tile);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
}
.slot.playing, .slot.pressed {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.slot.lifted { opacity: 0.4; }
.slot.drop { outline: 2px solid var(--accent-light); outline-offset: 1px; }

.dock-foot { margin-top: 10px; }
.hint { margin: 0; min-height: 44px; display: flex; align-items: center; font-size: 13px; color: var(--muted); }
.hint[hidden], .dock-foot .btn[hidden] { display: none; }

.btn {
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line-hi);
  background: var(--tile);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: rgba(255, 107, 107, 0.4); background: none; }
.btn.block, .dock-foot .btn { display: block; width: 100%; }

/* ── suggest ── */

.suggest {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 var(--gutter) 6px;
}
.suggest[hidden] { display: none; }
.sg-head { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.sg-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}
.sg-eyebrow {
  flex: none;
  font: 500 12px/1.2 var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.sg-ctx { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: var(--muted); }
.sg-key {
  flex: none;
  height: 28px;
  padding: 0 10px;
  background: none;
  border: 1px solid var(--line-hi);
  border-radius: 14px;
  font-size: 12px;
  color: var(--accent-light);
}
/* One row; on a narrow phone it scrolls sideways rather than wrapping. */
.sg-moods { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: none; }
.sg-moods::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 32px;
  padding: 0 10px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}
.chip[aria-checked='true'] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sg-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 6px;
}
.sg-list.wide { grid-template-columns: 1fr; }
.sg-row {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--tile);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  text-align: left;
}
.sg-row.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sg-row.on .tag, .sg-row.on .sg-arrow { color: var(--accent-ink); }
.sg-chord { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sg-chord .name { font-weight: 600; font-size: 13px; line-height: 1.15; }
.sg-chord .tag { font-size: 10.5px; color: var(--muted); }
.sg-arrow { flex: none; font-size: 12px; color: var(--muted); }
.sg-foot { display: flex; gap: 8px; }
.sg-foot .btn { flex: 1; height: 40px; padding: 0 8px; }

/* ── drag ghost ── */

.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
}
body.dragging .dock { box-shadow: inset 0 2px 0 var(--accent); }

/* ── toast ── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 240px; /* set from the dock's top when shown (main.js toast) */
  z-index: 40;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #2b2b44;
  border: 1px solid var(--line-hi);
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── sheets ── */

.sheet-back {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.6);
}
.sheet {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px var(--gutter) calc(env(safe-area-inset-bottom) + 18px);
  background: var(--panel);
  border-top: 1px solid var(--line-hi);
  border-radius: 16px 16px 0 0;
}
.sheet-title {
  margin: 0 0 4px;
  font: 500 13px/1 var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.sheet-note { margin: 0; font-size: 13px; color: var(--muted); }
.text {
  height: 44px;
  padding: 0 12px;
  background: var(--tile);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  font-size: 16px; /* 16px stops iOS zooming into the field */
  -webkit-user-select: text;
  user-select: text;
}

.noscript { padding: 24px; }

/* Short phones (SE): tighten the chrome so the grid keeps its four rows. */
@media (max-height: 700px) {
  .top { padding-bottom: 4px; }
  .transport { padding-bottom: 6px; }
  .source { padding-bottom: 6px; gap: 6px; }
  .context { padding-bottom: 6px; }
  .genre-btn, .octave { height: 30px; }
  .dock { padding-top: 6px; }
  .pat-head { min-height: 28px; }
  .dock-foot { margin-top: 6px; }
  .slot, .play { height: 52px; }
  .pattern + .pattern { margin-top: 4px; }
}
