/* ---------------------------------------------------------------------------
   boop — dark fairyfloss palette, chibi/rounded, mobile-first
   Touch targets: WCAG 2.2 SC 2.5.8 — primary controls ~44x44px, secondary
   (pattern/song chip icons) >=32x32px with >=8px spacing. Contrast pairs
   validated with ccc.pl (WCAG AA: 4.5:1 text, 3:1 large text/UI boundaries).
--------------------------------------------------------------------------- */

:root {
  color-scheme: dark;

  --bg: #241d33;
  --panel: #362a52;
  --panel-2: #423464;
  --border: #7a68a8;      /* meets 3:1 vs --bg — use where border alone conveys a boundary */
  --border-soft: #40325c; /* decorative dividers only */

  --text: #f6f1ff;
  --text-dim: #b8a9d9;
  --ink: #1a1424;         /* dark text/strokes on light pastel surfaces */
  --halo: #fffbe8;

  --pink: #ff8fd6;
  --mint: #8ef6c9;
  --lemon: #ffe066;
  --lilac: #c9a9ff;
  --peach: #ffab91;
  --playhead: #d6409f;

  /* Rounded rects throughout — no fully-circular (50%) or stadium/pill
     (999px) shapes anywhere, even on square icon buttons. */
  --radius-btn: 14px;   /* buttons, selects, chips, primary controls */
  --radius-icon: 9px;   /* small square icon buttons (chip icons, help toggle) */
  --radius-lg: 18px;
  --radius-md: 12px;
  --tap: 44px;   /* comfortable primary touch target */
  --tap-sm: 32px; /* secondary control minimum, still above the 24px WCAG floor */
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(circle at 15% 0%, rgba(255, 143, 214, 0.08), transparent 40%),
                     radial-gradient(circle at 85% 20%, rgba(142, 246, 201, 0.06), transparent 45%);
  color: var(--text);
  font-family: ui-rounded, 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* -------------------------------------------------------------------------
   Chrome — two slim rows, both quieter than the grid below them
------------------------------------------------------------------------- */

/* Sticky so Play/Stop/bpm/note-picker stay reachable while scrolling
   through a long grid — the grid itself is now part of normal page flow
   (no nested scroll container), so without this the toolbar would scroll
   away with everything else. */
.chrome {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-primary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.wordmark {
  font-size: 0.95rem;
  margin: 0 2px 0 0;
  letter-spacing: 0.02em;
  color: var(--pink);
  font-weight: 800;
}

.bar-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  opacity: 0.85;
}

/* -------------------------------------------------------------------------
   Buttons, selects, inputs — chibi/rounded, touch-target sized
------------------------------------------------------------------------- */

button {
  background: var(--panel);
  color: var(--text);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-btn);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: var(--pink);
}

button:active:not(:disabled) {
  transform: scale(0.94);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid var(--pink);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

select,
input[type='file'] {
  background: var(--panel);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-btn);
  min-height: var(--tap);
  padding: 0 12px;
  font: inherit;
  font-weight: 600;
}

/* -------------------------------------------------------------------------
   Transport + bpm (primary row)
------------------------------------------------------------------------- */

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

.bpm {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bpm button {
  min-width: var(--tap-sm);
  min-height: var(--tap-sm);
  padding: 0;
}

.bpm span {
  font-weight: 700;
  min-width: 2.4ch;
  text-align: center;
}

.bpm span::after {
  content: ' bpm';
  opacity: 0.55;
  font-weight: 400;
  font-size: 0.75em;
}

button.play {
  background: var(--pink);
  color: var(--ink);
  border-color: var(--pink);
  font-size: 1.05rem;
  padding: 0;
  box-shadow: 0 3px 0 0 rgba(214, 64, 159, 0.5);
}

button.play.playing {
  background: var(--peach);
  border-color: var(--peach);
  box-shadow: 0 3px 0 0 rgba(255, 171, 145, 0.5);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 3px 0 0 rgba(255, 171, 145, 0.5); }
  50%      { box-shadow: 0 3px 0 0 rgba(255, 171, 145, 0.5), 0 0 0 6px rgba(255, 171, 145, 0.18); }
}

/* -------------------------------------------------------------------------
   Secondary row — track/step config + project actions. Quieter, smaller
   text, still clears the WCAG 24px floor via --tap-sm.
------------------------------------------------------------------------- */

.mini-config,
.mini-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-btn {
  min-width: var(--tap-sm);
  min-height: var(--tap-sm);
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 700;
  background: transparent;
  border-color: var(--border-soft);
}

.mini-value {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 3ch;
  text-align: center;
}

.mini-select {
  min-height: var(--tap-sm);
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  background: transparent;
  border-color: var(--border-soft);
}

.mini-file {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.mini-file input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  border: none;
  min-height: 0;
}

.message {
  background: var(--panel-2);
  border: 1.5px solid var(--lemon);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  color: var(--lemon);
  font-weight: 700;
  font-size: 0.9rem;
  width: fit-content;
}

/* -------------------------------------------------------------------------
   Note picker
------------------------------------------------------------------------- */

.note-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-letters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.note-letter,
.sharp,
.waveform {
  min-width: var(--tap);
  padding: 0 10px;
}

.note-letter.active,
.sharp.active {
  background: var(--pink);
  border-color: var(--pink);
  color: var(--ink);
}

.waveform {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--lilac);
  border-color: var(--lilac);
  color: var(--ink);
}

.waveform-icon {
  width: 20px;
  height: 10px;
  flex: none;
}

.note-preview {
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  font-weight: 700;
  min-width: 3ch;
}

/* -------------------------------------------------------------------------
   Grid — the primary work surface
------------------------------------------------------------------------- */

main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.grid-scroll {
  position: relative; /* positioning context for .cursor-anchor */
  width: 100%;
  overflow-x: hidden; /* structurally impossible once cellW derives from container width — belt and suspenders */
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-soft);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.grid {
  display: block;
}

/* Invisible scroll target for the cursor's row — see boop.js's
   scrollIntoView call. scroll-margin-block is the native equivalent of the
   "land with one row of padding, not flush against the edge" behavior. */
.cursor-anchor {
  position: absolute;
  left: 0;
  width: 1px;
  visibility: hidden;
  pointer-events: none;
  scroll-margin-block: var(--tap);
}

/* -------------------------------------------------------------------------
   Patterns + song — de-emphasized, compact chip strips
------------------------------------------------------------------------- */

.strips {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.strip {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.strip-title {
  color: var(--text-dim);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  padding-left: 4px;
}

.strip-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  padding: 2px 2px 6px;
  -webkit-overflow-scrolling: touch;
}

.chip {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  background: var(--panel);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-btn);
  padding: 2px;
}

.chip.active {
  border-color: var(--mint);
  box-shadow: 0 0 0 2px rgba(142, 246, 201, 0.25);
}

.chip-label {
  min-height: 28px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-btn);
}

.chip-label-static {
  display: flex;
  align-items: center;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
}

.chip-icon {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: var(--radius-icon);
  font-size: 0.75rem;
  background: var(--panel-2);
}

.chip-play {
  background: var(--pink);
  border-color: var(--pink);
  color: var(--ink);
  font-size: 0.65rem;
}

.chip-play.playing {
  background: var(--peach);
  border-color: var(--peach);
  animation: pulse 1.1s ease-in-out infinite;
}

.chip-add {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: var(--radius-icon);
  flex: none;
  font-size: 1.1rem;
  background: var(--mint);
  border-color: var(--mint);
  color: var(--ink);
}

.chip-add-select {
  min-height: 36px;
  flex: none;
  font-size: 0.85rem;
}

/* -------------------------------------------------------------------------
   Help — native <details>/<summary> toggle, no JS/model state needed
------------------------------------------------------------------------- */

.help {
  align-self: flex-start;
}

.help summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-sm);
  height: var(--tap-sm);
  border-radius: var(--radius-icon);
  background: var(--panel);
  border: 1.5px solid var(--border-soft);
  color: var(--text-dim);
  font-weight: 800;
  cursor: pointer;
}

.help summary::-webkit-details-marker,
.help summary::marker {
  display: none;
  content: '';
}

.help summary:hover {
  border-color: var(--pink);
  color: var(--text);
}

.help p {
  margin: 8px 0 0;
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.6;
  max-width: 60ch;
}

/* -------------------------------------------------------------------------
   Wider screens — same single-column layout, just more breathing room.
   The grid stays full-width at every size (see .grid-scroll); patterns/song
   sit below it always, never beside it, so they can't compete for its width.
------------------------------------------------------------------------- */

@media (min-width: 768px) {
  .app {
    max-width: 980px;
    padding: 24px;
  }

  .chip-list {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}
