:root {
  --bg-1: #0b0c1e;
  --bg-2: #14112a;
  --bg-3: #1b1236;
  --panel: rgba(35, 30, 66, 0.55);
  --panel-solid: #201a3d;
  --line-soft: rgba(255, 255, 255, 0.08);
  --text: #f2f1f8;
  --text-dim: #a8a4c0;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --blue: #3b82f6;
  --gold: #f5b942;
  --good: #4ade80;
  --bad: #ff6b6b;
  --gradient: linear-gradient(90deg, var(--purple), var(--pink));
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

/* Alles altijd boven de vouw: de hele game past in de viewport, op elk formaat. */
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: radial-gradient(circle at 20% 0%, var(--bg-3), var(--bg-2) 45%, var(--bg-1) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.app {
  width: 100%;
  max-width: 640px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */

.topbar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.topbar h1 {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: clamp(1.1rem, 4.5vw, 1.8rem);
  font-weight: 800;
  letter-spacing: 0.01em;
}

.ai-gradient {
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line-soft);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { border-color: var(--purple); }

.dropdown {
  position: absolute;
  top: 46px;
  left: 0;
  background: var(--panel-solid);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 190px;
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.dropdown button, .dropdown a {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
}

.dropdown button:hover, .dropdown a:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- Stats row ---------- */

.stats-row {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  min-height: 64px;
}

.stat-icon { font-size: 1.3rem; }

.stat-label {
  color: var(--text-dim);
  font-size: 0.66rem;
}

.stat-value {
  font-weight: 700;
  font-size: 1rem;
}

.progress-ring {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: conic-gradient(var(--purple) var(--pct, 0%), rgba(255, 255, 255, 0.1) 0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring-inner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
}

/* ---------- Main / question ---------- */

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.question {
  flex: 0 0 auto;
  text-align: center;
  margin: 0 0 2px;
  font-size: clamp(0.95rem, 4vw, 1.4rem);
  font-weight: 700;
}

.subtitle {
  flex: 0 0 auto;
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 8px;
  font-size: 0.78rem;
}

/* ---------- Timer ---------- */

.timer-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}

.timer-bar-wrap {
  flex: 1;
  height: 7px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--gradient);
  border-radius: 999px;
}

.timer-bar.urgent {
  background: var(--bad);
  animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.timer-value {
  flex: 0 0 auto;
  min-width: 22px;
  text-align: right;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

/* ---------- Image cards ---------- */
/* Mobiel: onder elkaar. Desktop media query hieronder zet ze naast elkaar. */

.images-stack {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-card {
  position: relative;
  padding: 0;
  border: 3px solid var(--purple);
  border-radius: var(--radius);
  background: var(--panel-solid);
  overflow: hidden;
  cursor: pointer;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  display: block;
  box-shadow: 0 0 22px -6px var(--purple);
}

.image-card.card-b {
  border-color: var(--blue);
  box-shadow: 0 0 22px -6px var(--blue);
}

.image-card:hover:not(:disabled) {
  filter: brightness(1.05);
}

.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-card:disabled {
  cursor: default;
}

.image-card.correct {
  border-color: var(--good);
  box-shadow: 0 0 22px -4px var(--good);
}

.image-card.wrong {
  border-color: var(--bad);
  box-shadow: 0 0 22px -4px var(--bad);
}

.card-label {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(139, 92, 246, 0.85);
  color: #fff;
  z-index: 2;
}

.card-b .card-label {
  background: rgba(59, 130, 246, 0.85);
}

.tap-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  background: rgba(10, 8, 24, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  z-index: 2;
}

.image-card:disabled .tap-hint { display: none; }

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #10131a;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2;
}

.badge.show {
  opacity: 1;
  transform: translateY(0);
}

.badge.real { background: var(--good); }
.badge.ai { background: var(--bad); color: #fff; }

button.primary {
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 22px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

button.primary:hover { filter: brightness(1.08); }

button.secondary {
  background: none;
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 9px 22px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

button.secondary:hover { border-color: var(--purple); }

.hidden { display: none !important; }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 14, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.help-card, .end-card {
  background: var(--panel-solid);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 26px 28px;
  text-align: center;
  max-width: 380px;
  max-height: 90dvh;
  overflow-y: auto;
}

.help-card { text-align: left; }
.help-card h2, .end-card h2 { margin-top: 0; color: var(--text); text-align: center; }
.help-card ul { padding-left: 18px; color: var(--text-dim); font-size: 0.9rem; line-height: 1.5; }
.help-card .primary, .end-card .primary { display: block; margin: 16px auto 0; }

#scores-overlay { z-index: 21; }

/* ---------- Ronde-resultaat popup ---------- */

.result-popup {
  text-align: center;
  max-width: 320px;
}

.result-icon-big {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 6px;
}

.result-title-big {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.result-detail-big {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 18px;
}

.next-round-btn {
  width: 100%;
  padding: 13px 20px;
  font-size: 1rem;
}

.scores-card { text-align: center; }

.scores-list {
  list-style: none;
  counter-reset: rank;
  padding: 0;
  margin: 12px 0;
  text-align: left;
}

.scores-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.scores-list li::before {
  content: counter(rank) ".";
  color: var(--text-dim);
  font-weight: 700;
  margin-right: 8px;
  min-width: 1.4em;
}

.scores-list li .score-num {
  flex: 1;
  font-weight: 700;
}

.scores-list li .score-date {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.scores-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.end-highscore {
  color: var(--gold);
  font-weight: 700;
  margin: 4px 0 0;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Larger screens: images side by side, still one screen ---------- */

@media (min-width: 641px) {
  .app { max-width: 900px; }

  .images-stack { flex-direction: row; }
  .image-card { flex: 1 1 0; }

  .question { font-size: 1.4rem; }
  .subtitle { font-size: 0.9rem; margin-bottom: 12px; }

  .card-label { top: 12px; left: 12px; padding: 6px 12px; font-size: 0.85rem; }
  .tap-hint { bottom: 12px; right: 12px; padding: 6px 12px; font-size: 0.8rem; }
  .badge { top: 12px; right: 12px; padding: 5px 10px; font-size: 0.8rem; }

  .next-round-btn { max-width: 320px; }
}
