:root {
  --bg: #0e0c12;
  --surface: #17141d;
  --surface-2: #1f1b27;
  --border: #2e2838;
  --text: #ece6dc;
  --text-2: #a59cae;
  --text-3: #6f6779;
  --gold: #c9a46a;
  --scene: #c9a46a;
  --danger: #d0574f;
  --ok: #6fbf73;
  --music: #8e6cc9;
  --ambiance: #4f8fc0;
  --sfx: #d08a3c;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.45; }
body { min-height: 100vh; }
[hidden] { display: none !important; }

button {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.9rem;
  cursor: pointer; transition: background .15s, border-color .15s, transform .08s;
}
button:hover:not(:disabled) { border-color: var(--text-3); background: #28222f; }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}
button.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #d8b67f; }
button.danger { color: #f2b5b0; border-color: #5a2c2a; }
button.danger:hover:not(:disabled) { background: #3a1f1e; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px;
  background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--border); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--border); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px;
  border-radius: 50%; background: var(--gold); border: 3px solid var(--bg);
}
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--gold); border: 3px solid var(--bg); }
input[type=text], input[type=password], input[type=search], select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.6rem;
}

.brand { font-family: var(--serif); font-size: 2.6rem; letter-spacing: 0.08em; color: var(--gold); }
.brand.small { font-size: 1.25rem; }

.conn { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; color: var(--text-2); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.conn.on i { background: var(--ok); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.card h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--text-2); font-weight: 600;
}
.sub { font-size: 0.8rem; color: var(--text-3); }

.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.9rem; font-size: 0.85rem; box-shadow: 0 6px 24px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out; }
.toast.error { border-color: #5a2c2a; color: #f2b5b0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Player page ---------- */

.gate {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--scene) 14%, var(--bg)) 0%, var(--bg) 70%);
}
.gate-inner { text-align: center; max-width: 26rem; display: grid; gap: 1.1rem; justify-items: center; }
.gate-scene { font-family: var(--serif); font-size: 1.15rem; color: var(--text-2); }
.gate .primary { font-size: 1.1rem; padding: 0.85rem 2rem; border-radius: 999px; }
.gate .hint { font-size: 0.85rem; color: var(--text-3); }

.stage { max-width: 40rem; margin: 0 auto; padding: 1rem 1rem 3rem; display: grid; gap: 1.25rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.scene { text-align: center; display: grid; justify-items: center; gap: 0.6rem; padding: 1.5rem 0 0.5rem; }
.orb {
  --level: 0;
  width: 9rem; height: 9rem; border-radius: 50%; margin-bottom: 0.75rem;
  background: radial-gradient(circle at 50% 45%,
    color-mix(in srgb, var(--scene) 85%, white) 0%, var(--scene) 30%,
    color-mix(in srgb, var(--scene) 30%, transparent) 62%, transparent 72%);
  opacity: calc(0.45 + var(--level) * 1.6);
  transform: scale(calc(0.92 + var(--level) * 0.7));
  filter: blur(1px);
  transition: background 1.5s;
}
.scene h1 { font-family: var(--serif); font-weight: normal; font-size: clamp(1.8rem, 6vw, 2.6rem); line-height: 1.15; }
.scene p { color: var(--text-2); max-width: 32rem; }
.playing { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 0.4rem; }
.playing li { font-size: 0.78rem; padding: 0.2rem 0.6rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.playing li::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 0.4rem; vertical-align: middle; background: var(--music); }
.playing li.ambiance::before { background: var(--ambiance); }
.paused-note { font-size: 0.85rem; color: var(--gold); }

.caption {
  font-family: var(--serif); font-style: italic; font-size: 1.15rem; color: var(--text);
  min-height: 1.7em; transition: opacity .6s;
}

.mixer { display: grid; gap: 0.6rem; }
.mixer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.2rem; }
.mix-row { display: grid; grid-template-columns: 6.5rem 1fr 2.8rem; align-items: center; gap: 0.75rem; }
.mix-row label { font-size: 0.9rem; }
.mix-row output { font-size: 0.8rem; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.toggle { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.7rem; align-items: center;
  padding: 0.6rem 0.2rem 0; border-top: 1px solid var(--border); cursor: pointer; }
.toggle input { width: 1.15rem; height: 1.15rem; accent-color: var(--gold); }
.toggle small { grid-column: 2; color: var(--text-3); font-size: 0.8rem; }

@media (prefers-reduced-motion: reduce) {
  .orb { transform: none !important; transition: none; }
}

/* ---------- GM page ---------- */

.gm-header {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.gm-header .inner { max-width: 82rem; margin: 0 auto; padding: 0.6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.gm-header .spacer { flex: 1; }
.listeners { font-size: 0.8rem; color: var(--text-2); }
.listen-btn.on { border-color: var(--ok); color: #bfe8c1; }

.gm-grid { max-width: 82rem; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .gm-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; } }
.col { display: grid; gap: 1rem; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.card-head .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.card-head .actions button, .small-btn { font-size: 0.78rem; padding: 0.3rem 0.65rem; }

.now { border-left: 4px solid var(--scene); }
.now-title { font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; }
.now-desc { color: var(--text-2); font-size: 0.9rem; margin-top: 0.15rem; }
.transport { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.9rem; }
.transport .grow { flex: 1 1 12rem; display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--text-2); }
.transport select { font-size: 0.85rem; }

.layers { margin-top: 0.9rem; display: grid; gap: 0.15rem; }
.layer { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr) minmax(6rem, 11rem) 2.4rem 2rem;
  gap: 0.6rem; align-items: center; padding: 0.3rem 0; border-top: 1px solid var(--border); }
.layer .name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer output { font-size: 0.78rem; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.layer button { padding: 0.15rem 0; font-size: 0.85rem; color: var(--text-2); }
.empty { color: var(--text-3); font-size: 0.85rem; font-style: italic; padding: 0.4rem 0; }

.badge { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em; text-align: center;
  padding: 0.15rem 0.4rem; border-radius: 4px; background: var(--music); color: #fff; }
.badge.ambiance { background: var(--ambiance); }
.badge.sfx { background: var(--sfx); }

.playlist-bar { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; padding: 0.5rem 0.7rem;
  border-radius: 8px; background: var(--surface-2); font-size: 0.85rem; flex-wrap: wrap; }
.playlist-bar .grow { flex: 1; min-width: 8rem; color: var(--text-2); }
.playlist-bar strong { color: var(--text); font-weight: 600; }

.grid-buttons { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); }
.pad { position: relative; text-align: left; min-height: 3.6rem; padding: 0.55rem 2rem 0.55rem 0.7rem;
  display: flex; flex-direction: column; justify-content: center; gap: 0.1rem; overflow: hidden; }
.pad .label { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad .meta { font-size: 0.72rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad kbd { position: absolute; top: 0.35rem; right: 0.4rem; font: 0.65rem var(--sans); color: var(--text-3);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem; }
.scene-pad { border-left: 4px solid var(--pad-color, var(--gold)); }
.scene-pad.active { background: color-mix(in srgb, var(--pad-color, var(--gold)) 18%, var(--surface-2));
  border-color: var(--pad-color, var(--gold)); }
.amb-pad.on { background: color-mix(in srgb, var(--ambiance) 22%, var(--surface-2)); border-color: var(--ambiance); }
.amb-pad.on .meta { color: #a9cbe6; }
.sfx-pad { min-height: 3.2rem; }
.sfx-pad.fired { animation: fired .45s ease-out; }
@keyframes fired { 0% { background: var(--sfx); border-color: var(--sfx); } 100% {} }

.library-tools { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.library-tools input { flex: 1; min-width: 0; }
.library { max-height: 26rem; overflow-y: auto; }
.folder { display: flex; align-items: center; gap: 0.4rem; padding: 0.6rem 0 0.3rem;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); }
.folder span { flex: 1; }
.track { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.4rem; border-radius: 6px; font-size: 0.9rem; }
.track:hover { background: var(--surface-2); }
.track span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track.playing span { color: var(--gold); }

.deck-list { display: grid; gap: 0.35rem; margin-top: 0.6rem; }
.deck-row { display: grid; grid-template-columns: 8rem minmax(0, 1fr) auto; gap: 0.5rem; align-items: center; font-size: 0.8rem; }
.deck-row code { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--bg); padding: 0.2rem 0.4rem; border-radius: 4px; }
.deck-group { margin-top: 0.8rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
.help { font-size: 0.85rem; color: var(--text-2); display: grid; gap: 0.4rem; margin-top: 0.6rem; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.8rem; font-size: 0.85rem; margin-top: 0.6rem; }
.keys kbd { font: 0.75rem var(--sans); border: 1px solid var(--border); border-radius: 4px; padding: 0.05rem 0.4rem; justify-self: start; }

.upload { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.keygate { max-width: 82rem; margin: 1rem auto 0; padding: 0 1rem; }
.keygate .card { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; border-color: var(--gold); }

@media (max-width: 600px) {
  .layer { grid-template-columns: 4.6rem minmax(0, 1fr) 2rem; }
  .layer input, .layer output { display: none; }
  .mix-row { grid-template-columns: 5.5rem 1fr 2.6rem; }
}
