/* ============================================================
   Higher or Lower: World Facts -- Board Game Style
   ============================================================ */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a2a36;
  font-family: system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

#game {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

/* ===== BACKGROUND ===== */
.play-bg, .select-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center 30%, #15556e 0%, #0a2a36 70%, #061a22 100%);
  z-index: 0;
}
.select-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,215,0,0.06) 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(255,215,0,0.04) 0%, transparent 50%);
  pointer-events: none;
}

/* ===== TYPOGRAPHY ===== */
.game-title {
  font-family: Georgia, Cambria, serif;
  font-size: clamp(36px, 7vw, 64px);
  color: #ffd700;
  text-shadow: 0 3px 0 #7a6500, 0 6px 12px rgba(0,0,0,0.5);
  letter-spacing: 1px;
  line-height: 1;
}
.game-subtitle {
  font-family: system-ui, sans-serif;
  font-size: clamp(14px, 2.5vw, 22px);
  color: #bcd9e6;
  text-transform: uppercase;
  letter-spacing: 6px;
  margin-top: 6px;
  font-weight: 400;
}

/* ===== CHIPS ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1.5px solid rgba(255,255,255,0.12);
  color: #e0edf2;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.chip-icon { font-size: 14px; color: #ffd700; }
.chip-icon.trophy { color: #ffd700; }
.chip strong { color: #fff; font-weight: 900; }

/* ===== CATEGORY SELECT ===== */
.select-header { text-align: center; z-index: 1; margin-bottom: 10px; }
.streak-bar { display: flex; gap: 10px; z-index: 1; margin-bottom: 22px; }

.category-deck {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  z-index: 1;
  max-width: 460px;
  width: 90%;
  padding: 0 4px;
}

.category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px 16px;
  border-radius: 18px;
  border: 2.5px solid rgba(255,215,0,0.3);
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.03) 100%);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  opacity: 0;
  animation: tileFadeIn 0.4s ease forwards;
}
.category-tile:nth-child(1) { animation-delay: 0.05s; }
.category-tile:nth-child(2) { animation-delay: 0.12s; }
.category-tile:nth-child(3) { animation-delay: 0.19s; }
.category-tile:nth-child(4) { animation-delay: 0.26s; }

@keyframes tileFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.category-tile:hover {
  border-color: #ffd700;
  box-shadow: 0 0 24px rgba(255,215,0,0.15);
  transform: translateY(-3px);
}
.category-tile:active {
  transform: translateY(0);
  transition-duration: 0.05s;
}
.category-tile canvas {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,215,0,0.05);
  border: 2px solid rgba(255,215,0,0.15);
}
.category-tile .cat-name {
  font-size: 14px;
  font-weight: 700;
  color: #e0edf2;
  text-align: center;
  line-height: 1.2;
}
.category-tile .cat-count {
  font-size: 11px;
  color: #8ab4c4;
  font-weight: 400;
}
.select-hint {
  margin-top: 18px;
  font-size: 13px;
  color: #6f9aab;
  z-index: 1;
  letter-spacing: 1px;
}

/* ===== PLAY HUD ===== */
#play-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 14px;
  z-index: 10;
  pointer-events: none;
}
#play-hud .chip { pointer-events: auto; }
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; }
.category-chip {
  background: rgba(255,215,0,0.15);
  border-color: rgba(255,215,0,0.25);
  color: #ffd700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.progress-chip { font-size: 12px; font-weight: 600; color: #8ab4c4; }

/* ===== CARD AREA ===== */
#card-area {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 3vw, 36px);
  z-index: 1;
  width: 100%;
  max-width: 700px;
  padding: 0 8px;
  margin-top: -10px;
}

.card-slot {
  position: relative;
  width: clamp(120px, 32vw, 280px);
  height: clamp(172px, 46vw, 400px);
  border-radius: clamp(10px, 1.8vw, 18px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 2px 0 rgba(255,215,0,0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card-slot canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.card-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  text-align: center;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.card-value.show { opacity: 1; }

.value-number {
  display: block;
  font-size: clamp(28px, 6vw, 56px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  line-height: 1.1;
}
.value-unit {
  display: block;
  font-size: clamp(11px, 1.8vw, 18px);
  color: #bcd9e6;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
  margin-top: 2px;
  text-transform: lowercase;
}

.card-label {
  position: absolute;
  bottom: clamp(8px, 1.5vw, 16px);
  left: 0;
  right: 0;
  text-align: center;
  z-index: 2;
  font-size: clamp(10px, 1.6vw, 15px);
  font-weight: 700;
  color: #bcd9e6;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  padding: 0 8px;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.card-label.show { opacity: 1; }

.card-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.vs-text {
  font-family: Georgia, serif;
  font-size: clamp(14px, 2.5vw, 24px);
  color: rgba(255,215,0,0.5);
  font-style: italic;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* Card Flip Animation */
.card-slot.flipping canvas {
  animation: cardFlip 0.45s ease;
}
@keyframes cardFlip {
  0%   { transform: rotateY(0deg); }
  45%  { transform: rotateY(90deg); }
  55%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

/* Card States */
.card-slot.correct canvas {
  box-shadow: 0 0 30px rgba(34,197,94,0.5), 0 8px 32px rgba(0,0,0,0.5);
  outline: 3px solid rgba(34,197,94,0.6);
  outline-offset: -3px;
}
.card-slot.wrong canvas {
  box-shadow: 0 0 30px rgba(239,68,68,0.5), 0 8px 32px rgba(0,0,0,0.5);
  outline: 3px solid rgba(239,68,68,0.6);
  outline-offset: -3px;
}

/* ===== BUTTON AREA ===== */
#button-area {
  display: flex;
  gap: clamp(10px, 3vw, 24px);
  z-index: 5;
  margin-top: clamp(10px, 2.5vh, 28px);
  width: 100%;
  max-width: 480px;
  padding: 0 12px;
  justify-content: center;
}

.game-button {
  position: relative;
  border: none;
  border-radius: 16px;
  padding: 16px 32px;
  font-family: system-ui, sans-serif;
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  flex: 1;
  touch-action: manipulation;
}

.btn-higher {
  background: linear-gradient(180deg, #34d399 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 6px 0 #047857, 0 8px 20px rgba(0,0,0,0.3);
}
.btn-higher:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #047857, 0 12px 28px rgba(0,0,0,0.35); }
.btn-higher:active { transform: translateY(4px); box-shadow: 0 2px 0 #047857, 0 4px 10px rgba(0,0,0,0.3); }

.btn-lower {
  background: linear-gradient(180deg, #f87171 0%, #dc2626 100%);
  color: #fff;
  box-shadow: 0 6px 0 #b91c1c, 0 8px 20px rgba(0,0,0,0.3);
}
.btn-lower:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #b91c1c, 0 12px 28px rgba(0,0,0,0.35); }
.btn-lower:active { transform: translateY(4px); box-shadow: 0 2px 0 #b91c1c, 0 4px 10px rgba(0,0,0,0.3); }

.btn-higher:disabled, .btn-lower:disabled {
  opacity: 0.35;
  transform: translateY(3px);
  box-shadow: 0 3px 0 currentColor;
  pointer-events: none;
}

.btn-arrow { font-size: 0.7em; }

/* ===== STATUS MESSAGE ===== */
#play-status {
  position: absolute;
  bottom: clamp(60px, 10vh, 100px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  transition: opacity 0.3s;
  text-align: center;
  max-width: 85%;
}
#play-status.hidden { opacity: 0; }
.status-msg.correct {
  background: rgba(34,197,94,0.2);
  border: 1px solid rgba(34,197,94,0.4);
  color: #86efac;
}
.status-msg.wrong {
  background: rgba(239,68,68,0.2);
  border: 1px solid rgba(239,68,68,0.4);
  color: #fca5a5;
}

/* ===== OVERLAYS ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6,26,34,0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  transition: opacity 0.3s;
}
.overlay.hidden { display: none; }

.overlay-panel {
  background: linear-gradient(180deg, #1a4050 0%, #0e2e3c 100%);
  border: 2px solid rgba(255,215,0,0.3);
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 380px;
  width: 88%;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.result-icon { font-size: 48px; margin-bottom: 8px; }
.result-icon.wrong-icon { color: #ef4444; }

.result-title {
  font-family: Georgia, Cambria, serif;
  font-size: 28px;
  color: #ffd700;
  margin-bottom: 6px;
}
.result-title.wrong-title { color: #f87171; }

.result-explainer {
  font-size: 14px;
  color: #bcd9e6;
  line-height: 1.5;
  margin-bottom: 16px;
  padding: 0 4px;
}

.result-stats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
}
.stat-label {
  font-size: 13px;
  color: #8ab4c4;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.stat-value {
  font-size: 28px;
  font-weight: 900;
  color: #ffd700;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn-retry {
  background: linear-gradient(180deg, #ffd700 0%, #d4a800 100%);
  color: #1a1a2e;
  box-shadow: 0 5px 0 #a88200, 0 8px 20px rgba(0,0,0,0.3);
  padding: 14px 22px;
  font-size: 15px;
  flex: 1;
}
.btn-retry:active { transform: translateY(3px); box-shadow: 0 2px 0 #a88200; }

.btn-switch {
  background: rgba(255,255,255,0.1);
  color: #bcd9e6;
  border: 1.5px solid rgba(255,255,255,0.15);
  box-shadow: 0 5px 0 rgba(0,0,0,0.2), 0 8px 20px rgba(0,0,0,0.2);
  padding: 14px 18px;
  font-size: 14px;
  flex: 1;
}
.btn-switch:active { transform: translateY(3px); }

.complete-icon { font-size: 52px; margin-bottom: 6px; }
.complete-title {
  font-family: Georgia, Cambria, serif;
  font-size: 28px;
  color: #ffd700;
  margin-bottom: 4px;
}
.complete-sub { font-size: 14px; color: #bcd9e6; margin-bottom: 16px; }

/* ===== PARTICLES ===== */
.particle-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  overflow: hidden;
}
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFly 0.6s ease-out forwards;
}
@keyframes particleFly {
  0%   { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 520px) {
  .category-deck { gap: 10px; width: 94%; }
  .category-tile { padding: 12px 8px 10px; gap: 6px; }
  .category-tile canvas { width: 48px; height: 48px; }
  .category-tile .cat-name { font-size: 12px; }

  #play-hud { padding: 6px 8px; flex-wrap: wrap; gap: 4px; }
  .hud-right { flex-wrap: wrap; justify-content: flex-end; }
  .chip { padding: 4px 10px; font-size: 11px; gap: 4px; }

  .game-button { padding: 14px 16px; font-size: 15px; letter-spacing: 1px; }
  .overlay-panel { padding: 24px 18px; }
  .result-title, .complete-title { font-size: 22px; }
  .select-hint { font-size: 11px; }
}

@media (max-height: 500px) {
  .card-slot { width: clamp(100px, 22vw, 180px); height: clamp(143px, 32vw, 260px); }
  #button-area { margin-top: 6px; }
  .game-button { padding: 10px 16px; font-size: 14px; }
}
