/* ═══ Common Game Styles (shared by all 7 training games) ═══ */
:root {
  --primary: oklch(0.52 0.14 145);
  --primary-light: oklch(0.92 0.06 145);
  --accent: oklch(0.62 0.20 30);
  --gold: oklch(0.75 0.15 85);
  --success: oklch(0.62 0.18 145);
  --danger: oklch(0.58 0.22 25);
  --surface: #fff;
  --bg: oklch(0.97 0.005 90);
  --text-1: oklch(0.25 0.02 260);
  --text-2: oklch(0.45 0.02 260);
  --text-3: oklch(0.65 0.01 260);
  --border: oklch(0.90 0.01 90);
  --radius: 16px;
  --combo-warmth: 0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Noto Sans SC', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100dvh; height: 100dvh;
  overflow: hidden;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  max-width: 430px; margin: 0 auto;
}

/* Combo overlay */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 100%,
    rgba(255, 176, 64, calc(var(--combo-warmth) * 0.16)) 0%,
    transparent 70%);
  mix-blend-mode: screen;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
  z-index: 9999;
}
body[data-combo-tier]::before { opacity: 1; }
body[data-combo-tier="3"] { --combo-warmth: 0.28; }
body[data-combo-tier="5"] { --combo-warmth: 0.46; }
body[data-combo-tier="7"] { --combo-warmth: 0.58; }

/* Flash */
body.flash-correct { animation: flashGreen 220ms ease; }
body.flash-wrong { animation: flashRed 260ms ease; }
@keyframes flashGreen {
  0%,100% { box-shadow: inset 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 60px oklch(0.72 0.18 145 / 0.3); }
}
@keyframes flashRed {
  0%,100% { box-shadow: inset 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 60px oklch(0.58 0.22 25 / 0.3); }
}

/* ═══ Topbar ═══ */
.game-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 100;
}
.game-back {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer;
  font-size: 18px; background: var(--bg);
  transition: background 0.15s;
}
.game-back:active { background: var(--border); }
.game-title { flex: 1; font-weight: 700; font-size: 15px; }
.game-star-display { font-size: 14px; }
.game-star-display .dim { opacity: 0.3; }

/* ═══ Timer ═══ */
.timer-section { padding: 10px 16px 4px; flex-shrink: 0; }
.timer-bar-wrap {
  height: 8px; border-radius: 4px;
  background: var(--border); position: relative; overflow: hidden;
}
.timer-bar-fill {
  height: 100%; border-radius: 4px;
  background: var(--success);
  transition: width 50ms linear, background 0.3s;
  width: 100%;
}
.timer-bar-fill.warning { background: oklch(0.72 0.16 85); }
.timer-bar-fill.danger { background: var(--danger); animation: pulse 0.5s infinite; }
@keyframes pulse { 50% { opacity: 0.7; } }
.timer-bar-text {
  position: absolute; right: 8px; top: -1px;
  font-size: 10px; font-weight: 700; color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
}

/* ═══ Info Row ═══ */
.info-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; font-size: 13px; color: var(--text-2); flex-shrink: 0;
}
.info-row-left { font-size: 13px; color: var(--text-2); }
.info-row-left b { font-family: 'JetBrains Mono', monospace; color: var(--text-1); }
.combo-display {
  font-weight: 800; font-size: 14px; color: var(--accent);
  transition: transform 0.15s;
}
.combo-display.active { transform: scale(1.15); }
.score-display {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700; font-size: 16px; color: var(--primary);
  transition: transform 0.2s;
}
.score-display.bump { animation: scoreBump 300ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes scoreBump { 0% { transform: scale(1); } 55% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* ═══ Progress Dots ═══ */
.progress-dots {
  display: flex; justify-content: center; gap: 6px;
  padding: 6px 16px 10px; flex-shrink: 0;
}
.progress-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); transition: all 0.2s;
}
.progress-dot.current { background: var(--primary); transform: scale(1.3); }
.progress-dot.correct { background: var(--success); }
.progress-dot.wrong { background: var(--danger); }

/* ═══ Table Area ═══ */
.table-area {
  flex: 1; padding: 8px 12px; min-height: 120px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 5px;
}
.hand-section, .river-section, .display-section {
  margin-bottom: 10px;
}
.hand-section { margin-top: auto; }
.hand-label, .river-label, .section-label {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  margin-bottom: 4px; padding-left: 4px;
}
.hand-tiles, .river-tiles, .display-tiles {
  display: flex; flex-wrap: wrap; gap: 3px;
  justify-content: center;
}

/* Tiles */
.tile-img {
  height: 44px; width: auto; border-radius: 4px;
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.1);
  transition: transform 0.1s, box-shadow 0.1s;
  user-select: none; -webkit-user-drag: none;
}
.tile-img.small { height: 36px; }
.tile-img.highlight {
  box-shadow: 0 0 0 2px var(--gold), 0 2px 8px oklch(0.75 0.15 85 / 0.4);
  transform: translateY(-2px);
}
.tile-img.clickable { cursor: pointer; }
.tile-img.clickable:hover { transform: translateY(-3px); box-shadow: 0 3px 8px oklch(0 0 0 / 0.15); }
.tile-img.clickable:active { transform: translateY(0); }
.tile-img.selected {
  box-shadow: 0 0 0 3px var(--primary), 0 2px 8px oklch(0.52 0.14 145 / 0.3);
  transform: translateY(-4px);
}
.tile-img.dimmed { opacity: 0.4; }

/* ═══ Question Area ═══ */
.question-area {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  text-align: center; flex-shrink: 0;
  border-top: 1px solid var(--border); background: var(--surface);
}
.question-text {
  font-size: 16px; font-weight: 700; margin-bottom: 6px;
  line-height: 1.4;
}
.question-hint {
  font-size: 12px; color: var(--text-3); margin-bottom: 12px;
  min-height: 16px;
}
.answer-btns {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  max-width: 360px; margin: 0 auto;
}
.answer-btn {
  padding: 14px 8px; border: 2px solid var(--border);
  border-radius: 14px; background: var(--surface);
  font-size: 18px; font-weight: 800; cursor: pointer;
  transition: all 0.12s; color: var(--text-1);
  font-family: 'JetBrains Mono', 'Noto Sans SC', monospace;
}
.answer-btn:active { transform: scale(0.96); }
.answer-btn.correct { border-color: var(--success); background: oklch(0.95 0.08 145); color: var(--success); }
.answer-btn.wrong { border-color: var(--danger); background: oklch(0.95 0.08 25); color: var(--danger); }
.answer-btn.disabled { pointer-events: none; opacity: 0.7; }
.answer-btn.label-btn { font-size: 14px; font-family: 'Noto Sans SC', sans-serif; }

/* ═══ Countdown ═══ */
.countdown-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: oklch(0.15 0.02 260 / 0.85);
  backdrop-filter: blur(6px);
}
.countdown-number {
  font-size: 72px; font-weight: 900; color: white;
  animation: countPop 0.8s ease infinite;
}
@keyframes countPop {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}
.countdown-label { font-size: 14px; color: oklch(1 0 0 / 0.7); margin-top: 12px; }

/* ═══ Feedback ═══ */
.feedback-overlay {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 28px; font-weight: 900; z-index: 150;
  padding: 8px 20px; border-radius: 12px;
  animation: feedPop 0.7s ease forwards;
  pointer-events: none;
}
.feedback-overlay.correct { color: var(--success); }
.feedback-overlay.wrong { color: var(--danger); }
@keyframes feedPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

/* Milestone */
.milestone-toast, .milestone-pop {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  background: oklch(0.2 0.02 260 / 0.9); color: white;
  padding: 8px 20px; border-radius: 20px; font-size: 13px; font-weight: 700;
  z-index: 150; animation: milePop 1.2s ease forwards;
  pointer-events: none;
}
@keyframes milePop {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  20% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ═══ Result ═══ */
.result-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: oklch(0.98 0.005 90 / 0.97);
  backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  overflow-y: auto;
}
.result-overlay.show { display: flex; }
.result-card {
  text-align: center; padding: 32px 24px;
  max-width: 380px; width: 100%;
}
.result-item {
  opacity: 0; animation: resultIn 0.4s ease forwards;
}
@keyframes resultIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.result-near-miss {
  margin: 0 auto 14px; padding: 9px 12px; border-radius: 12px;
  background: oklch(0.95 0.12 85 / 0.3); border: 1px solid oklch(0.82 0.12 85);
  color: oklch(0.55 0.12 85); font-size: 13px; font-weight: 700;
}
.result-emoji { font-size: 56px; margin-bottom: 8px; }
.result-title { font-size: 22px; font-weight: 900; margin-bottom: 4px; }
.result-subtitle { font-size: 14px; color: var(--text-2); margin-bottom: 16px; }
.result-score-total {
  font-family: 'JetBrains Mono', monospace;
  font-size: 42px; font-weight: 900; color: var(--primary);
}
.result-score-label { font-size: 12px; color: var(--text-3); margin-bottom: 12px; }
.result-stars { font-size: 24px; margin-bottom: 16px; }
.result-stats { display: flex; justify-content: center; gap: 24px; margin-bottom: 16px; }
.result-stat { text-align: center; }
.result-stat-value { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 16px; }
.result-stat-label { font-size: 11px; color: var(--text-3); }
.result-mlp { font-size: 16px; font-weight: 700; color: var(--gold); margin-bottom: 12px; }
.result-upgrade { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 12px; }
.result-btn {
  display: block; width: 100%; max-width: 260px; margin: 8px auto;
  padding: 14px; border-radius: 14px; font-size: 15px; font-weight: 700;
  cursor: pointer; border: none; transition: all 0.15s;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:active { transform: scale(0.97); }
.secondary-btn { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.secondary-btn:active { transform: scale(0.97); }

/* ═══ Leaderboard ═══ */
.lb-overlay {
  position: fixed; inset: 0;
  background: oklch(0.98 0.005 90 / 0.95);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; padding: 24px;
}
.lb-card {
  background: var(--surface); border-radius: 20px;
  padding: 28px 24px; text-align: center;
  width: 100%; max-width: 340px;
  box-shadow: 0 4px 24px oklch(0 0 0 / 0.08);
  animation: resultIn 0.4s ease;
}
.lb-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.lb-subtitle { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }
.lb-input {
  width: 100%; padding: 12px 16px; border-radius: 12px;
  background: var(--bg); border: 2px solid var(--border);
  color: var(--text-1); font-size: 16px; text-align: center; outline: none;
  transition: border-color 0.2s;
}
.lb-input:focus { border-color: var(--primary); }
.lb-input::placeholder { color: var(--text-3); }
.lb-submit {
  width: 100%; padding: 13px; border-radius: 12px; margin-top: 12px;
  background: var(--primary); color: white;
  font-size: 15px; font-weight: 800; cursor: pointer; border: none;
  transition: transform 0.15s;
}
.lb-submit:active { transform: scale(0.95); }
.lb-submit:disabled { opacity: 0.4; pointer-events: none; }
.lb-skip {
  margin-top: 10px; background: none; border: none;
  color: var(--text-3); font-size: 13px; cursor: pointer;
  text-decoration: underline;
}
.lb-rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 16px; border-radius: 20px;
  background: var(--gold); color: white;
  font-family: 'JetBrains Mono', monospace; font-size: 18px; font-weight: 800;
  margin: 8px 0 12px;
}
.lb-list { margin-top: 12px; text-align: left; max-height: 240px; overflow-y: auto; }
.lb-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; font-size: 13px;
}
.lb-row:nth-child(odd) { background: var(--bg); }
.lb-row.me { background: oklch(0.95 0.08 145); border: 1px solid oklch(0.82 0.12 145); }
.lb-row-rank {
  font-family: 'JetBrains Mono', monospace; font-weight: 700; width: 28px;
  color: var(--text-3); text-align: center;
}
.lb-row-rank.top1 { color: oklch(0.75 0.15 85); }
.lb-row-rank.top2 { color: oklch(0.65 0.02 260); }
.lb-row-rank.top3 { color: oklch(0.60 0.08 50); }
.lb-row-name { flex: 1; font-weight: 600; color: var(--text-1); }
.lb-row-score { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--primary); }
.lb-row-time { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-3); width: 48px; text-align: right; }

/* ═══ Discard Section (winning-hand star1) ═══ */
.discard-section {
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 6px;
}
.discard-label {
  font-size: 12px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 1px;
}
.discard-tile {
  padding: 8px 16px; border-radius: 12px;
  background: oklch(0.96 0.06 25 / 0.4); border: 2px solid oklch(0.8 0.12 25);
}

/* ═══ Wait Select Grid (winning-hand star3) ═══ */
.wait-select-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 6px; margin-bottom: 12px; padding: 0 4px;
}
.wait-tile-btn {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 2px; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface); cursor: pointer; transition: all 0.15s;
  gap: 2px;
}
.wait-tile-btn .tile-img { height: 36px; }
.wait-tile-num { font-size: 10px; color: var(--text-3); font-weight: 600; }
.wait-tile-btn.selected {
  border-color: var(--primary); background: oklch(0.95 0.08 145);
  transform: scale(1.05);
}
.wait-tile-btn.correct {
  border-color: var(--correct); background: oklch(0.95 0.12 145);
}
.wait-tile-btn.wrong {
  border-color: var(--wrong); background: oklch(0.95 0.12 25);
}
.wait-tile-btn.disabled { pointer-events: none; opacity: 0.7; }
.wait-confirm-btn {
  max-width: 200px; margin: 0 auto; display: block;
}

/* ═══ Tile Option Buttons (winning-hand star2) ═══ */
.tile-option-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; min-height: 52px;
}
.tile-option-label {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  white-space: nowrap;
}
.tile-option-tiles {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
}
.tile-option-tiles .tile-img { height: 32px; }

/* ═══ Responsive ═══ */
@media (max-width: 380px) {
  .tile-img { height: 38px; }
  .tile-img.small { height: 30px; }
  .answer-btn { padding: 12px 6px; font-size: 16px; }
  .wait-tile-btn .tile-img { height: 30px; }
  .wait-select-grid { gap: 4px; }
}

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