/* ── Design tokens (Apple-style) ─────────────────────────────────── */

:root {
  /* page chrome */
  --page-bg: #fbfaf6;
  --card-bg: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #86868b;
  --border: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.12);
  --accent: #0071e3;
  --accent-hover: #0058b8;
  --success: #1f7a3f;
  --error: #c0392b;

  /* shadow ladder */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.05);

  /* radii */
  --radius-card: 16px;
  --radius-input: 10px;
  --radius-button: 10px;
  --radius-pill: 999px;

  /* typography */
  /* Inter — ПЕРВЫМ (он уже грузится глобально, vendor/inter.css), чтобы весь
     апп совпадал по шрифту с редактором (раньше хаб=system, редактор=Inter →
     шрифт «прыгал» при смене вкладок). Системные — фоллбэк. */
  --font-sans: "InterVariable", "Inter var", "Inter", -apple-system, BlinkMacSystemFont,
    "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* easing */
  --ease-apple: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-quick: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern", "liga", "ss01";
  letter-spacing: -0.005em;
}

body {
  padding: 40px 20px 80px;
  min-height: 100vh;
}

main {
  max-width: 920px;
  margin: 0 auto;
}

/* ── Header ─────────────────────────────────────────────────────── */

header {
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.018em;
}

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

.health {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.health::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d2d2d7;
}

.health.ok::before {
  background: #34c759;
}

.health.fail::before {
  background: #ff3b30;
}

.health span {
  color: var(--ink-2);
}

/* ── Sections / cards ───────────────────────────────────────────── */

section {
  margin: 16px 0;
  padding: 24px 28px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
}

section h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ── Forms ──────────────────────────────────────────────────────── */

label {
  display: block;
  margin: 12px 0;
  font-size: 13px;
  color: var(--ink-2);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

input[type="file"] {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink-2);
  transition: border-color 200ms var(--ease-quick), background 200ms var(--ease-quick);
}

input[type="file"]:hover {
  border-color: var(--border-strong);
}

button {
  margin-top: 16px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-button);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background 180ms var(--ease-quick), transform 180ms var(--ease-quick);
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
}

.button-ghost:hover:not(:disabled) {
  background: rgba(0, 113, 227, 0.06);
}

/* ── Format picker ──────────────────────────────────────────────── */

.format-picker {
  margin: 14px 0 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.format-picker legend {
  margin-bottom: 6px;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  grid-column: 1 / -1;
}

.format-option {
  margin: 0;
  position: relative;
  cursor: pointer;
}

.format-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.format-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--page-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color 180ms var(--ease-quick), background 180ms var(--ease-quick),
    box-shadow 180ms var(--ease-quick);
  text-align: left;
}

.format-option:hover .format-card {
  border-color: var(--border-strong);
}

.format-option input[type="radio"]:checked + .format-card {
  border-color: var(--accent);
  background: rgba(0, 113, 227, 0.04);
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.10);
}

.format-icon {
  display: block;
  background: var(--ink);
  border-radius: 3px;
  flex-shrink: 0;
}

.format-icon[data-aspect="9-16"] {
  width: 14px;
  height: 24px;
}

.format-icon[data-aspect="16-9"] {
  width: 28px;
  height: 16px;
}

.format-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.format-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.format-meta {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* ── Status messages ────────────────────────────────────────────── */

.status {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-input);
  font-size: 13px;
  letter-spacing: -0.005em;
}

.status.info {
  background: rgba(0, 113, 227, 0.08);
  color: #0058b8;
}

.status.error {
  background: rgba(255, 59, 48, 0.08);
  color: var(--error);
}

.status.ok {
  background: rgba(52, 199, 89, 0.10);
  color: var(--success);
}

.status-inline {
  font-size: 13px;
  color: var(--muted);
}

.status-inline.error {
  color: var(--error);
}

.status-inline.ok {
  color: var(--success);
}

/* ── Player section ─────────────────────────────────────────────── */

.meta {
  margin: 0 0 18px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.meta code {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Stage controls (palette + actions above stage) ─────────────── */

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.palette-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.palette-switcher .label {
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}

.palette-btn {
  margin: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  cursor: pointer;
  background: transparent;
  transition: transform 180ms var(--ease-apple), border-color 180ms var(--ease-quick),
    box-shadow 180ms var(--ease-quick);
}

.palette-btn:hover {
  transform: scale(1.08);
}

.palette-btn[data-theme="light"] { background: #fdfaf2; }
.palette-btn[data-theme="dark"] { background: #0d0d10; }
.palette-btn[data-theme="blackboard"] { background: #1d3a2a; }
.palette-btn[data-theme="notebook"] { background: #f0f6fb; }

.palette-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.16);
}

.layout-picker,
.arrow-color-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.arrow-color-picker .label {
  font-size: 12px;
  color: var(--muted);
}

.color-swatches {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
}

.color-swatch {
  margin: 0;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  background: var(--c, #ccc);
  cursor: pointer;
  position: relative;
  transition: transform 160ms var(--ease-apple), box-shadow 160ms var(--ease-quick),
    border-color 160ms var(--ease-quick);
  flex-shrink: 0;
}

.color-swatch:hover {
  transform: scale(1.18);
  border-color: rgba(0, 0, 0, 0.18);
}

.color-swatch.active {
  transform: scale(1.15);
  border-color: var(--page-bg);
  box-shadow: 0 0 0 2px var(--c, var(--accent)), var(--shadow-1);
}

.color-swatch-custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(
    from 0deg,
    #ff3b30, #ff9500, #ffcc00, #34c759, #00c7be, #0071e3, #5856d6, #af52de, #ff2d92, #ff3b30
  );
  overflow: hidden;
}

.color-swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  appearance: none;
  -webkit-appearance: none;
}

.color-swatch-custom.active {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-1);
  border-color: var(--page-bg);
}

#arrow-color-reset {
  margin: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
}

.layout-picker .label {
  font-size: 12px;
  color: var(--muted);
}

.layout-picker select {
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card-bg);
  color: var(--ink-2);
  cursor: pointer;
  letter-spacing: -0.005em;
  transition: border-color 180ms var(--ease-quick);
}

.layout-picker select:hover {
  border-color: var(--border-strong);
}

.layout-picker select:focus {
  outline: none;
  border-color: var(--accent);
}

.button-small {
  padding: 6px 14px;
  font-size: 13px;
  margin-top: 0;
}

.button-success-flash {
  background: rgba(52, 199, 89, 0.12);
  color: #1f7a3f;
  border-color: #34c759;
}

/* ── Output composite frame (wraps stage + speaker) ─────────────── */

#output-frame {
  position: relative;
  width: 100%;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

#output-frame[data-mode="horizontal"] #speaker-slot {
  /* Speaker as a circular bottom-right overlay — Apple Dynamic Island vibe.
     Graphite #1D1D1F with a subtle gradient and a hairline light edge. */
  position: absolute;
  width: 22%;
  aspect-ratio: 1 / 1;
  right: 3%;
  bottom: 3%;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.10);
  background: #1d1d1f;
  z-index: 5;
}

#output-frame[data-mode="vertical"] {
  /* 9:16 phone-style frame. Speaker is a small circle near the top.
     The 16:9 canvas occupies the centre of the frame and is zoomed-in
     so more content is readable on a vertical screen. */
  background: #1a1a1c;
  border-radius: var(--radius-card);
  overflow: hidden;
  width: min(420px, 100%);
  aspect-ratio: 9 / 16;
  padding: 0;
  gap: 0;
  align-self: center;
  flex-direction: column;
  justify-content: center;
}

#output-frame[data-mode="vertical"] #speaker-slot {
  position: absolute;
  /* Small circular speaker overlay near the top — same Apple-card vibe
     as the horizontal mode, just resized and re-positioned. */
  width: 38%;
  aspect-ratio: 1 / 1;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32), 0 2px 6px rgba(0, 0, 0, 0.22);
  background: #000;
  z-index: 5;
}

#output-frame[data-mode="vertical"] #stage-wrapper {
  /* Canvas is wider than the phone frame so its 16:9 content reads bigger;
     overflow:hidden on the parent crops the sides cleanly. */
  width: 125%;
  flex: 0 0 auto;
  margin: 0 -12.5%;
}

#output-frame[data-mode="vertical"] #stage {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16 / 9 !important;
  border-radius: 0 !important;
  border: 0 !important;
  max-width: none !important;
  max-height: none !important;
}

#speaker-slot {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

#speaker-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  background: #1a1a1c;
  /* Mirror the speaker so they appear to face the canvas content. */
  transform: scaleX(-1);
}

/* Placeholder shown when no speaker video is attached */
#speaker-slot.placeholder #speaker-video {
  display: none;
}

#speaker-slot.placeholder::before {
  content: "СПИКЕР";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 25%, #2a2a2e 0%, #1d1d1f 55%, #131315 100%);
  color: #86868b;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ── Compose-mode toolbar ───────────────────────────────────────── */

.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}

.compose-toolbar .label {
  font-size: 12px;
  color: var(--muted);
}

.segmented {
  display: inline-flex;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.segment {
  margin: 0;
  padding: 6px 14px;
  background: transparent;
  color: var(--ink-2);
  border: 0;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms var(--ease-quick), color 180ms var(--ease-quick);
}

.segment.active {
  background: var(--card-bg);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.segment:hover:not(.active) {
  color: var(--ink);
}

/* ── Stage / world ──────────────────────────────────────────────── */

#stage-wrapper {
  position: relative;
  width: 100%;
  margin: 0;
  display: flex;
  justify-content: center;
}

#stage {
  position: relative;
  /* Width/height set by JS based on viewport aspect + container size + window height.
     CSS aspect-ratio is fallback only (used before JS measures). */
  aspect-ratio: var(--stage-aspect, 16 / 9);
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-1), inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  transition: background-color 320ms var(--ease-apple), color 320ms var(--ease-apple);
  background-color: #fdfaf2;
  color: #1d1d1f;
  --stage-ink: #1d1d1f;
  --stage-muted: #6e6e73;
}

#stage[data-theme="light"] {
  background-color: #fdfaf2;
  color: #1d1d1f;
  --stage-ink: #1d1d1f;
  --stage-muted: #6e6e73;
}

#stage[data-theme="dark"] {
  background-color: #0d0d10;
  color: #f5f5f7;
  --stage-ink: #f5f5f7;
  --stage-muted: #98989d;
}

#stage[data-theme="blackboard"] {
  background-color: #1d3a2a;
  color: #f0e9d2;
  --stage-ink: #f0e9d2;
  --stage-muted: #b8a880;
}

#stage[data-theme="notebook"] {
  background-color: #f0f6fb;
  color: #1f3559;
  --stage-ink: #1f3559;
  --stage-muted: #5a6f8c;
}

#world {
  position: absolute;
  top: 0;
  left: 0;
  /* Width/height & transform set by JS. */
  color: var(--stage-ink);
}

.stage-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  text-align: center;
  width: 80%;
  color: var(--stage-muted, var(--muted));
  font-size: 14px;
}

.scene {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.scene-draw_svg svg,
.scene-arrow svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.scene-arrow path,
.scene-arrow line {
  stroke: var(--arrow-color, currentColor);
}

.scene-text {
  font-family: var(--font-sans);
  color: var(--stage-ink);
  font-weight: 500;
  letter-spacing: -0.022em;
  white-space: pre-line;
  text-align: center;
  line-height: 1.12;
}

.scene-label {
  font-family: var(--font-sans);
  color: var(--stage-muted);
  font-weight: 400;
  letter-spacing: -0.005em;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

/* Scene "headers" can be heavier — auto-detect via font_size>=70 in JS could also add a class; for now plain. */

/* ── Audio + transport ──────────────────────────────────────────── */

audio {
  display: block;
  width: 100%;
  margin: 12px 0 0;
  filter: contrast(1.05);
}

/* ── Collapsible details panels ─────────────────────────────────── */

details.panel {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

details.panel > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: -0.005em;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  outline: none;
}

details.panel > summary::after {
  content: "▾";
  color: var(--muted);
  transition: transform 180ms var(--ease-quick);
  font-size: 11px;
}

details.panel[open] > summary::after {
  transform: rotate(-180deg);
}

details.panel > summary::-webkit-details-marker {
  display: none;
}

details.panel[open] > summary {
  margin-bottom: 12px;
}

/* ── Align controls ─────────────────────────────────────────────── */

#align-controls,
#scenario-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#align-controls button,
#scenario-controls button {
  margin-top: 0;
}

#pipeline-card {
  margin: 18px 0 12px;
  padding: 18px 20px;
  background: linear-gradient(180deg, var(--card-bg) 0%, rgba(0, 113, 227, 0.03) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
}

.pipeline-header h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pipeline-header .hint {
  margin: 0 0 14px;
}

.pipeline-controls,
.gen-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.gen-controls button {
  margin-top: 0;
}

.gen-mode {
  margin-top: 16px;
  padding: 16px 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--card-bg);
}

.gen-mode-primary {
  border-color: rgba(0, 113, 227, 0.30);
  background: linear-gradient(180deg, var(--card-bg) 0%, rgba(0, 113, 227, 0.025) 100%);
}

.gen-mode h4 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.gen-mode .hint.small {
  font-size: 12px;
  margin: 0 0 12px;
}

.gen-mode-secondary > summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: -0.005em;
  list-style: none;
}

.gen-mode-secondary > summary::-webkit-details-marker {
  display: none;
}

.gen-mode-secondary > summary::after {
  content: " ▾";
  color: var(--muted);
  font-size: 11px;
}

.gen-mode-secondary[open] > summary::after {
  content: " ▴";
}

.gen-mode-secondary[open] > summary {
  margin-bottom: 8px;
}

.prompt-preview-wrap {
  margin-bottom: 10px;
}

.prompt-preview-wrap > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  list-style: none;
}

.prompt-preview-wrap > summary::-webkit-details-marker {
  display: none;
}

.prompt-preview-wrap > summary::after {
  content: " ▾";
  font-size: 10px;
}

#prompt-preview {
  margin-top: 6px;
  font-size: 11px;
  max-height: 220px;
  font-family: var(--font-mono);
  background: var(--page-bg);
  color: var(--ink-2);
}

.manual-input-label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12px;
  color: var(--muted);
}

#manual-scenario-input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  resize: vertical;
  min-height: 140px;
  letter-spacing: -0.005em;
  transition: border-color 200ms var(--ease-quick);
}

#manual-scenario-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pipeline-controls button {
  margin-top: 0;
  padding: 9px 22px;
  font-size: 14px;
}

#pipeline-steps {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

#pipeline-steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  transition: color 200ms var(--ease-quick);
}

#pipeline-steps li.step-active {
  color: var(--accent);
  font-weight: 500;
}

#pipeline-steps li.step-done {
  color: var(--success);
}

#pipeline-steps li.step-error {
  color: var(--error);
}

.step-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 200ms var(--ease-quick), color 200ms var(--ease-quick);
}

.step-active .step-marker {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  animation: step-pulse 1.4s ease-in-out infinite;
}

.step-done .step-marker {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.step-done .step-marker::after {
  content: "✓";
  position: absolute;
}

.step-done .step-marker {
  font-size: 0;
}

.step-done .step-marker::before {
  content: "✓";
  font-size: 12px;
}

.step-error .step-marker {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

@keyframes step-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 113, 227, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(0, 113, 227, 0); }
}

/* ── Render / MP4 export ────────────────────────────────────────── */

#render-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

#render-controls button,
#render-controls a {
  margin-top: 0;
}

#render-progress-wrap {
  margin: 8px 0 6px;
  display: flex;
  align-items: center;
  gap: 12px;
}

#render-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--page-bg);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border);
}

#render-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 250ms var(--ease-quick);
}

#render-progress-text {
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

/* ── YouTube metadata panel ─────────────────────────────────────── */

#youtube-controls-top {
  margin-bottom: 8px;
  min-height: 16px;
}

.youtube-field {
  margin: 12px 0;
}

.youtube-field-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.youtube-field-header label {
  flex: 1;
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.youtube-field-header .hint.small {
  font-size: 11px;
  font-family: var(--font-mono);
}

.copy-mini-button {
  margin: 0;
  padding: 4px 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-button);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms var(--ease-quick);
}

.copy-mini-button:hover {
  background: rgba(0, 113, 227, 0.06);
}

.copy-mini-button.copied {
  background: rgba(52, 199, 89, 0.12);
  color: var(--success);
  border-color: #34c759;
}

#youtube-panel input[type="text"],
#youtube-panel textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  letter-spacing: -0.005em;
  transition: border-color 200ms var(--ease-quick);
  resize: vertical;
}

#youtube-panel input[type="text"]:focus,
#youtube-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
}

#yt-title {
  font-weight: 500;
  font-size: 14px;
}

#yt-tags {
  font-family: var(--font-mono);
  font-size: 12px;
  min-height: 60px;
}

.youtube-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.youtube-actions button {
  margin-top: 0;
}

/* ── Render mode (when ?render=1) ───────────────────────────────── */

body.render-mode {
  margin: 0 !important;
  padding: 0 !important;
  background: #000 !important;
}

body.render-mode header,
body.render-mode #upload-section,
body.render-mode .stage-toolbar,
body.render-mode #pipeline-card,
body.render-mode audio,
body.render-mode details.panel,
body.render-mode .meta {
  display: none !important;
}

/* The hub/editor layer (added on top of the original standalone player) must
   step aside in render mode, otherwise the hub overlay covers the headless
   capture. render.py drives player.js → #world inside #player-section, so we
   force that visible and hide the new app-views. */
body.render-mode #view-hub,
body.render-mode #view-editor,
body.render-mode .app-topbar,
body.render-mode nav.app-tabs,
body.render-mode .app-tabs,
body.render-mode .mini-tabs {
  display: none !important;
}
/* #player-section (the standalone player render.py drives) lives inside the
   #view-auto app-view, which is display:none unless it's the active view.
   Force it visible so the headless capture sees the rendered #world. */
body.render-mode #view-auto {
  display: block !important;
}
body.render-mode #player-section {
  display: block !important;
}
/* The speaker-slot placeholder ("СПИКЕР" circle) is an editor affordance — it
   must never bleed into the rendered MP4. A real speaker video (slot without
   .placeholder) is still allowed through. */
body.render-mode #speaker-slot.placeholder {
  display: none !important;
}
/* Fixed chrome (theme toggle, account avatar/dropdown) must not bleed into the
   render. They sit outside <header>, so the generic header hide misses them. */
body.render-mode .theme-toggle-fixed,
body.render-mode .account-avatar-btn,
body.render-mode #account-dropdown,
body.render-mode .account-dropdown {
  display: none !important;
}

body.render-mode main {
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

body.render-mode #player-section {
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

body.render-mode h2 {
  display: none !important;
}

body.render-mode #stage-wrapper {
  margin: 0 !important;
}

body.render-mode #stage {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Aligned text block ─────────────────────────────────────────── */

#text-display {
  margin-top: 10px;
}

pre {
  margin: 0;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 280px;
  overflow-y: auto;
  color: var(--ink-2);
}

#text-aligned {
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 15px;
  line-height: 1.7;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--ink);
}

.word {
  border-radius: 4px;
  padding: 0 1px;
  cursor: pointer;
  transition: background-color 100ms var(--ease-quick), color 100ms var(--ease-quick);
}

.word:hover {
  background: rgba(0, 113, 227, 0.08);
}

.word.fuzzy {
  color: #b48a1f;
}

.word.interp {
  color: #b9b6ad;
  border-bottom: 1px dashed currentColor;
}

.word.active {
  background: var(--accent);
  color: #fff;
}

.word.active.fuzzy,
.word.active.interp {
  color: #fff;
}

/* ── Assets panel ───────────────────────────────────────────────── */

.dropzone {
  margin: 0 0 16px;
  padding: 24px 16px;
  background: var(--card-bg);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-input);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  transition: background 200ms var(--ease-quick), border-color 200ms var(--ease-quick),
    transform 200ms var(--ease-apple);
  cursor: pointer;
}

.dropzone:hover {
  border-color: var(--accent);
  color: var(--ink-2);
}

.dropzone.dragover {
  background: rgba(0, 113, 227, 0.06);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.005);
}

.dropzone strong {
  color: var(--ink);
  font-weight: 500;
}

.dropzone input[type="file"] {
  display: none;
}

.assets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.asset-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 11px;
  color: var(--ink-2);
  transition: transform 180ms var(--ease-apple), box-shadow 180ms var(--ease-quick),
    border-color 180ms var(--ease-quick);
}

.asset-thumb:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--border-strong);
}

.asset-thumb img,
.asset-thumb svg {
  width: 80px;
  height: 80px;
  object-fit: contain;
  color: var(--ink-2);
}

.asset-thumb .asset-name {
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.asset-thumb .asset-type {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
