/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --bg:            #0d0d0d;
  --surface:       #1a1a1a;
  --surface-2:     #252525;
  --border:        #2e2e2e;
  --accent:        #d4a017;
  --accent-dark:   #b08510;
  --accent-glow:   rgba(212, 160, 23, 0.25);
  --text:          #f0ece0;
  --text-muted:    #7a7060;
  --correct:       #2d6a4f;
  --correct-bg:    #0f2318;
  --correct-text:  #6fcf97;
  --wrong:         #7a2020;
  --wrong-bg:      #210f0f;
  --wrong-text:    #eb5757;
  --radius:        12px;
  --radius-sm:     8px;
  --radius-sheet:  20px 20px 0 0;
  --shadow:        0 6px 24px rgba(0, 0, 0, 0.7);
  --shadow-sm:     0 2px 8px rgba(0, 0, 0, 0.5);
  --transition:    300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 150ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* Each screen manages its own scroll */
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

.screen--active {
  display: flex;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
.welcome-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  gap: 1.25rem;
  min-height: 100dvh;
  min-height: 100vh; /* fallback */
}

.welcome-logo {
  font-size: 5rem;
  line-height: 1;
  filter: drop-shadow(0 0 24px var(--accent-glow));
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0);    }
  50%       { transform: translateY(-8px); }
}

.welcome-title {
  font-size: clamp(2.25rem, 9vw, 3.25rem);
  font-weight: 900;
  color: var(--accent);
  text-align: center;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 0 0 50px var(--accent-glow);
}

.welcome-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  text-align: center;
  letter-spacing: 0.02em;
}

#welcome-clue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.clue-reveal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition-fast);
}

.clue-reveal-btn:active {
  color: var(--accent);
}

.welcome-clue-word {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  animation: bounceIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.welcome-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
  margin-top: 0.5rem;
}

.name-input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.9rem 1rem;
  text-align: center;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
}

.name-input::placeholder {
  color: var(--text-muted);
}

.name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  min-height: 52px;
  padding: 0.75rem 1.5rem;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), opacity var(--transition-fast), background-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.95);
  opacity: 0.88;
}

.btn--primary {
  background: var(--accent);
  color: #0d0d0d;
}

.btn--primary:active {
  background: var(--accent-dark);
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.btn--large {
  font-size: 1.125rem;
  min-height: 58px;
  width: 100%;
}

/* ============================================================
   QUESTION SCREEN
   ============================================================ */
.question-wrapper {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
}

.question-header {
  flex-shrink: 0;
  padding: 0.875rem 1rem 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  /* subtle shadow to separate from grid */
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  position: relative;
  z-index: 2;
}

.question-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.q-number {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width var(--transition);
}

.q-enigma {
  font-size: clamp(1.2rem, 5.5vw, 1.65rem);
  font-weight: 800;
  font-style: italic;
  color: var(--text);
  line-height: 1.25;
  text-align: center;
  margin-bottom: 0.5rem;
  transition: opacity 200ms ease, transform 200ms ease;
}

.q-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ============================================================
   POSTER GRID
   ============================================================ */
.poster-grid-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px;
  /* Ensure last row is never clipped by the browser bottom bar */
  padding-bottom: max(80px, calc(env(safe-area-inset-bottom) + 80px));
}

.poster-card {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  border: 2px solid transparent;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  will-change: transform;
}

.poster-card:active {
  transform: scale(0.93);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  border-color: var(--accent);
}

.poster-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Skeleton shimmer while loading */
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-2) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.poster-card img.loaded {
  animation: none;
  background: none;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Tablet / desktop */
@media (min-width: 600px) {
  .poster-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 12px;
  }
}

@media (min-width: 900px) {
  .poster-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ============================================================
   QUESTION TRANSITION ANIMATIONS
   ============================================================ */
.q-enigma.anim-exit {
  opacity: 0;
  transform: translateX(-40px);
}

.q-enigma.anim-enter {
  opacity: 0;
  transform: translateX(40px);
}

.poster-grid-container.anim-fade-out {
  opacity: 0;
  transition: opacity 180ms ease;
}

.poster-grid-container.anim-fade-in {
  opacity: 1;
  transition: opacity 180ms ease;
}

/* ============================================================
   OVERLAY
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 99;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: all;
}

/* ============================================================
   BOTTOM SHEET
   ============================================================ */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--radius-sheet);
  border-top: 1px solid var(--border);
  transform: translateY(100%);
  transition: transform var(--transition);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
}

.bottom-sheet.is-open {
  transform: translateY(0);
}

.bs-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

.bs-content {
  padding: 1rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
}

.bs-poster {
  width: min(55vw, 200px);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  border: 2px solid var(--accent);
}

.bs-title {
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  line-height: 1.3;
  max-width: 260px;
}

.bs-question-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.bs-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
}

/* ============================================================
   SCORE SCREEN
   ============================================================ */
#screen-score {
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  min-height: 100vh;
}

.score-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
  padding: 2rem 1.5rem;
  text-align: center;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
}

.score-gif {
  width: 100%;
  max-width: 320px;
  height: auto;
  border-radius: 12px;
  object-fit: cover;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score-gif.revealed {
  opacity: 1;
  transform: scale(1);
}

.score-number-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.2rem;
}

.score-count {
  font-size: clamp(4.5rem, 20vw, 7rem);
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 60px var(--accent-glow);
}

.score-total {
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
}

.score-message {
  font-size: 1.15rem;
  font-weight: 700;
  font-style: italic;
  color: var(--text);
}

.score-film {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: -6px;
}

.score-name {
  font-size: 0.9rem;
  color: var(--text-muted);
  min-height: 1.35rem;
}

.clue-block {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  text-align: center;
  width: 100%;
  max-width: 280px;
  animation: bounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.clue-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.clue-word {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
}

.score-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
  margin-top: 0.75rem;
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  width: 100%;
  height: 100%;
}

/* ============================================================
   RESULTS SCREEN
   ============================================================ */
.results-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
}

.results-header {
  padding: 1.5rem 1rem 1rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
}

.results-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
}

.results-summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.results-list {
  list-style: none;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.result-row {
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.result-row--correct {
  background: var(--correct-bg);
  border: 1px solid var(--correct);
}

.result-row--wrong {
  background: var(--wrong-bg);
  border: 1px solid var(--wrong);
}

.result-row__num {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-row--correct .result-row__num { color: var(--correct-text); }
.result-row--wrong   .result-row__num { color: var(--wrong-text); }

.result-row__enigma {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.result-row__answer {
  font-size: 0.975rem;
  font-weight: 700;
  color: var(--text);
}

.result-row__correct-answer {
  font-size: 0.82rem;
  color: var(--correct-text);
  margin-top: 0.1rem;
  padding-top: 0.3rem;
  border-top: 1px solid rgba(45, 106, 79, 0.3);
}

.results-actions {
  padding: 0.75rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.results-actions .btn {
  width: 100%;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
