/* ==========================================================================
   Memory Match — style.css
   Premium dark theme with 3D main menu, centered board gameplay.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;

  --ink: #e8f1ff;
  --muted: #93aacd;
  --surface: #0e2440;

  --primary: #38bdf8;
  --primary-dark: #0284c7;
  --blue: #2563eb;

  --success: #34d399;
  --danger: #fb7185;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-sm: 0 2px 8px rgba(2, 8, 20, 0.45);
  --shadow-md: 0 8px 24px rgba(2, 8, 20, 0.55);
  --shadow-lg: 0 18px 44px rgba(1, 5, 14, 0.65);

  --gap-board: clamp(5px, 1vmin, 12px);
  --card-max: clamp(72px, 13vmin, 116px);

  color-scheme: dark;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: #040c1a;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}

/* ---------- Hide scrollbars everywhere (still scrollable) ---------- */
html { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar { width: 0; height: 0; display: none; }
body { scrollbar-width: none; -ms-overflow-style: none; }
body::-webkit-scrollbar { width: 0; height: 0; display: none; }
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* ---------- Screen system ---------- */
.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.screen[hidden] { display: none; }

/* ==========================================================================
   MAIN MENU
   ========================================================================== */
.menu-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 120% 80% at 50% 110%, rgba(37, 99, 235, 0.35), transparent 65%),
    radial-gradient(ellipse 60% 50% at 80% 10%, rgba(56, 189, 248, 0.18), transparent 55%),
    radial-gradient(ellipse 50% 45% at 15% 20%, rgba(99, 50, 200, 0.15), transparent 55%),
    radial-gradient(circle at 50% 50%, #0a1628 0%, #060e1c 100%);
  background-attachment: fixed;
}

/* Animated floating particles for depth */
.menu-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: particleFloat linear infinite;
}

.p1 { width: 6px; height: 6px; left: 10%; background: rgba(56,189,248,0.5); animation-duration: 18s; animation-delay: 0s; }
.p2 { width: 4px; height: 4px; left: 25%; background: rgba(99,102,241,0.4); animation-duration: 22s; animation-delay: 2s; }
.p3 { width: 8px; height: 8px; left: 40%; background: rgba(56,189,248,0.3); animation-duration: 20s; animation-delay: 4s; }
.p4 { width: 5px; height: 5px; left: 55%; background: rgba(139,92,246,0.4); animation-duration: 24s; animation-delay: 1s; }
.p5 { width: 7px; height: 7px; left: 70%; background: rgba(56,189,248,0.35); animation-duration: 19s; animation-delay: 3s; }
.p6 { width: 4px; height: 4px; left: 85%; background: rgba(236,72,153,0.35); animation-duration: 21s; animation-delay: 5s; }
.p7 { width: 6px; height: 6px; left: 33%; background: rgba(52,211,153,0.35); animation-duration: 23s; animation-delay: 6s; }
.p8 { width: 5px; height: 5px; left: 66%; background: rgba(251,191,36,0.3); animation-duration: 17s; animation-delay: 2s; }

@keyframes particleFloat {
  0%   { bottom: -10%; opacity: 0; transform: translateX(0) scale(0.5); }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { bottom: 110%; opacity: 0; transform: translateX(60px) scale(1.2); }
}

/* 3D perspective container */
.menu-container {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(28px, 5vh, 52px);
  perspective: 1200px;
  animation: menuFadeIn 0.8s ease both;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(40px) rotateX(8deg); }
  to { opacity: 1; transform: translateY(0) rotateX(0); }
}

/* Logo area */
.menu-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-logo-icon {
  font-size: clamp(4rem, 12vw, 7rem);
  line-height: 1;
  filter: drop-shadow(0 8px 24px rgba(56, 189, 248, 0.45));
  animation: logoPulse 3s ease-in-out infinite alternate;
}

@keyframes logoPulse {
  from { transform: scale(1) translateY(0); filter: drop-shadow(0 8px 24px rgba(56,189,248,0.45)); }
  to   { transform: scale(1.05) translateY(-6px); filter: drop-shadow(0 14px 36px rgba(56,189,248,0.55)); }
}

.menu-title {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 3.8rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-align: center;
  color: #f2f8ff;
  text-shadow:
    0 0 30px rgba(56, 189, 248, 0.4),
    0 4px 0 rgba(2, 20, 44, 0.9),
    0 8px 0 rgba(2, 14, 30, 0.7),
    0 16px 40px rgba(0, 0, 0, 0.6);
}

.menu-subtitle {
  margin: 0;
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7cb8e8;
}

/* 3D button stack */
.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(360px, 88vw);
}

.menu-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px 28px;
  border: none;
  border-radius: 16px;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease, filter 0.2s ease;
  transform-style: preserve-3d;
  transform: translateZ(0);
}

.menu-btn:active { transform: translateZ(-8px) scale(0.97); }

.menu-btn-icon {
  font-size: 1.3rem;
  width: 32px;
  text-align: center;
}

/* Primary button (Play) */
.menu-btn-primary {
  color: #ffffff;
  background: linear-gradient(145deg, #0ea5e9, #2563eb, #1d4ed8);
  box-shadow:
    0 4px 0 #1e40af,
    0 6px 0 #1e3a8a,
    0 12px 28px rgba(14, 165, 233, 0.45),
    inset 0 1px 0 rgba(255,255,255,0.15);
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.menu-btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-3px) translateZ(4px);
  box-shadow:
    0 4px 0 #1e40af,
    0 6px 0 #1e3a8a,
    0 18px 36px rgba(14, 165, 233, 0.55),
    inset 0 1px 0 rgba(255,255,255,0.15);
}

.menu-btn-primary:active {
  transform: translateY(2px) translateZ(-4px);
  box-shadow:
    0 1px 0 #1e40af,
    0 2px 8px rgba(14, 165, 233, 0.3),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Secondary buttons */
.menu-btn-secondary {
  color: #d6e8ff;
  background: linear-gradient(160deg, rgba(30, 64, 100, 0.8), rgba(14, 36, 64, 0.9));
  border: 1px solid rgba(96, 165, 250, 0.2);
  box-shadow:
    0 3px 0 rgba(10, 25, 50, 0.8),
    0 6px 16px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(148, 197, 255, 0.08);
}

.menu-btn-secondary:hover {
  background: linear-gradient(160deg, rgba(40, 80, 120, 0.85), rgba(18, 44, 78, 0.95));
  border-color: rgba(96, 165, 250, 0.35);
  transform: translateY(-2px) translateZ(3px);
  box-shadow:
    0 3px 0 rgba(10, 25, 50, 0.8),
    0 12px 24px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(148, 197, 255, 0.1);
}

.menu-btn-secondary:active {
  transform: translateY(1px) translateZ(-2px);
}

/* Tertiary (full screen) */
.menu-btn-tertiary {
  color: var(--muted);
  background: rgba(148, 197, 255, 0.06);
  border: 1px solid rgba(148, 197, 255, 0.12);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  font-size: 0.95rem;
  padding: 12px 24px;
}

.menu-btn-tertiary:hover {
  background: rgba(148, 197, 255, 0.12);
  color: #bae6fd;
  transform: translateY(-1px);
}

/* ==========================================================================
   LEVEL SELECT SCREEN
   ========================================================================== */
.level-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 120% 80% at 50% 110%, rgba(37, 99, 235, 0.28), transparent 65%),
    radial-gradient(circle at 50% 50%, #0a1628, #060e1c);
}

.level-screen::before {
  content: '';
  position: absolute;
  inset: -25%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(36% 30% at 30% 25%, rgba(56, 189, 248, 0.2), transparent 62%),
    radial-gradient(32% 28% at 72% 20%, rgba(139, 92, 246, 0.16), transparent 62%),
    radial-gradient(28% 30% at 55% 90%, rgba(52, 211, 153, 0.12), transparent 62%);
  filter: blur(46px);
  animation: auroraDrift 22s ease-in-out infinite alternate;
}

.level-screen-inner {
  position: relative;
  z-index: 1;
  width: min(600px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: menuFadeIn 0.5s ease both;
}

.level-screen-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.level-screen-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 900;
  color: #f2f8ff;
  flex: 1;
}

.level-screen-sub {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding: 4px;
}

.level-cell {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid transparent;
  background: rgba(20, 48, 80, 0.6);
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.level-cell:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.15);
  color: #bae6fd;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}

.level-cell.done {
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
}

.level-cell.current {
  background: linear-gradient(135deg, var(--primary), var(--blue));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 18px rgba(56, 189, 248, 0.5);
}

.level-cell.locked {
  opacity: 0.35;
  cursor: not-allowed;
  font-size: 0.8rem;
}

.level-cell.locked::after {
  content: '🔒';
  font-size: 0.75rem;
}

/* ==========================================================================
   GAMEPLAY SCREEN
   ========================================================================== */
.game-screen {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 560px at 88% -12%, rgba(56, 189, 248, 0.14), transparent 60%),
    radial-gradient(820px 520px at -12% 112%, rgba(37, 99, 235, 0.18), transparent 58%),
    linear-gradient(158deg, #050f1f 0%, #081a33 42%, #0a2342 74%, #0d2c52 100%);
}

/* Slow-drifting aurora glow */
.game-screen::before {
  content: '';
  position: absolute;
  inset: -25%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(38% 32% at 22% 28%, rgba(56, 189, 248, 0.28), transparent 62%),
    radial-gradient(34% 28% at 78% 18%, rgba(139, 92, 246, 0.24), transparent 62%),
    radial-gradient(30% 34% at 64% 88%, rgba(52, 211, 153, 0.16), transparent 62%),
    radial-gradient(26% 26% at 38% 72%, rgba(251, 113, 133, 0.14), transparent 62%);
  filter: blur(42px);
  animation: auroraDrift 20s ease-in-out infinite alternate;
}

/* Twinkling star field + vignette */
.game-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255,255,255,0.55), transparent 60%),
    radial-gradient(1px 1px at 28% 65%, rgba(255,255,255,0.4), transparent 60%),
    radial-gradient(2px 2px at 76% 32%, rgba(255,255,255,0.5), transparent 60%),
    radial-gradient(1px 1px at 88% 72%, rgba(255,255,255,0.4), transparent 60%),
    radial-gradient(1.5px 1.5px at 46% 22%, rgba(125,211,252,0.6), transparent 60%),
    radial-gradient(1px 1px at 62% 82%, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(1.5px 1.5px at 8% 84%, rgba(125,211,252,0.5), transparent 60%),
    radial-gradient(1px 1px at 92% 12%, rgba(255,255,255,0.5), transparent 60%),
    radial-gradient(1.5px 1.5px at 34% 44%, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(1px 1px at 56% 8%, rgba(255,255,255,0.45), transparent 60%),
    radial-gradient(1.5px 1.5px at 68% 54%, rgba(255,255,255,0.4), transparent 60%),
    radial-gradient(1px 1px at 22% 92%, rgba(255,255,255,0.45), transparent 60%),
    radial-gradient(ellipse 100% 70% at 50% 108%, rgba(1, 6, 16, 0.5), transparent 65%);
  opacity: 0.8;
  animation: twinkle 4s ease-in-out infinite alternate;
}

/* Floating particles on gameplay too */
.game-particles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

/* Keep real content above the backdrop layers */
.topbar,
.board-area {
  position: relative;
  z-index: 2;
}

@keyframes auroraDrift {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate(3%, -4%) rotate(90deg) scale(1.12); }
  100% { transform: translate(-4%, 3%) rotate(180deg) scale(1.06); }
}

@keyframes twinkle {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}

/* ---------- Top Bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px clamp(10px, 2vw, 20px);
  background: rgba(8, 20, 40, 0.92);
  border-bottom: 1px solid rgba(96, 165, 250, 0.15);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
  z-index: 10;
  gap: 8px;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.5vw, 16px);
}

.topbar-center { flex: 0 0 auto; }
.topbar-right { margin-left: auto; }

.topbar-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 10px;
  background: rgba(148, 197, 255, 0.06);
  border-radius: 8px;
  min-width: 56px;
}

.topbar-label {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-value {
  font-size: clamp(0.85rem, 2.2vw, 1.05rem);
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  color: #f2f8ff;
}

.topbar-best {
  font-size: 0.68rem;
  color: #7dd3fc;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Low-time warning */
.stat-time.warning .topbar-value {
  color: var(--danger);
  animation: pulse-warn 0.85s ease-in-out infinite alternate;
}

/* Icon button (pause, back) */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(148, 187, 255, 0.2);
  background: rgba(148, 197, 255, 0.08);
  color: #bae6fd;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(148, 197, 255, 0.18);
  transform: scale(1.08);
}

/* ---------- Board ---------- */
.board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vw, 20px);
  min-height: 0;
  overflow: hidden;
}

.board {
  --cols: 4;
  --rows: 4;

  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap-board);
  align-content: center;
  justify-content: center;

  width: min(
    100%,
    calc(var(--cols) * var(--card-max) + (var(--cols) - 1) * var(--gap-board))
  );
  max-width: 700px;
}

.board.locked { pointer-events: none; }

/* ---------- Cards ---------- */
.card {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.2s ease;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.55, 1);
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(8px, 1.6vmin, 14px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  line-height: 1;
}

.card-front {
  color: #bcd9ff;
  font-weight: 900;
  font-size: clamp(1.1rem, calc(30vmin / var(--cols)), 3.1rem);
  text-shadow: 0 2px 8px rgba(1, 8, 20, 0.8);
  background:
    radial-gradient(circle at 30% 22%, rgba(125, 211, 252, 0.22), transparent 48%),
    repeating-linear-gradient(45deg, rgba(125, 180, 255, 0.06) 0 9px, transparent 9px 18px),
    linear-gradient(150deg, #1c4070 0%, #14305a 55%, #0e2344 100%);
  border: 1px solid rgba(125, 175, 255, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(190, 220, 255, 0.18),
    var(--shadow-sm);
}

.card-back {
  transform: rotateY(180deg);
  font-size: clamp(1rem, calc(30vmin / var(--cols)), 2.9rem);
  background: #eef5ff;
  border: 2px solid rgba(125, 175, 255, 0.55);
  box-shadow: var(--shadow-sm);
}

/* Hover lift */
@media (hover: hover) and (pointer: fine) {
  .card:not(.flipped):not(.matched):hover {
    transform: translateY(-4px);
  }
  .card:not(.flipped):not(.matched):hover .card-face {
    box-shadow: inset 0 1px 0 rgba(190, 220, 255, 0.18), var(--shadow-lg);
  }
}

.card.matched { cursor: default; }
.card.matched .card-back {
  border-color: rgba(52, 211, 153, 0.85);
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.35), 0 0 14px rgba(52, 211, 153, 0.35);
  animation: match-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card.wrong { animation: shake 0.38s ease; }
.card.wrong .card-front {
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 160, 160, 0.25), transparent 48%),
    linear-gradient(150deg, #6e1c33 0%, #54122a 60%, #3d0e20 100%);
  border-color: rgba(251, 113, 133, 0.6);
}

/* ==========================================================================
   MODALS (shared)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 8, 20, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.22s ease both;
}

.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(170deg, #10294a, #0b1f39);
  border: 1px solid rgba(96, 165, 250, 0.24);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 5vw, 30px);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(56, 189, 248, 0.08);
  animation: pop-in 0.3s cubic-bezier(0.34, 1.45, 0.64, 1) both;
}

.modal h2 {
  margin: 0 0 0.8rem;
  font-size: clamp(1.3rem, 4.5vw, 1.55rem);
  font-weight: 900;
  color: #7dd3fc;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.16);
  color: #bae6fd;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.modal-close:hover {
  background: rgba(56, 189, 248, 0.3);
  transform: rotate(90deg);
}

/* Pause modal */
.modal-pause {
  text-align: center;
}

.pause-icon {
  font-size: 3rem;
  margin-bottom: 8px;
  animation: bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.pause-actions {
  flex-direction: column;
  align-items: center;
}

.modal-pause .pause-actions .btn {
  flex: 0 0 auto;
  width: min(200px, 100%);
  min-height: 44px;
  padding: 0.55rem 1.2rem;
  font-size: 0.95rem;
}

/* Rules list */
.rules {
  counter-reset: step;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.rules li {
  counter-increment: step;
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.97rem;
  line-height: 1.45;
  color: #dbe8fc;
}

.rules li::before {
  content: counter(step);
  flex: none;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--blue));
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
}

.tip {
  margin: 0.95rem 0 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.25);
  color: #fcd34d;
  font-size: 0.88rem;
  font-weight: 600;
}

.modal-action { width: 100%; }

/* Win / fail */
.modal-win { text-align: center; }

.win-emoji {
  font-size: clamp(3.2rem, 12vw, 4.4rem);
  line-height: 1;
  animation: bounce-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

.win-message {
  margin: 0.2rem 0 1rem;
  color: var(--muted);
  font-weight: 600;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 0.9rem;
}

.win-stat {
  background: rgba(148, 197, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
}

.win-stat dt {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.win-stat dd {
  margin: 0.25rem 0 0;
  font-size: clamp(1.05rem, 3.5vw, 1.3rem);
  font-weight: 900;
  color: #7dd3fc;
}

.best-note {
  margin: 0 0 0.95rem;
  font-weight: 800;
  color: #fbbf24;
  animation: pulse-note 1.4s ease-in-out infinite alternate;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-actions .btn { flex: 1 1 150px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 47px;
  padding: 0.62rem 1.05rem;
  border: none;
  border-radius: 12px;
  font-size: 0.98rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s, background 0.2s;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.4);
}

.btn-primary:hover {
  filter: brightness(1.12);
  box-shadow: 0 8px 22px rgba(14, 165, 233, 0.5);
}

.btn-secondary {
  color: #cfe3ff;
  background: rgba(148, 197, 255, 0.09);
  border: 1px solid rgba(148, 187, 255, 0.28);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: rgba(148, 197, 255, 0.16);
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(18px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes match-pop {
  0%  { transform: scale(1); }
  45% { transform: scale(1.09); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px) rotate(-2deg); }
  40% { transform: translateX(7px) rotate(2deg); }
  60% { transform: translateX(-5px) rotate(-1.5deg); }
  80% { transform: translateX(5px) rotate(1.5deg); }
}
@keyframes bounce-in {
  0%  { opacity: 0; transform: scale(0.3); }
  70% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes pulse-note { from { opacity: 0.72; } to { opacity: 1; } }
@keyframes pulse-warn { from { opacity: 0.55; } to { opacity: 1; } }

/* ---------- Small phones ---------- */
@media (max-width: 380px) {
  .btn { font-size: 0.92rem; padding: 0.58rem 0.8rem; }
  .menu-title { font-size: 2rem; }
  .topbar { padding: 6px 8px; gap: 4px; }
  .topbar-stat { padding: 3px 6px; min-width: 44px; }
  .topbar-label { font-size: 0.5rem; }
  .topbar-value { font-size: 0.8rem; }
}

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