/* Audio Studio — Material 3 Expressive styling (hand-written tokens, no build step) */
:root {
  color-scheme: light;
  /* colour roles (seed ~ #6D4AFF, tertiary coral) */
  --primary: #5b3fd6; --on-primary: #fff;
  --primary-container: #e6deff; --on-primary-container: #1d0060;
  --secondary: #5f5b71; --secondary-container: #e5dff9; --on-secondary-container: #1b192c;
  --tertiary: #9b4061; --tertiary-container: #ffd9e2; --on-tertiary-container: #3e001d;
  --error: #ba1a1a; --error-container: #ffdad6;
  --surface: #fdf8ff; --surface-dim: #ddd8e3;
  --surface-c-lowest: #ffffff; --surface-c-low: #f7f2fc; --surface-c: #f1ecf7; --surface-c-high: #ebe6f1; --surface-c-highest: #e6e0eb;
  --on-surface: #1c1b20; --on-surface-variant: #48454f; --outline: #79757f; --outline-variant: #cac4d0;
  --inverse-surface: #312f36; --inverse-on-surface: #f4eff7;
  /* shape scale (expressive = rounder, bigger) */
  --r-xs: 4px; --r-s: 8px; --r-m: 12px; --r-l: 16px; --r-xl: 28px; --r-xxl: 48px; --r-full: 999px;
  /* motion: expressive springs approximated with overshooting béziers */
  --spring-fast: cubic-bezier(.42, 1.67, .21, .9);
  --spring-default: cubic-bezier(.38, 1.21, .22, 1);
  --ease-emph: cubic-bezier(.2, 0, 0, 1);
  --font: "Roboto Flex", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --primary: #cabeff; --on-primary: #2f0b9b;
    --primary-container: #4524bd; --on-primary-container: #e6deff;
    --secondary: #c9c3dc; --secondary-container: #48455a; --on-secondary-container: #e5dff9;
    --tertiary: #ffb0c8; --tertiary-container: #7d2949; --on-tertiary-container: #ffd9e2;
    --error: #ffb4ab; --error-container: #93000a;
    --surface: #141218; --surface-dim: #141218;
    --surface-c-lowest: #0f0d13; --surface-c-low: #1c1b20; --surface-c: #201f25; --surface-c-high: #2b292f; --surface-c-highest: #36343a;
    --on-surface: #e6e0e9; --on-surface-variant: #cac4d0; --outline: #948f99; --outline-variant: #48454f;
    --inverse-surface: #e6e0e9; --inverse-on-surface: #312f36;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--surface); color: var(--on-surface); font-size: 15px; line-height: 1.45;
  font-variation-settings: "wdth" 100; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.ms { font-family: "Material Symbols Rounded"; font-weight: normal; font-style: normal; font-size: 22px; line-height: 1;
  letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; direction: ltr;
  font-variation-settings: "FILL" 0, "wght" 500, "opsz" 24; -webkit-font-smoothing: antialiased; user-select: none; }
.active > .ms, .ms.fill { font-variation-settings: "FILL" 1, "wght" 600, "opsz" 24; }
.display { font-size: 44px; line-height: 1.1; margin: 8px 0 4px; font-weight: 800; font-variation-settings: "wdth" 120; letter-spacing: -.5px; }
.headline { font-size: clamp(28px, 4vw, 40px); line-height: 1.12; margin: 0; font-weight: 750; font-variation-settings: "wdth" 115; letter-spacing: -.4px; }
.title { font-size: 20px; margin: 0; font-weight: 650; font-variation-settings: "wdth" 108; }
.muted { color: var(--on-surface-variant); margin: 4px 0 0; }
.small { font-size: 13px; }
.error { color: var(--error); min-height: 1.2em; margin: 4px 0; font-size: 14px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; } .row.end { justify-content: flex-end; }

/* ---------------- buttons (shape-morphing) ---------------- */
.btn { --h: 40px; font: inherit; font-weight: 600; font-variation-settings: "wdth" 105; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; height: var(--h); padding: 0 20px; border: 0; cursor: pointer; border-radius: var(--r-full);
  transition: border-radius .35s var(--spring-fast), transform .35s var(--spring-fast), background .2s, box-shadow .2s;
  position: relative; overflow: hidden; white-space: nowrap; color: inherit; background: transparent; }
.btn::after { content: ""; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity .15s; }
.btn:hover::after { opacity: .08; } .btn:active::after { opacity: .12; }
.btn:active { border-radius: var(--r-m); transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn .ms { font-size: 20px; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.btn.outlined { border: 1px solid var(--outline-variant); color: var(--on-surface-variant); }
.btn.text { color: var(--primary); padding: 0 12px; }
.btn.danger { color: var(--error); }
.btn.xl { --h: 64px; padding: 0 32px; font-size: 18px; border-radius: var(--r-xl); }
.btn.xl .ms { font-size: 26px; }
.btn.xl:active { border-radius: var(--r-l); }
.btn.morph.busy { border-radius: var(--r-l); background: var(--tertiary-container); color: var(--on-tertiary-container); }
.icon-btn { width: 40px; height: 40px; border-radius: var(--r-full); border: 0; display: inline-grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--on-surface-variant); transition: border-radius .3s var(--spring-fast), background .2s; flex: none; }
.icon-btn:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.icon-btn:active { border-radius: var(--r-m); }
.icon-btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.icon-btn.play { width: 56px; height: 56px; border-radius: var(--r-l); background: var(--primary); color: var(--on-primary); }
.icon-btn.play.playing { border-radius: var(--r-full); background: var(--tertiary); color: #fff; }
.icon-btn.play .ms { font-size: 30px; }

/* connected button group (M3 Expressive) */
.button-group { display: inline-flex; gap: 2px; margin: 24px 0 8px; flex-wrap: wrap; }
.seg { font: inherit; font-weight: 600; height: 56px; padding: 0 24px; border: 0; cursor: pointer; display: inline-flex; gap: 8px; align-items: center;
  background: var(--surface-c-highest); color: var(--on-surface-variant); border-radius: var(--r-s);
  transition: border-radius .4s var(--spring-fast), background .25s, color .25s; font-size: 16px; }
.seg:first-child { border-radius: var(--r-full) var(--r-s) var(--r-s) var(--r-full); }
.seg:last-child { border-radius: var(--r-s) var(--r-full) var(--r-full) var(--r-s); }
.seg.active { background: var(--primary); color: var(--on-primary); border-radius: var(--r-full); }
.seg:active { border-radius: var(--r-m); }

/* ---------------- login ---------------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.login-blob { position: absolute; width: 900px; height: 900px; background: radial-gradient(circle at 30% 30%, var(--primary-container), transparent 60%),
  radial-gradient(circle at 70% 70%, var(--tertiary-container), transparent 55%); filter: blur(20px); opacity: .9;
  border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%; animation: blob 18s ease-in-out infinite alternate; }
@keyframes blob { to { border-radius: 63% 37% 38% 62% / 58% 33% 67% 42%; transform: rotate(40deg) scale(1.08); } }
.login-card { position: relative; width: min(420px, 100%); background: var(--surface-c-low); border-radius: var(--r-xxl); padding: 40px 32px 32px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 8px 40px rgb(0 0 0 / .12); }
.login-card .btn { margin-top: 8px; }
.brand-mark { width: 48px; height: 48px; border-radius: 16px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center;
  clip-path: polygon(50% 0, 61% 10%, 75% 6%, 80% 20%, 94% 25%, 90% 39%, 100% 50%, 90% 61%, 94% 75%, 80% 80%, 75% 94%, 61% 90%, 50% 100%, 39% 90%, 25% 94%, 20% 80%, 6% 75%, 10% 61%, 0 50%, 10% 39%, 6% 25%, 20% 20%, 25% 6%, 39% 10%); }
.brand-mark.big { width: 72px; height: 72px; } .brand-mark.big .ms { font-size: 36px; }

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: 96px 1fr; min-height: 100%; }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 0;
  background: var(--surface-c-low); }
.rail .brand-mark { margin-bottom: 20px; }
.rail-spacer { flex: 1; }
.rail-item { font: inherit; font-size: 12px; font-weight: 600; border: 0; background: none; color: var(--on-surface-variant); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 80px; max-width: 80px; overflow: hidden; }
.rail-item span:last-child { max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .ms { width: 56px; height: 32px; display: grid; place-items: center; border-radius: var(--r-full);
  transition: background .25s, width .4s var(--spring-fast); }
.rail-item:hover .ms { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.rail-item.active { color: var(--on-surface); }
.rail-item.active .ms { background: var(--secondary-container); color: var(--on-secondary-container); width: 64px; }
.content { padding: 32px clamp(16px, 4vw, 56px) 80px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.view { animation: enter .45s var(--ease-emph); }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: 80px; flex-direction: row; justify-content: space-around;
    padding: 8px 4px; z-index: 5; }
  .rail .brand-mark, .rail-spacer { display: none; }
  .content { padding-bottom: 110px; }
  .seg { padding: 0 16px; height: 48px; }
}

/* ---------------- cards & fields ---------------- */
.card { background: var(--surface-c-low); border-radius: var(--r-xl); padding: 24px; }
.form-card { margin-top: 16px; display: flex; flex-direction: column; gap: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--on-surface-variant); }
.field input, .field select, .field textarea { font: inherit; font-size: 16px; font-weight: 400; color: var(--on-surface);
  background: var(--surface-c-highest); border: 0; border-bottom: 2px solid var(--outline); border-radius: var(--r-s) var(--r-s) 0 0;
  padding: 12px 14px; outline: none; transition: border-color .2s, border-radius .3s var(--spring-default); width: 100%; }
.field textarea { resize: vertical; min-height: 56px; }
.field.big textarea { font-size: 18px; border-radius: var(--r-l) var(--r-l) var(--r-xs) var(--r-xs); padding: 16px 18px; }
.field input:focus, .field select:focus, .field textarea:focus { border-bottom-color: var(--primary); }
.field.search { flex-direction: row; align-items: center; background: var(--surface-c-high); border-radius: var(--r-full); padding: 0 16px;
  margin: 20px 0; max-width: 480px; }
.field.search input { background: none; border: 0; }
.field.slider input { padding: 0; height: 40px; background: none; border: 0; accent-color: var(--primary); }
.field.slider b { color: var(--primary); }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--surface-c-highest); border-radius: var(--r-full); padding: 4px; width: fit-content; }
.stepper output { min-width: 32px; text-align: center; font-size: 18px; font-weight: 700; color: var(--on-surface); }
.advanced summary { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--primary); list-style: none; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced[open] summary { margin-bottom: 16px; }
.actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.actions .muted { flex: 1; min-width: 200px; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; color: var(--on-surface); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 52px; height: 32px; border-radius: var(--r-full); background: var(--surface-c-highest); border: 2px solid var(--outline);
  position: relative; transition: background .2s; flex: none; }
.switch .thumb { position: absolute; top: 6px; left: 6px; width: 16px; height: 16px; border-radius: 50%; background: var(--outline);
  transition: all .35s var(--spring-fast); }
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track .thumb { left: 22px; top: 2px; width: 24px; height: 24px; background: var(--on-primary); }
.switch input:focus-visible + .track { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------------- templates ---------------- */
.templates-head { display: flex; align-items: center; gap: 16px; margin-top: 24px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; height: 32px; padding: 0 14px; border-radius: var(--r-s); cursor: pointer;
  border: 1px solid var(--outline-variant); background: none; color: var(--on-surface-variant); transition: border-radius .3s var(--spring-fast), background .2s; }
.chip.active { background: var(--secondary-container); color: var(--on-secondary-container); border-color: transparent; border-radius: var(--r-l); }
.carousel { display: flex; gap: 12px; overflow-x: auto; padding: 16px 2px 12px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.tpl { scroll-snap-align: start; flex: 0 0 184px; height: 168px; border: 0; cursor: pointer; text-align: left; font: inherit; padding: 18px;
  display: flex; flex-direction: column; justify-content: space-between; border-radius: var(--r-xl); color: var(--on-primary-container);
  background: var(--primary-container); transition: border-radius .45s var(--spring-fast), transform .45s var(--spring-fast), flex-basis .45s var(--spring-default); }
.tpl:nth-child(3n+2) { background: var(--tertiary-container); color: var(--on-tertiary-container); }
.tpl:nth-child(3n+3) { background: var(--secondary-container); color: var(--on-secondary-container); }
.tpl:hover { border-radius: var(--r-xxl); transform: translateY(-3px); }
.tpl:active { transform: scale(.96); }
.tpl.selected { flex-basis: 236px; outline: 3px solid var(--primary); outline-offset: 2px; }
.tpl .ms { font-size: 36px; font-variation-settings: "FILL" 1, "wght" 500; }
.tpl b { font-size: 17px; font-variation-settings: "wdth" 110; display: block; }
.tpl small { opacity: .75; font-weight: 600; }

/* ---------------- progress / loader ---------------- */
.progress { margin-top: 16px; display: flex; align-items: center; gap: 20px; background: var(--surface-c); }
.progress p { margin: 2px 0 0; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; color: var(--primary); }
/* M3 Expressive loading indicator: a morphing polygon */
.loader { width: 48px; height: 48px; display: grid; place-items: center; flex: none; }
.loader span { width: 38px; height: 38px; background: var(--primary); animation: morph 1.6s var(--spring-default) infinite; }
@keyframes morph {
  0%   { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%, 50% 0, 50% 0, 50% 0, 50% 0); transform: rotate(0); border-radius: 0; }
  33%  { clip-path: polygon(50% 0, 85% 15%, 100% 50%, 85% 85%, 50% 100%, 15% 85%, 0 50%, 15% 15%); transform: rotate(120deg); }
  66%  { clip-path: polygon(20% 0, 80% 0, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0 80%, 0 20%); transform: rotate(240deg); }
  100% { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%, 50% 0, 50% 0, 50% 0, 50% 0); transform: rotate(360deg); }
}

/* ---------------- results & library ---------------- */
.results { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }
.result-group { background: var(--surface-c-low); border-radius: var(--r-xl); padding: 20px; animation: enter .5s var(--spring-default); }
.result-group h3 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.take { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; padding: 12px; border-radius: var(--r-l);
  background: var(--surface-c-lowest); margin-top: 10px; }
.take .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.take .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: var(--r-full); background: var(--surface-c-high); color: var(--on-surface-variant); }
.badge.warn { background: var(--error-container); color: var(--error); }
.take .tools { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.wave { height: 36px; width: 100%; display: block; margin-top: 6px; cursor: pointer; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list.compact .take { grid-template-columns: 1fr auto; margin: 0; }
.empty { padding: 48px 16px; text-align: center; color: var(--on-surface-variant); }
.empty .ms { font-size: 48px; display: block; margin: 0 auto 8px; }

@media (max-width: 600px) {
  .take { grid-template-columns: auto 1fr; }
  .take .tools { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------------- admin ---------------- */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-top: 24px; }
.admin-grid .wide { grid-column: 1 / -1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--on-surface-variant); } .kv dd { margin: 0; font-weight: 500; word-break: break-all; }
pre.log { background: var(--surface-c-lowest); border-radius: var(--r-l); padding: 12px 14px; font-size: 12px; max-height: 260px; overflow: auto;
  white-space: pre-wrap; word-break: break-word; }
.pill-ok { color: #1b6e2f; } .pill-bad { color: var(--error); }
@media (prefers-color-scheme: dark) { .pill-ok { color: #8ad89b; } }

/* ---------------- dialog / snackbar ---------------- */
.dlg { border: 0; border-radius: var(--r-xl); padding: 24px; background: var(--surface-c-high); color: var(--on-surface); width: min(460px, 92vw); }
.dlg::backdrop { background: rgb(0 0 0 / .4); }
.dlg[open] { animation: pop .4s var(--spring-fast); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.dlg form { display: flex; flex-direction: column; gap: 14px; }
.snackbar { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 150%); background: var(--inverse-surface); color: var(--inverse-on-surface);
  padding: 14px 20px; border-radius: var(--r-m); max-width: min(560px, 92vw); transition: transform .45s var(--spring-fast); z-index: 20; font-weight: 500; }
.snackbar.show { transform: translate(-50%, 0); }
@media (max-width: 760px) { .snackbar { bottom: 96px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
