:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --raise: #1e2127;
  --line: #2a2e36;
  --text: #eceef1;
  --muted: #a0a6b0;
  --accent: #e8ff59;
  --accent-ink: #111;
  --danger: #ff6b6b;
  --radius: 12px;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 500 15px/1.45 var(--ui); }
button, input, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 8px; font-weight: 700; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 76px 300px minmax(0, 1fr);
  grid-template-rows: 68px minmax(0, 1fr);
  height: 100dvh;
}
.rail { grid-row: 1 / span 2; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px; border-right: 1px solid var(--line); background: var(--panel); }
.brand { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 900; letter-spacing: -0.04em; margin-bottom: 10px; }
.rail-btn { width: 64px; min-height: 58px; display: grid; place-items: center; gap: 2px; padding: 6px 0; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; }
.rail-btn:hover { background: var(--raise); color: var(--text); }
.rail-btn[aria-current="page"] { background: var(--raise); color: var(--accent); }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }

.topbar { grid-column: 2 / span 2; grid-row: 1; }
.panel { grid-column: 2; grid-row: 2; }
.canvas { grid-column: 3; grid-row: 2; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
h1 { font-size: 18px; font-weight: 900; letter-spacing: -0.02em; }
.top-actions, .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }

.panel { overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.group { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0; background: var(--panel); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.group h2, legend, summary { font-size: 13px; font-weight: 700; color: var(--text); }
legend { padding: 0 4px; }
summary { cursor: pointer; min-height: 24px; }
details[open] > summary { margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input:not([type]), input[type="text"], textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); outline: none; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.add-row { display: flex; gap: 8px; }
#bulkForm { display: flex; flex-direction: column; gap: 8px; }

.btn { min-height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--raise); color: var(--text); font-weight: 700; font-size: 13px; cursor: pointer; transition: background .15s, transform .1s; }
.btn:hover { background: #272b33; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #f1ff8c; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tpl { position: relative; display: flex; flex-direction: column; gap: 6px; cursor: pointer; font-size: 12px; font-weight: 700; color: var(--muted); }
.tpl input { position: absolute; opacity: 0; }
.tpl .swatch { height: 54px; border-radius: 9px; border: 2px solid var(--line); display: grid; gap: 3px; padding: 6px; }
.tpl .swatch i { border-radius: 3px; }
.tpl input:checked + .swatch { border-color: var(--accent); }
.tpl input:checked ~ span { color: var(--text); }
.tpl input:focus-visible + .swatch { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw-arena { background: #0b0b0f; }
.sw-whiteboard { background: #f4f2ec; }
.sw-elite { background: #0a0a0a; }

.tier-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tier-edit { display: grid; grid-template-columns: 36px 1fr 32px 32px 32px; gap: 4px; align-items: center; }
.tier-edit input[type="color"] { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.tier-edit input:not([type]) { min-height: 36px; padding: 6px 8px; }
.icon-btn { width: 32px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--raise); cursor: pointer; font-weight: 700; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ---------- Canvas ---------- */
.canvas { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 16px; outline: none; }
.stage-wrap { display: flex; justify-content: center; width: 100%; }

.pool, .shots { width: min(760px, 100%); border: 1px dashed var(--line); border-radius: var(--radius); padding: 14px; }
.pool h2, .shots h2 { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.pool-items { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; border-radius: 9px; }
.pool .chip { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--raise); color: var(--text); font-weight: 700; cursor: grab; }
.empty { text-align: center; padding: 18px 8px 6px; color: var(--muted); }
.empty p { margin: 0 0 12px; }
.empty strong { color: var(--text); }

.reveal-bar { display: none; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.counter { min-width: 70px; text-align: center; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.shots { display: none; border-style: solid; background: var(--panel); }
.shots-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.shots-head h2 { margin: 0; color: var(--text); font-size: 15px; }
.shot-list { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.shot-list li::marker { color: var(--muted); font-weight: 700; }
.shot-list b { display: block; }
.shot-list span { color: var(--muted); font-size: 13px; }

body[data-mode="reveal"] .pool { display: none; }
body[data-mode="reveal"] .reveal-bar { display: flex; }
body[data-mode="shots"] .pool { display: none; }
body[data-mode="shots"] .shots { display: block; }
body[data-mode="shots"] .stage-wrap { display: none; }

.drop.over { background: rgba(232, 255, 89, .12); outline: 2px dashed var(--accent); outline-offset: -2px; }
.chip.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip.dragging { opacity: .4; }

/* ---------- Stage (what gets filmed) ---------- */
.stage {
  container-type: size;
  aspect-ratio: 9 / 16;
  height: min(78dvh, 940px);
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* % not cq units: an element's own padding resolves against its parent, not itself */
  gap: 1.3%;
  padding: 8% 4% 7%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.stage-title { text-align: center; line-height: 1.02; overflow-wrap: anywhere; }
.rows { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: .9cqh; }
.row { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 17cqw minmax(0, 1fr); overflow: hidden; }
.label { display: grid; place-items: center; text-align: center; padding: 0 1cqw; overflow-wrap: anywhere; line-height: 1; background: var(--tier); color: var(--ink); }
.row .drop { display: flex; flex-wrap: wrap; align-content: center; align-items: center; gap: .8cqh 1.2cqw; padding: .8cqh 1.6cqw; min-width: 0; overflow: hidden; }
.stage .chip { border: 0; cursor: grab; font-weight: 800; font-size: 2.05cqh; line-height: 1.1; padding: .9cqh 1.8cqw; max-width: 100%; overflow-wrap: anywhere; }
.place { margin-left: auto; min-height: 36px; padding: 0 12px; border-radius: 8px; border: 2px dashed currentColor; background: transparent; font: 700 12px var(--ui); cursor: pointer; opacity: .85; }
.place:hover { opacity: 1; }
.stage-empty-row { opacity: .35; font-size: 1.6cqh; font-weight: 700; }

/* Arena */
.stage[data-template="arena"] { background: radial-gradient(120% 60% at 50% 0%, #1d1f2b 0%, #0b0b0f 60%); color: #fff; font-family: var(--ui); }
.stage[data-template="arena"] .stage-title { font-size: 4.3cqh; font-weight: 900; text-transform: uppercase; letter-spacing: -0.02em; }
.stage[data-template="arena"] .row { border-radius: 1.1cqh; background: rgba(255, 255, 255, .055); }
.stage[data-template="arena"] .label { font-size: 4.4cqh; font-weight: 900; }
.stage[data-template="arena"] .chip { background: #fff; color: #0b0b0f; border-radius: .9cqh; box-shadow: 0 .4cqh 0 rgba(0, 0, 0, .35); }

/* Whiteboard */
.stage[data-template="whiteboard"] { background: linear-gradient(160deg, #fbfaf6 0%, #eceae3 100%); color: #141414; font-family: var(--ui); }
.stage[data-template="whiteboard"] .stage-title { font-family: "Permanent Marker", cursive; font-size: 4.4cqh; font-weight: 400; transform: rotate(-1.5deg); }
.stage[data-template="whiteboard"] .row { border: .35cqh solid #141414; border-radius: .6cqh; background: rgba(255, 255, 255, .5); }
.stage[data-template="whiteboard"] .label { background: transparent; color: var(--tier); font-family: "Permanent Marker", cursive; font-size: 4.6cqh; border-right: .35cqh solid #141414; }
.stage[data-template="whiteboard"] .chip { position: relative; background: #fff; color: #141414; border: .2cqh solid #141414; border-radius: .3cqh; box-shadow: .4cqh .5cqh 0 rgba(0, 0, 0, .18); }
.stage[data-template="whiteboard"] .chip:nth-child(odd) { transform: rotate(-1.6deg); }
.stage[data-template="whiteboard"] .chip:nth-child(even) { transform: rotate(1.4deg); }
.stage[data-template="whiteboard"] .chip::before { content: ""; position: absolute; top: -1cqh; left: 50%; width: 5cqw; height: 1.6cqh; transform: translateX(-50%) rotate(-3deg); background: rgba(250, 220, 120, .8); }

/* Elite */
.stage[data-template="elite"] { background: radial-gradient(90% 50% at 50% 0%, #2a2210 0%, #0a0a0a 65%); color: #f5e7b2; font-family: var(--ui); }
.stage[data-template="elite"] .stage-title { font-family: "Playfair Display", Georgia, serif; font-size: 4.2cqh; font-weight: 900; color: #d4af37; letter-spacing: .01em; }
.stage[data-template="elite"] .row { grid-template-columns: 25cqw minmax(0, 1fr); border: .15cqh solid rgba(212, 175, 55, .45); border-radius: .4cqh; background: rgba(212, 175, 55, .04); }
.stage[data-template="elite"] .label { font-family: "Playfair Display", Georgia, serif; font-size: 2.3cqh; font-weight: 900; letter-spacing: .06em; overflow-wrap: normal; }
.stage[data-template="elite"] .chip { background: #141414; color: #f5e7b2; border: .15cqh solid #d4af37; border-radius: .4cqh; }

/* Reveal animation */
.chip.pop { animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop {
  from { opacity: 0; transform: translateY(-40%) scale(.5); }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .chip.pop { animation: none; }
  .btn { transition: none; }
}

/* Present (fullscreen) */
.stage:fullscreen { height: 100dvh; width: auto; margin: auto; border-radius: 0; box-shadow: none; }
.stage::backdrop { background: #000; }
.stage:fullscreen .place { display: none; }

/* Dialog + toast */
dialog { width: min(560px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
#importForm { display: flex; flex-direction: column; gap: 12px; }
#importForm h2 { font-size: 17px; }
#importText { font: 13px/1.4 ui-monospace, Menlo, monospace; }
.error { margin: 0; min-height: 1em; color: var(--danger); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; transition: opacity .2s, transform .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Topic picker, logos ---------- */
select { width: 100%; min-height: 42px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); font: inherit; }
select:focus { border-color: var(--accent); outline: none; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.pill:hover { color: var(--text); border-color: var(--muted); }
.add-form { display: flex; flex-direction: column; gap: 8px; }
input[type="file"] { font-size: 12px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: .45em; }
.chip img { width: 1.25em; height: 1.25em; object-fit: contain; border-radius: .2em; flex: none; pointer-events: none; }
.chip.hl { outline: .5cqh solid var(--accent); outline-offset: .3cqh; }

/* ---------- Storyboard ---------- */
.storyboard { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px; margin: 8px 0 18px; }
.frame { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.frame figcaption { font-size: 12px; font-weight: 700; color: var(--muted); line-height: 1.3; }
.stage.mini { height: auto; width: 100%; border-radius: 8px; box-shadow: none; position: relative; pointer-events: none; }
.stage.mini .chip { cursor: default; }
.mini-cta { position: absolute; left: 4cqw; right: 4cqw; bottom: 4cqh; padding: 1.5cqh 3cqw; border-radius: 1cqh; background: var(--accent); color: var(--accent-ink); font: 800 2.4cqh/1.15 var(--ui); text-align: center; }
.sub { font-size: 13px; color: var(--muted); margin: 0 0 10px; }

/* ---------- Recorder ---------- */
.recorder { display: none; width: 100%; max-width: 1000px; gap: 20px; align-items: start; justify-content: center; }
body[data-mode="record"] .recorder { display: flex; }
body[data-mode="record"] .stage-wrap, body[data-mode="record"] .pool { display: none; }
#recCanvas { height: min(80dvh, 900px); aspect-ratio: 9 / 16; max-width: 100%; border-radius: 16px; background: #000; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.rec-side { width: 320px; display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 16px; }
.rec-side h2 { font-size: 16px; }
.rec-side h3 { font-size: 13px; margin: 0 0 6px; }
.rec-main { display: flex; align-items: center; gap: 12px; }
.btn.rec { flex: 1; min-height: 52px; background: #e5383b; border-color: #e5383b; color: #fff; font-size: 15px; }
.btn.rec:hover { background: #f25c5f; }
.btn.rec.live { background: transparent; color: #ff6b6b; border-color: #ff6b6b; }
.rec-time { min-width: 52px; font: 800 18px var(--ui); font-variant-numeric: tabular-nums; color: var(--muted); }
body.is-recording .rec-time { color: #ff6b6b; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.take-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.take-list li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.take-list li span { flex: 1; min-width: 120px; }
#takePreview { width: 100%; max-height: 360px; border-radius: 10px; background: #000; margin-top: 8px; }
@media (prefers-reduced-motion: no-preference) {
  body.is-recording .btn.rec.live { animation: blink 1.2s ease-in-out infinite; }
}
@keyframes blink { 50% { opacity: .55; } }

/* ---------- Phones ---------- */
@media (max-width: 900px) {
  .recorder { flex-direction: column; align-items: center; }
  #recCanvas { height: auto; width: min(100%, 420px); }
  .rec-side { width: 100%; }
  .shell { display: flex; flex-direction: column; height: auto; min-height: 100dvh; padding-bottom: 76px; }
  .topbar { order: 1; padding: 12px 16px; flex-wrap: wrap; }
  .canvas { order: 2; padding: 16px; overflow: visible; }
  .panel { order: 3; border-right: 0; padding: 0 16px 16px; overflow: visible; }
  .rail { position: fixed; inset: auto 0 0 0; z-index: 40; flex-direction: row; justify-content: space-around; height: 72px; padding: 6px; border-right: 0; border-top: 1px solid var(--line); }
  .brand { display: none; }
  .rail-btn { width: auto; flex: 1; }
  .stage { height: auto; width: min(100%, 420px); }
  .toast { bottom: 90px; }
}
