:root {
  --bg: #0c0c0f;
  --bg-2: #121218;
  --panel: #16161c;
  --line: #2a2a34;
  --text: #f3efe6;
  --muted: #9a958a;
  --accent: #e8c07a;
  --accent-dim: rgba(232, 192, 122, 0.16);
  --rec: #ff3b30;
  --ok: #7dcea0;
  --cue: #e8c07a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --prompt-size: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  margin: 0;
  min-height: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Segoe UI", "Avenir Next", "Avenir", ui-sans-serif, system-ui,
    sans-serif;
  letter-spacing: 0.01em;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.view {
  min-height: 100%;
  min-height: 100dvh;
}

#view-setup,
#view-done {
  padding: calc(28px + var(--safe-top)) 22px calc(40px + var(--safe-bottom));
  max-width: 1120px;
  margin: 0 auto;
}

.setup-header {
  max-width: 640px;
  margin-bottom: 28px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  font-weight: 650;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 620;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 650;
}

.lede,
.hint {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.hint {
  font-size: 13px;
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.side {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

textarea {
  width: 100%;
  resize: vertical;
  min-height: 220px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
}

textarea:focus,
input[type="range"]:focus-visible,
button:focus-visible,
a:focus-visible,
video:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.script-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.script-preview {
  margin-top: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
}

.script-preview.empty {
  color: var(--muted);
}

.script-preview p {
  margin: 0 0 12px;
}

.script-preview p:last-child {
  margin-bottom: 0;
}

.control {
  margin-top: 14px;
}

.control:first-of-type {
  margin-top: 8px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.camera-frame {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}

.camera-frame video,
.pip,
#playback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

#playback {
  transform: none;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  height: auto;
}

.camera-status {
  position: absolute;
  inset: auto 12px 12px;
  margin: 0;
  color: #d9d4c8;
  font-size: 13px;
  text-shadow: 0 1px 8px #000;
}

.camera-frame.live .camera-status {
  display: none;
}

.mic-meter {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
}

.mic-meter span {
  width: 4px;
  height: 30%;
  background: var(--line);
  border-radius: 2px;
  transition: height 80ms linear, background 80ms linear;
}

.mic-meter span.on {
  background: var(--ok);
}

.mic-meter.hot span.on {
  background: var(--rec);
}

.raw-video,
.offscreen-canvas {
  position: fixed;
  left: -100vw;
  top: 0;
  width: 160px;
  height: 90px;
  opacity: 0;
  pointer-events: none;
}

.btn,
.btn-stop,
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  min-height: 46px;
}

.btn.primary {
  width: 100%;
  background: var(--accent);
  color: #1a1408;
}

.btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.secondary {
  width: 100%;
  margin-top: 12px;
  background: var(--accent-dim);
  color: var(--accent);
}

.btn.ghost {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.text-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

#view-session {
  position: relative;
  overflow: hidden;
  background: #050506;
}

.session-bar {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rec-badge,
.session-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 12, 15, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  backdrop-filter: blur(10px);
}

.rec-badge.live .rec-dot {
  animation: pulse 1.1s ease-in-out infinite;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rec);
  box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.16);
}

.session-status {
  color: var(--muted);
}

.btn-stop {
  background: var(--rec);
  color: white;
  padding: 10px 16px;
  min-height: 40px;
}

.prompter {
  position: absolute;
  inset: 0;
}

.prompter-window {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.prompter-track {
  padding: 0 8vw 50vh;
  max-width: 980px;
  margin: 0 auto;
  font-size: var(--prompt-size);
  line-height: 1.38;
  font-weight: 500;
  text-align: center;
  will-change: transform;
}

.prompter-track p {
  margin: 0 0 0.72em;
  color: rgba(243, 239, 230, 0.38);
  transition: color 180ms ease;
}

.prompter-track p.is-current {
  color: var(--text);
}

.prompter-track p.is-passed {
  color: rgba(243, 239, 230, 0.18);
}

.cue {
  position: absolute;
  left: 0;
  right: 0;
  top: 32%;
  z-index: 3;
  pointer-events: none;
  height: 0;
  border-top: 1px solid rgba(232, 192, 122, 0.85);
}

.cue span {
  position: absolute;
  left: 50%;
  top: -5px;
  width: 9px;
  height: 9px;
  margin-left: -4px;
  background: var(--cue);
  transform: rotate(45deg);
}

.prompter-fade {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  height: 28%;
}

.prompter-fade.top {
  top: 0;
  background: linear-gradient(to bottom, #050506, transparent);
}

.prompter-fade.bottom {
  bottom: 0;
  height: 34%;
  background: linear-gradient(to top, #050506, transparent);
}

.pip {
  position: absolute;
  right: calc(14px + var(--safe-right));
  bottom: calc(92px + var(--safe-bottom));
  width: min(220px, 34vw);
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  border: 2px solid rgba(255, 59, 48, 0.8);
  z-index: 5;
  box-shadow: var(--shadow);
  object-fit: cover;
}

.session-controls {
  position: absolute;
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.session-controls .control {
  margin: 0;
  background: rgba(12, 12, 15, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 12px 10px;
  backdrop-filter: blur(10px);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 8;
  background: rgba(5, 5, 6, 0.35);
  font-size: clamp(72px, 18vw, 160px);
  font-weight: 650;
  letter-spacing: -0.06em;
  color: var(--text);
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}

.done-grid {
  display: grid;
  gap: 16px;
}

.done-actions {
  display: grid;
  gap: 10px;
  max-width: 420px;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (max-width: 860px) {
  .setup-grid {
    grid-template-columns: 1fr;
  }

  #view-setup,
  #view-done {
    padding: calc(18px + var(--safe-top)) 14px calc(24px + var(--safe-bottom));
  }

  .prompter-track {
    padding-left: 5vw;
    padding-right: 5vw;
    font-size: var(--prompt-size);
  }

  .pip {
    width: 96px;
    bottom: calc(118px + var(--safe-bottom));
    aspect-ratio: 3 / 4;
  }

  .session-status {
    display: none;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .pip {
    width: 88px;
    bottom: calc(10px + var(--safe-bottom));
  }

  .session-controls {
    max-width: 420px;
  }
}
