:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: #191c20;
  --panel-soft: #22262c;
  --line: #343a43;
  --text: #f3f5f7;
  --muted: #aeb6c0;
  --dim: #737d8a;
  --accent: #f2c14e;
  --accent-strong: #ffd76d;
  --danger: #ff6b6b;
  --ok: #60d394;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

.controller-shell {
  min-width: 1040px;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(242, 193, 78, 0.08), transparent 34%),
    radial-gradient(circle at 85% 10%, rgba(96, 211, 148, 0.09), transparent 26%),
    var(--bg);
}

.controller {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 22px;
}

.topbar,
.cue-board,
.next-strip,
.controls,
.cue-list {
  border: 1px solid var(--line);
  background: rgba(25, 28, 32, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 22px;
  border-radius: 8px;
}

.error-line {
  margin: 10px 0 0;
  padding: 10px 14px;
  border: 1px solid rgba(255, 107, 107, 0.45);
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.12);
  color: #ffd7d7;
  font-size: 14px;
  font-weight: 800;
}

.eyebrow,
.label,
dt {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-pill {
  min-width: 88px;
  padding: 8px 10px;
  border: 1px solid rgba(96, 211, 148, 0.45);
  border-radius: 999px;
  color: var(--ok);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.warn {
  border-color: rgba(255, 107, 107, 0.5);
  color: var(--danger);
}

.status-pill.muted {
  border-color: var(--line);
  color: var(--muted);
}

.cue-board {
  display: grid;
  grid-template-columns: minmax(250px, 0.8fr) minmax(420px, 1.3fr) minmax(280px, 0.9fr);
  gap: 1px;
  margin-top: 16px;
  border-radius: 8px;
  overflow: hidden;
}

.live-panel,
.selected-panel,
.scene-panel {
  min-height: 320px;
  padding: 22px;
  background: var(--panel);
}

.selected-panel {
  background: #1d2127;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading strong {
  color: var(--accent-strong);
  font-size: 34px;
  line-height: 1;
}

.subtitle-preview {
  margin: 0 0 24px;
  min-height: 88px;
  color: var(--text);
  font-size: 30px;
  font-weight: 800;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.selected-panel .subtitle-preview {
  min-height: 104px;
  font-size: 36px;
}

.subtitle-preview.empty {
  color: var(--dim);
}

.meta-grid,
.detail-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.meta-grid {
  grid-template-columns: 1fr;
}

.detail-list div,
.meta-grid div {
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

dd {
  margin: 5px 0 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.45;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.scene-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.scene-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101216;
  overflow: hidden;
}

.scene-preview.blank {
  background:
    linear-gradient(135deg, rgba(242, 193, 78, 0.05), transparent 42%),
    #101216;
}

.scene-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scene-preview span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-weight: 800;
}

.scene-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.scene-caption strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-strip {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: 8px;
}

.next-strip strong {
  color: var(--accent-strong);
  font-size: 22px;
}

.next-strip p {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: grid;
  grid-template-columns: 58px 112px 58px 58px minmax(130px, 1fr) 58px 78px 78px 78px;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
}

button {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #17130a;
}

.jump-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111419;
}

.jump-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.jump-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
}

.cue-list {
  margin-top: 16px;
  max-height: 210px;
  overflow: auto;
  border-radius: 8px;
}

.cue-list ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cue-item {
  display: grid;
  grid-template-columns: 76px 110px 130px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 48px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(52, 58, 67, 0.72);
  color: var(--muted);
  cursor: pointer;
}

.cue-item:hover,
.cue-item:focus-visible {
  background: rgba(242, 193, 78, 0.08);
  outline: none;
}

.cue-item.selected {
  background: rgba(242, 193, 78, 0.14);
  color: var(--text);
}

.cue-item.live {
  box-shadow: inset 4px 0 0 var(--ok);
}

.cue-id {
  color: var(--accent-strong);
  font-weight: 900;
}

.cue-scene,
.cue-actor {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cue-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 700;
}

.projector-shell {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

.projector-stage {
  display: grid;
  grid-template-rows: 20% 80%;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

.background-layer {
  grid-row: 2;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.background-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.subtitle-layer {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: 1vh 4vw;
  background: #000;
  pointer-events: none;
}

.projector-subtitle {
  width: 100%;
  margin: 0;
  color: #fff;
  text-align: center;
  font-size: min(4vw, 7vh);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow-wrap: normal;
}

.projector-subtitle.hidden,
.projector-subtitle:empty {
  display: none;
}

@media (max-width: 1180px) {
  .controller-shell {
    min-width: 900px;
  }

  .controller {
    width: calc(100vw - 24px);
  }

  .cue-board {
    grid-template-columns: minmax(230px, 0.8fr) minmax(360px, 1.25fr) minmax(230px, 0.75fr);
  }

  .controls {
    grid-template-columns: 52px 100px 52px 52px minmax(100px, 1fr) 52px 70px 70px 70px;
  }
}

@media (max-width: 920px) {
  .controller-shell {
    min-width: 0;
  }

  .controller {
    width: calc(100vw - 18px);
    padding: 12px 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-row {
    justify-content: flex-start;
  }

  .cue-board {
    grid-template-columns: 1fr;
  }

  .live-panel,
  .selected-panel,
  .scene-panel {
    min-height: 0;
  }

  .controls {
    grid-template-columns: repeat(4, 1fr);
  }

  .jump-box {
    grid-column: span 2;
  }

  .cue-item {
    grid-template-columns: 70px 100px 1fr;
  }

  .cue-item .cue-actor {
    display: none;
  }
}

/* Controller editing and controls remain usable on narrow laptop windows. */
.controller-shell { min-width: 0; }
.topbar > div { min-width: 0; }
.editor-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.editor-toolbar button { height: 40px; padding: 0 16px; }
.editor-toolbar span, .help-line { color: var(--muted); font-size: 13px; line-height: 1.6; }
.editor-toolbar span { flex: 1 1 280px; }
.help-line { margin: 10px 2px; }
.controls { display: flex; flex-wrap: wrap; }
.controls button { flex: 0 0 auto; padding: 0 14px; font-size: 14px; }
.jump-box { flex: 1 1 140px; min-width: 140px; }
button:disabled { opacity: .4; cursor: default; }
.editable-field { border-radius: 4px; outline: 1px dashed var(--accent); outline-offset: 4px; cursor: text; min-height: 1.5em; white-space: pre-wrap; }
.editable-field:focus { outline: 2px solid var(--accent); background: rgba(242,193,78,.06); }
.editable-field:empty::before { content: '클릭하여 입력'; color: var(--dim); }
.editable-image { cursor: pointer; outline: 1px dashed var(--accent); }
.scene-caption { flex-direction: column; align-items: flex-start; }
.scene-caption strong { width: 100%; white-space: normal; overflow-wrap: anywhere; }
#sceneSelectLabel { font-size: 13px; color: var(--muted); }
#cueSceneSelect { display: block; width: 100%; margin-top: 8px; padding: 10px; color: var(--text); background: var(--panel-soft); border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.next-strip p { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.cue-board { grid-template-columns: minmax(0, .8fr) minmax(0, 1.3fr) minmax(0, .9fr); }
.live-panel, .selected-panel, .scene-panel { min-width: 0; }
@media (max-width: 920px) { .cue-board { grid-template-columns: 1fr; } }

.projector-fullscreen-button { position: fixed; bottom: 18px; right: 18px; z-index: 5; padding: 12px 20px; height: auto; font-size: 16px; }


.font-size-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0 20px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.font-size-controls label { width: 100%; font-size: 14px; }
.font-size-controls output { color: var(--accent); font-weight: bold; margin-left: 8px; }
.font-size-controls input { flex: 1; min-width: 100px; accent-color: #f2c14e; }
.font-size-controls button { padding: 8px 12px; height: auto; font-size: 13px; }
.font-size-controls small { width: 100%; color: var(--muted); }

.live-preview { width: 100%; min-height: 120px; background: #000; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: grid; place-items: center; }
.live-preview img { display: block; width: 100%; height: auto; }
.live-preview span { color: var(--muted); padding: 24px; font-size: 14px; }

.next-dialogue { min-width: 0; }
.next-pronunciation { display: flex; align-items: baseline; gap: 12px; margin-top: 8px; }
.next-pronunciation .label { flex-shrink: 0; }
.next-pronunciation p { color: var(--muted); font-size: 18px; font-weight: 400; line-height: 1.5; }

/* Window geometry follows the image's object-fit crop, including projector resizing. */
.background-layer, .subtitle-layer { grid-column: 1; }
.window-effect, .scene-dimmer { grid-area: 2 / 1; min-height: 0; pointer-events: none; position: relative; overflow: hidden; }
.window-effect[hidden] { display: none; }
#windowFrame { position: absolute; overflow: hidden; perspective: 1600px; transform-style: preserve-3d; }
.window-pane { position: absolute; top: 0; width: 50%; height: 100%; background: linear-gradient(115deg, #d8e9ef14, #ffffff03 50%, #c3dcea1a); }
/* Trim the sash artwork's transparent outer margin so hinges meet the opening. */
.window-pane { overflow: hidden; }
.window-pane img { display: block; position: absolute; left: -1.6%; top: -1.5%; width: 103%; height: 103%; }
.left-pane { left: 0; transform-origin: 0% 50%; }
.right-pane { right: 0; transform-origin: 100% 50%; }
.right-pane img { transform: scaleX(-1); }
.scene-dimmer { background: black; opacity: 0; }

/* Keep all sash children beneath the same blackout plane. */
.projector-stage { isolation: isolate; }
.background-layer { z-index: 0; }
.window-effect { z-index: 1; }
.scene-dimmer { z-index: 2; }
.subtitle-layer { z-index: 3; }
/* Match the softly lit bedroom instead of a bright isolated product photo. */
.window-pane img { filter: brightness(.68) saturate(.55); }
#windowFrame { box-shadow: inset 0 2px 5px #10182070; }

.portal-layer { background: transparent; grid-area: 2 / 1; z-index: 1; min-height: 0; position: relative; overflow: hidden; pointer-events: none; opacity: 0; }
#goldenPortal { position: absolute; width: 100%; height: 100%; }
