:root {
  --bg: #0a0b0f;
  --panel: #13151c;
  --panel-2: #171a22;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --ink: #ece7dd;
  --muted: #9c988f;
  --accent: #f0a83c;
  --accent-2: #7fb2ff;
  --good: #5fd08a;
  --warn: #ff9f57;
  --radius: 12px;
  --touch: 44px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.sr, .skip {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip:focus {
  position: fixed; top: 8px; left: 8px; z-index: 200; width: auto; height: auto; clip: auto;
  background: var(--accent); color: #16181d; padding: 10px 14px; border-radius: 8px; font-weight: 700;
}

/* ---------------- header ---------------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #14161d, #0e1015);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.mark { color: var(--accent); display: grid; place-items: center; }
.brand-text h1 { font-size: 16px; margin: 0; letter-spacing: 0.01em; }
.brand-text .sub { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

.header-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.field-label { text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.field-label b { color: var(--ink); font-weight: 600; }
select, input[type="number"] {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; min-height: 38px;
}
input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; height: 22px; width: 100%; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--accent), #6b5a3a); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6.5px; border-radius: 50%; background: #f6efe2; border: 2px solid #2a2c34; }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: #6b5a3a; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #f6efe2; border: 2px solid #2a2c34; }
.field-haze input { width: 130px; }

.tool-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: 9px; padding: 9px 13px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; min-height: 38px;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-accent { background: #2c2416; border-color: #6a5426; color: #ffd894; }
.btn-primary { background: #2c2416; border-color: #6a5426; color: #ffd894; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 10px; font-size: 12px; min-height: 34px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------------- layout ---------------- */
.layout {
  flex: 1; min-height: 0; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: 290px minmax(0, 1fr) 320px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); }

/* ---------------- rig ---------------- */
.rig-list { overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 40%; }
.fx-row {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid transparent; border-radius: 9px;
  padding: 8px 9px; color: var(--ink); font: inherit; cursor: pointer; min-height: var(--touch);
}
.fx-row:hover { border-color: var(--line-2); }
.fx-row.sel { border-color: var(--accent); background: #1d1a14; }
.fx-ch { font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700; color: var(--accent); width: 22px; }
.fx-sw { width: 12px; height: 24px; border-radius: 4px; border: 1px solid var(--line-2); flex: none; }
.fx-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fx-name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-type { font-size: 10.5px; color: var(--muted); }
.fx-lvl { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }

.rig-editor { overflow: auto; padding: 10px 12px 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.ed-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ed-title h3 { margin: 0; font-size: 14px; }
.ed-sub { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.ed-note { font-size: 11.5px; color: var(--muted); margin: 4px 0 0; border-left: 2px solid var(--line-2); padding-left: 8px; }

.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; }
.ctl-label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 10.5px; font-weight: 700; }
.ctl-val { font-variant-numeric: tabular-nums; color: var(--ink); font-size: 12px; }
.ctl-select { width: 100%; min-height: var(--touch); }
.ctl-check { flex-direction: row; align-items: center; gap: 10px; min-height: var(--touch); }
.ctl-check input { width: 20px; height: 20px; accent-color: var(--accent); }
.ctl-check .ctl-label { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink); font-weight: 500; }

.gel-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.gel-sw { width: 100%; aspect-ratio: 1; border-radius: 6px; border: 2px solid rgba(255, 255, 255, 0.14); cursor: pointer; padding: 0; min-height: 30px; }
.gel-sw.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.gel-name { font-size: 11.5px; color: var(--muted); }

/* ---------------- stage ---------------- */
.stage-wrap { display: flex; flex-direction: column; min-height: 0; gap: 10px; }
.stage-frame {
  position: relative; flex: 1; min-height: 220px; border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; background: #05060a;
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#stage:active { cursor: grabbing; }
.stage-overlay { position: absolute; inset: 0; pointer-events: none; padding: 10px 12px; display: flex; flex-direction: column; justify-content: space-between; }
.scene-blurb { font-size: 12px; color: rgba(236, 231, 221, 0.72); max-width: 46ch; text-shadow: 0 1px 6px #000; }
.live-readout { align-self: flex-end; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(236, 231, 221, 0.7); border: 1px solid var(--line-2); border-radius: 999px; padding: 4px 10px; background: rgba(8, 9, 12, 0.6); }

.transport {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: relative;
}
.transport-main { display: flex; gap: 8px; }
.btn-go {
  background: linear-gradient(180deg, #3a2f18, #241d10); border-color: #7a5f28; color: #ffdd9e;
  font-weight: 800; letter-spacing: 0.08em; padding: 10px 22px; min-height: var(--touch);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-go:not(:disabled):hover { background: #4a3a1c; }
.btn-icon { min-width: var(--touch); min-height: var(--touch); font-size: 15px; }
.key-hint { font-size: 10px; color: #b79a63; letter-spacing: 0.04em; }
.transport-state { display: flex; gap: 16px; flex: 1; min-width: 220px; align-items: center; flex-wrap: wrap; }
.state-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.state-cell.grow { flex: 1; min-width: 150px; }
.state-key { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.state-val { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state-val.next { color: var(--accent-2); }
.fade-track { display: block; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.09); overflow: hidden; }
.fade-track.active { box-shadow: 0 0 0 1px rgba(240, 168, 60, 0.5); }
.fade-bar { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ffd894); }
.fade-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.transport-side { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.field-time input { width: 78px; }
.mod-chip {
  position: static; align-self: center; display: flex; align-items: center; gap: 8px;
  background: #2a2113; border: 1px solid #6a5426; color: #ffd894; border-radius: 999px;
  padding: 4px 6px 4px 12px; font-size: 11.5px;
}
.mod-chip[hidden] { display: none; }

/* ---------------- cues ---------------- */
.cue-list { overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 120px; }
.cue-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid transparent; cursor: pointer; min-height: var(--touch);
}
.cue-row:hover { border-color: var(--line-2); }
.cue-row.live { border-color: var(--accent); background: #1d1a14; }
.cue-row.next { border-color: var(--accent-2); }
.cue-row.cmp { box-shadow: inset 3px 0 0 var(--accent-2); }
.cue-num { font-weight: 800; font-size: 13px; width: 18px; color: var(--accent); }
.cue-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cue-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cue-info { font-size: 10.5px; color: var(--muted); }
.cue-state { font-size: 9.5px; letter-spacing: 0.1em; font-weight: 700; color: var(--accent); }
.cue-go { background: #241d10; border: 1px solid #6a5426; color: #ffd894; border-radius: 7px; padding: 6px 10px; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; min-height: 32px; }
.empty { color: var(--muted); font-size: 12px; padding: 8px; }

.notes { border-top: 1px solid var(--line); padding: 10px 12px 14px; max-height: 46%; overflow: auto; }
.notes.collapsed .notes-list { display: none; }
.notes-head { display: flex; align-items: center; justify-content: space-between; }
.notes-head h3 { font-size: 12px; margin: 0; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.notes-list { display: flex; flex-direction: column; gap: 7px; margin-top: 8px; }
.note { border-left: 3px solid var(--line-2); padding: 6px 0 6px 9px; display: flex; flex-direction: column; gap: 2px; }
.note-good { border-color: var(--good); }
.note-warn { border-color: var(--warn); }
.note-info { border-color: var(--accent-2); }
.note-title { font-size: 12.5px; font-weight: 700; }
.note-text { font-size: 12px; color: #c6c1b7; }

/* ---------------- tabbar ---------------- */
.tabbar { display: none; }

/* ---------------- modals ---------------- */
.modal { position: fixed; inset: 0; background: rgba(4, 5, 8, 0.78); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-box.wide { width: min(1040px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.plot-wrap { background: #0d0f14; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: 0 0 auto; }
#plot-canvas { display: block; width: 100%; margin: 0 auto; }
.paperwork { display: grid; gap: 16px; }
table.paper { width: 100%; border-collapse: collapse; font-size: 12px; }
table.paper caption { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding-bottom: 6px; }
table.paper th, table.paper td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.paper th { color: var(--muted); font-weight: 600; font-size: 11px; }
table.paper tr:hover td { background: rgba(255, 255, 255, 0.03); }

.compare-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: 0 0 auto; }
.cmp-pane { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.cmp-pane h4 { margin: 0 0 8px; font-size: 13px; }
.cmp-pane img { width: 100%; border-radius: 8px; display: block; }
.cmp-stat { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }
.compare-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; flex: 0 0 auto; }
.cmp-card { background: var(--panel-2); border: 2px solid transparent; border-radius: 10px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; color: var(--ink); font: inherit; text-align: left; }
.cmp-card.sel { border-color: var(--accent); }
.cmp-card img { width: 100%; border-radius: 6px; display: block; }
.cmp-num { font-size: 11px; font-weight: 700; color: var(--accent); }
.cmp-label { font-size: 11.5px; color: var(--muted); }

/* ---------------- rehearsal ---------------- */
body.rehearsal .layout { grid-template-columns: minmax(0, 1fr); }
body.rehearsal #panel-rig, body.rehearsal #panel-cues, body.rehearsal .header-tools .tool-buttons .btn:not(#btn-rehearsal) { display: none; }
body.rehearsal .stage-frame { min-height: 300px; }
body.rehearsal .transport { padding: 14px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr) 280px; }
}

@media (max-width: 860px) {
  body { overflow: auto; height: auto; min-height: 100%; }
  .app-header { padding: 10px 12px; gap: 10px; }
  .header-tools { width: 100%; gap: 10px; }
  .field-haze input { width: 100%; }
  .field-haze { flex: 1; min-width: 140px; }
  .tool-buttons { width: 100%; }
  .tool-buttons .btn { flex: 1; min-width: 120px; }
  .layout { display: flex; flex-direction: column; flex: none; min-height: 0; padding: 8px 8px 76px; }
  .stage-wrap { order: -1; flex: 0 0 auto; margin-bottom: 10px; }
  .stage-frame { flex: 0 0 auto; height: 42vh; min-height: 240px; }
  .panel { display: none; flex: 0 0 auto; margin-bottom: 10px; }
  input[type="range"] { height: 40px; }
  body[data-tab="rig"] #panel-rig { display: flex; }
  body[data-tab="cues"] #panel-cues { display: flex; }
  .rig-list { max-height: none; }
  .notes { max-height: none; }
  .tabbar {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: #0e1015; border-top: 1px solid var(--line); z-index: 50;
  }
  .tabbar button { min-height: var(--touch); border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--ink); font: inherit; font-weight: 600; }
  .tabbar button.on { border-color: var(--accent); color: #ffd894; background: #1d1a14; }
  .transport { align-items: stretch; }
  .transport-main { width: 100%; }
  .btn-go { flex: 1; }
  .transport-side { width: 100%; }
  .transport-side .field-time { flex: 1; }
  .field-time input { width: 100%; }
  .compare-pair { grid-template-columns: 1fr; }
  body.rehearsal .tabbar { display: none; }
  body.rehearsal .layout { padding-bottom: 10px; }
}

@media (max-width: 420px) {
  .gel-grid { grid-template-columns: repeat(6, 1fr); }
  .brand-text .sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fade-bar { transition: none; }
}
