:root {
  --color-text: #f0f0f0;
  --color-text-muted: rgba(240, 240, 240, 0.6);
  --color-bg: #030303;
  --color-accent: #e53935; /* Cinematic red */
  --color-accent-hover: #ff5252;
  --font-ui: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-serif: 'Noto Serif SC', serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

/* --- App Shell (Desktop Phone Mockup) --- */
.app-shell {
  min-height: 100svh;
  background: var(--color-bg);
  position: relative;
}

/* Background Film Grain Effect */
.app-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* --- Entry & Result Screens --- */
.entry-screen,
.result-screen {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(40px + env(safe-area-inset-top)) 24px calc(32px + env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 0%, rgba(229, 57, 53, 0.15), transparent 60%), var(--color-bg);
}

.entry-background-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.72;
  filter: contrast(1.05) brightness(0.72) saturate(0.92);
  pointer-events: none;
}

.entry-screen::before,
.result-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(to bottom, rgba(3, 3, 3, 0.18) 0%, rgba(3, 3, 3, 0.72) 72%, rgba(3, 3, 3, 0.96) 100%),
    radial-gradient(circle at 50% 8%, rgba(229, 57, 53, 0.2), transparent 52%);
  pointer-events: none;
}

.entry-copy,
.route-picker,
.entry-actions,
.result-screen > * {
  position: relative;
  z-index: 1;
}

/* Typography */
.entry-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: 10vh;
  animation: fade-in-up 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.subtitle {
  margin: 0 0 12px;
  color: var(--color-accent);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

h3 {
  margin: 24px 0 12px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.description {
  margin: 16px 0 0;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1.6;
  font-weight: 300;
}

/* Animations */
@keyframes fade-in-up {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Buttons & Interactions */
.route-option,
.primary-button,
.secondary-button,
.choice-button {
  min-height: 52px;
  border: 0;
  border-radius: 0; /* Brutalist sharp edges */
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-weight: 500;
  letter-spacing: 0.05em;
}

.secondary-button {
  width: 100%;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.route-picker {
  display: grid;
  gap: 12px;
  margin-top: auto;
  margin-bottom: 24px;
  animation: fade-in-up 1s 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.route-option {
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.route-option.selected {
  color: #fff;
  border-color: var(--color-accent);
  background: rgba(229, 57, 53, 0.1);
}

.entry-actions,
.result-actions {
  display: grid;
  gap: 16px;
  animation: fade-in-up 1s 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.warmup-status {
  min-height: 20px;
  margin: 0;
  color: var(--color-text-muted);
  font-size: 12px;
  text-align: center;
  font-weight: 300;
  letter-spacing: 0.05em;
}

.inline-retry-button {
  min-height: 0;
  margin-left: 12px;
  padding: 4px 12px;
  border: 1px solid var(--color-accent);
  border-radius: 0;
  color: var(--color-accent);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.inline-retry-button:hover {
  background: rgba(229, 57, 53, 0.1);
}

.primary-button {
  width: 100%;
  color: #ffffff;
  background: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 14px;
}

.primary-button:hover:not(:disabled) {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(229, 57, 53, 0.3);
}

.primary-button:disabled {
  color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.05);
  cursor: not-allowed;
}

.player-screen {
  position: relative;
  height: 100svh;
  overflow: hidden;
  background: var(--color-bg);
}

.player-video,
video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--color-bg);
  filter: contrast(1.05) brightness(0.95);
}

.player-video {
  position: absolute;
  inset: 0;
}

.preloaded-video {
  visibility: hidden;
  pointer-events: none;
}

.status-layer,
.transition-layer {
  position: absolute;
  left: 24px;
  right: 24px;
  top: calc(24px + env(safe-area-inset-top));
  padding: 14px 16px;
  border-radius: 0;
  color: var(--color-text);
  background: rgba(3, 3, 3, 0.85);
  backdrop-filter: blur(8px);
  border-left: 2px solid var(--color-accent);
  font-size: 13px;
  text-align: left;
  letter-spacing: 0.05em;
  animation: fade-in-up 0.5s ease-out;
}

.status-layer {
  z-index: 5;
}

.transition-layer {
  top: auto;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 3;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  border-left: none;
  background: transparent;
  backdrop-filter: none;
  font-family: var(--font-ui);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.metric-hud {
  position: absolute;
  z-index: 2;
  top: calc(20px + env(safe-area-inset-top));
  left: 20px;
  right: 20px;
  display: grid;
  gap: 12px;
  pointer-events: none;
}

.metric-item {
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 2px solid var(--color-accent);
  background: rgba(3, 3, 3, 0.7);
  backdrop-filter: blur(12px);
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metric-row span {
  color: var(--color-text-muted);
}

.metric-row strong {
  color: #fff;
  font-size: 12px;
}

.metric-track {
  height: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
}

.metric-track i {
  display: block;
  height: 100%;
  background: var(--color-accent);
  box-shadow: 0 0 10px var(--color-accent);
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.metric-toast {
  position: absolute;
  z-index: 4;
  top: calc(90px + env(safe-area-inset-top));
  left: 50%;
  padding: 10px 20px;
  color: #fff;
  background: rgba(229, 57, 53, 0.9);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: translateX(-50%);
  box-shadow: 0 10px 30px rgba(229, 57, 53, 0.4);
}

.metric-toast.pop {
  animation: metric-pop 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.text-layer {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(32px + env(safe-area-inset-bottom));
  white-space: pre-line;
  color: #fff;
  font-family: var(--font-serif);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.9), 0 1px 4px rgba(0, 0, 0, 0.8);
  font-size: 18px;
  line-height: 1.6;
  text-align: center;
  font-weight: 400;
  letter-spacing: 0.05em;
}

.choice-overlay {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  padding: 20px;
  background: linear-gradient(to top, rgba(3,3,3,0.9) 0%, rgba(3,3,3,0.7) 60%, transparent 100%);
  backdrop-filter: blur(4px);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.choice-timer {
  margin: 0 0 8px 0;
  color: var(--color-accent);
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.choice-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.choice-button span {
  min-width: 0;
  text-align: center;
}

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

.choice-button:active,
.choice-button:hover:not(:disabled) {
  background: rgba(229, 57, 53, 0.15);
  border-color: var(--color-accent);
}

.metric-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 20px;
  margin: 32px 0 0;
  padding: 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ending-progress {
  margin: 16px 0 0;
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metric-list dt {
  color: var(--color-text-muted);
  font-size: 13px;
  letter-spacing: 0.05em;
}

.metric-list dd {
  margin: 0;
  font-weight: 500;
  color: #fff;
}

.choice-history {
  margin: 0;
  padding-left: 0;
  list-style: none;
  color: var(--color-text-muted);
  line-height: 1.8;
  font-size: 13px;
}

.choice-history li {
  position: relative;
  padding-left: 16px;
}

.choice-history li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--color-accent);
}

[hidden] {
  display: none !important;
}

@keyframes metric-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
  15%,
  85% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
}

@media (min-width: 640px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
  }

  body {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
    background: #030303;
    background-image:
      linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center center;
  }

  .app-shell {
    width: min(414px, calc((100vh - 64px) * 0.462));
    height: min(896px, calc(100vh - 64px));
    justify-self: center;
    align-self: center;
    min-height: 0;
    aspect-ratio: 414 / 896;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--color-bg);
    box-shadow:
      0 40px 100px rgba(0, 0, 0, 0.8),
      0 0 0 12px #0a0a0a,
      0 0 0 13px rgba(255, 255, 255, 0.1);
  }

  .entry-screen,
  .result-screen,
  .player-screen {
    width: 100%;
    height: 100%;
    min-height: 0;
  }
}
