:root {
  --bg: #f2e8d5;
  --surface: #fbf5e6;
  --text: #362715;
  --text-muted: #7c6a4d;
  --primary: #a8791f;
  --primary-hover: #8f6519;
  --terracotta: #b23a2e;
  --aegean: #2f5d73;
  --correct: #4c7a3d;
  --incorrect: #a23325;
  --border: #ddc9a0;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(90, 61, 20, 0.12);
  --font-display: "Cinzel", Georgia, "Times New Roman", serif;
  --font-body: "Spectral", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1712;
    --surface: #29221a;
    --text: #f0e6d2;
    --text-muted: #b3a081;
    --primary: #d4a94a;
    --primary-hover: #e3bc63;
    --terracotta: #d1614f;
    --aegean: #6ea3bb;
    --border: #43392a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

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

/* Decorative animated background — purely visual, sits behind everything, never intercepts clicks */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
}

.bg-blob {
  position: absolute;
  width: 42vmax;
  height: 42vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.35;
  animation: blob-drift 22s ease-in-out infinite alternate;
}

.bg-blob--1 { top: -15%; left: -10%; background: var(--primary); animation-delay: 0s; }
.bg-blob--2 { bottom: -20%; right: -10%; background: var(--terracotta); animation-delay: -7s; }
.bg-blob--3 { top: 30%; right: 20%; background: var(--aegean); animation-delay: -14s; opacity: 0.22; }

@keyframes blob-drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(6%, 8%) scale(1.15); }
}

.bg-emoji {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.bg-emoji-item {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: 2.4rem;
  opacity: 0.12;
  animation: emoji-float 7s ease-in-out infinite;
  animation-delay: var(--delay);
}

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

@media (prefers-reduced-motion: reduce) {
  .bg-blob, .bg-emoji-item { animation: none; }
}

@media (max-width: 600px) {
  .bg-emoji-item { font-size: 1.6rem; }
}

/* Greek key (meander) divider, used under the header and above the footer */
.key-pattern {
  height: 14px;
  margin: 10px auto 0;
  max-width: 320px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='16' viewBox='0 0 40 16'%3E%3Cpath d='M0 8 H8 V0 H16 V8 H24 V16 H32 V8 H40' fill='none' stroke='%23a8791f' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: center;
  opacity: 0.6;
}

@media (prefers-color-scheme: dark) {
  .key-pattern {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='16' viewBox='0 0 40 16'%3E%3Cpath d='M0 8 H8 V0 H16 V8 H24 V16 H32 V8 H40' fill='none' stroke='%23d4a94a' stroke-width='2'/%3E%3C/svg%3E");
  }
}

.site-footer .key-pattern { margin: 0 auto 10px; }

.site-header {
  text-align: center;
  padding: 28px 16px 8px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  transition: transform 0.4s ease;
}

.brand:hover .brand-icon { transform: rotate(-14deg) scale(1.08); }

.brand-name {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.01em;
}

.tagline {
  color: var(--text-muted);
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.ad-slot {
  width: min(728px, 92vw);
  margin: 12px auto;
}

.ad-slot-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-align: center;
}

.ad-slot-mock {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 90px;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--surface), var(--bg));
}

.ad-slot-mock-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.ad-slot-mock-art {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  opacity: 0.6;
}

.ad-slot-mock-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ad-slot-mock-lines span {
  display: block;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
}

.ad-slot-mock-lines span:first-child { width: 70%; }
.ad-slot-mock-lines span:last-child { width: 45%; }

.app {
  flex: 1;
  width: min(720px, 92vw);
  margin: 8px auto 32px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.panel-animate { animation: panel-enter 0.32s ease both; }

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .panel-animate { animation: none; }
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 20px 0 10px;
}
.panel h2:first-child { margin-top: 0; }

.summary-score, .question-text { font-family: var(--font-display); }

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover { border-color: var(--primary); transform: translateY(-1px); }
.chip:active { transform: translateY(0) scale(0.97); }

.chip--selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  animation: chip-pop 0.28s ease;
}

@keyframes chip-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.pill:hover { border-color: var(--primary); transform: translateY(-1px); }

.pill--selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  animation: chip-pop 0.28s ease;
}

.select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  padding: 10px 18px;
  font-size: 0.95rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

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

.btn:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(91, 61, 245, 0.18); }
.btn:not(:disabled):active { transform: translateY(0) scale(0.98); box-shadow: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-large {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  margin-top: 24px;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 0;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-panel { text-align: center; }
.error-panel p { color: var(--text-muted); margin-bottom: 16px; }

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.progress-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.badge--easy { color: var(--correct); }
.badge--hard { color: var(--incorrect); }

.score {
  margin-left: auto;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
}

.question-text {
  font-size: 1.3rem;
  line-height: 1.4;
  margin: 0 0 20px;
}

.answers {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.answers--boolean {
  grid-template-columns: 1fr 1fr;
}

.answer-btn {
  text-align: left;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.answer-btn:hover:not(:disabled) { border-color: var(--primary); transform: translateX(3px); }
.answer-btn:active:not(:disabled) { transform: translateX(1px) scale(0.99); }

.answer-btn--correct {
  background: color-mix(in srgb, var(--correct) 18%, var(--surface));
  border-color: var(--correct);
  font-weight: 700;
}

.answer-btn--incorrect {
  background: color-mix(in srgb, var(--incorrect) 18%, var(--surface));
  border-color: var(--incorrect);
}

.answer-btn--dimmed { opacity: 0.5; }

.summary-panel { text-align: center; }

.summary-score {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--primary);
  margin: 12px 0 24px;
}

.summary-pct {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 500;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.site-footer a { color: var(--primary); }

.chip-emoji { margin-right: 4px; }

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.streak-badge-icon {
  width: 1em;
  height: 1em;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.15));
}

.streak-badge--active {
  --tier-color: #ff8a3d;
  background: color-mix(in srgb, var(--tier-color) 20%, var(--surface));
  border-color: var(--tier-color);
  color: var(--tier-color);
  animation: streak-badge-pulse 1.6s ease-in-out infinite;
}

@keyframes streak-badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tier-color) 35%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--tier-color) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .streak-badge--active { animation: none; }
}

.muted { color: var(--text-muted); font-size: 0.9rem; }
.muted.small { font-size: 0.75rem; margin-top: -6px; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* Challenge intro */
.challenge-panel { text-align: center; }
.challenge-stats { color: var(--text-muted); margin-bottom: 8px; }

/* Head-to-head comparison on summary */
.opponent-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 16px 0 4px;
}

.opponent-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.opponent-label { font-weight: 700; font-size: 0.85rem; }
.opponent-score { font-size: 1.3rem; font-weight: 800; color: var(--primary); }
.opponent-streak { font-size: 0.75rem; color: var(--text-muted); }
.opponent-vs { color: var(--text-muted); font-size: 0.8rem; }

.opponent-result {
  font-weight: 700;
  margin-bottom: 8px;
}

.summary-streak { color: var(--text-muted); margin-top: -12px; margin-bottom: 20px; }

.summary-section {
  text-align: left;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 20px;
}

.summary-section h3 { margin: 0 0 10px; font-size: 0.95rem; }

.nickname-row {
  display: flex;
  gap: 8px;
}

.text-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.submit-message { font-size: 0.8rem; color: var(--text-muted); margin: 8px 0 0; }
.share-status { font-size: 0.8rem; color: var(--text-muted); margin: 8px 0 0; min-height: 1em; }

/* Leaderboard */
.leaderboard-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.leaderboard-rank { font-weight: 700; color: var(--text-muted); width: 2.2em; }
.leaderboard-name { flex: 1; font-weight: 600; }
.leaderboard-streak { font-weight: 700; color: var(--terracotta); }

/* Celebration: confetti burst */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--drift), 100vh) rotate(var(--rot)); opacity: 0; }
}

/* Celebration: streak toast — color/border set inline per mythological tier by celebration.js */
.streak-toast {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  z-index: 61;
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-family: var(--font-display);
  font-weight: 700;
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 18px;
  padding: 12px 24px;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: streak-toast-pop 1.6s ease forwards;
  max-width: min(90vw, 480px);
  text-align: left;
  line-height: 1.3;
}

.streak-toast-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

@keyframes streak-toast-pop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -55%) scale(0.9); opacity: 0; }
}

/* Celebration: screen effects for the highest mythological tiers */
@keyframes fx-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, -1px); }
  80% { transform: translate(3px, 1px); }
}

.fx-shake { animation: fx-shake 0.4s ease; }

.fx-flash {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
  background: radial-gradient(circle, var(--flash-color, #fff) 0%, transparent 70%);
  animation: fx-flash-anim 0.6s ease-out forwards;
}

@keyframes fx-flash-anim {
  0% { opacity: 0.75; }
  100% { opacity: 0; }
}

.fx-flash--lightning {
  animation: fx-lightning-anim 0.65s ease-out forwards;
}

@keyframes fx-lightning-anim {
  0% { opacity: 0; }
  8% { opacity: 0.9; }
  18% { opacity: 0.15; }
  28% { opacity: 0.8; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .fx-shake { animation: none; }
}

@media (max-width: 480px) {
  .panel { padding: 18px; }
  .question-text { font-size: 1.1rem; }
  .opponent-compare { gap: 10px; }
}
