/*
 * Lilliss Studio styles.
 * Calm, high-contrast and dyslexia-friendly: Atkinson Hyperlegible, 18px base,
 * generous spacing, 44px+ touch targets, visible focus, one coral primary action.
 * Dark by default; light follows prefers-color-scheme. No inline styles (CSP).
 */

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #0c1320;
  --glow-warm: rgba(255, 138, 112, 0.10);
  --glow-cool: rgba(79, 209, 197, 0.08);
  --surface: #121c2b;
  --surface-2: #192536;
  --surface-3: #213047;
  --border: #26364d;
  --border-strong: #60799b;
  --text: #edf1f7;
  --text-muted: #a9b6c9;
  --coral: #ff8a70;
  --coral-hover: #ffa18b;
  --coral-glow: rgba(255, 138, 112, 0.32);
  --coral-soft: rgba(255, 138, 112, 0.18);
  --on-coral: #1d0f0b;
  --teal: #4fd1c5;
  --teal-strong: #79e0d6;
  --teal-soft: rgba(79, 209, 197, 0.15);
  --teal-glow: rgba(79, 209, 197, 0.45);
  --on-teal: #052421;
  --danger: #ff8591;
  --danger-soft: rgba(255, 133, 145, 0.12);
  --danger-line: rgba(255, 133, 145, 0.5);
  --warn: #ffcb6b;
  --warn-soft: rgba(255, 203, 107, 0.12);
  --focus: #ffd166;
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.75);
  --shadow-float: 0 18px 48px -12px rgba(0, 0, 0, 0.6);
  --toast-bg: #edf1f7;
  --toast-text: #0c1320;
  --toast-action: #0b6e66;
  --toast-danger: #b32539;
  --overlay: rgba(6, 10, 18, 0.74);
  /* Canvas colours, read by js/canvas.js */
  --wave: #7fe0d6;
  --wave-dim: #4f6687;
  --wave-ghost: rgba(127, 224, 214, 0.22);
  --wave-mini: #5f7899;
  --wave-played: #ff8a70;
  --wave-bg: #0e1726;
  --sel-fill: rgba(79, 209, 197, 0.10);
  --shade: rgba(5, 9, 16, 0.6);
  --playhead: #ff8a70;
  --clip: #ff8591;

  --font: "Atkinson Hyperlegible", "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --page: 46rem;
  --page-wide: 68rem;
  --gutter: 1rem;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f1e9;
    --glow-warm: rgba(214, 96, 70, 0.10);
    --glow-cool: rgba(12, 122, 113, 0.08);
    --surface: #fffdf8;
    --surface-2: #f3eee3;
    --surface-3: #e8e1d2;
    --border: #e0d8c8;
    --border-strong: #857859;
    --text: #18212f;
    --text-muted: #4b5668;
    --coral: #c0462c;
    --coral-hover: #a63a23;
    --coral-glow: rgba(192, 70, 44, 0.28);
    --coral-soft: rgba(192, 70, 44, 0.14);
    --on-coral: #ffffff;
    --teal: #0c7a71;
    --teal-strong: #08645d;
    --teal-soft: rgba(12, 122, 113, 0.11);
    --teal-glow: rgba(12, 122, 113, 0.35);
    --on-teal: #ffffff;
    --danger: #b32539;
    --danger-soft: rgba(179, 37, 57, 0.08);
    --danger-line: rgba(179, 37, 57, 0.4);
    --warn: #8a5600;
    --warn-soft: rgba(196, 132, 0, 0.12);
    --focus: #1c5fd0;
    --shadow: 0 18px 40px -26px rgba(60, 45, 20, 0.35);
    --shadow-float: 0 18px 48px -14px rgba(40, 30, 10, 0.35);
    --toast-bg: #18212f;
    --toast-text: #f4f1e9;
    --toast-action: #79e0d6;
    --toast-danger: #ff8591;
    --overlay: rgba(244, 241, 233, 0.82);
    --wave: #0c7a71;
    --wave-dim: #8a94a3;
    --wave-ghost: rgba(12, 122, 113, 0.2);
    --wave-mini: #768194;
    --wave-played: #c0462c;
    --wave-bg: #f8f5ee;
    --sel-fill: rgba(12, 122, 113, 0.09);
    --shade: rgba(244, 241, 233, 0.72);
    --playhead: #c0462c;
    --clip: #b32539;
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: var(--border-strong);
    --text-muted: var(--text);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-size: 112.5%; /* 18px */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 1rem;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(56rem 26rem at 8% -6rem, var(--glow-warm), transparent 70%),
    radial-gradient(48rem 24rem at 96% -4rem, var(--glow-cool), transparent 70%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: 0.01em;
  word-spacing: 0.05em;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.has-player { padding-bottom: 6rem; }

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: 0; font-weight: 700; }
h1 { font-size: clamp(1.6rem, 1.35rem + 1.2vw, 2rem); }
h2 { font-size: 1.3rem; }
p { margin: 0; }
a { color: var(--teal); text-underline-offset: 0.2em; text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
svg { flex: none; }
.icon { width: 1.25em; height: 1.25em; display: block; }
strong { font-weight: 700; }

kbd {
  font: inherit;
  font-size: 0.85em;
  font-weight: 700;
  padding: 0.05em 0.45em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 3px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}

:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
main:focus, h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }

::selection { background: var(--teal-soft); }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  z-index: 100;
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { top: 0.75rem; }

.hint { color: var(--text-muted); font-size: 0.95rem; }
.lead { font-size: 1.15rem; }

/* ---------- Layout ---------- */
.topbar-inner,
main {
  width: min(100% - 2 * var(--gutter), var(--page-wide));
  margin-inline: auto;
}

.screen { padding: 0.5rem 0 4rem; display: grid; gap: 1.75rem; align-content: start; }
.screen-page { max-width: var(--page); margin-inline: auto; }
.screen-wide { max-width: var(--page-wide); }
.screen-center {
  min-height: 62vh;
  min-height: 62dvh;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 1.25rem;
}

/* ---------- Top bar ---------- */
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 0 1.25rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 48px;
  padding-right: 0.25rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
}
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand-name { white-space: nowrap; }
.topnav { display: flex; gap: 0.35rem; }
.topnav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 48px;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 700;
  text-decoration: none;
}
.topnav-link:hover { color: var(--text); background: var(--surface-2); }
.topnav-link[aria-current="page"] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -3px 0 var(--teal); }

@media (max-width: 26rem) {
  .topbar-inner { gap: 0.4rem; }
  .brand { gap: 0.5rem; font-size: 1rem; }
  .brand-mark { width: 34px; height: 34px; }
  .topnav { gap: 0.15rem; }
  .topnav-link { padding: 0.45rem 0.55rem; font-size: 0.95rem; }
  .topnav-link .icon { display: none; }
}

.offline-banner {
  width: min(100% - 2 * var(--gutter), var(--page));
  margin: 0 auto;
}
.offline-banner:not(.is-on) .icon { display: none; }
.offline-banner.is-on {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
}

/* ---------- Cards and sections ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.15rem, 4vw, 2rem);
  box-shadow: var(--shadow);
  display: grid;
  gap: 1.1rem;
  min-width: 0;
}
.card-narrow { width: min(100%, 32rem); }
.card-title { font-size: 1.25rem; }
.card-text { max-width: 60ch; }

.section { display: grid; gap: 1rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.section-title { font-size: 1.35rem; }
.section-count { color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.55rem 1.1rem;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-3); border-color: var(--text-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn:disabled:hover,
.btn[aria-disabled="true"]:hover { background: var(--surface-2); border-color: var(--border-strong); }

.btn-primary {
  background: var(--coral);
  border-color: var(--coral);
  color: var(--on-coral);
  box-shadow: 0 10px 28px -12px var(--coral-glow);
}
.btn-primary:hover { background: var(--coral-hover); border-color: var(--coral-hover); }
.btn-primary:disabled:hover,
.btn-primary[aria-disabled="true"]:hover { background: var(--coral); border-color: var(--coral); }
.btn-xl { width: 100%; min-height: 64px; font-size: 1.25rem; border-radius: 18px; }
.btn-wide { justify-self: start; }
.btn-small { min-height: 44px; padding: 0.4rem 0.85rem; font-size: 0.92rem; }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-quiet:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-toggle[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); color: var(--text); }
.btn[aria-busy="true"] { cursor: progress; }

.btn-round {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--teal);
  color: var(--on-teal);
  cursor: pointer;
  flex: none;
}
.btn-round .icon { width: 24px; height: 24px; }
.btn-round-quiet { background: transparent; color: var(--text-muted); }
.btn-round-quiet:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 0.5rem; }
.field-label { display: block; font-weight: 700; font-size: 1.05rem; margin-bottom: 0.5rem; }
.field .field-label { margin-bottom: 0; }

.input {
  width: 100%;
  min-height: 56px;
  padding: 0.7rem 1rem;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1.05rem;
}
.input::placeholder { color: var(--text-muted); opacity: 1; }
.input:hover { border-color: var(--text-muted); }
.input:focus-visible { border-color: var(--teal); outline-offset: 2px; }
.input-big { min-height: 60px; font-size: 1.1rem; }

.notice {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 4px solid var(--teal);
}
.notice-error { background: var(--danger-soft); border-left-color: var(--danger); }
.notice-warn { background: var(--warn-soft); border-left-color: var(--warn); }

/* Pills (radio buttons that look like big chips) */
.choice { display: grid; gap: 0.6rem; }
.choice .field-label { margin-bottom: 0.6rem; }
.pills { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.pills-two { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 24rem; }
.pill { position: relative; display: block; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.pill-face {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 56px;
  padding: 0.5rem 0.6rem;
  border: 2px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.pill-face:hover { border-color: var(--text-muted); }
.pill-check { display: none; color: var(--teal); }
.pill input:checked + .pill-face { background: var(--teal-soft); border-color: var(--teal); }
.pill input:checked + .pill-face .pill-check {
  display: block;
  position: absolute;
  top: -0.5rem;
  right: -0.35rem;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0.2rem;
  border-radius: 50%;
  background: var(--teal);
  color: var(--on-teal);
  box-shadow: 0 0 0 2px var(--surface);
}
.pill input:focus-visible + .pill-face { outline: 3px solid var(--focus); outline-offset: 3px; }
/* After the base rules, so it wins at phone widths. */
@media (max-width: 26rem) {
  .pills { gap: 0.45rem; }
  .pill-face { padding: 0.5rem 0.35rem; gap: 0.25rem; font-size: 1rem; }
}

/* Range sliders */
.slider-field { display: grid; gap: 0.35rem; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; font-weight: 700; }
.slider-head output { font-weight: 700; color: var(--teal); font-variant-numeric: tabular-nums; }
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.range:disabled { opacity: 0.45; cursor: not-allowed; }
.range::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: var(--border-strong); }
.range::-moz-range-track { height: 8px; border-radius: 999px; background: var(--border-strong); }
.range::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--teal); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--teal);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--teal);
}
.range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--teal);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--teal);
}
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--teal), 0 0 0 6px var(--focus); }
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--teal), 0 0 0 6px var(--focus); }

/* ---------- Get audio ---------- */
.get-card { gap: 1.4rem; }
.get-form { display: grid; gap: 1.4rem; }
.link-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.link-row .input { flex: 1 1 14rem; min-width: 0; }
.link-row .btn { flex: none; min-height: 60px; }

.or {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: -0.4rem 0;
  color: var(--text-muted);
  font-weight: 700;
}
.or::before, .or::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: var(--border); }

.file-row { display: grid; gap: 0.75rem; justify-items: start; }
.btn-file { min-height: 56px; padding-inline: 1.3rem; }
.file-row input:focus-visible + .btn-file { outline: 3px solid var(--focus); outline-offset: 3px; }

.chosen { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; width: 100%; }
.chosen-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.35rem 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--teal-soft);
  border: 1px solid var(--teal);
}
.chosen-item .icon { color: var(--teal); }
.chosen-name { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.chosen-size { color: var(--text-muted); white-space: nowrap; font-size: 0.92rem; }

@media (hover: none) { .drop-hint { display: none; } }

/* ---------- Working on (jobs) ---------- */
.job-list, .asset-list, .device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }

.job {
  display: grid;
  gap: 0.9rem;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise-in 0.35s var(--ease);
}
.job:focus-visible { outline-offset: 2px; }
.job[data-tone="failed"] { border-color: var(--danger-line); }
.job[data-tone="ready"] { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft), var(--shadow); }
.job-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 0.75rem 0.85rem; }
.job-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--teal);
  flex: none;
}
.job[data-tone="failed"] .job-icon { background: var(--danger-soft); color: var(--danger); }
.job[data-tone="ready"] .job-icon { background: var(--teal); color: var(--on-teal); }
.job-text { min-width: 0; padding-top: 0.15rem; }
.job-title { font-weight: 700; overflow-wrap: anywhere; }
.job-detail { color: var(--text-muted); }
.job[data-tone="failed"] .job-detail { color: var(--text); }
.job-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.job-actions:empty { display: none; }
@media (max-width: 34rem) {
  .job-head { grid-template-columns: auto minmax(0, 1fr); }
  .job-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .job-actions .btn { flex: 1 1 auto; }
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--teal-soft);
  border-top-color: var(--teal);
  animation: spin 0.9s linear infinite;
}

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.step { position: relative; display: grid; justify-items: center; gap: 0.3rem; color: var(--text-muted); font-size: 0.9rem; text-align: center; }
.step::before {
  content: "";
  position: absolute;
  top: 11px;
  right: 50%;
  width: 100%;
  height: 3px;
  background: var(--border-strong);
}
.step:first-child::before { display: none; }
.step-dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  background: var(--surface);
}
.step-dot .icon { width: 15px; height: 15px; stroke-width: 3; }
.step.is-done { color: var(--text); }
.step.is-done::before, .step.is-current::before, .step.is-waiting::before, .step.is-failed::before { background: var(--teal); }
.step.is-done .step-dot { background: var(--teal); border-color: var(--teal); color: var(--on-teal); }
.step.is-current, .step.is-waiting { color: var(--text); font-weight: 700; }
.step.is-current .step-dot { border-color: var(--coral); animation: pulse 1.6s ease-in-out infinite; }
.step.is-waiting .step-dot { border-color: var(--coral); border-style: dotted; }
.step.is-failed { color: var(--danger); font-weight: 700; }
.step.is-failed .step-dot { background: var(--danger); border-color: var(--danger); color: var(--surface); }

.progress { display: flex; align-items: center; gap: 0.75rem; }
.bar { flex: 1; height: 10px; border-radius: 999px; background: var(--border-strong); overflow: hidden; }
.bar-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--teal-strong));
  transition: width 0.45s var(--ease);
}
.progress-pct { min-width: 3.2em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.job.is-leaving, .asset.is-leaving, .toast.is-leaving { animation: leave 0.45s var(--ease) forwards; pointer-events: none; }

/* ---------- Library ---------- */
.library-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; color: var(--text-muted); }

.empty {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  padding: 2.5rem 1.25rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
}
.empty-icon .icon, .empty-icon.icon { width: 40px; height: 40px; color: var(--teal); margin-bottom: 0.4rem; }
.empty-title { font-size: 1.15rem; font-weight: 700; }

.asset {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.85rem 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.asset.is-current { border-color: var(--teal); }
.asset.is-new { animation: arrive 2.2s var(--ease); }

.play-btn {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--teal);
  color: var(--on-teal);
  cursor: pointer;
  transition: transform 0.1s, background-color 0.15s;
}
.play-btn:hover { background: var(--teal-strong); }
.play-btn:active { transform: scale(0.96); }
.play-btn .icon { width: 26px; height: 26px; }

.asset-head { min-width: 0; display: grid; gap: 0.2rem; }
.asset-title-line { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem 0.6rem; }
.asset-title {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  min-height: 44px;
  padding: 0.2rem 0.3rem;
  margin: -0.2rem -0.3rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
  cursor: text;
}
.asset-title:hover { background: var(--surface-2); }
.title-text { overflow-wrap: anywhere; }
.rename-hint { color: var(--text-muted); opacity: 0.7; transition: opacity 0.15s; }
.rename-hint .icon { width: 18px; height: 18px; }
.asset-title:hover .rename-hint, .asset-title:focus-visible .rename-hint { opacity: 1; }
.rename-input { min-height: 48px; font-weight: 700; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
}
.asset-meta { color: var(--text-muted); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.asset-meta .dot { padding: 0 0.35em; }

.mini-wave {
  grid-column: 1 / -1;
  position: relative;
  height: 52px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.mini-canvas { display: block; width: 100%; height: 100%; }

.asset-foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; }
.keep-chip { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; font-size: 0.95rem; color: var(--text-muted); }
.keep-chip .icon { width: 18px; height: 18px; }
.keep-chip.is-kept { color: var(--teal); }
.keep-chip.is-soon { color: var(--warn); }
.asset-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

@media (max-width: 34rem) {
  .asset { padding: 0.9rem; }
  .asset-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .asset-actions .btn { width: 100%; }
}

/* ---------- Editor ---------- */
.edit-head { display: flex; align-items: flex-start; gap: 0.75rem; }
.edit-heading { min-width: 0; display: grid; gap: 0.2rem; padding-top: 0.2rem; }
.edit-heading h1 { overflow-wrap: anywhere; }
.back-link { flex: none; color: var(--text); }
.edit-body { display: grid; gap: 1.5rem; }
.edit-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); align-items: start; }

.wave-card { gap: 1rem; }
.wave-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.tool-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }
@media (max-width: 34rem) {
  .tool-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .tool-group .btn { padding-inline: 0.4rem; }
  .tool-group .icon { display: none; }
}

.wave-stage {
  position: relative;
  border-radius: var(--radius-sm);
  background: var(--wave-bg);
  border: 1px solid var(--border);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}
.wave-canvas { display: block; width: 100%; height: 240px; border-radius: inherit; }
@media (max-width: 34rem) { .wave-canvas { height: 190px; } }

.handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 44px;
  margin-left: -22px;
  cursor: ew-resize;
  touch-action: none;
  z-index: 2;
}
.handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  background: var(--teal);
}
.handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  background: var(--teal);
  border: 3px solid var(--wave-bg);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.handle:hover::after, .handle.is-dragging::after { background: var(--teal-strong); }
.handle:focus-visible { outline: none; }
.handle:focus-visible::after { box-shadow: 0 0 0 3px var(--focus); }
.handle.is-out { visibility: hidden; }
.handle-flag {
  position: absolute;
  bottom: 6px;
  padding: 0.05rem 0.45rem;
  border-radius: 6px;
  background: var(--teal);
  color: var(--on-teal);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
}
.handle-start .handle-flag { left: 22px; border-bottom-left-radius: 0; }
.handle-end .handle-flag { right: 22px; border-bottom-right-radius: 0; }
.wave-stage.is-tight .handle-flag { display: none; }

.overview {
  position: relative;
  height: 48px;
  border-radius: 10px;
  background: var(--wave-bg);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.overview:active { cursor: grabbing; }
.overview-canvas { display: block; width: 100%; height: 100%; }

.transport { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.btn-play { min-width: 8.5rem; background: var(--teal); border-color: var(--teal); color: var(--on-teal); }
.btn-play:hover { background: var(--teal-strong); border-color: var(--teal-strong); }
.clock { margin-left: auto; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock-sep { color: var(--text-muted); padding: 0 0.4em; font-weight: 400; }
#clock-total { color: var(--text-muted); font-weight: 400; }
@media (max-width: 34rem) {
  .transport .btn { flex: 1 1 auto; }
  .clock { margin-left: 0; width: 100%; text-align: center; }
}

.time-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.time-row { display: flex; gap: 0.5rem; }
.time-input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; }
.time-row .btn { flex: none; min-height: 56px; }

.save-card { justify-items: stretch; }
.keys { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; align-items: center; }
.keys-label { font-weight: 700; }
@media (hover: none) and (pointer: coarse) {
  .keys, .time-row kbd { display: none; }
}

/* ---------- Settings ---------- */
.device {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--border);
}
.device:first-child { border-top: 0; padding-top: 0; }
.device-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--teal); flex: none; }
.device-text { flex: 1 1 12rem; min-width: 0; }
.device-name { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.device-meta { color: var(--text-muted); font-size: 0.95rem; }
.device-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.confirm-text { font-weight: 700; flex-basis: 100%; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--teal-soft);
  color: var(--teal-strong);
  border: 1px solid var(--teal);
}

.link-result { display: grid; gap: 0.75rem; padding-top: 0.5rem; }
.qr-box {
  justify-self: start;
  width: min(100%, 236px);
  padding: 12px;
  border-radius: var(--radius-md);
  background: #ffffff;
  box-shadow: var(--shadow);
}
.qr-box svg { display: block; width: 100%; height: auto; }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row .input { flex: 1; min-width: 0; font-size: 0.95rem; }
.copy-row .btn { flex: none; min-height: 56px; }

.meter { height: 14px; }
.meter-text { font-size: 1.05rem; }
.bar.is-high .bar-fill { background: var(--coral); }
.facts { margin: 0; display: grid; gap: 0.1rem; }
.facts > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; border-top: 1px solid var(--border); }
.facts > div:first-child { border-top: 0; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.facts .is-good { color: var(--teal); }
.facts .is-bad { color: var(--danger); }

/* ---------- Signed out / loading ---------- */
.signed-out { justify-items: center; text-align: center; gap: 0.9rem; padding-block: 2.5rem; }
.signed-out-icon.icon, .signed-out-icon .icon { width: 52px; height: 52px; color: var(--teal); }

.loader { display: flex; align-items: center; gap: 7px; height: 52px; }
.loader span { width: 9px; height: 100%; border-radius: 5px; background: var(--teal); animation: eq 1.1s ease-in-out infinite; }
.loader span:nth-child(2) { animation-delay: -0.85s; }
.loader span:nth-child(3) { animation-delay: -0.6s; background: var(--coral); }
.loader span:nth-child(4) { animation-delay: -0.35s; background: var(--coral); }
.loader span:nth-child(5) { animation-delay: -0.1s; background: var(--coral); }

.noscript { padding: 2rem; text-align: center; font-size: 1.2rem; }

/* ---------- Now playing bar ---------- */
.now-playing {
  position: fixed;
  left: 50%;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  width: min(100% - 1.5rem, 40rem);
  padding: 0.55rem 0.6rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--surface-3);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  transform: translateX(-50%);
  animation: float-in 0.3s var(--ease);
}
.np-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-time { color: var(--text-muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.np-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--surface-2); }
.np-fill { display: block; width: 0; height: 100%; background: var(--coral); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: grid;
  gap: 0.6rem;
  width: min(100% - 2rem, 32rem);
  transform: translateX(-50%);
  pointer-events: none;
}
body.has-player .toasts { bottom: calc(6.25rem + env(safe-area-inset-bottom, 0px)); }
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.5rem 0.55rem 1.1rem;
  border-radius: 16px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-float);
  pointer-events: auto;
  animation: rise-in 0.25s var(--ease);
}
.toast-error { border-left: 6px solid var(--toast-danger); }
.toast-icon { display: grid; place-items: center; color: var(--toast-danger); flex: none; }
.toast-icon .icon { width: 24px; height: 24px; }
.toast-text { flex: 1; min-width: 0; padding: 0.3rem 0; font-weight: 700; }
.toast-action {
  min-height: 44px;
  padding: 0.35rem 0.9rem;
  border: 2px solid currentColor;
  border-radius: 12px;
  background: transparent;
  color: var(--toast-action);
  font-weight: 700;
  cursor: pointer;
}
.toast-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  opacity: 0.75;
  cursor: pointer;
}
.toast-close:hover { opacity: 1; }
.toast :focus-visible { outline-color: var(--toast-action); }

/* ---------- Drop overlay ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.drop-box {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  padding: 3rem clamp(1.5rem, 8vw, 5rem);
  border: 3px dashed var(--teal);
  border-radius: 28px;
  background: var(--surface);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}
.drop-box .icon { width: 48px; height: 48px; color: var(--teal); }

/* ---------- Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--coral-soft); }
  50% { box-shadow: 0 0 0 7px var(--coral-soft); }
}
@keyframes eq {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes float-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes leave {
  to { opacity: 0; transform: translateY(10px) scale(0.98); }
}
@keyframes arrive {
  0% { opacity: 0; transform: translateY(-12px); box-shadow: 0 0 0 0 var(--teal-glow); }
  20% { opacity: 1; transform: none; box-shadow: 0 0 0 4px var(--teal-glow); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .asset.is-new { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft), var(--shadow); }
}

@media (forced-colors: active) {
  .handle::before, .handle::after, .bar-fill, .np-fill { background: Highlight; }
  .pill input:checked + .pill-face { border-color: Highlight; }
}
