:root {
  --bg: #0b0c12;
  --panel: #12141c;
  --panel-2: #191c27;
  --panel-3: #222634;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #eceef6;
  --muted: #9aa0b4;
  --faint: #6b7186;
  --accent: #9b8cff;
  --accent-ink: #14112b;
  --accent-soft: rgba(155, 140, 255, 0.16);
  --mint: #5de4c7;
  --danger: #ff6b7a;
  --radius: 16px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  --mono: 'Cascadia Code', 'SF Mono', ui-monospace, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(155, 140, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(93, 228, 199, 0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.45 var(--font);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- bovenbalk ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: rgba(11, 12, 18, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.logo { width: 30px; height: 30px; }
.brand-name { font-weight: 750; font-size: 18px; letter-spacing: -0.01em; }
.title-input {
  flex: 1; min-width: 0; max-width: 420px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 8px 12px; font-size: 16px; font-weight: 600;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--line-2); background: var(--panel); outline: none; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 999px; padding: 9px 16px; border: 1px solid var(--line-2);
  background: var(--panel-2); font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .1s;
  position: relative;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--panel-3); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ada0ff; }
.btn.dirty::after {
  content: ''; position: absolute; top: 4px; right: 6px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 2px var(--bg);
}

/* ---- indeling ---- */
.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: 'controls stage';
  gap: 28px;
  max-width: 1360px; margin: 0 auto; padding: 24px;
}
.controls { grid-area: controls; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stage {
  grid-area: stage; position: sticky; top: 78px; align-self: start;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

/* ---- telefoon-preview ---- */
.phone {
  position: relative;
  width: min(410px, calc((100vh - 190px) * 9 / 16));
  min-width: 260px;
  aspect-ratio: 9 / 16;
  border-radius: 34px;
  padding: 8px;
  background: linear-gradient(160deg, #2a2d3a, #12131a 40%, #1d1f29);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 60px rgba(155, 140, 255, 0.12);
}
.phone canvas { display: block; width: 100%; height: 100%; border-radius: 27px; background: #000; }
.big-play {
  position: absolute; inset: 0; margin: auto; width: 84px; height: 84px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(10, 10, 20, 0.45); backdrop-filter: blur(8px);
  display: grid; place-items: center; color: #fff;
  transition: opacity .2s, transform .2s;
}
.big-play svg { width: 34px; height: 34px; fill: currentColor; stroke: none; margin-left: 4px; }
.big-play:hover { transform: scale(1.05); }
.playing .big-play { opacity: 0; pointer-events: none; transform: scale(.9); }
.render-badge {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: rgba(10, 10, 20, 0.7); border: 1px solid var(--line-2); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--muted); white-space: nowrap;
}
.phone:fullscreen {
  background: #000; padding: 0; border-radius: 0; width: 100vw; display: grid; place-items: center;
}
.phone:fullscreen canvas { width: auto; height: 100vh; max-width: 100vw; aspect-ratio: 9 / 16; border-radius: 0; }

.transport {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:hover { background: var(--panel-3); }
.icon-btn.play { background: var(--accent); color: var(--accent-ink); width: 46px; height: 46px; }
.icon-btn.play:hover { background: #ada0ff; }
.icon-btn.play svg { fill: currentColor; stroke: none; }
.i-pause { display: none; }
.playing .i-pause { display: block; }
.playing .i-play { display: none; }
.time { font-variant-numeric: tabular-nums; font-size: 14px; padding: 0 10px; min-width: 96px; text-align: center; }
.time .sep { color: var(--faint); margin: 0 4px; }
#tTotal { color: var(--muted); }
.loop-toggle { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--faint); cursor: pointer; }
.loop-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.loop-toggle:has(input:checked) { color: var(--mint); background: rgba(93, 228, 199, 0.1); }
.loop-toggle:has(input:focus-visible) { outline: 2px solid var(--accent); }
.song-info { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---- kaarten ---- */
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 80px), var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px 20px;
}
.card h2 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

.prog {
  width: 100%; resize: vertical; min-height: 64px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 14px 16px; font: 600 22px/1.35 var(--mono); letter-spacing: 0.01em;
}
.prog:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; min-height: 34px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 5px 11px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2);
  font-weight: 650; font-size: 15px; transition: background .12s, border-color .12s;
}
.chip small { color: var(--faint); font-weight: 600; font-size: 11px; }
.chip:hover { border-color: var(--accent); }
.chip.current { background: var(--accent-soft); border-color: var(--accent); }
.chip.error { border-color: rgba(255, 107, 122, 0.6); color: var(--danger); background: rgba(255, 107, 122, 0.08); cursor: help; }
.chips .empty { color: var(--faint); font-size: 14px; align-self: center; }

.help { margin-top: 14px; padding: 14px 16px; background: var(--panel-2); border-radius: 12px; color: var(--muted); font-size: 14px; }
.help p { margin: 0 0 8px; }
.help p:last-child { margin: 8px 0 0; }
.help ul { margin: 0; padding-left: 18px; }
.help li { margin: 3px 0; }
.help code { font-family: var(--mono); color: var(--text); background: var(--panel-3); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.presets { margin-top: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.label, .field-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.presets .label { min-width: 118px; }
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 5px 12px;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.preset:hover { color: var(--text); border-color: var(--accent); }

/* ---- velden ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; margin-top: 4px; }
.span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > label { color: var(--muted); font-size: 13px; font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; margin-left: auto; }
.unit { color: var(--faint); font-size: 12px; }
.field input[type='text'] {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px;
}
.field input[type='text']:focus { outline: none; border-color: var(--accent); }

input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type='range']::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--panel-3) var(--p, 50%));
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 6px; background: var(--panel-3); }
input[type='range']::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; margin-top: -6px;
  background: #fff; border: none; box-shadow: 0 0 0 4px var(--accent-soft), 0 2px 6px rgba(0, 0, 0, .4);
}
input[type='range']::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: none; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; border: none; background: transparent; border-radius: 7px; padding: 6px 4px;
  font-size: 13px; font-weight: 650; color: var(--muted); white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked='true'] { background: var(--panel-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  width: 36px; height: 20px; border-radius: 999px; background: var(--panel-3); position: relative; flex: none;
  transition: background .15s;
}
.switch span::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #cfd2de; transition: transform .15s, background .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggles { display: flex; flex-wrap: wrap; gap: 12px 22px; margin-top: 18px; }

/* ---- klanken ---- */
.sound-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 18px; }
.sound {
  text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
  transition: border-color .12s, background .12s;
}
.sound b { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sound span { font-size: 12px; color: var(--faint); line-height: 1.3; }
.sound:hover { border-color: var(--line-2); background: var(--panel-3); }
.sound[aria-checked='true'] { border-color: var(--accent); background: var(--accent-soft); }
.sound[aria-checked='true'] span { color: var(--muted); }

/* ---- thema's ---- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-bottom: 18px; }
.theme {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--muted);
}
.theme i { display: block; width: 100%; height: 34px; border-radius: 8px; }
.theme:hover { border-color: var(--line-2); color: var(--text); }
.theme[aria-checked='true'] { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.custom-colors { display: flex; gap: 18px; flex-wrap: wrap; margin: -4px 0 18px; font-size: 13px; color: var(--muted); }
.custom-colors label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.custom-colors input[type='color'] {
  width: 34px; height: 34px; border: 1px solid var(--line-2); border-radius: 10px; padding: 2px; background: var(--bg); cursor: pointer;
}

/* ---- bibliotheek ---- */
.library {
  width: min(560px, calc(100vw - 32px)); max-height: min(720px, calc(100vh - 64px));
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 20px; padding: 0;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6);
}
.library::backdrop { background: rgba(4, 4, 10, 0.6); backdrop-filter: blur(4px); }
.lib-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 0 22px; }
.lib-head h2 { margin: 0; font-size: 18px; }
.lib-where { margin: 4px 22px 12px; color: var(--muted); font-size: 13px; }
.lib-list { display: flex; flex-direction: column; gap: 6px; padding: 0 14px 16px; overflow: auto; max-height: calc(min(720px, 100vh - 64px) - 90px); }
.lib-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid transparent; cursor: pointer;
}
.lib-item:hover { border-color: var(--line-2); }
.lib-item.active { border-color: var(--accent); }
.lib-item .t { font-weight: 700; }
.lib-item .p { grid-column: 1; font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .d { font-size: 12px; color: var(--faint); }
.lib-item .del { grid-row: 1 / span 2; grid-column: 2; }
.lib-item .del:hover { color: var(--danger); background: rgba(255, 107, 122, 0.1); }
.lib-empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 999px; padding: 10px 18px; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 107, 122, 0.6); }

/* ---- responsief ---- */
@media (max-width: 860px) {
  .studio { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'stage' 'controls'; padding: 16px; gap: 18px; }
  .stage { position: static; }
  .phone { width: min(100%, calc(62vh * 9 / 16)); min-width: 0; border-radius: 28px; }
  .phone canvas { border-radius: 21px; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .title-input { order: 3; flex-basis: 100%; max-width: none; }
  .btn span { display: none; }
  .btn { padding: 9px 11px; }
}
@media (max-width: 520px) {
  .sound-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .prog { font-size: 18px; }
  .card { padding: 16px; }
}
