:root {
  color-scheme: dark;
  --bg-deep: #172126;
  --bg: #2f3e46;
  --bg-elevated: #364850;
  --bg-soft: #5f8575;
  --bg-bottom: #10171a;
  --ink: #f3f5f4;
  --ink-muted: #b0b8bc;
  --ink-strong: #10171a;
  --accent: #44d7a8;
  --accent-soft: rgba(68, 215, 168, 0.2);
  --ok: #5f8575;
  --line: rgba(243, 245, 244, 0.16);
  --danger: #ff6b5a;
  --danger-ink: #ffd2cb;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --glow-accent: rgba(68, 215, 168, 0.2);
  --glow-mist: rgba(176, 184, 188, 0.18);
  --overlay-scrim: rgba(7, 20, 17, 0.72);
  --overlay-scrim-strong: rgba(7, 20, 17, 0.92);
  --panel-bg: linear-gradient(180deg, #364850, #172126);
  --chip-bg: rgba(16, 23, 26, 0.68);
  --stage-bg: #050708;
  --camera-chrome: #10171a;
  --toast-bg: rgba(16, 23, 26, 0.92);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'DM Sans', 'Segoe UI', sans-serif;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
}

/* iOS 26.1 WebKit regression (bug #301994): env(safe-area-inset-top) reports
   0px inside installed home-screen apps, so everything padded by --safe-top
   slides under the status bar / Dynamic Island. Enforce a status-bar-sized
   floor there. 59px clears the Dynamic Island; max() defers to the real
   env() value the moment Apple fixes it. Scoped to iOS (touch-callout) in
   standalone display so browsers, Android, and desktop PWAs are untouched. */
@supports (-webkit-touch-callout: none) {
  @media (display-mode: standalone) and (pointer: coarse) {
    :root {
      --safe-top: max(env(safe-area-inset-top, 0px), 59px);
    }
  }
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg-deep: #dfeae4;
    --bg: #eef5f1;
    --bg-elevated: #ffffff;
    --bg-soft: #d5e6dd;
    --bg-bottom: #cfdcd5;
    --ink: #1a2824;
    --ink-muted: #5a6d66;
    --ink-strong: #102019;
    --accent: #1f8a68;
    --accent-soft: rgba(31, 138, 104, 0.14);
    --ok: #3f6f5f;
    --line: rgba(26, 40, 36, 0.12);
    --danger: #c84b3c;
    --danger-ink: #8a2e24;
    --shadow: 0 18px 44px rgba(23, 45, 38, 0.12);
    --glow-accent: rgba(31, 138, 104, 0.18);
    --glow-mist: rgba(95, 133, 117, 0.16);
    --overlay-scrim: rgba(238, 245, 241, 0.78);
    --overlay-scrim-strong: rgba(238, 245, 241, 0.94);
    --panel-bg: linear-gradient(180deg, #ffffff, #e7f0eb);
    --chip-bg: rgba(255, 255, 255, 0.78);
    --stage-bg: #121a18;
    --camera-chrome: #eef5f1;
    --toast-bg: rgba(255, 255, 255, 0.94);
  }
}

* {
  box-sizing: border-box;
}

/* Percentage heights, not dvh: the initial containing block is always the
 * real viewport — including inside in-app browsers (the X iOS WebView
 * under-reports dvh on first layout, which squeezed the app into the top
 * half of the screen over a black void). On modern iOS Safari the ICB is
 * dynamic, so 100% tracks the toolbar exactly like dvh did. */
html,
body,
#root {
  margin: 0;
  min-height: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 10% -10%, var(--glow-accent), transparent 55%),
    radial-gradient(90% 70% at 100% 0%, var(--glow-mist), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 58%, var(--bg-bottom) 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.screen {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  animation: rise-in 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.project-screen {
  padding: 0;
  animation: none;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-record {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(240, 79, 58, 0.55);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 18px rgba(240, 79, 58, 0);
    transform: scale(1.03);
  }
}

@keyframes soft-glow {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 0.8;
  }
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--ink-muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.muted {
  color: var(--ink-muted);
}

.btn {
  min-height: var(--tap);
  border-radius: 999px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary {
  background: var(--accent);
  color: var(--ink-strong);
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-icon {
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  padding: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg-elevated) 55%, transparent);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  transition: transform 160ms ease, opacity 160ms ease;
}

.btn-icon:active {
  transform: scale(0.94);
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.error-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 38%, transparent);
  color: var(--danger-ink);
  font-size: 0.92rem;
  line-height: 1.4;
}

.go-button {
  width: 84px;
  height: 84px;
  min-width: 84px;
  border-radius: 50%;
  /* White specular in BOTH themes — via --bg-elevated it was white in light
   * (the look we want) but a murky dark smudge in dark mode. */
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.72), transparent 18%),
    linear-gradient(145deg, var(--accent), var(--ok));
  color: var(--ink-strong);
  border: 4px solid color-mix(in srgb, var(--bg-elevated) 72%, transparent);
  box-shadow: 0 16px 34px var(--accent-soft);
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  transition: transform 160ms ease, opacity 160ms ease;
}

.go-button:active {
  transform: scale(0.95);
}

.go-button.compact {
  width: 58px;
  height: 58px;
  min-width: 58px;
  border-width: 3px;
  font-size: 1.05rem;
}

.go-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg-bottom) 45%, transparent);
  animation: fade-in 200ms ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  max-height: min(78dvh, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-bg);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  border-top: 1px solid var(--line);
  padding: 18px 16px calc(18px + var(--safe-bottom));
  box-shadow: var(--shadow);
  animation: rise-in 280ms ease both;
}

.sheet h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.sheet-lede {
  margin: 0;
  line-height: 1.45;
}

.sheet-message {
  margin: 12px 0 0;
  line-height: 1.4;
}

.sheet-message.is-error {
  color: var(--danger-ink);
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sheet-actions .btn {
  flex: 1;
  min-width: 96px;
}

.export-percent {
  margin: 8px 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.watermark-note {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.link-button {
  padding: 0;
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Post-checkout landing (/unlocked) */
.unlocked-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.unlocked-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 340px;
}

.unlocked-card h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  letter-spacing: -0.03em;
  margin: 0;
}

.unlocked-card p {
  line-height: 1.5;
  margin: 0;
}

.unlocked-card .btn {
  margin-top: 12px;
  min-width: 220px;
}

.export-celebrate-art {
  display: block;
  margin: 0 auto 10px;
  border-radius: 20px;
}

.brand-mark-picture,
.brand-hero-art-picture,
.home-empty-art-picture,
.onboarding-art-picture,
.export-celebrate-art-picture {
  display: inline-grid;
  line-height: 0;
}

.brand-mark,
.brand-hero-art,
.home-empty-art,
.onboarding-art,
.export-celebrate-art {
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.35));
  animation: rise-in 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
  border-radius: 22px;
  object-fit: cover;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.field label {
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.field input[type='text'],
.field input[type='number'] {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  overflow: hidden;
  margin-top: 14px;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  width: 0%;
  transition: width 160ms linear;
}

.sheet-copy {
  margin: 10px 0 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.sheet-footnote {
  display: block;
  margin: 14px auto 0;
  font-size: 0.85rem;
}

.sheet-utility-links {
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.update-toast {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  background: var(--toast-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: rise-in 220ms ease both;
}

.update-toast button {
  color: var(--accent);
  font-weight: 700;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(128px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  background: var(--toast-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  white-space: nowrap;
  animation: rise-in 220ms ease both;
  box-shadow: var(--shadow);
}

.toast button {
  color: var(--accent);
  font-weight: 700;
}

/* Full-screen export progress with a live view of the frame being encoded. */
.export-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  background: #000;
  animation: fade-in 180ms ease both;
}

.export-overlay-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px 8px;
}

.export-preview-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 14px;
  background: #0a0f0d;
}

.export-overlay-info {
  flex: 0 0 auto;
  padding: 16px 20px calc(20px + var(--safe-bottom));
  background: var(--panel-bg);
  border-top: 1px solid var(--line);
  text-align: center;
}

.export-overlay-info h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.export-overlay-info p {
  margin: 0;
}

/* Project preview playback (OK Video: tap edges to skip, middle to stop). */
.playback-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fade-in 180ms ease both;
}

.playback-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.playback-progress {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 2;
  pointer-events: none;
}

.playback-progress span {
  display: block;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
  flex-basis: 0;
}

.playback-progress span i {
  display: block;
  height: 100%;
  background: #fff;
  transition: width 160ms linear;
}

.playback-tap-zones {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  z-index: 1;
}

.playback-tap-zones button {
  opacity: 0;
}

.playback-resume {
  position: absolute;
  z-index: 3;
  padding: 14px 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-weight: 700;
}

.playback-caption {
  position: absolute;
  bottom: calc(18px + var(--safe-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.82rem;
  z-index: 2;
  pointer-events: none;
}

.playback-empty {
  color: rgba(255, 255, 255, 0.85);
  margin: 0 0 14px;
}

/* Keyboard hints only make sense where a keyboard is likely present. */
.key-hints {
  display: none;
  padding: 4px 16px 10px;
  font-size: 11px;
  color: var(--ink-soft, rgba(255, 255, 255, 0.55));
  text-align: center;
  user-select: none;
}

.key-hints kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: inherit;
  font-size: 10px;
  background: rgba(127, 127, 127, 0.12);
}

@media (hover: hover) and (pointer: fine) {
  .key-hints {
    display: block;
  }
}

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

@media (min-width: 720px) {
  body {
    overflow: auto;
  }

  .app-shell {
    margin-top: 24px;
    margin-bottom: 24px;
    height: min(920px, calc(100dvh - 48px));
    border-radius: 28px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

/* ---------------------------------------------------------------------------
   Web components: hosts are transparent wrappers — every kv-* element renders
   the same DOM tree the app always styled, so layout rules (flex children,
   positioning) keep applying to the inner elements unchanged. */
kv-app,
kv-home-page,
kv-project-page,
kv-record-screen,
kv-editor-screen,
kv-timeline,
kv-trim-strip,
kv-clip-preview,
kv-playback-overlay,
kv-export-overlay,
kv-export-sheet,
kv-confirm-sheet,
kv-rename-sheet,
kv-home-options-sheet,
kv-upsell-sheet,
kv-restore-sheet,
kv-onboarding-overlay,
kv-about-page,
kv-privacy-page,
kv-terms-page,
kv-unlocked-page {
  display: contents;
}

/* The vanilla components toggle overlays with the `hidden` attribute instead
   of conditional rendering — it must always win over class display rules. */
[hidden] {
  display: none !important;
}
