:root {
  color-scheme: dark;
  --ink: #f8f7f1;
  --muted: #a9a9a2;
  --surface: #121212;
  --surface-raised: #191919;
  --surface-soft: #222220;
  --line: #33332f;
  --accent: #f4d84a;
  --accent-ink: #121109;
  --danger: #ff796d;
  --focus: #fff2a5;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: #080808;
  color: var(--ink);
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(244, 216, 74, 0.09), transparent 24rem),
    #080808;
}

button,
textarea,
select,
input { font: inherit; }

button,
select,
input[type="color"] { cursor: pointer; }

button:focus-visible,
textarea:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 8, 8, 0.88);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 950;
  letter-spacing: -0.08em;
  box-shadow: 0 0 30px rgba(244, 216, 74, 0.16);
}

.brand strong,
.brand small { display: block; }
.brand strong { font-size: 1.05rem; letter-spacing: -0.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 0.78rem; }

.top-actions,
.cue-actions,
.cue-file-actions,
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button,
.icon-button,
.stage-controls button,
.preset {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 750;
  padding: 10px 13px;
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.button:hover,
.icon-button:hover,
.stage-controls button:hover,
.preset:hover { transform: translateY(-1px); border-color: #5c5c54; }

.button-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button-quiet { background: transparent; }
.button-danger { background: transparent; color: var(--danger); border-color: rgba(255, 121, 109, 0.36); }
.button:disabled { opacity: 0.38; cursor: not-allowed; transform: none; }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-size: 1.5rem;
}

.workspace {
  width: min(1720px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(330px, 1fr) minmax(440px, 1.55fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 18, 18, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

.cue-panel,
.compose-panel { padding: 16px; }

.panel-heading,
.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.69rem;
  font-weight: 850;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }
h1,
h2 { margin-bottom: 0; font-size: 1.15rem; letter-spacing: -0.025em; }

.save-status {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.cue-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 245px);
  min-height: 190px;
  overflow: auto;
  scrollbar-width: thin;
}

.cue-card {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-raised);
  color: inherit;
  text-align: left;
}

.cue-card:hover { border-color: #5c5c54; }
.cue-card.is-active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.cue-number { color: var(--accent); font-size: 0.75rem; font-weight: 900; }
.cue-copy { min-width: 0; }
.cue-title { display: block; overflow: hidden; color: var(--ink); font-weight: 760; text-overflow: ellipsis; white-space: nowrap; }
.cue-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; }

.cue-empty,
.editor-empty {
  padding: 32px 16px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  color: var(--muted);
}
.cue-empty p { margin: 6px 0 16px; font-size: 0.85rem; }
.cue-file-actions { margin-top: 12px; }

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field-message { margin-bottom: 13px; }
.field-label { color: #d5d4cc; font-size: 0.79rem; font-weight: 780; }
.field-meta { color: var(--muted); font-size: 0.72rem; text-align: right; }

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0d0d0d;
  color: var(--ink);
}

textarea { min-height: 164px; padding: 13px; line-height: 1.55; resize: vertical; }
select { min-height: 42px; padding: 8px 34px 8px 10px; }
select:disabled { opacity: 0.45; cursor: not-allowed; }

.field-grid { display: grid; gap: 10px; margin-bottom: 12px; }
.field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cue-actions { margin-top: 12px; }

.settings { margin-top: 18px; border-top: 1px solid var(--line); }
.settings summary { padding: 15px 0 4px; cursor: pointer; font-weight: 800; list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary span { float: right; color: var(--accent); transition: transform 150ms ease; }
.settings[open] summary span { transform: rotate(180deg); }
.settings-body { display: grid; gap: 12px; padding-top: 12px; }

.preset { flex: 1 1 auto; padding: 8px; color: var(--muted); font-size: 0.73rem; }
.preset.is-active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

.color-field input {
  width: 100%;
  height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d0d0d;
}

.range-row { display: grid; gap: 7px; }
.range-row label { display: flex; justify-content: space-between; gap: 10px; color: #d5d4cc; font-size: 0.79rem; font-weight: 780; }
.range-row output { color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.toggle-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; color: #d5d4cc; font-size: 0.78rem; }
.toggle input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

.preview-panel { padding: 16px; position: sticky; top: 96px; }
.preview-heading { margin-bottom: 12px; }
.preview-frame {
  width: 100%;
  min-height: 300px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #3d3d39;
  border-radius: 15px;
  background: #030303;
  aspect-ratio: 16 / 9;
}
.preview-frame.is-portrait { aspect-ratio: 9 / 16; max-height: none; margin-inline: auto; width: min(100%, 38.8125vh, 420px); }

.stage {
  --stage-bg: #080808;
  --stage-fg: #ffffff;
  --stage-highlight: #f4d84a;
  --stage-font-size: 112px;
  --motion-duration: 12s;
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--stage-bg);
  color: var(--stage-fg);
  container-type: size;
}

.stage-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 5vmin, 72px);
  overflow: hidden;
}

.stage-text {
  max-width: 100%;
  margin: 0;
  color: var(--stage-fg);
  font-size: var(--stage-font-size);
  font-weight: var(--stage-weight, 900);
  line-height: 1.02;
  letter-spacing: -0.035em;
  text-align: var(--stage-align, center);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.stage-text.is-highlighted {
  color: var(--stage-highlight-ink, #111109);
  background: var(--stage-highlight);
  padding: 0.08em 0.18em 0.12em;
  border-radius: 0.12em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.stage.is-mirrored { transform: scaleX(-1); }

.stage[data-motion="ticker"] .stage-content {
  inset: 0 auto;
  width: max-content;
  min-width: 100%;
  padding-inline: 0;
  animation: ticker-forward var(--motion-duration) linear infinite;
}
.stage[data-motion="ticker"][data-direction="reverse"] .stage-content { animation-name: ticker-reverse; }
.stage[data-motion="ticker"] .stage-text { max-width: none; padding-inline: 8vw; white-space: pre; }

.stage[data-motion="teleprompter"] .stage-content {
  inset: auto 0;
  height: auto;
  min-height: 100%;
  align-items: flex-start;
  animation: teleprompter-forward var(--motion-duration) linear infinite;
}
.stage[data-motion="teleprompter"][data-direction="reverse"] .stage-content { animation-name: teleprompter-reverse; }
.stage[data-motion="teleprompter"] .stage-text { line-height: 1.3; }
.stage.is-paused .stage-content { animation-play-state: paused !important; }

@keyframes ticker-forward { from { transform: translateX(100%); } to { transform: translateX(-100%); } }
@keyframes ticker-reverse { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes teleprompter-forward { from { transform: translateY(100%); } to { transform: translateY(-100%); } }
@keyframes teleprompter-reverse { from { transform: translateY(-100%); } to { transform: translateY(100%); } }

.stage-qr-content { flex-direction: column; gap: clamp(12px, 2.5vmin, 28px); text-align: center; }
.stage-qr {
  display: block;
  width: min(62%, 520px);
  height: auto;
  width: min(62cqw, 62cqh);
  height: min(62cqw, 62cqh);
  max-width: 76%;
  max-height: 70%;
  padding: clamp(8px, 1.4vmin, 18px);
  border-radius: clamp(8px, 1.2vmin, 18px);
  background: #fff;
  image-rendering: pixelated;
}
.stage-qr-message { max-width: 84%; margin: 0; color: var(--stage-fg); font-size: clamp(14px, 3.8cqh, 34px); font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.stage-error { max-width: 80%; color: #ffb4ad; font-size: clamp(16px, 3vw, 34px); font-weight: 800; text-align: center; }
.stage-placeholder { color: rgba(255, 255, 255, 0.48); font-size: clamp(18px, 4vw, 42px); font-weight: 750; text-align: center; }
.stage.is-blackout::after { content: ""; position: absolute; inset: 0; z-index: 12; background: #000; }

.shortcut-hint { margin: 12px 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.6; }
kbd { display: inline-block; min-width: 1.7em; padding: 1px 5px; margin: 0 2px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-soft); color: var(--ink); text-align: center; }

.presentation {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: #000;
}
.presentation .stage { width: 100vw; height: 100vh; }
.presentation.orientation-landscape { display: grid; place-items: center; background: #000; }
.presentation.orientation-landscape .stage { width: min(100vw, 177.78vh); height: min(100vh, 56.25vw); }
.presentation.orientation-portrait { display: grid; place-items: center; background: #000; }
.presentation.orientation-portrait .stage { width: min(100vw, 56.25vh); height: min(100vh, 177.78vw); }

.stage-controls {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 15px;
  background: rgba(10, 10, 10, 0.8);
  backdrop-filter: blur(14px);
  opacity: 1;
  transition: opacity 180ms ease, transform 180ms ease;
}
.stage-controls.is-hidden { opacity: 0; pointer-events: none; transform: translate(-50%, 12px); }
.stage-controls button { padding: 9px 11px; background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.16); font-size: 0.8rem; }
.stage-position { min-width: 48px; color: #d8d8d3; font-size: 0.78rem; text-align: center; }

.countdown {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.92);
  color: var(--accent);
  font-size: min(42vw, 42vh);
  font-weight: 950;
}

.toast {
  position: fixed;
  z-index: 200;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 15px;
  border: 1px solid #4a4a42;
  border-radius: 12px;
  background: #24241f;
  color: #fff;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.38);
  font-weight: 700;
  font-size: 0.85rem;
}

body.is-presenting { overflow: hidden; }
body.is-display .operator-only { display: none !important; }
body.is-display { overflow: hidden; background: #000; }
body.is-display .presentation { display: block !important; }
body.is-display #stageExitBtn { display: none; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(220px, 0.78fr) minmax(330px, 1.22fr); }
  .preview-panel { grid-column: 1 / -1; position: static; }
  .preview-frame { max-height: 72vh; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .brand small { display: none; }
  .top-actions { justify-content: flex-end; }
  .workspace { width: min(100% - 16px, 720px); grid-template-columns: 1fr; padding-top: 8px; }
  .cue-list { min-height: 0; max-height: 280px; }
  .field-grid-3 { grid-template-columns: 1fr; }
  .preview-panel { grid-column: auto; }
  .stage-controls { overflow-x: auto; justify-content: flex-start; }
}

@media (max-width: 520px) {
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions .button { flex: 1; }
  .field-grid-2,
  .toggle-grid { grid-template-columns: 1fr; }
  .cue-actions .button { flex: 1 1 42%; }
  .preview-heading { align-items: flex-start; }
  .shortcut-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
  .stage[data-motion="ticker"] .stage-content,
  .stage[data-motion="teleprompter"] .stage-content { animation-play-state: paused; }
}
