/* Mash ∞ Loop — design tokens and components. See design/ART_DIRECTION.md. */

@property --pulse { syntax: "<number>"; inherits: true; initial-value: 0; }

/* The light of the room is the colour of the song that is playing (theme.js
   sets these numbers; CSS animates them, so every colour built from them
   changes together). acc = this song, acc2 = the next one, g = the ground. */
@property --acc-l { syntax: "<number>"; inherits: true; initial-value: 0.8; }
@property --acc-c { syntax: "<number>"; inherits: true; initial-value: 0.1; }
@property --acc-h { syntax: "<number>"; inherits: true; initial-value: 40; }
@property --acc2-l { syntax: "<number>"; inherits: true; initial-value: 0.8; }
@property --acc2-c { syntax: "<number>"; inherits: true; initial-value: 0.1; }
@property --acc2-h { syntax: "<number>"; inherits: true; initial-value: 40; }
@property --gh { syntax: "<number>"; inherits: true; initial-value: 40; }
@property --gc { syntax: "<number>"; inherits: true; initial-value: 0.012; }
@property --fill-a { syntax: "<number>"; inherits: true; initial-value: 0; }

:root {
  color-scheme: dark;

  /* Ground and surfaces: the song's hue at a whisper of chroma, depth by
     lightness only. */
  --ink-0: oklch(0.16 var(--gc) var(--gh));
  --ink-1: oklch(0.195 calc(var(--gc) * 1.1) var(--gh));
  --ink-2: oklch(0.235 calc(var(--gc) * 1.15) var(--gh));
  --ink-3: oklch(0.29 calc(var(--gc) * 1.2) var(--gh));
  --line: oklch(0.36 calc(var(--gc) * 1.3) var(--gh) / 0.7);
  --line-soft: oklch(0.36 calc(var(--gc) * 1.3) var(--gh) / 0.35);

  --text: oklch(0.95 calc(var(--gc) * 0.6) var(--gh));
  --text-muted: oklch(0.76 calc(var(--gc) * 0.8) var(--gh));
  --text-faint: oklch(0.63 calc(var(--gc) * 0.8) var(--gh));

  /* The light. */
  --acc: var(--acc-l) var(--acc-c) var(--acc-h);
  --acc2: var(--acc2-l) var(--acc2-c) var(--acc2-h);
  --accent: oklch(var(--acc));
  --accent-hi: oklch(calc(var(--acc-l) + 0.06) calc(var(--acc-c) * 0.85) calc(var(--acc-h) + 4));
  --accent-lo: oklch(var(--acc) / 0.16);
  --on-accent: oklch(0.2 calc(var(--acc-c) * 0.3) var(--acc-h));
  --accent-2: oklch(var(--acc2));
  --danger: oklch(0.74 0.14 30);

  --glow: 0 0 0 1px oklch(var(--acc) / 0.55), 0 0 28px -6px oklch(var(--acc) / 0.75);
  --focus: 0 0 0 2px var(--ink-0), 0 0 0 4px var(--accent), 0 0 18px oklch(var(--acc) / 0.45);

  /* A song change re-lights the room over a bar or two, not in a blink. */
  transition: --acc-l 1.4s var(--ease-in-out), --acc-c 1.4s var(--ease-in-out), --acc-h 1.4s var(--ease-in-out),
    --acc2-l 1.4s var(--ease-in-out), --acc2-c 1.4s var(--ease-in-out), --acc2-h 1.4s var(--ease-in-out),
    --gh 2s var(--ease-in-out), --gc 2s var(--ease-in-out), --fill-a 1.2s var(--ease-out);

  --font-display: "Unbounded", "Be Vietnam Pro", system-ui, sans-serif;
  --font-text: "Be Vietnam Pro", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;

  --step--2: 0.6875rem;   /* 11 */
  --step--1: 0.8125rem;   /* 13 */
  --step-0: 0.9375rem;    /* 15 */
  --step-1: 1.125rem;     /* 18 */
  --step-title: clamp(1.25rem, 0.9rem + 1.4vw, 2.5rem);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius: 14px;
  --round: 999px;
  --tap: 44px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-instant: 80ms;
  --dur-fast: 160ms;
  --dur-base: 240ms;
  --dur-slow: 420ms;
  --dur-slower: 700ms;
  --dur-cine: 1200ms;

  --panel-w: 392px;
  --topbar-h: 64px;
}

@supports (transition-timing-function: linear(0, 1)) {
  :root { --ease-spring: linear(0, 0.35 8%, 0.79 18%, 1.03 30%, 1.07 38%, 1.03 50%, 0.99 66%, 1); }
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 1ms; --dur-base: 1ms; --dur-slow: 160ms; --dur-slower: 160ms; --dur-cine: 160ms; }
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

html { background: var(--ink-0); scrollbar-gutter: stable; }

body {
  min-height: 100dvh;
  color: var(--text);
  font: 400 var(--step-0) / 1.55 var(--font-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: transparent;
}

::selection { background: var(--accent); color: var(--on-accent); }

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: none; box-shadow: var(--focus); }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-style: normal; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

kbd {
  font: 500 var(--step--2) / 1 var(--font-mono);
  padding: 3px 6px 2px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  color: var(--text-muted);
}

/* Section labels stay in sentence case: tracked capitals crowd Vietnamese
   marks (rulebook E3). The short kickers on the stage are the only capitals. */
.label {
  font: 600 var(--step--2) / 1.4 var(--font-text);
  letter-spacing: 0.02em;
  color: var(--text-faint);
}

/* Thin, quiet scrollbars in the panel. */
* { scrollbar-width: thin; scrollbar-color: var(--ink-3) transparent; }

/* --------------------------------------------------------------- field */

/* One light field for the page: the playing song's colour where its loop is,
   the next song's colour where the next loop grows in, and a low glow of
   both from the floor. The bass moves it (--pulse, from viz.js). */
.field {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(44% 54% at var(--key-x, 38%) 46%, oklch(var(--acc) / calc(0.07 + var(--pulse) * 0.06)), transparent 70%),
    radial-gradient(38% 48% at var(--fill-x, 78%) 56%, oklch(var(--acc2) / calc(var(--fill-a) * (1 + var(--pulse) * 0.4))), transparent 72%),
    radial-gradient(70% 46% at 22% 112%, oklch(0.3 calc(var(--acc-c) * 0.55) var(--acc-h) / 0.55), transparent 70%),
    radial-gradient(70% 46% at 80% 112%, oklch(0.3 calc(var(--acc2-c) * 0.55) var(--acc2-h) / 0.45), transparent 70%),
    var(--ink-0);
  transition: --pulse var(--dur-base) var(--ease-out);
}

.field::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ------------------------------------------------------------- top bar */

.topbar {
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font: 600 1.0625rem / 1 var(--font-display);
  letter-spacing: -0.01em;
  padding: 6px 8px;
  margin-left: -8px;
  border-radius: 10px;
}

.brand__inf { width: 34px; height: 17px; overflow: visible; }

.brand__path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 120;
  stroke-dashoffset: 0;
}

.brand__dot { fill: var(--accent-hi); filter: drop-shadow(0 0 3px oklch(var(--acc) / 0.9)); }

@media (prefers-reduced-motion: no-preference) {
  .js .brand__path { animation: draw-inf var(--dur-slower) var(--ease-out) both; }
}

.topbar__end { justify-self: end; display: flex; align-items: center; gap: var(--space-3); }

.keys { display: inline-flex; gap: 4px; }

.to-panel { display: none; }

/* Segmented control (mode switch and panel tabs): hairline pill with a
   filled accent indicator that slides to the selected option. */
.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--round);
  background: oklch(0.195 var(--gc) var(--gh) / 0.6);
  isolation: isolate;
}

.seg button {
  position: relative;
  min-height: 34px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--round);
  background: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--step--1);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out);
}

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

/* The chosen option gets its own accent fill the moment the sliding
   indicator arrives under it, so its label is always dark on the accent. */
.seg button.on {
  color: var(--on-accent);
  background: var(--accent);
  transition: color 1ms linear var(--dur-slow), background-color 1ms linear var(--dur-slow);
}

.seg__ind {
  position: absolute;
  z-index: -1;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--ind-w, 0);
  transform: translateX(var(--ind-x, 0));
  border-radius: var(--round);
  background: var(--accent);
  box-shadow: 0 0 18px -6px oklch(var(--acc) / 0.8);
  transition: transform var(--dur-slow) var(--ease-spring), width var(--dur-slow) var(--ease-out);
}

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  height: calc(100dvh - var(--topbar-h));
}

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

.stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) var(--space-4);
  min-width: 0;
  min-height: 0;
}

.readout {
  position: absolute;
  top: var(--space-4);
  z-index: 2;
  font: 400 var(--step--2) / 1.5 var(--font-mono);
  letter-spacing: 0.06em;
  color: var(--text-faint);
  max-width: 44%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.readout b { color: var(--accent); font-weight: 500; }

.readout--tl { left: var(--space-5); }

.readout--tr { right: var(--space-5); text-align: right; }

.readout--tr .mono { color: var(--text-muted); }

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* The caption that sits inside the playing loop; viz.js keeps it centred on
   the ring as the ring moves. */
.ring-center {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--rc-w, 360px);
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 6px;
  pointer-events: none;
  transform: translate(var(--rc-x, 50%), var(--rc-y, 40%)) translate(-50%, -50%);
  opacity: var(--rc-o, 1);
}

.rc-kicker {
  font: 500 var(--step--2) / 1.4 var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--accent);
}

.rc-title {
  font: 500 var(--rc-size, var(--step-title)) / 1.16 var(--font-display);
  letter-spacing: -0.02em;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding-bottom: 0.08em;
}

.rc-meta {
  display: grid;
  gap: 2px;
  font-size: var(--step--1);
  line-height: 1.5;
  color: var(--text-muted);
}

.rc-meta .mono { font-size: var(--step--2); letter-spacing: 0.04em; color: var(--text-faint); }

.rc-artist { display: block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ring-center[data-size="s"] .rc-title { -webkit-line-clamp: 2; }

.ring-center[data-size="s"] .rc-meta .mono, .ring-center[data-size="s"] .rc-kicker { display: none; }

.tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  max-width: 260px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: oklch(0.21 var(--gc) var(--gh) / 0.92);
  backdrop-filter: blur(8px);
  font-size: var(--step--1);
  line-height: 1.45;
  pointer-events: none;
  transform: translate(var(--tip-x, 0), var(--tip-y, 0));
}

.tip b { font-weight: 600; }

.tip .mono { color: var(--accent); }

.tip small { display: block; color: var(--text-faint); font-size: var(--step--2); margin-top: 2px; }

/* Exits as buttons for keyboard and screen-reader users: visually hidden
   (the canvas draws them as dots) until focus enters, then a small panel. */
.exits {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 4;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.exits:focus-within {
  width: auto;
  height: auto;
  max-width: min(340px, 100%);
  padding: 12px;
  overflow: visible;
  clip-path: none;
  white-space: normal;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: oklch(0.2 var(--gc) var(--gh) / 0.95);
}

.exits ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }

.exits button {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  font-size: var(--step--1);
  color: var(--text-muted);
}

.exits button:hover, .exits button:focus-visible { background: var(--ink-3); color: var(--text); }

.exits button .mono { color: var(--accent); font-size: var(--step--2); margin-left: 4px; }

.exits button.is-bad { color: var(--danger); }

.ring-center[data-mode="idle"] .rc-title { font-weight: 500; }

/* Two lines tall whatever it says, so a longer status never shrinks the stage. */
.next {
  min-height: 3.1em;
  max-width: min(720px, 100%);
  text-align: center;
  font-size: var(--step--1);
  color: var(--text-muted);
  text-wrap: balance;
}

.next strong { color: var(--text); font-weight: 600; }

.next .eta { font-family: var(--font-mono); color: var(--accent); font-variant-numeric: tabular-nums; }

/* The deck: one floating pill, like Aether's single control. */
.deck {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: var(--round);
  background: oklch(0.195 var(--gc) var(--gh) / 0.72);
  backdrop-filter: blur(14px);
}

.deck__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--round);
  background: none;
  color: var(--text-muted);
  font-size: var(--step--1);
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}

.deck__btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--dur-base) var(--ease-spring); }

.deck__btn:active { transform: scale(0.96); }

.deck__btn:disabled { opacity: 0.38; cursor: default; }

@media (hover: hover) {
  .deck__btn:not(:disabled):hover { color: var(--text); background: var(--ink-2); border-color: var(--line-soft); }
  .deck__btn:not(:disabled):hover svg { transform: translateY(-2px); }
}

.deck__play {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--glow);
  transition: transform var(--dur-instant) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

.deck__play svg { grid-area: 1 / 1; width: 24px; height: 24px; fill: currentColor; }

.deck__play .i-pause, .deck__play .i-load { display: none; }

.deck__play[data-state="pause"] .i-play { display: none; }

.deck__play[data-state="pause"] .i-pause { display: block; }

.deck__play[data-state="load"] .i-play { display: none; }

.deck__play[data-state="load"] .i-load { display: block; width: 30px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 26 94; }

@media (prefers-reduced-motion: no-preference) {
  .deck__play[data-state="load"] .i-load { animation: trace 1.1s linear infinite; }
}

.deck__play:active { transform: scale(0.95); }

.deck__play:disabled { cursor: progress; }

@media (hover: hover) {
  .deck__play:hover { background: var(--accent-hi); box-shadow: 0 0 0 1px oklch(var(--acc) / 0.7), 0 0 40px -6px oklch(var(--acc) / 0.95); }
}

.deck__play:focus-visible { box-shadow: var(--focus), var(--glow); }

.deck__vol {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 10px;
  margin-left: 4px;
  border-left: 1px solid var(--line-soft);
  color: var(--text-muted);
}

.deck__vol svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.deck__vol input { width: 92px; }

.deck__vol em { font-size: var(--step--2); width: 3.2ch; color: var(--text-faint); }

/* Setlist: the session as a chain of small linked loops. */
.setlist {
  list-style: none;
  margin: 0;
  padding: 0 var(--space-2);
  display: flex;
  align-items: center;
  max-width: 100%;
  min-height: 30px;
  overflow-x: auto;
  scrollbar-width: none;
  mask-image: linear-gradient(90deg, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}

.setlist li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-size: var(--step--2);
  color: var(--text-faint);
  white-space: nowrap;
}

/* The link glyph says how the songs were joined; its colour runs from the
   song before to the song after. */
.setlist li + li::before {
  content: "";
  width: 22px;
  height: 10px;
  margin: 0 6px 0 4px;
  background: linear-gradient(90deg, var(--from, var(--text-faint)), var(--hue));
  mask: var(--via-glyph) center / contain no-repeat;
  opacity: 0.95;
}

.setlist li[data-via="cut"]::before, .setlist li[data-via="fade"]::before, .setlist li[data-via="brake"]::before { opacity: 0.7; }

.setlist li[data-via="cut"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M0 5h22M11 0v10' stroke='%23000' stroke-width='1.2' fill='none'/></svg>"); }

.setlist li[data-via="blend"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M11 5c3-4 8-4 8 0s-5 4-8 0-8-4-8 0 5 4 8 0z' stroke='%23000' stroke-width='1.3' fill='none'/></svg>"); }

.setlist li[data-via="drop"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M0 5h22M11 0v10M8 1h6' stroke='%23000' stroke-width='1.2' fill='none'/></svg>"); }

.setlist li[data-via="echo"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><circle cx='5' cy='5' r='3.5' stroke='%23000' stroke-width='1.2' fill='none'/><circle cx='12' cy='5' r='2.5' stroke='%23000' stroke-width='1' fill='none' opacity='.6'/><circle cx='18' cy='5' r='1.6' stroke='%23000' stroke-width='1' fill='none' opacity='.35'/></svg>"); }

.setlist li[data-via="brake"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M0 5c6 0 10-0.5 14-3M17 1v8' stroke='%23000' stroke-width='1.2' fill='none'/></svg>"); }

.setlist li[data-via="roll"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M1 8V2M6 8V2M10 8V2M13 8V2M15.5 8V2M17.5 8V2M19 8V2' stroke='%23000' stroke-width='1.1' fill='none'/></svg>"); }

.setlist li[data-via="fade"] { --via-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 10'><path d='M0 5h22' stroke='%23000' stroke-width='1.2' stroke-dasharray='2 2.5' fill='none'/></svg>"); }

.setlist .loop {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--hue);
  flex: none;
}

.setlist li:last-child { color: var(--text); }

.setlist li:last-child .loop { box-shadow: 0 0 10px var(--hue); }

@media (prefers-reduced-motion: no-preference) {
  .js .setlist li { animation: link-in var(--dur-slow) var(--ease-out) both; }
}

/* ----------------------------------------------------------------- panel */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line-soft);
  /* Frosted: the room's light reaches the library too. */
  background:
    linear-gradient(180deg, oklch(var(--acc) / 0.05), transparent 30%),
    oklch(0.17 var(--gc) var(--gh) / 0.58);
  backdrop-filter: blur(22px) saturate(1.25);
}

.panel > .tabs { margin: var(--space-4) var(--space-4) 0; display: grid; }

.tab { display: none; padding: var(--space-5) var(--space-4) var(--space-6); overflow-y: auto; min-height: 0; flex: 1; }

.tab.on { display: block; }

@media (prefers-reduced-motion: no-preference) {
  .js .tab.on { animation: tab-in var(--dur-slow) var(--ease-out) both; }
}

.hint, .row small, .keys-line { font-size: var(--step--2); line-height: 1.55; color: var(--text-faint); }

/* Add / search */
.add { display: grid; gap: var(--space-2); }

.add__field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink-0);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.add__field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-lo); }

.add__field svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--text-faint); stroke-width: 1.6; stroke-linecap: round; }

.add__field input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border: 0;
  background: none;
  outline: none;
}

.add__field input::placeholder { color: var(--text-faint); }

.add__field button, .ghost, .result button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid oklch(var(--acc) / 0.55);
  border-radius: 10px;
  background: var(--accent-lo);
  color: var(--accent-hi);
  font-weight: 600;
  font-size: var(--step--1);
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out), color var(--dur-fast);
}

.add__field button:active, .ghost:active, .result button:active { transform: scale(0.97); }

@media (hover: hover) {
  .add__field button:hover, .ghost:hover, .result button:not(:disabled):hover { background: var(--accent); color: var(--on-accent); }
}

.result button:disabled { border-color: var(--line); background: none; color: var(--text-faint); cursor: default; }

/* Upload: a dashed well under the search field; the whole page takes drops. */
.drop {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--text-faint);
  font-size: var(--step--2);
  line-height: 1.45;
  cursor: pointer;
  transition: border-color var(--dur-fast), background-color var(--dur-fast), color var(--dur-fast);
}

.drop svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.drop b { display: block; font-size: var(--step--1); font-weight: 600; color: var(--text-muted); }

.drop:has(+ input:focus-visible) { box-shadow: var(--focus); }

@media (hover: hover) {
  .drop:hover { border-color: oklch(var(--acc) / 0.6); color: var(--text-muted); }
}

body.dragging .drop, .drop.over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-lo);
  color: var(--text);
}

body.dragging::after {
  content: "Thả file nhạc để thêm vào thư viện";
  position: fixed;
  inset: 12px;
  z-index: 50;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: oklch(0.16 var(--gc) var(--gh) / 0.72);
  backdrop-filter: blur(6px);
  font: 500 var(--step-1) / 1.3 var(--font-display);
  color: var(--text);
  pointer-events: none;
}

.empty .sample-btn { display: block; width: auto; margin: var(--space-4) auto 0; padding: 0 20px; }

.upload-row { display: grid; gap: 6px; padding: 10px 14px; font-size: var(--step--1); color: var(--text-muted); }

.upload-row + .upload-row { border-top: 1px solid var(--line-soft); }

.upload-row .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.upload-row .progress { margin-top: 0; }

.upload-row.err { color: var(--danger); }

.ghost { width: 100%; margin: var(--space-2) 0 var(--space-3); }

.results:not(:empty) {
  margin-top: var(--space-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--ink-1);
}

.result {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: 8px 8px 8px 10px;
}

.result + .result { border-top: 1px solid var(--line-soft); }

.result img { width: 64px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--ink-2); filter: saturate(0.7) contrast(1.05); }

.result .t { font-size: var(--step--1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.result .s { font: 400 var(--step--2) / 1.5 var(--font-mono); color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.results .msg { padding: 12px 14px; font-size: var(--step--1); color: var(--text-muted); }

.worker { min-height: 1.5em; margin: var(--space-4) 0 var(--space-2); font-size: var(--step--2); color: var(--accent); }

.worker:empty { margin: var(--space-2) 0 0; }

.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin: var(--space-4) 0 var(--space-3); }

.shelf-head .mono { font-size: var(--step--2); color: var(--text-faint); }

/* Track shelf: every song is a little loop drawn from its own analysis. */
.tracks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.track {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: 8px 8px 8px 10px;
  border-radius: 12px;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.track .mini { width: 38px; height: 38px; display: block; transition: transform var(--dur-cine) var(--ease-out); }

.track .t { font-size: var(--step--1); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.track .s { font: 400 var(--step--2) / 1.55 var(--font-mono); color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.track .s.err { font-family: var(--font-text); color: var(--danger); white-space: normal; }

.track .s .a { font-family: var(--font-text); color: var(--text-muted); }

.track .acts { display: flex; gap: 2px; }

.track .acts button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text-faint);
  transition: color var(--dur-fast), background-color var(--dur-fast), transform var(--dur-instant);
}

.track .acts svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.track .acts button[data-act="play"] svg { fill: currentColor; stroke: none; }

.track .acts button:active { transform: scale(0.92); }

@media (hover: hover) {
  .track:hover { background: var(--ink-2); }
  .track:hover .mini { transform: rotate(90deg); }
  .track .acts button:hover { color: var(--text); background: var(--ink-3); }
  .track .acts button[data-act="play"]:hover { color: var(--on-accent); background: var(--accent); }
  .track .acts button[data-act="delete"]:hover { color: var(--danger); }
  /* Secondary actions wait for the pointer; touch and keyboard always see them. */
  .track:not(:hover):not(:focus-within) .acts button:not([data-act="play"]) { opacity: 0; }
}

.track.playing { background: linear-gradient(90deg, var(--accent-lo), transparent 70%); }

.track.playing::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.track.playing .t { color: var(--accent-hi); }

@media (prefers-reduced-motion: no-preference) {
  .track.playing .mini { animation: spin 14s linear infinite; }
}

.track.off { opacity: 0.5; }

.track.off .s::after { content: " · ngoài chuỗi"; font-family: var(--font-text); }

.progress { height: 2px; margin-top: 6px; background: var(--ink-3); border-radius: 2px; overflow: hidden; }

.progress i { display: block; height: 100%; background: var(--accent); box-shadow: 0 0 8px var(--accent); transition: width var(--dur-slow) var(--ease-out); }

.pending {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1turn), var(--ink-3) 0);
  mask: radial-gradient(circle, transparent 13px, #000 14px);
}

.empty { padding: var(--space-5) var(--space-2); text-align: center; color: var(--text-muted); font-size: var(--step--1); }

.empty svg { width: 64px; height: 32px; display: block; margin: 0 auto var(--space-3); fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; opacity: 0.8; }

/* Settings */
.group { display: grid; gap: var(--space-4); padding-bottom: var(--space-5); margin-bottom: var(--space-5); border-bottom: 1px solid var(--line-soft); }

.group:last-child { border-bottom: 0; margin-bottom: 0; }

.row { display: grid; gap: 8px; }

.row__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); font-size: var(--step--1); }

.row__head em { color: var(--accent); font-size: var(--step--2); text-align: right; }

/* Range: hairline track, accent fill (set by --v from JS), thumb a small loop. */
input[type="range"] {
  --v: 50%;
  width: 100%;
  height: 22px;
  margin: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) var(--v), var(--ink-3) var(--v));
}

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

input[type="range"]::-moz-range-progress { height: 2px; background: var(--accent); }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--ink-0);
  border: 3px solid var(--accent);
  box-shadow: 0 0 10px oklch(var(--acc) / 0.5);
  transition: transform var(--dur-fast) var(--ease-spring);
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-0);
  border: 3px solid var(--accent);
}

input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.25); }

input[type="range"]:focus-visible { box-shadow: none; }

input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }

.kinds { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }

.kinds .sub { grid-column: 1 / -1; padding: 0; margin-bottom: 8px; font-size: var(--step--1); }

.kind {
  position: relative;
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--ink-1);
  cursor: pointer;
  transition: border-color var(--dur-fast), background-color var(--dur-fast), transform var(--dur-instant);
}

.kind input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }

.kind svg { width: 40px; height: 20px; fill: none; stroke: var(--text-faint); stroke-width: 1.6; transition: stroke var(--dur-fast); }

.kind span { font-size: var(--step--2); line-height: 1.4; color: var(--text-faint); }

.kind b { display: block; font-size: var(--step--1); font-weight: 600; color: var(--text-muted); }

.kind:has(input:checked) { border-color: oklch(var(--acc) / 0.6); background: var(--accent-lo); }

.kind:has(input:checked) svg { stroke: var(--accent); }

.kind:has(input:checked) b { color: var(--text); }

/* What the chain looks for: one row per criterion, a small loop for a radio. */
.choices { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }

.choices .sub { padding: 0; margin-bottom: 6px; font-size: var(--step--1); }

.choice {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--ink-1);
  cursor: pointer;
  transition: border-color var(--dur-fast), background-color var(--dur-fast), transform var(--dur-instant);
}

.choice input {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 2px solid var(--text-faint);
  border-radius: 50%;
  background: var(--ink-0);
  cursor: pointer;
  transition: border-color var(--dur-fast), box-shadow var(--dur-base) var(--ease-out);
}

.choice input:focus-visible { outline: none; box-shadow: none; }

.choice:has(input:focus-visible) { box-shadow: var(--focus); }

.choice span { font-size: var(--step--2); line-height: 1.4; color: var(--text-faint); }

.choice b { display: inline; margin-right: 8px; font-size: var(--step--1); font-weight: 600; color: var(--text-muted); }

.choice:has(input:checked) { border-color: oklch(var(--acc) / 0.6); background: var(--accent-lo); }

.choice:has(input:checked) input { border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--ink-0), inset 0 0 0 8px var(--accent), 0 0 10px -2px var(--accent); }

.choice:has(input:checked) b { color: var(--text); }

.choice:active { transform: scale(0.985); }

@media (hover: hover) {
  .choice:hover { border-color: var(--line); }
}

/* Theme tiles: three dots of the colours the theme would give this library. */
.swatch { display: flex; height: 20px; align-items: center; padding-left: 2px; }

.swatch i {
  width: 16px;
  height: 16px;
  margin-right: -5px;
  border-radius: 50%;
  background: var(--c, var(--ink-3));
  box-shadow: 0 0 0 2px var(--ink-1);
  transition: background-color var(--dur-slow) var(--ease-out), transform var(--dur-base) var(--ease-spring);
}

.look:has(input:checked) .swatch i { box-shadow: 0 0 0 2px var(--ink-1), 0 0 12px -2px var(--c); }

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .look:hover .swatch i:nth-child(1) { transform: translateX(-2px); }
  .look:hover .swatch i:nth-child(3) { transform: translateX(2px); }
}

.tip .dot { display: inline-block; width: 8px; height: 8px; margin: 0 4px 1px 2px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }

.kind:has(input:focus-visible) { box-shadow: var(--focus); }

.kind:active { transform: scale(0.97); }

@media (hover: hover) {
  .kind:hover { border-color: var(--line); }
}

.keys-line kbd { margin: 0 2px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1199px) {
  :root { --panel-w: 344px; }
  .keys { display: none; }
}

@media (max-width: 899px) {
  :root { --topbar-h: 58px; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .topbar { grid-template-columns: auto 1fr auto; gap: var(--space-3); padding: 0 var(--space-4); }
  .mode { justify-self: center; }
  .seg button { padding: 0 12px; }
  .to-panel {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0 4px;
    color: var(--text-muted);
    font-size: var(--step--1);
    text-decoration: none;
    border-radius: 8px;
  }
  .stage { padding: var(--space-3) var(--space-4) var(--space-4); }
  /* Taller than wide, so the two loops stand as an 8 with room for both. */
  .canvas-wrap { height: min(122vw, 68svh, 760px); }
  .readout { top: var(--space-3); }
  .readout--tl { left: var(--space-4); }
  .readout--tr { right: var(--space-4); }
  .deck { position: sticky; bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); z-index: 5; }
  .panel { border-left: 0; border-top: 1px solid var(--line-soft); }
  .tab { overflow: visible; }
}

@media (max-width: 1199px) and (min-width: 900px) {
  .kinds { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .brand { font-size: 0.875rem; gap: 4px; }
  .brand__inf { width: 26px; height: 13px; }
  .topbar__end { display: none; }
  .topbar { grid-template-columns: auto 1fr; }
  .mode { justify-self: end; }
  .ro-stats { display: none; }
  .readout--tl { max-width: 62%; }
  .readout--tr { max-width: 34%; }
  .deck { gap: 2px; padding: 5px 6px; }
  .deck__btn { padding: 0 10px; }
  .deck__btn span { display: none; }
  .deck__vol input { width: 64px; }
  .deck__vol em { display: none; }
  .readout { max-width: 46%; }
  .kinds { grid-template-columns: 1fr; }
  .kind { grid-template-columns: 40px 1fr; align-items: center; }
}

@media (max-width: 380px) {
  .seg button { padding: 0 9px; font-size: var(--step--2); }
}

/* -------------------------------------------------------------- keyframes */

@keyframes draw-inf { from { stroke-dashoffset: 120; } to { stroke-dashoffset: 0; } }

@keyframes trace { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -120; } }

@keyframes spin { to { transform: rotate(1turn); } }

@keyframes link-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

@keyframes tab-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
