:root {
  --bg: #0a0e13;
  --stage: #070a0e;
  --panel: #111820;
  --panel-2: #1a2531;
  --text: #dce5ec;
  --muted: #61788a;
  --accent: #4fe0c4;
  --accent-ink: #052a23;
  --alert: #e2394a;
  --border: #1f2b39;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: Consolas, "SF Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 64px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

.wordmark {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.wordmark span { color: var(--accent); }

.subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---- layout ---- */

.workspace {
  width: 100%;
  max-width: 940px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
}

@media (min-width: 880px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 32px;
  }
}

.viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* ---- preview stage ---- */

.stage {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, #101922 0%, var(--stage) 78%);
  border: 0.5px solid var(--border);
  border-radius: 18px;
  transition: border-color 0.15s;
}

.stage.dragover {
  border-color: var(--accent);
}

.canvas-wrap {
  position: relative;
  height: min(66vh, 620px);
  max-width: 100%;
  aspect-ratio: 9 / 16;
  background: #05080b;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 0 8px #0d141b,
    0 0 0 9px #223040,
    0 24px 48px -12px rgba(0, 0, 0, 0.9);
}

#story-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#story-canvas:active { cursor: grabbing; }

.monitor-tag,
.dim-readout {
  position: absolute;
  top: 11px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(220, 229, 236, 0.9);
  background: rgba(5, 8, 11, 0.6);
  padding: 4px 8px;
  border-radius: 5px;
  z-index: 3;
  pointer-events: none;
}

.monitor-tag {
  left: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dim-readout {
  right: 11px;
  letter-spacing: 0.06em;
  text-transform: none;
}

.rec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--alert);
  display: inline-block;
}

@media (prefers-reduced-motion: no-preference) {
  .rec-dot { animation: pulse 2.4s ease-in-out infinite; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---- empty state ---- */

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #070b0f;
  border: none;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s;
}

/* Author-level `display` beats the UA sheet's [hidden] rule, so restate it. */
.empty-state[hidden] { display: none; }

.empty-state svg {
  width: 30px;
  height: 30px;
  margin-bottom: 6px;
}

.empty-state:hover,
.empty-state:focus-visible { color: var(--accent); }

.empty-state:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

.es-title { font-size: 0.92rem; color: var(--text); }
.es-sub { font-size: 0.78rem; }

.ratio-warning {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  z-index: 3;
  background: rgba(5, 8, 11, 0.88);
  border: 0.5px solid rgba(226, 57, 74, 0.6);
  color: #f5b4bb;
  font-size: 0.7rem;
  line-height: 1.45;
  padding: 7px 9px;
  border-radius: 7px;
  text-align: center;
  margin: 0;
}

/* ---- legend ---- */

.legend {
  display: flex;
  gap: 18px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 7px;
}

.key {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  display: inline-block;
}

.key-unsafe {
  background: repeating-linear-gradient(
    -45deg,
    rgba(226, 57, 74, 0.75) 0 2px,
    rgba(226, 57, 74, 0.12) 2px 5px
  );
}

.key-safe {
  border: 1.5px solid var(--accent);
  background: transparent;
}

/* ---- sidebar ---- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 15px;
  background: var(--panel);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.tab-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tab-group-label {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab-row button {
  font-family: var(--font-body);
  font-size: 0.83rem;
  padding: 8px 12px;
  border-radius: 7px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.tab-row button:hover {
  color: var(--text);
  border-color: #33455a;
}

.tab-row button.active {
  background: var(--panel-2);
  color: var(--accent);
  border-color: var(--accent);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  cursor: pointer;
}

.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--panel-2);
  border: 0.5px solid var(--border);
  border-radius: 999px;
  transition: border-color 0.15s;
  pointer-events: none;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.16s ease, background 0.16s;
}

.switch input:checked + .switch-track { border-color: var(--accent); }

.switch input:checked + .switch-track::before {
  transform: translateX(16px);
  background: var(--accent);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.zoom-row {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 0.85rem;
  color: var(--muted);
}

.zoom-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.zoom-row .readout {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text);
  min-width: 3.4em;
  text-align: right;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  border-top: 0.5px solid var(--border);
  padding-top: 14px;
}

.file-name {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ghost-btn {
  font-family: inherit;
  font-size: 0.78rem;
  padding: 6px 11px;
  border-radius: 6px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

button#download-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

button#download-btn:hover:not(:disabled) { opacity: 0.88; }

button#download-btn:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

.hint {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
  margin: 0;
  padding: 0 2px;
}
