/* ============================================
   BLINDTEST — Design System
   "Concert poster nocturne"
   ============================================ */

:root {
  /* Fonts */
  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Geist', system-ui, sans-serif;
  --font-mono: 'Geist Mono', monospace;

  /* Surfaces */
  --bg-base:      #0F0A1A;
  --bg-elevated:  #1A1226;
  --bg-overlay:   #251934;
  --bg-glass:     rgba(26, 18, 38, 0.7);

  /* Text */
  --text-primary:   #F5F0E8;
  --text-secondary: #B5ABBF;
  --text-muted:     #6B5F78;
  --text-inverse:   #0F0A1A;

  /* Borders */
  --border-subtle:  rgba(245, 240, 232, 0.08);
  --border-default: rgba(245, 240, 232, 0.15);
  --border-strong:  rgba(245, 240, 232, 0.3);

  /* Accents */
  --accent-gold:    #FFD93D;
  --accent-magenta: #FF1F8F;
  --accent-cream:   #F5F0E8;

  /* Semantic */
  --success: #4ADE80;
  --warning: #FBBF24;
  --danger:  #EF4444;
  --info:    #60A5FA;

  /* QCM */
  --qcm-red:    #E63950;
  --qcm-blue:   #3D8AE0;
  --qcm-yellow: #E0B73D;
  --qcm-green:  #4FA84A;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;
  --space-24: 96px;
  --space-32: 128px;

  /* Breakpoints */
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
}

/* ---- Base ---- */
body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.bg-base { background: var(--bg-base); }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--accent-gold); }
.border-gold { border-color: var(--accent-gold); }

/* ---- Accent color for inputs ---- */
.accent-gold { accent-color: var(--accent-gold); }

/* ---- Film grain overlay ---- */
.grain-overlay {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  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='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* ---- Atmosphere gradient mesh ---- */
.atmosphere {
  position: relative;
  isolation: isolate;
}
.atmosphere::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(40% 60% at 20% 30%, rgba(255, 217, 61, 0.18), transparent 70%),
    radial-gradient(35% 55% at 80% 70%, rgba(255, 31, 143, 0.15), transparent 70%);
  filter: blur(40px);
}

/* Intensified atmosphere for podium/final */
.atmosphere--intense {
  position: relative;
  isolation: isolate;
}
.atmosphere--intense::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(45% 65% at 15% 25%, rgba(255, 217, 61, 0.28), transparent 65%),
    radial-gradient(40% 60% at 85% 65%, rgba(255, 31, 143, 0.22), transparent 65%),
    radial-gradient(50% 50% at 50% 50%, rgba(255, 217, 61, 0.08), transparent 80%);
  filter: blur(50px);
}

/* ---- Typography ---- */
.display-xl {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 10vw, 8rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
}
.display-l {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.display-m {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

.body-l { font-family: var(--font-body); font-size: 1.125rem; line-height: 1.5; }
.body-m { font-family: var(--font-body); font-size: 1rem; line-height: 1.5; }
.body-s { font-family: var(--font-body); font-size: 0.875rem; line-height: 1.45; color: var(--text-muted); }

.mono { font-family: var(--font-mono); letter-spacing: -0.01em; }

/* ---- Buttons ---- */
.btn-primary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 28px;
  background: var(--accent-gold);
  color: var(--text-inverse);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1), background 200ms;
  position: relative;
}
.btn-primary:hover { background: #FFE066; transform: translateY(-2px); }
.btn-primary:active { transform: translateY(0); transition-duration: 80ms; }
.btn-primary:disabled { background: var(--text-muted); cursor: not-allowed; opacity: 0.5; transform: none; }

.btn-secondary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 28px;
  background: transparent;
  color: var(--text-primary);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1), border-color 200ms, color 200ms;
}
.btn-secondary:hover { border-color: var(--accent-gold); color: var(--accent-gold); transform: translateY(-2px); }
.btn-secondary:active { transform: translateY(0); transition-duration: 80ms; }
.btn-secondary.border-gold { border-color: var(--accent-gold); }
.btn-secondary.text-gold { color: var(--accent-gold); }

/* ---- QCM Buttons ---- */
.qcm-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px;
  border: none;
  border-radius: 16px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: white;
  cursor: pointer;
  transition: transform 120ms ease-out, filter 120ms;
  position: relative;
  overflow: hidden;
}
.qcm-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent 50%);
  pointer-events: none;
}
.qcm-btn:active { transform: scale(0.97); filter: brightness(1.15); }
.qcm-btn.selected { outline: 4px solid var(--accent-cream); outline-offset: -4px; }
.qcm-btn--red    { background: var(--qcm-red); }
.qcm-btn--blue   { background: var(--qcm-blue); }
.qcm-btn--yellow { background: var(--qcm-yellow); color: #1A1226; }
.qcm-btn--green  { background: var(--qcm-green); }

/* ---- Input ---- */
.input {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-default);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1.125rem;
  transition: border-color 200ms, background 200ms;
}
.input:focus {
  outline: none;
  border-color: var(--accent-gold);
  background: var(--bg-overlay);
}
.input::placeholder { color: var(--text-muted); }

/* ---- Card ---- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.card--active { border-color: var(--accent-gold); }
.card--rank-1 {
  background: linear-gradient(135deg, rgba(255,217,61,0.12), var(--bg-elevated));
  border-color: var(--accent-gold);
}

/* ---- Timer ---- */
.timer { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.timer svg { width: 100%; height: 100%; }
.timer-bg { fill: none; stroke: var(--border-subtle); stroke-width: 6; }
.timer-progress {
  fill: none;
  stroke: var(--accent-gold);
  stroke-width: 6;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 1s linear, stroke 300ms;
}
.timer--critical .timer-progress { stroke: var(--accent-magenta); }
.timer--critical .timer-text { color: var(--accent-magenta); animation: pulse 0.5s infinite alternate; }
.timer-text {
  position: absolute;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 2rem;
}

/* ---- Avatar ---- */
.avatar {
  width: var(--avatar-size, 48px);
  height: var(--avatar-size, 48px);
  border-radius: 50%;
  border: 1.5px solid var(--border-default);
  background: var(--bg-overlay);
  object-fit: cover;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar--leader {
  border: 2px solid var(--accent-gold);
  box-shadow: 0 0 20px rgba(255, 217, 61, 0.4);
}
.avatar--contender {
  border: 2px solid var(--accent-magenta);
  animation: pulse-border 600ms ease-in-out infinite alternate;
}
.avatar--offline { opacity: 0.4; filter: grayscale(0.6); }

.avatar-overlay {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  border: 2px solid var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6em;
}
.avatar-overlay--submitted { background: var(--success); }
.avatar-overlay--rejected  { background: var(--danger); }
.avatar-overlay--catchup   { background: var(--accent-gold); }
.avatar-overlay--offline   { background: var(--text-muted); }

/* ---- Chip ---- */
.chip {
  display: inline-block;
  padding: 6px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---- Animations ---- */
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.1); } }

@keyframes pulse-border {
  from { box-shadow: 0 0 0 0 rgba(255, 31, 143, 0.4); }
  to   { box-shadow: 0 0 0 8px rgba(255, 31, 143, 0); }
}

.pulse-soft { animation: pulse-soft 2s ease-in-out infinite; }
@keyframes pulse-soft {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.9; }
}

/* ---- Reveal sequence ---- */
.reveal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 26, 0.95);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: reveal-fade-in 300ms ease-out;
}
@keyframes reveal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.reveal-answer {
  animation: reveal-zoom 800ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}
@keyframes reveal-zoom {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---- Leaderboard FLIP animation ---- */
.leaderboard-item {
  transition: transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Points float ---- */
.points-float {
  animation: float-up 1.5s cubic-bezier(0, 0, 0.2, 1) forwards;
  position: absolute;
  pointer-events: none;
}
@keyframes float-up {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

/* ---- Stagger entrance ---- */
.stagger-enter {
  animation: stagger-in 400ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes stagger-in {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* ---- Podium ---- */
.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: podium-rise 800ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes podium-rise {
  from { transform: translateY(60px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.podium-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  position: relative;
  clip-path: polygon(10% 0%, 90% 0%, 100% 100%, 0% 100%);
}
.podium-bar--1 {
  height: 160px;
  background: linear-gradient(180deg, rgba(255,217,61,0.3), rgba(255,217,61,0.08));
}
.podium-bar--1::after {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(10% 0%, 90% 0%, 100% 100%, 0% 100%);
  border: 2px solid var(--accent-gold);
  pointer-events: none;
}
.podium-bar--2 {
  height: 110px;
  background: linear-gradient(180deg, rgba(245,240,232,0.1), rgba(245,240,232,0.03));
}
.podium-bar--3 {
  height: 80px;
  background: linear-gradient(180deg, rgba(245,240,232,0.08), rgba(245,240,232,0.02));
}

/* ---- Sudden death background ---- */
.sudden-death-bg {
  background: linear-gradient(135deg, rgba(255,31,143,0.25), var(--bg-base));
  animation: sd-pulse 2s ease-in-out infinite;
}
@keyframes sd-pulse {
  0%, 100% { background: linear-gradient(135deg, rgba(255,31,143,0.15), var(--bg-base)); }
  50% { background: linear-gradient(135deg, rgba(255,31,143,0.3), var(--bg-base)); }
}

/* ---- Correct/Wrong flash ---- */
.flash-correct {
  animation: flash-green 600ms ease-out;
}
@keyframes flash-green {
  0% { background: rgba(74, 222, 128, 0.3); }
  100% { background: transparent; }
}
.flash-wrong {
  animation: flash-red 600ms ease-out;
}
@keyframes flash-red {
  0% { background: rgba(239, 68, 68, 0.3); }
  100% { background: transparent; }
}

/* ---- Containment for performance ---- */
.leaderboard-container {
  contain: layout style paint;
}
.timer {
  contain: layout style paint;
}

/* ---- QR frame ---- */
.qr-frame {
  background: var(--bg-elevated);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---- Focus states ---- */
*:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
