:root {
  --bg: #051c5a;
  --bg-2: #0a2a7a;
  --panel: #0d2f85;
  --panel-2: #143a9a;
  --panel-glass: rgba(13, 47, 133, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --text: #f6f8ff;
  --muted: #aebbe8;
  --accent: #ffd617;
  --accent-ink: #051c5a;
  --ok: #4be08a;
  --gold: #ffd617;
  --display: "Open Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "Open Sans", "Segoe UI", system-ui, sans-serif;
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--display);
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow-x: hidden;
}

/* Background Crossfade Layers (bg2.webp -> bg3.webp) */
.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}

.bg-layer-2 {
  background-image:
    url("/trivia/uploads/bg2.webp"),
    radial-gradient(1400px 700px at 85% -10%, rgba(255, 214, 23, 0.18), transparent 60%),
    radial-gradient(1000px 600px at -10% 110%, rgba(90, 160, 255, 0.24), transparent 60%);
  opacity: 1;
}

.bg-layer-3 {
  background-image:
    url("/trivia/uploads/bg3.webp"),
    radial-gradient(1400px 700px at 85% -10%, rgba(255, 214, 23, 0.18), transparent 60%),
    radial-gradient(1000px 600px at -10% 110%, rgba(90, 160, 255, 0.24), transparent 60%);
  opacity: 0;
}

body.is-revealed .bg-layer-2 {
  opacity: 0;
}

body.is-revealed .bg-layer-3 {
  opacity: 1;
}

/* Subtle background grid pattern matching trivia game */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45), transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45), transparent 75%);
  z-index: 1;
}

/* Navigation / Actions Top Bar */
.top-nav {
  position: fixed;
  top: 14px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 50;
  pointer-events: none;
}

.top-nav > * {
  pointer-events: auto;
}

.nav-links, .nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(13, 47, 133, 0.82);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 7px 15px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.2s ease;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.nav-btn:hover {
  background: var(--panel-2);
  border-color: var(--line-strong);
  color: var(--accent);
  transform: translateY(-1px);
}

.nav-btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
}

.nav-btn.primary:hover {
  background: #ffe043;
  color: var(--accent-ink);
  box-shadow: 0 0 20px rgba(255, 214, 23, 0.45);
}

/* Stage container */
#stage {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 900px;
  margin: auto;
  padding: 46px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header & Brand */
header {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
  cursor: pointer;
  user-select: none;
}

.brand strong {
  color: var(--text);
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 16px;
}

/* 12-Star EU Logo */
.eu {
  position: relative;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  background: #003399;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.eu i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5.5px;
  height: 5.5px;
  margin: -2.75px 0 0 -2.75px;
  background: var(--accent);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transform: rotate(var(--a)) translateY(-9.5px) rotate(calc(-1 * var(--a)));
}

h1 {
  font-weight: 900;
  letter-spacing: -0.03em;
  font-size: clamp(24px, 3.8vw, 42px);
  line-height: 1.05;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1 em {
  font-style: normal;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 214, 23, 0.4);
}

.subtitle {
  margin: 0;
  font-size: clamp(13.5px, 1.6vw, 16px);
  color: var(--muted);
  font-weight: 400;
  max-width: 560px;
  line-height: 1.4;
  transition: opacity 0.3s ease;
}

/* Main QR Card Frame — Hidden until revealed */
.qr-card {
  position: relative;
  width: auto;
  max-width: 100%;
  background: var(--panel-glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(12px, 1.6vw, 22px);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.9) translateY(14px);
  transition:
    opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.9s ease;
}

body.is-revealed .qr-card {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

.qr-card::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: calc(var(--radius) + 1px);
  padding: 1px;
  background: linear-gradient(135deg, rgba(255, 214, 23, 0.4), transparent 50%, rgba(90, 160, 255, 0.3));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* High Contrast Pure White QR Container - Maximized size */
.qr-frame {
  position: relative;
  width: min(88vw, calc(100dvh - 210px), 740px);
  aspect-ratio: 1 / 1;
  background: #ffffff;
  border-radius: 16px;
  padding: clamp(10px, 1.4vw, 18px);
  display: grid;
  place-items: center;
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.06);
  margin: 0;
}

.qr-frame svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* Footer note */
footer {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  max-width: 600px;
  line-height: 1.4;
  text-align: center;
  opacity: 0.85;
}

footer b {
  color: var(--text);
}

/* Fullscreen mode adaptations - Extra Large Display */
:fullscreen body, :-webkit-full-screen body {
  padding: 10px;
  justify-content: center;
}

:fullscreen #stage, :-webkit-full-screen #stage {
  padding: 0;
  max-width: 1000px;
}

:fullscreen header, :-webkit-full-screen header {
  margin-bottom: 8px;
}

:fullscreen h1, :-webkit-full-screen h1 {
  font-size: clamp(22px, 3vw, 36px);
  margin-bottom: 4px;
}

:fullscreen .subtitle, :-webkit-full-screen .subtitle {
  font-size: 14px;
}

:fullscreen .qr-card, :-webkit-full-screen .qr-card {
  padding: 14px;
}

:fullscreen .qr-frame, :-webkit-full-screen .qr-frame {
  width: min(92vw, calc(100dvh - 130px), 860px);
}

:fullscreen footer, :-webkit-full-screen footer {
  margin-top: 8px;
  font-size: 11px;
}

/* Print Styles */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
  }
  .bg-layer, body::before, .top-nav, footer {
    display: none !important;
  }
  #stage {
    margin: 0 !important;
    max-width: 100% !important;
  }
  .qr-card {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    padding: 20px 0 !important;
  }
  .qr-card::after {
    display: none !important;
  }
  .qr-frame {
    max-width: 540px !important;
    border: 2px solid #000 !important;
    box-shadow: none !important;
  }
  h1 {
    color: #000000 !important;
    font-size: 32px !important;
  }
  h1 em {
    color: #000000 !important;
    text-shadow: none !important;
  }
}

/* Mobile responsive */
@media (max-width: 600px) {
  body {
    padding: 12px 8px;
  }
  .top-nav {
    position: static;
    margin-bottom: 12px;
    width: 100%;
  }
  #stage {
    padding: 0 4px 10px;
    margin: 0 auto;
  }
  .qr-card {
    padding: 12px;
  }
  .qr-frame {
    width: min(92vw, calc(100dvh - 180px));
    padding: 12px;
  }
}
