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

/* ── Base ──────────────────────────────────────────────────────────────── */
body {
  background: #f0f4ff;
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 16px;
}

.container {
  width: 100%;
  max-width: 480px;
  position: relative;
}

/* ── Screens ───────────────────────────────────────────────────────────── */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.hidden {
  display: none !important;
}

/* ── Start Screen ──────────────────────────────────────────────────────── */
.start-logo {
  font-size: 80px;
  margin-top: 24px;
  animation: float 3s ease-in-out infinite;
}

.game-title {
  font-size: 40px;
  font-weight: 900;
  color: #3730a3;
  letter-spacing: -1px;
}

.game-subtitle {
  font-size: 16px;
  color: #6366f1;
  text-align: center;
}

.best-display {
  font-size: 14px;
  color: #6b7280;
  margin-top: 8px;
}

/* ── Section Title ─────────────────────────────────────────────────────── */
.section-title {
  font-size: 22px;
  font-weight: 700;
  color: #3730a3;
  margin-top: 16px;
}

/* ── Difficulty Cards ──────────────────────────────────────────────────── */
.difficulty-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.diff-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: #fff;
  border: 2px solid #e0e7ff;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  text-align: left;
}

.diff-card:hover {
  transform: translateY(-2px);
  border-color: #7c3aed;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.15);
}

.diff-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.diff-name {
  font-size: 18px;
  font-weight: 700;
  color: #3730a3;
  flex: 1;
}

.diff-desc {
  font-size: 13px;
  color: #6b7280;
}

/* ── Category Cards ────────────────────────────────────────────────────── */
.category-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.cat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px;
  background: #fff;
  border: 2px solid #e0e7ff;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.cat-card:hover {
  transform: translateY(-2px);
  border-color: #7c3aed;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.15);
}

.cat-card--random {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px;
}

.cat-icon {
  font-size: 32px;
}

.cat-name {
  font-size: 16px;
  font-weight: 700;
  color: #3730a3;
}

/* ── Game Header ───────────────────────────────────────────────────────── */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 4px;
}

.game-title-small {
  font-size: 18px;
  font-weight: 800;
  color: #3730a3;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #6366f1;
  border-radius: 8px;
  padding: 6px 14px;
  min-width: 60px;
}

.score-label {
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.5px;
}

.score-value {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  line-height: 1.2;
}

/* ── Game Meta Row ─────────────────────────────────────────────────────── */
.game-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  padding: 4px 0;
}

#hud-round { color: #6366f1; }
#hud-streak { color: #f97316; }

/* ── Phase Banner ──────────────────────────────────────────────────────── */
.phase-banner {
  width: 100%;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  color: #3730a3;
  min-height: 26px;
  padding: 2px 0;
}

/* ── Grid Wrapper ──────────────────────────────────────────────────────── */
.grid-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

/* ── Game Grid ─────────────────────────────────────────────────────────── */
.game-grid {
  display: grid;
  gap: 8px;
  background: #dde3f8;
  border-radius: 14px;
  padding: 10px;
  width: 100%;
  height: 100%;
}

/* ── Grid Cells ────────────────────────────────────────────────────────── */
.grid-cell {
  background: rgba(255, 255, 255, 0.55);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 6vw, 42px);
  cursor: default;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  user-select: none;
  min-width: 0;
  min-height: 0;
  border: 2px solid transparent;
}

.grid-cell.cell--lit {
  background: #ffd700;
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.7);
  animation: glow-pulse 0.7s ease-in-out infinite;
  transform: scale(1.04);
}

.grid-cell.cell--selectable {
  cursor: pointer;
}

.grid-cell.cell--selectable:hover {
  background: rgba(237, 233, 254, 0.8);
  transform: scale(1.05);
}

.grid-cell.cell--selected {
  background: #ede9fe;
  border-color: #7c3aed;
  border-width: 3px;
}

.grid-cell.cell--correct {
  background: #dcfce7;
  border-color: #16a34a;
  border-width: 3px;
  animation: correct-pop 0.4s ease;
}

.grid-cell.cell--missed {
  background: #fed7aa;
  border-color: #f97316;
  border-width: 3px;
  animation: missed-pulse 0.5s ease 2;
}

.grid-cell.cell--wrong {
  background: #fee2e2;
  border-color: #dc2626;
  border-width: 3px;
  animation: wrong-shake 0.35s ease;
}

/* ── Countdown Overlay ─────────────────────────────────────────────────── */
.overlay-inner {
  position: absolute;
  inset: 0;
  background: rgba(55, 48, 163, 0.55);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.countdown-number {
  font-size: 100px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0,0,0,0.3);
  animation: countdown-pop 0.6s ease;
}

/* ── Game Controls ─────────────────────────────────────────────────────── */
.game-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.game-controls button {
  flex: 1;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
button {
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
  min-height: 48px;
}

button:hover {
  background: #6d28d9;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.btn-secondary {
  background: #a5b4fc;
  color: #3730a3;
}

.btn-secondary:hover {
  background: #818cf8;
  color: #fff;
}

/* ── Results Overlay ───────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 24px;
}

.overlay-box {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.result-emoji {
  font-size: 56px;
}

.overlay-box h2 {
  font-size: 26px;
  font-weight: 900;
  color: #3730a3;
}

.overlay-box p {
  font-size: 15px;
  color: #6b7280;
  text-align: center;
}

.result-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

#result-correct { color: #16a34a; }
#result-missed  { color: #f97316; }
#result-wrong   { color: #dc2626; }

.overlay-box button {
  margin-top: 4px;
}

/* ── Game Over Screen ──────────────────────────────────────────────────── */
.gameover-icon {
  font-size: 72px;
  margin-top: 24px;
}

#gameover-score {
  font-size: 18px;
  font-weight: 700;
  color: #3730a3;
}

#gameover-rounds {
  font-size: 15px;
  color: #6b7280;
}

/* ── Keyframe Animations ───────────────────────────────────────────────── */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.6); }
  50%       { box-shadow: 0 0 24px rgba(255, 215, 0, 1); }
}

@keyframes correct-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
}

@keyframes missed-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes countdown-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 420px) {
  body { padding: 12px 10px; }
  .game-title { font-size: 30px; }
  .start-logo { font-size: 60px; }
  .game-title-small { font-size: 15px; }
  .score-value { font-size: 16px; }
  .score-box { padding: 5px 10px; min-width: 50px; }
  .game-grid { gap: 5px; padding: 7px; }
  .grid-cell { border-radius: 7px; }
  .countdown-number { font-size: 72px; }
}
