:root {
  --bg-void: #050811;
  --surface-deck: rgba(10, 15, 28, 0.84);
  --surface-field: rgba(255, 255, 255, 0.045);
  --border-hairline: rgba(232, 198, 128, 0.18);
  --border-strong: rgba(232, 198, 128, 0.42);
  --ink-ivory: #f3efe6;
  --ink-muted: #8f9bb3;
  --accent-gold: #e4b45c;
  --accent-gold-hi: #f7d98e;
  --rec-red: #f04848;
  --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #0d162c 0%, var(--bg-void) 72%);
  color: var(--ink-ivory);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 18px 16px;
  max-width: 1280px;
  margin: 0 auto;
}

/* Top HUD */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0.16em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-ivory);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent-gold-hi), var(--accent-gold));
  box-shadow: 0 0 12px rgba(228, 180, 92, 0.75);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-deck);
  border: 1px solid var(--border-hairline);
  border-radius: 999px;
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s, background 0.18s;
}

.seg-btn:hover {
  color: var(--ink-ivory);
}

.seg-btn.active {
  background: rgba(228, 180, 92, 0.18);
  color: var(--accent-gold-hi);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-hairline);
  background: var(--surface-deck);
  color: var(--ink-ivory);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}

.ghost-btn:hover {
  border-color: var(--border-strong);
  background: rgba(20, 29, 52, 0.9);
}

/* Cinema Stage */
.stage-wrap {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  background: #02040a;
  border: 1px solid var(--border-hairline);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.stage[data-aspect="9:16"] {
  aspect-ratio: 9 / 16;
}

.stage[data-aspect="1:1"] {
  aspect-ratio: 1 / 1;
}

@media (max-aspect-ratio: 16/10) {
  .stage[data-aspect="16:9"] {
    width: 100%;
    height: auto;
    max-height: 100%;
  }
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Loader */
.loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(4, 7, 15, 0.88);
  color: var(--ink-muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  z-index: 5;
  transition: opacity 0.35s ease;
}

.loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-ring {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(228, 180, 92, 0.2);
  border-top-color: var(--accent-gold);
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Recording Tally */
.rec-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 10, 14, 0.82);
  border: 1px solid rgba(240, 72, 72, 0.45);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #ffd7d7;
}

.rec-badge[hidden] {
  display: none;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rec-red);
  box-shadow: 0 0 10px var(--rec-red);
  animation: pulse 1s ease-in-out infinite;
}

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

/* Transport Scrubber Overlay */
.transport {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 26px 14px 11px;
  background: linear-gradient(to top, rgba(3, 5, 11, 0.88) 0%, rgba(3, 5, 11, 0.4) 65%, transparent 100%);
  opacity: 0.92;
  transition: opacity 0.2s;
}

.stage:hover .transport,
.transport:focus-within {
  opacity: 1;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-ivory);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-gold-hi);
}

.icon-btn svg[hidden] {
  display: none;
}

.scrubber {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  outline: none;
  cursor: pointer;
  accent-color: var(--accent-gold);
}

.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent-gold-hi);
  border: 2px solid #101522;
  box-shadow: 0 0 10px rgba(247, 217, 142, 0.7);
}

.timecode {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: rgba(243, 239, 230, 0.85);
  white-space: nowrap;
}

/* Control Deck */
.deck {
  background: var(--surface-deck);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.deck-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr);
}

.field {
  position: relative;
  display: flex;
  align-items: center;
}

.field input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--surface-field);
  color: var(--ink-ivory);
  font-family: var(--font-ui);
  font-size: 0.96rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.18s, background 0.18s;
}

.field-main input {
  padding-right: 42px;
}

.field input::placeholder {
  color: var(--ink-muted);
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
}

.field input:focus {
  border-color: var(--accent-gold);
  background: rgba(228, 180, 92, 0.06);
}

.inline-btn {
  position: absolute;
  right: 5px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.inline-btn:hover {
  color: var(--accent-gold-hi);
  background: rgba(255, 255, 255, 0.08);
}

/* Swatches & CTAs */
.swatches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.deck-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  margin-right: 4px;
}

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

.swatch:hover {
  color: var(--ink-ivory);
  border-color: rgba(255, 255, 255, 0.25);
}

.swatch.active {
  color: var(--ink-ivory);
  border-color: var(--border-strong);
  background: rgba(228, 180, 92, 0.14);
}

.swatch-chip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
}

.chip-classic {
  background: linear-gradient(135deg, #ffffff 0%, #f5f0e4 46%, #d9a03d 54%, #9c6b1c 100%);
}

.chip-solidgold {
  background: linear-gradient(135deg, #fff1ba 0%, #e6b44d 50%, #8a5b14 100%);
}

.chip-chrome {
  background: linear-gradient(135deg, #ffffff 0%, #c8d6eb 50%, #5b6e8a 100%);
}

.cta-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.secondary-btn,
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  border-radius: 10px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, filter 0.18s, border-color 0.18s, background 0.18s;
}

.secondary-btn {
  border: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-ivory);
}

.secondary-btn:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.09);
}

.primary-btn {
  border: 0;
  background: linear-gradient(135deg, #f3cd78 0%, #d49b39 100%);
  color: #120d05;
  box-shadow: 0 6px 24px rgba(228, 180, 92, 0.28);
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.primary-btn:active:not(:disabled),
.secondary-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.primary-btn.recording {
  background: linear-gradient(135deg, #ff6262 0%, #cc2b2b 100%);
  color: #fff;
  box-shadow: 0 6px 24px rgba(240, 72, 72, 0.35);
}

.share-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}

.share-bar[hidden] {
  display: none;
}

.share-url {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent-gold-hi);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  outline: none;
}

.share-mini-btn {
  height: 32px;
  padding: 0 12px;
  font-size: 0.78rem;
  text-decoration: none;
}

/* Focus visibility */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-gold-hi);
  outline-offset: 2px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(15, 21, 38, 0.95);
  border: 1px solid var(--border-strong);
  color: var(--ink-ivory);
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Full-screen ?show=... viral viewer mode (no edit UI, pure cinema!) */
body.show-mode {
  background: #000;
}

body.show-mode .app {
  max-width: none;
  padding: 0;
  gap: 0;
  grid-template-rows: 1fr;
}

body.show-mode .topbar,
body.show-mode .deck,
body.show-mode .transport {
  display: none;
}

body.show-mode .stage-wrap {
  width: 100vw;
  height: 100dvh;
}

body.show-mode .stage {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

.show-hud {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 7px;
  opacity: 0.32;
  transition: opacity 0.25s ease;
}

.show-hud[hidden] {
  display: none;
}

.show-hud:hover,
.show-hud:focus-within,
body.show-mode.ended .show-hud {
  opacity: 0.94;
}

.show-pill {
  appearance: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(6, 10, 20, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink-ivory);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}

.show-pill:hover {
  border-color: var(--border-strong);
  background: rgba(14, 21, 38, 0.92);
}

.show-make-btn {
  border-color: var(--border-strong);
  color: var(--accent-gold-hi);
}

/* Mobile responsiveness */
@media (max-width: 700px) {
  .app {
    padding: 10px 10px 12px;
    gap: 9px;
  }

  .ghost-btn span {
    display: none;
  }

  .deck-inputs {
    grid-template-columns: 1fr;
  }

  .deck-controls {
    flex-wrap: wrap;
  }

  .cta-group {
    width: 100%;
  }

  .cta-group .primary-btn {
    flex: 1;
  }

  .deck-label {
    display: none;
  }
}
