:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1d1f21;
  --muted: #6b6f75;
  --border: #d9dadc;
  --accent: #3a6df0;
  --accent-text: #ffffff;
  --error: #c62828;
  --ok: #2e7d32;
  --grid: #d0d2d6;
  --wave: #6b7a99;
  --playhead: #e5484d;
  --inst-vowel: #3a6df0;
  --inst-sonorant: #2e9e6b;
  --inst-fricative: #d9822b;
  --inst-plosive: #c4398f;
  --inst-motif: #8a63d2;
  --inst-percussion: #6b6f75;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
/* Dark colours: when the system asks for them, or the Theme button chose
   them (data-theme on <html>, see theme.js); "light" overrides the system. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a;
    --grid: #34373c;
    --wave: #8da2c9;
    --playhead: #ff6369;
    --inst-vowel: #6d94ff;
    --inst-sonorant: #4cc38a;
    --inst-fricative: #f1a14c;
    --inst-plosive: #e66bb4;
    --inst-motif: #a98be8;
    --inst-percussion: #9a9ea5;
    --panel: #212326;
    --text: #e4e5e7;
    --muted: #9a9ea5;
    --border: #3a3d42;
    --accent: #6d94ff;
    --accent-text: #0e1116;
    --error: #ff7b72;
    --ok: #7ee787;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17181a;
  --grid: #34373c;
  --wave: #8da2c9;
  --playhead: #ff6369;
  --inst-vowel: #6d94ff;
  --inst-sonorant: #4cc38a;
  --inst-fricative: #f1a14c;
  --inst-plosive: #e66bb4;
  --inst-motif: #a98be8;
  --inst-percussion: #9a9ea5;
  --panel: #212326;
  --text: #e4e5e7;
  --muted: #9a9ea5;
  --border: #3a3d42;
  --accent: #6d94ff;
  --accent-text: #0e1116;
  --error: #ff7b72;
  --ok: #7ee787;
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.4 system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.bar h1 { font-size: 16px; margin: 0 8px 0 0; }
.doc-name { color: var(--muted); }
.spacer { flex: 1; }
button, .button, select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.button select { border: 0; padding: 0; background: var(--panel); }
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: 0;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.panel-head { display: flex; align-items: baseline; gap: 12px; }
.panel h2 { font-size: 14px; margin: 0; }
.panel h3 { font-size: 13px; margin: 8px 0 0; color: var(--muted); font-weight: 600; }
.validity.ok { color: var(--ok); }
.validity.bad { color: var(--error); }
.audio-state { color: var(--muted); font-size: 12px; }
textarea {
  flex: 1;
  min-height: 420px;
  width: 100%;
  resize: vertical;
  font: 13px/1.5 var(--mono);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.field input {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}
.transport { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.volume { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; color: var(--muted); }
.typewriter {
  min-height: 72px;
  padding: 12px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.hidden-text { color: transparent; }
.rhythm-options { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; margin: 8px 0; }
.rhythm-options input[type="number"] { width: 64px; }
.lanes { display: grid; gap: 4px; margin-top: 10px; }
.lanes canvas { width: 100%; display: block; background: var(--bg); border-radius: 4px; }
#roll { height: 150px; }
#wave { height: 56px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; background: var(--c); vertical-align: -1px; }
.tab-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tab-row .audition { margin-left: auto; }
button.audition .icon { width: 12px; height: 12px; }
.meter { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--accent); transition: width 60ms linear; }
.status-line { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.problems { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.problems li { font-size: 13px; }
.problems li.none { color: var(--muted); }
.problems button {
  border: 0;
  padding: 0;
  text-align: left;
  color: var(--error);
  display: inline;
}
.problems code { font-family: var(--mono); font-weight: 600; }
.drop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 6px 12px;
  border-radius: 6px;
}

.tooltip {
  position: fixed;
  z-index: 20;
  max-width: min(340px, calc(100vw - 16px));
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 12.5px;
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}

/* ---- view tabs and the visual editor ---- */
.tabs { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 4px 10px;
  color: var(--muted);
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab.inherits { font-style: italic; }
.visual {
  flex: 1;
  min-height: 420px;
  max-height: calc(100vh - 170px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 4px;
}
.v-section h3 { font-size: 13px; margin: 0 0 8px; color: var(--text); }
.groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px 20px; }
.group h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 8px 0 4px; }
.row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 46px 20px;
  align-items: center;
  gap: 6px;
  min-height: 28px;
}
.row .label { font-size: 13px; cursor: help; text-decoration: underline dotted color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 3px; }
.row.default .label { color: var(--muted); }
.row.bad .label { color: var(--error); }
.row-problem { grid-column: 1 / -1; color: var(--error); font-size: 12px; }
.ctl { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ctl input[type="range"] { flex: 1; min-width: 60px; accent-color: var(--accent); }
.ctl input[type="text"], .ctl select, .add-row input, .ctl .num {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 0;
}
.ctl input[type="text"], .ctl select { flex: 1; }
.ctl .num { width: 76px; flex: none; }
.row.default .ctl .num, .row.default .ctl select, .row.default .ctl input[type="text"] { color: var(--muted); }
.ctl input.invalid { border-color: var(--error); }
.unit { font-size: 11px; color: var(--muted); }
.reset { border: 0; padding: 0 2px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.inherits-note { padding: 12px 0; }
.pattern { font-family: var(--mono); letter-spacing: 0.08em; }
.beat .row { grid-template-columns: 110px minmax(0, 1fr) 140px; }
.beat .actions { display: flex; gap: 4px; justify-content: flex-end; }
button.small { padding: 1px 8px; font-size: 12px; }
.card { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin-bottom: 8px; }
.card summary { cursor: pointer; display: flex; align-items: center; gap: 6px; }
.card summary .tab-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tab-row .audition { margin-left: auto; }
button.audition .icon { width: 12px; height: 12px; }
details.sample summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
.add-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
select.add { font-size: 13px; }
.samples { list-style: none; padding: 0; margin: 0 0 8px; font-size: 13px; }
.samples li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.samples .none { color: var(--muted); }
.samples button { margin-left: auto; }
.language { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
#lang { flex: 1; min-height: 320px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.steps { display: grid; grid-template-columns: repeat(var(--steps), minmax(0, 1fr)); gap: 2px; min-width: 0; }
.step {
  height: 22px;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  position: relative;
}
.step.beat-start { border-left: 2px solid var(--muted); }
.step.hit { background: var(--accent); border-color: var(--accent); }
.step.ghost { background: color-mix(in srgb, var(--accent) 40%, var(--panel)); }
[data-path="rhythm.accents"] .step::after {
  content: "";
  position: absolute;
  left: 2px; right: 2px; bottom: 2px;
  height: calc(var(--level, 0) * 16px);
  background: var(--inst-motif);
  border-radius: 2px;
}
.row.default[data-path="rhythm.accents"] .step::after { opacity: 0.4; }
.tab.bad { color: var(--error); }
#add-sample { align-self: flex-start; }

/* Modes: the Voice editor and the Dialogue editor share the bar and the
   page; body[data-mode] says which one shows. */
body[data-mode="voice"] #dialogue-mode,
body[data-mode="dialogue"] #voice-mode,
body[data-mode="dialogue"] .voice-only { display: none; }
.modes { border-bottom: 0; margin-right: 8px; }
.stage { display: flex; justify-content: center; background: #1a1c2c; border-radius: 6px; padding: 0; }
.game { border: 0; display: block; max-width: 100%; background: #1a1c2c; }
#dlg-doc { min-height: 360px; }
#dlg-from { width: 4.5em; font: inherit; }

/* The Script tab */
.script { display: flex; flex-direction: column; gap: 6px; min-height: 360px; }
.script h3 { margin: 10px 0 6px; }
.speakers, .lines { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.speaker, .line { display: grid; gap: 4px; border-left: 4px solid var(--c, var(--border)); padding: 4px 8px; background: var(--bg); border-radius: 4px; }
.speaker { grid-template-columns: 6em 1fr 1fr 5em auto auto; align-items: center; }
.speaker .row-problem { grid-column: 1 / -1; }
.speaker input, .speaker select, .line-main select, .line-main input { min-width: 0; font: inherit; }
.line-main { display: grid; grid-template-columns: 9em 1fr auto auto auto auto auto; gap: 4px; align-items: center; }
.line.current { outline: 2px solid var(--accent); }
.speaker.bad, .line.bad { border-left-color: var(--error); }
.row-problem { color: var(--error); font-size: 12px; }
.row-problem:empty { display: none; }
.timing summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.timing-fields { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 4px 0; }
.timing-fields input[type=number] { width: 5.5em; font: inherit; }
.field-inline { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.icon-btn { min-width: 2em; }
@media (max-width: 700px) {
  .speaker { grid-template-columns: 1fr 1fr; }
  .line-main { grid-template-columns: 1fr auto auto auto; }
  .line-main .text { grid-column: 1 / -1; order: 5; }
}
