:root {
  color-scheme: dark;
  --bg: #111513;
  --panel: #19201d;
  --panel-soft: #212a26;
  --line: #344039;
  --ink: #f7fbf8;
  --muted: #a9b8ae;
  --primary: #38a3a5;
  --primary-strong: #1f7a86;
  --accent: #f7c948;
  --danger: #df5555;
  --shadow: 0 20px 48px rgb(0 0 0 / 0.35);
  --radius: 8px;
  --tap: 44px;
  --edge-bottom: 6px;
  --prompt-size: 34px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

svg {
  display: block;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sprite,
input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: min(980px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    12px
    var(--edge-bottom);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.topbar-actions,
.prompt-controls,
.record-controls,
.sheet-actions {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 8px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.48rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.12rem;
}

.stage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #050706;
  box-shadow: var(--shadow);
  overflow: hidden;
  isolation: isolate;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  transform: scaleX(-1);
  background: #050706;
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
  background: radial-gradient(circle at center, rgb(56 163 165 / 0.12), transparent 42%), #050706;
  z-index: 4;
}

.camera-empty.is-hidden {
  display: none;
}

.camera-start {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border: 1px solid rgb(255 255 255 / 0.14);
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 16px 34px rgb(0 0 0 / 0.32);
}

.camera-start svg {
  width: 1.65rem;
  height: 1.65rem;
}

.prompter-mask {
  position: absolute;
  inset: 12% 5% 14%;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
  -webkit-mask-image: linear-gradient(transparent, #000 15%, #000 78%, transparent);
  mask-image: linear-gradient(transparent, #000 15%, #000 78%, transparent);
}

.read-line {
  position: absolute;
  top: 43%;
  left: 0;
  right: 0;
  height: 2px;
  background: rgb(247 201 72 / 0.85);
  box-shadow: 0 0 18px rgb(247 201 72 / 0.38);
}

.script-track {
  min-height: 100%;
  padding: 42vh 0 64vh;
  color: #fff;
  font-size: var(--prompt-size);
  font-weight: 850;
  line-height: 1.35;
  letter-spacing: 0;
  text-align: center;
  text-wrap: balance;
  text-shadow:
    0 2px 5px rgb(0 0 0 / 0.92),
    0 0 18px rgb(0 0 0 / 0.74);
  white-space: pre-wrap;
  will-change: transform;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: clamp(5rem, 22vw, 10rem);
  font-weight: 950;
  background: rgb(0 0 0 / 0.34);
  text-shadow: 0 10px 28px rgb(0 0 0 / 0.4);
  z-index: 5;
}

.countdown.is-hidden {
  display: none;
}

.controls {
  display: grid;
  gap: 8px;
  min-height: 0;
}

.prompt-controls {
  display: grid;
  grid-template-columns: var(--tap) var(--tap) minmax(0, 1fr) var(--tap) var(--tap);
  gap: 7px;
}

.record-controls {
  display: grid;
  grid-template-columns: 72px minmax(62px, 1fr) var(--tap) var(--tap);
  gap: 8px;
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
}

.icon-button {
  width: var(--tap);
  padding: 0;
}

.primary-icon {
  border-color: var(--primary);
  background: var(--primary-strong);
  color: #fff;
}

.icon-button.is-active {
  border-color: var(--accent);
  background: rgb(247 201 72 / 0.16);
  color: var(--accent);
}

.pause-icon,
.icon-button.is-active .play-icon {
  display: none;
}

.icon-button.is-active .pause-icon {
  display: block;
}

.speed-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.speed-control input {
  width: 100%;
  accent-color: var(--primary);
}

.timer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.record-button {
  position: relative;
  display: grid;
  place-items: center;
  justify-self: center;
  width: 62px;
  height: 62px;
  min-height: 62px;
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: inset 0 0 0 5px rgb(255 255 255 / 0.1);
}

.record-button span {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--danger);
  transition:
    width 160ms ease,
    height 160ms ease,
    border-radius 160ms ease;
}

.record-button.is-recording span {
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.script-sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.script-sheet.is-hidden {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.58);
}

.sheet-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  max-width: 720px;
  max-height: min(78vh, 720px);
  margin: 0 auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #101513;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
}

.sheet-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(92px, auto) minmax(92px, auto);
  gap: 8px;
}

.text-button {
  gap: 8px;
  padding: 0 14px;
}

.primary-text {
  border-color: var(--primary);
  background: var(--primary-strong);
}

.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

body.is-recording-view {
  background: #050706;
}

body.is-recording-view .app {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

body.is-recording-view .topbar {
  display: none;
}

body.is-recording-view .stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.is-recording-view #preview {
  width: 100%;
  height: 100%;
}

body.is-recording-view .prompter-mask {
  inset: 7% 5% 20%;
}

body.is-recording-view .script-track {
  padding-top: 38vh;
}

body.is-recording-view .controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 8px 10px var(--edge-bottom);
  background: linear-gradient(transparent, rgb(5 7 6 / 0.84) 18%, rgb(5 7 6 / 0.96));
}

body.is-recording-view .record-controls {
  grid-template-columns: 72px minmax(0, 1fr) 72px;
}

body.is-recording-view .timer {
  grid-column: 1;
}

body.is-recording-view .record-button {
  grid-column: 2;
}

body.is-recording-view #download-button,
body.is-recording-view #share-button {
  display: none;
}

@media (min-width: 780px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .controls {
    align-content: end;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 1.38rem;
  }

  .prompter-mask {
    inset: 10% 4% 15%;
  }

  .record-controls {
    grid-template-columns: 72px minmax(62px, 1fr) var(--tap) var(--tap);
    gap: 7px;
  }

  .speed-control {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .speed-control span {
    display: none;
  }

  body.is-recording-view .record-controls {
    grid-template-columns: 72px minmax(0, 1fr) 72px;
  }
}

html.is-standalone {
  --edge-bottom: 0px;
}

@media (display-mode: standalone), (display-mode: fullscreen) {
  :root {
    --edge-bottom: 0px;
  }
}
