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

:root {
  --toi: #c00;
  --toi-dark: #900;
  --toi-light: #e44;
  --bg: #f4f2ee;
  --card: #ffffff;
  --surface: #fafafa;
  --text: #1a1a1a;
  --text-muted: #555;
  --muted: #888;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --border: #e0ddd8;
  --radius: 16px;
  --sm: 10px;
  --font: 'Inter', -apple-system, sans-serif;
  --font-title: 'Playfair Display', serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeUp{from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}
@keyframes fadeScale{from{opacity:0;transform:scale(0.95)}to{opacity:1;transform:scale(1)}}
@keyframes slideIn{from{opacity:0;transform:translateX(-15px)}to{opacity:1;transform:translateX(0)}}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:0.5}}
@keyframes breathe{0%,100%{transform:scale(1)}50%{transform:scale(1.05)}}
@keyframes shimmer{0%{background-position:-200% 0}100%{background-position:200% 0}}
@keyframes countPop{0%{transform:scale(0.5);opacity:0}50%{transform:scale(1.15)}100%{transform:scale(1);opacity:1}}

.anim-in{animation:fadeUp 0.5s ease forwards}
.anim-in-fast{animation:fadeUp 0.3s ease forwards}
.anim-scale{animation:fadeScale 0.3s ease forwards}
.anim-slide{animation:slideIn 0.4s ease forwards}

/* Apply staggered animation to option buttons */
.opt-btn:nth-child(1){animation:slideIn 0.3s ease 0.05s both}
.opt-btn:nth-child(2){animation:slideIn 0.3s ease 0.1s both}
.opt-btn:nth-child(3){animation:slideIn 0.3s ease 0.15s both}
.opt-btn:nth-child(4){animation:slideIn 0.3s ease 0.2s both}

/* TOI accent bar at top */
.toi-accent-bar {
  height: 4px;
  background: linear-gradient(90deg, var(--toi), #e04, #c06);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

/* Background texture / pattern */
.screen-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(204,0,0,0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(0,50,150,0.04) 0%, transparent 50%),
    repeating-linear-gradient(45deg, transparent, transparent 40px, rgba(255,255,255,0.008) 40px, rgba(255,255,255,0.008) 41px);
  z-index: -1;
  pointer-events: none;
}

/* Screens */
.screen { display: none; flex-direction: column; min-height: 100vh; position: relative; }
.screen.active { display: flex; }

/* Animations */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.animate-in { animation: fadeUp 0.5s ease forwards; }

/* ============= JOIN SCREEN ============= */
#screen-join {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.join-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  position: relative;
  backdrop-filter: blur(10px);
}

.join-crest {
  margin-bottom: 1.5rem;
}

.crest-text {
  font-family: var(--font-title);
  font-size: 3rem;
  font-weight: 900;
  color: var(--toi);
  line-height: 1;
  letter-spacing: -2px;
}

.crest-sub {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 0.2rem;
}

.join-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.6rem;
}

.join-highlight {
  color: var(--toi);
}

.join-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.join-team {
  color: var(--accent);
  font-weight: 600;
}

.join-stats {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.jstat {
  background: var(--surface);
  padding: 0.5rem 1rem;
  border-radius: var(--sm);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.jstat-num {
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.join-form input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--sm);
  padding: 0.9rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
}

.join-form input:focus {
  border-color: var(--accent);
}

.join-form input::placeholder {
  color: var(--text-muted);
  text-align: center;
}

.btn-toi {
  background: var(--toi);
  color: white;
  border: none;
  border-radius: var(--sm);
  padding: 0.9rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.btn-toi:hover:not(:disabled) {
  background: var(--toi-dark);
  box-shadow: 0 4px 20px rgba(204,0,0,0.3);
  transform: translateY(-1px);
}

.btn-toi:active:not(:disabled) { transform: scale(0.98); }
.btn-toi:disabled { opacity: 0.4; cursor: default; }

.join-footer {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 1px;
  margin-top: 1.5rem;
}

/* ============= QUIZ SCREEN ============= */
#screen-quiz {
  padding: 1rem;
  align-items: center;
}

.quiz-container {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding-top: 1rem;
  animation: fadeUp 0.4s ease forwards;
}

/* Top bar: question counter + dots + score */
.quiz-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.q-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.q-counter {
  font-weight: 700;
  font-size: 1rem;
  color: var(--toi);
  background: rgba(204,0,0,0.1);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-variant: tabular-nums;
}

.q-progress-dots {
  display: flex;
  gap: 4px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface);
  transition: background 0.3s;
}

.progress-dot.done { background: var(--green); }
.progress-dot.current { background: var(--toi); }
.progress-dot.wrong { background: var(--red); }

.q-score {
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--green);
  font-variant: tabular-nums;
}

/* Progress bar */
.quiz-progress-track {
  height: 3px;
  background: var(--surface);
  border-radius: 2px;
  margin-bottom: 1.5rem;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--toi), var(--toi-light));
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

/* Main question area */
.quiz-main {
  margin-bottom: 1.25rem;
  position: relative;
}

.q-media-area {
  width: 100%;
  max-height: 240px;
  overflow: hidden;
  border-radius: var(--sm);
  margin-bottom: 1rem;
  background: var(--surface);
  position: relative;
}

.q-media-area img,
.q-media-area video {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
}

.q-media-placeholder {
  height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--surface), #1a1a28);
}

.media-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: breathe 2s ease-in-out infinite;
}

.media-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Timer ring overlaid next to question */
.q-timer-area {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.timer-ring {
  position: relative;
  width: 72px;
  height: 72px;
}

.timer-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-bg {
  fill: none;
  stroke: var(--surface);
  stroke-width: 4;
}

.timer-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-dasharray: 200;  /* 2 * pi * 34 ≈ 213.6, using 200 for visual */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.timer-fill.warning { stroke: var(--amber); }
.timer-fill.danger { stroke: var(--red); }

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: 800;
  font-variant: tabular-nums;
}

.q-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  padding: 0 0.5rem;
}

/* Options grid */
.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.opt-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--sm);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-align: left;
  width: 100%;
  position: relative;
}

.opt-btn:hover:not(.disabled) {
  border-color: var(--accent);
  background: #e8f0fe;
  transform: translateY(-1px);
}

.opt-btn:active:not(.disabled) { transform: scale(0.98); }

.opt-btn.selected {
  border-color: var(--accent);
  background: #dbeafe;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.opt-btn.correct {
  border-color: var(--green);
  background: #dcfce7;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.15);
}

.opt-btn.wrong {
  border-color: var(--red);
  background: #fee2e2;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.opt-btn.revealed {
  border-color: var(--green);
  background: #dcfce7;
}

.opt-btn.disabled { cursor: default; pointer-events: none; }

.opt-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.opt-label {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.3;
}

/* Next question indicator (wayground-style) */
.quiz-next-indicator {
  text-align: center;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s;
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  z-index: 100;
}

.quiz-next-indicator.visible {
  opacity: 1;
}

.next-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.3rem;
  display: block;
}

.next-bar {
  height: 3px;
  background: var(--surface);
  border-radius: 2px;
  overflow: hidden;
}

.next-fill {
  height: 100%;
  background: var(--accent);
  width: 100%;
  animation: shrinkBar 3s linear forwards;
}

@keyframes shrinkBar {
  from { width: 100%; }
  to { width: 0%; }
}

/* ============= THANK YOU SCREEN ============= */
#screen-thanks {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.thanks-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.thanks-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  animation: pulse 2s ease-in-out infinite;
}

.thanks-title {
  font-family: var(--font-title);
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.3rem;
}

.thanks-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.thanks-score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--sm);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.thanks-score-num {
  font-size: 3rem;
  font-weight: 900;
  color: var(--green);
  line-height: 1;
}

.thanks-score-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.thanks-funfact {
  background: var(--surface);
  border-left: 3px solid var(--toi);
  padding: 1rem;
  margin-bottom: 1.5rem;
  text-align: left;
  border-radius: 0 var(--sm) var(--sm) 0;
}

.ff-label {
  font-size: 0.75rem;
  color: var(--toi);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.4rem;
}

.ff-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.thanks-crest {
  font-family: var(--font-title);
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--toi);
  letter-spacing: -2px;
  margin-bottom: 0.3rem;
}

.thanks-footer {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ============= RESPONSIVE ============= */
@media (max-width: 600px) {
  .join-card, .thanks-card { padding: 1.5rem 1.25rem; }
  .join-title { font-size: 1.4rem; }
  .quiz-options { grid-template-columns: 1fr; gap: 0.5rem; }
  .opt-btn { padding: 0.75rem; }
  .q-text { font-size: 0.95rem; }
  .q-counter { font-size: 0.85rem; }
  .q-score { font-size: 1.1rem; }
  .quiz-next-indicator { width: 240px; bottom: 1rem; }
  .timer-ring { width: 60px; height: 60px; }
  .timer-text { font-size: 1.1rem; }
}