/* TABJ: dark DJ workspace in the Crongemas palette. */
:root {
  color-scheme: dark;
  --bg: #111119;
  --panel: #1b1b2a;
  --panel-2: #23233a;
  --line: #34324a;
  --line-2: #4a4760;
  --ink: #f9f3e9;
  --muted: #c9c1cf;
  --dim: #9c95a8;
  --a: #6fd6c2;      /* Deck A */
  --b: #ff8f55;      /* Deck B */
  --live: #d7f869;
  --cue: #b6a4ff;
  --bad: #ff6b6b;
  --display: Impact, 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --r: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.4 var(--body); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dim { color: var(--dim); }
.small { font-size: 12px; }
kbd {
  font: 11px/1 var(--mono); padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--muted);
}
:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 12px; border-radius: 6px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line-2);
  font: 600 12px/1 var(--body); letter-spacing: .04em; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover:not(:disabled) { background: #2d2c47; border-color: #6b6788; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line); color: var(--ink); }
.btn.primary { background: var(--live); border-color: var(--live); color: #171724; }
.btn.primary:hover { background: #e4ff86; border-color: #e4ff86; }
.btn.small { min-height: 26px; padding: 0 8px; font-size: 11px; }
.btn.icon { width: 32px; padding: 0; font-size: 15px; }
.btn.danger:hover:not(:disabled) { color: var(--bad); }
.linkish { background: none; border: 0; color: var(--live); padding: 0; cursor: pointer; text-decoration: underline; }

/* ---------- header ---------- */
.bar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: #151521; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.logo { font: 28px/1 var(--display); letter-spacing: .03em; color: var(--ink); }
.logo::first-letter { color: var(--a); }
.family { font: 11px/1 var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .12em; }
.set-name input {
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px;
  font: 600 15px/1.2 var(--body); width: 220px;
}
.set-name input:hover, .set-name input:focus { border-color: var(--line-2); background: var(--panel); outline: none; }
.set-meta { font: 12px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.pill {
  font: 700 10px/1 var(--mono); letter-spacing: .08em; padding: 5px 7px; border-radius: 99px;
  border: 1px solid var(--line-2); color: var(--dim); white-space: nowrap;
}
.pill[data-state="ok"] { color: var(--a); border-color: color-mix(in srgb, var(--a) 45%, transparent); }
.pill[data-state="fail"] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }

.banner {
  display: flex; align-items: center; gap: 12px; padding: 9px 16px;
  background: #3a2a1c; border-bottom: 1px solid #6b4a2a; color: #ffd9bf; font-size: 13px;
}
.banner span { flex: 1; }
.banner[hidden] { display: none; }

/* ---------- workspace ---------- */
.workspace { padding: 14px 16px 40px; display: grid; gap: 14px; max-width: 1500px; margin: 0 auto; }
.decks { display: grid; grid-template-columns: minmax(0, 1fr) 170px minmax(0, 1fr); gap: 14px; align-items: stretch; }

.deck {
  --accent: var(--a);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: border-color .2s, box-shadow .2s;
}
.deck[data-deck="b"] { --accent: var(--b); }
.deck[data-live="true"] { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent), 0 8px 30px -12px color-mix(in srgb, var(--accent) 40%, transparent); }

.deck-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.deck-letter {
  font: 22px/1 var(--display); color: #171724; background: var(--accent);
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 6px; flex: none;
}
.badge {
  font: 700 10px/1 var(--mono); letter-spacing: .08em; padding: 5px 6px; border-radius: 4px;
  background: var(--panel-2); color: var(--muted); flex: none;
}
.badge.status[data-status="playing"] { background: var(--accent); color: #171724; }
.badge.status[data-status="cued"], .badge.status[data-status="paused"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.badge.status[data-status="loading"], .badge.status[data-status="buffering"] { color: var(--ink); }
.badge.status[data-status="unavailable"], .badge.status[data-status="error"], .badge.status[data-status="stalled"] { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.badge.live-tag { background: var(--live); color: #171724; }
.badge[hidden] { display: none; }
.deck-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.screen { position: relative; border-radius: 6px; overflow: hidden; background: #08080d; border: 1px solid var(--line); }
/* YouTube requires a visible player of at least 200x200; 16:9 here never drops below that at our minimum width. */
.player-host { aspect-ratio: 16 / 9; min-height: 200px; width: 100%; }
.player-host > iframe, .player-host > .player-slot, .player-host > div { width: 100%; height: 100%; display: block; border: 0; }
.screen-note {
  /* Outside the player frame: TABJ never draws over a playing YouTube player. */
  font-size: 12px; color: var(--muted); padding: 6px 9px; border-top: 1px solid var(--line); background: #0d0d15;
}
.screen-note[data-kind="warn"] { color: #ffc6c6; background: color-mix(in srgb, var(--bad) 12%, #0d0d15); }
/* An empty deck has no video, so its hint may sit in the middle of the blank frame. */
.deck[data-status="empty"] .screen-note {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none;
  background: none; border: 0; color: var(--dim); white-space: nowrap;
}
.screen-note[hidden] { display: none; }

.clock { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--mono); }
.elapsed { font-size: 30px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.remain { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.remain[data-warn="true"] { color: var(--bad); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .45; } }

.timeline {
  position: relative; height: 46px; border-radius: 5px; cursor: pointer; touch-action: none;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(255,255,255,.05) calc(10% - 1px) 10%),
    #0c0c14;
  border: 1px solid var(--line); overflow: hidden;
}
.tl-buffer { position: absolute; inset: auto auto 0 0; height: 4px; background: var(--line-2); width: 0; }
.tl-region { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 10%, transparent); border-left: 0; }
.tl-region[hidden] { display: none; }
.tl-played { position: absolute; left: 0; top: 0; bottom: 4px; width: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 28%, transparent)); }
.tl-head { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ink); box-shadow: 0 0 8px var(--ink); left: 0; }
.tl-marks { position: absolute; inset: 0; pointer-events: none; }
.tl-mark { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.tl-mark::after {
  content: attr(data-label); position: absolute; top: 2px; left: 3px;
  font: 700 9px/1 var(--mono); padding: 2px 3px; border-radius: 2px; color: #171724;
}
.tl-mark.cue { background: var(--cue); }
.tl-mark.cue::after { background: var(--cue); }
.tl-mark.low::after { top: auto; bottom: 7px; }
.tl-mark.in, .tl-mark.out { background: var(--live); }
.tl-mark.in::after, .tl-mark.out::after { background: var(--live); }
.tl-mark.out::after { left: auto; right: 3px; }

.transport { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.transport .play { min-width: 52px; font-size: 14px; background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.transport .sep { flex: 1; }
.transport .pt .pt-val { font: 11px/1 var(--mono); color: var(--live); }
.transport .pt .pt-val:empty { display: none; }
.transport .mark { color: var(--cue); }

.cues { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.cue-chip { display: flex; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.cue-jump {
  display: flex; gap: 6px; align-items: center; background: none; border: 0; cursor: pointer; padding: 4px 7px;
  font: 12px/1 var(--mono); color: var(--muted);
}
.cue-jump b { color: #171724; background: var(--cue); border-radius: 3px; padding: 2px 4px; font-size: 10px; }
.cue-jump:hover { color: var(--ink); background: #2d2c47; }
.cue-label { width: 72px; background: transparent; border: 0; border-left: 1px solid var(--line); padding: 4px 6px; font-size: 12px; }
.cue-label:focus { outline: none; background: #11111b; }
.cue-del { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 4px 6px; font-size: 11px; }
.cue-del:hover { color: var(--bad); }

/* ---------- mixer ---------- */
.mixer {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; justify-content: center;
}
.mix-head { font: 18px/1 var(--display); letter-spacing: .1em; color: var(--dim); text-align: center; }
.fader-wrap { display: flex; align-items: center; gap: 6px; }
.fader-end { font: 14px/1 var(--display); }
.fader-end.a { color: var(--a); }
.fader-end.b { color: var(--b); }
input[type="range"] { accent-color: var(--live); width: 100%; min-width: 0; }
#crossfader { height: 28px; }
.mix-go {
  min-height: 52px; flex-direction: column; gap: 7px; font: 17px/1 var(--display); letter-spacing: .06em;
  background: #2a2a1a; border-color: color-mix(in srgb, var(--live) 50%, transparent); color: var(--live);
}
.mix-go[data-to="a"] { --to: var(--a); }
.mix-go[data-to="b"] { --to: var(--b); }
.mix-go[data-active="true"], .mix-go[data-active="true"]:hover:not(:disabled) { background: var(--live); border-color: var(--live); color: #171724; }
.mix-progress { display: block; width: 80%; height: 3px; border-radius: 2px; background: rgba(215, 248, 105, .18); overflow: hidden; }
.mix-progress span { display: block; height: 100%; width: 0; background: var(--to, var(--live)); }
.mix-go[data-active="true"] .mix-progress { background: rgba(23, 23, 36, .25); }
.mix-go[data-active="true"] .mix-progress span { background: #171724; }
.mix-row { display: flex; gap: 8px; justify-content: space-between; }
.mini { display: flex; flex-direction: column; gap: 4px; font: 700 10px/1 var(--mono); letter-spacing: .08em; color: var(--dim); }
.mini select { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px; font-size: 12px; }
.mini.toggle { flex-direction: row; align-items: center; gap: 5px; cursor: pointer; }
.mini.toggle input { accent-color: var(--live); width: 16px; height: 16px; }

/* ---------- setlist ---------- */
.setlist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.add { display: flex; gap: 8px; }
.add textarea {
  flex: 1; resize: none; background: #11111b; border: 1px solid var(--line-2); border-radius: 6px;
  padding: 8px 10px; font: 13px/1.35 var(--mono); min-height: 36px;
}
.add textarea:focus { outline: none; border-color: var(--live); }
.add .btn { min-height: 36px; }
.add-feedback { font-size: 12px; color: var(--muted); min-height: 18px; padding: 6px 2px 2px; }
.add-feedback[data-kind="warn"] { color: #ffc6a8; }
.add-feedback[data-kind="ok"] { color: var(--a); }

.tracks { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
.track {
  display: grid; grid-template-columns: 14px 26px 64px minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  padding: 6px 8px; border-radius: 6px; border: 1px solid transparent; background: #171726;
}
.track:hover { border-color: var(--line); }
.track[data-kind="live"] { border-color: color-mix(in srgb, var(--live) 50%, transparent); background: color-mix(in srgb, var(--live) 6%, #171726); }
.track[data-kind="deck-a"] { border-left: 3px solid var(--a); }
.track[data-kind="deck-b"] { border-left: 3px solid var(--b); }
.track.dragging { opacity: .4; }
.track.drop-before { box-shadow: 0 -2px 0 var(--live); }
.track.drop-after { box-shadow: 0 2px 0 var(--live); }
.grip { color: var(--dim); cursor: grab; font-size: 11px; letter-spacing: -2px; user-select: none; }
.num { font: 12px/1 var(--mono); color: var(--dim); }
.thumb {
  width: 64px; height: 36px; border-radius: 3px; display: block;
  --stripes: repeating-linear-gradient(135deg, var(--panel-2) 0 6px, #1e1e31 6px 12px);
  background-image: var(--stripes); background-size: cover; background-position: center;
}
.info { min-width: 0; }
.t-title { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 2px 4px; margin-left: -5px; font-weight: 600; text-overflow: ellipsis; }
.t-title:hover { border-color: var(--line); }
.t-title:focus { outline: none; border-color: var(--line-2); background: #11111b; }
.t-meta { font: 11px/1.3 var(--mono); color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-top: 2px; }
.t-state { font: 700 10px/1 var(--mono); letter-spacing: .06em; color: var(--dim); white-space: nowrap; }
.t-state[data-kind="live"] { color: var(--live); }
.t-state[data-kind="deck-a"] { color: var(--a); }
.t-state[data-kind="deck-b"] { color: var(--b); }
.t-state[data-kind="bad"] { color: var(--bad); }
.t-actions { display: flex; gap: 2px; }
.t-actions .deck-a { color: var(--a); }
.t-actions .deck-b { color: var(--b); }
.t-note { grid-column: 3 / -1; }
.t-note textarea { width: 100%; background: #11111b; border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 8px; font-size: 13px; resize: vertical; }
.empty { text-align: center; padding: 26px 10px 18px; color: var(--muted); }
.empty p { margin: 4px 0; }
.empty[hidden] { display: none; }

/* ---------- overlays ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 20;
  background: #26263d; border: 1px solid var(--line-2); color: var(--ink); padding: 9px 14px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.45); max-width: calc(100vw - 32px);
}
.toast[data-kind="warn"] { border-color: #8a5a35; color: #ffd9bf; }
.toast[hidden] { display: none; }
dialog {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 18px 20px; max-width: 460px; width: calc(100vw - 32px);
}
dialog::backdrop { background: rgba(5, 5, 10, .7); }
dialog h2 { font: 22px/1 var(--display); letter-spacing: .04em; margin: 0 0 12px; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 7px 14px; margin: 0 0 12px; }
.keys dt { text-align: right; }
.keys dd { margin: 0; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .decks { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .mixer { grid-column: 1 / -1; grid-row: 2; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .mixer .mix-head { display: none; }
  .fader-wrap { flex: 1 1 260px; }
  .mix-go { flex-direction: row; min-height: 40px; }
}
@media (max-width: 760px) {
  .bar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .set-name input { width: 150px; }
  .set-meta { order: 5; width: 100%; }
  .bar-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .bar-actions #btn-help { margin-left: auto; }
  .workspace { padding: 12px 16px 40px; gap: 12px; }
  .decks { grid-template-columns: minmax(0, 1fr); }
  .mixer { grid-row: auto; order: 2; }
  .deck[data-deck="b"] { order: 3; }
  .elapsed { font-size: 26px; }
  .transport .sep { display: none; }
  .track { grid-template-columns: 22px 56px minmax(0, 1fr); gap: 4px 8px; }
  .grip { display: none; }
  .thumb { width: 56px; height: 32px; }
  .t-state { grid-column: 3; }
  .t-actions { grid-column: 1 / -1; justify-content: flex-end; flex-wrap: wrap; }
  .t-actions .btn.small { min-height: 32px; min-width: 32px; }
  .t-note { grid-column: 1 / -1; }
}

/* ---------- stage view: the page becomes a video feed ---------- */
.stage-bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: 64px; z-index: 10;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: #0b0b12; border-top: 1px solid var(--line);
}
.stage-bar[hidden] { display: none; }
.sb-now { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.sb-deck { font: 20px/1 var(--display); width: 30px; height: 30px; display: grid; place-items: center; border-radius: 6px; color: #171724; background: var(--a); flex: none; }
.sb-deck[data-deck="b"] { background: var(--b); }
.sb-text { display: flex; flex-direction: column; min-width: 0; }
.sb-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-next { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-time { font: 600 15px/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-progress { flex: 0 1 220px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.sb-progress span { display: block; height: 100%; width: 0; background: var(--ink); }
.small-go { min-height: 40px; flex-direction: row; padding: 0 16px; font-size: 15px; }

body[data-view="stage"] { overflow: hidden; background: #000; }
body[data-view="stage"] .bar,
body[data-view="stage"] .banner,
body[data-view="stage"] .setlist,
body[data-view="stage"] .mixer { display: none; }
body[data-view="stage"] .workspace { padding: 0; max-width: none; }
body[data-view="stage"] .decks {
  position: fixed; inset: 0 0 64px 0; gap: 0; background: #000;
  grid-template-rows: minmax(0, 1fr); align-items: center;
}
body[data-view="stage"][data-clean-feed="true"] .decks { bottom: 0; }
body[data-view="stage"][data-clean-feed="true"] .stage-bar { display: none; }
/* The deck boxes dissolve so the two screens sit side by side; nothing is moved in the page, so the players never reload. */
body[data-view="stage"] .deck { display: contents; }
body[data-view="stage"] .deck > :not(.screen) { display: none; }
body[data-view="stage"] .screen { grid-row: 1; border: 0; border-radius: 0; background: #000; height: 100%; display: flex; flex-direction: column; justify-content: center; min-width: 0; overflow: hidden; }
/* A deck that isn't playing is off the feed entirely (its column is 0 wide). It is never playing while hidden. */
body[data-view="stage"] .deck[data-feed="hidden"] .screen { visibility: hidden; }
body[data-view="stage"] .deck[data-deck="a"] .screen { grid-column: 1; }
body[data-view="stage"] .deck[data-deck="b"] .screen { grid-column: 2; }
body[data-view="stage"] .player-host { width: min(100%, calc((100vh - 64px) * 16 / 9)); margin: 0 auto; min-height: 200px; }
body[data-view="stage"][data-clean-feed="true"] .player-host { width: min(100%, calc(100vh * 16 / 9)); }
body[data-view="stage"] .screen-note { display: none; }
@media (max-width: 760px) {
  .stage-bar { height: auto; flex-wrap: wrap; padding: 8px 16px; gap: 8px 12px; }
  .sb-progress { display: none; }
}
