:root {
  color-scheme: light;
  --bg-top: #0b2149;
  --bg-bottom: #3f2b96;
  --panel: rgba(255, 255, 255, 0.12);
  --text: #f8fbff;
  --text-muted: rgba(248, 251, 255, 0.78);
  --accent: #ffd166;
  --accent-strong: #ff8c42;
  --success: #7bd389;
  --shadow: 0 20px 60px rgba(8, 15, 38, 0.32);
  --card-size: clamp(76px, 11vw, 96px);
  --surface-border: rgba(255, 255, 255, 0.12);
  --chip-bg: rgba(255, 255, 255, 0.1);
  --secondary-button-bg: rgba(255, 255, 255, 0.12);
  --secondary-button-text: var(--text);
  --secondary-button-border: transparent;
  --card-back-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.08));
  --card-back-border: rgba(255, 255, 255, 0.15);
  --message-color: var(--text-muted);
  --theme-toggle-bg: rgba(255, 255, 255, 0.14);
  --theme-toggle-text: var(--text);
  --theme-toggle-border: rgba(255, 255, 255, 0.18);
}

body[data-theme="day"] {
  --bg-top: #eef6ff;
  --bg-bottom: #d9e8ff;
  --panel: rgba(255, 255, 255, 0.72);
  --text: #1f2342;
  --text-muted: rgba(31, 35, 66, 0.72);
  --surface-border: rgba(31, 35, 66, 0.08);
  --chip-bg: rgba(31, 35, 66, 0.06);
  --secondary-button-bg: rgba(31, 35, 66, 0.08);
  --secondary-button-text: #1f2342;
  --secondary-button-border: rgba(31, 35, 66, 0.12);
  --card-back-bg: linear-gradient(160deg, rgba(255, 255, 255, 0.92), rgba(233, 241, 255, 0.98));
  --card-back-border: rgba(31, 35, 66, 0.12);
  --shadow: 0 20px 60px rgba(42, 76, 133, 0.16);
  --message-color: rgba(31, 35, 66, 0.76);
  --theme-toggle-bg: rgba(31, 35, 66, 0.08);
  --theme-toggle-text: #1f2342;
  --theme-toggle-border: rgba(31, 35, 66, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.12), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button {
  font: inherit;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

.app-shell {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.hero,
.controls-panel,
.board-panel {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid var(--surface-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-topbar {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.theme-toggle-button {
  border: 1px solid var(--theme-toggle-border);
  background: var(--theme-toggle-bg);
  color: var(--theme-toggle-text);
  border-radius: 999px;
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#themeToggleIcon,
.memory-card-symbol {
  font-family: "Noto Color Emoji", "Segoe UI Emoji", "Apple Color Emoji", "Twemoji Mozilla", sans-serif;
}

.theme-toggle-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(7, 14, 36, 0.14);
}

.eyebrow,
.subtitle,
.status-label,
.modal-badge,
.modal-message,
.modal-stat-label,
.game-message {
  color: var(--text-muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  margin: 0 0 0.75rem;
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 4vw, 3.5rem);
}

.subtitle {
  margin: 0;
  max-width: 42rem;
  line-height: 1.5;
}

.controls-panel {
  margin-top: 1.25rem;
  padding: 1.25rem;
  text-align: center;
}

.level-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.level-button,
.restart-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.level-button,
.secondary-button {
  background: var(--secondary-button-bg);
  color: var(--secondary-button-text);
  border: 1px solid var(--secondary-button-border);
}

.level-button:hover,
.restart-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(7, 14, 36, 0.22);
}

.level-button.is-active,
.restart-button,
.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #1a1832;
  font-weight: 700;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1rem;
  justify-content: center;
}

.status-chip {
  min-width: 130px;
  padding: 0.95rem 1rem;
  border-radius: 18px;
  background: var(--chip-bg);
  text-align: center;
}

.status-chip strong,
.modal-stat strong {
  display: block;
  margin-top: 0.15rem;
  font-size: 1.1rem;
}

.board-panel {
  margin-top: 1.25rem;
  padding: 1.25rem;
}

.game-message {
  margin: 1rem 0 0;
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.5;
  text-align: center;
  color: var(--message-color);
}

.game-board {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(var(--columns, 5), var(--card-size));
  justify-content: center;
}

.memory-card {
  aspect-ratio: 1;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--card-back-bg);
  border: 1px solid var(--card-back-border);
  border-radius: 20px;
  box-shadow: 0 12px 22px rgba(8, 15, 38, 0.18);
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

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

.memory-card:hover {
  transform: translateY(-2px);
}

.memory-card-symbol {
  display: grid;
  place-items: center;
}

.memory-card-symbol {
  font-size: clamp(1.75rem, 3.6vw, 2.4rem);
  font-weight: 800;
}

.memory-card.is-flipped,
.memory-card.is-matched {
  background: linear-gradient(180deg, #fffef9, #ffedd7);
  color: #1d2240;
  border-color: rgba(255, 255, 255, 0.6);
  transform: rotateY(180deg);
}

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

.memory-card-content {
  display: grid;
  justify-items: center;
}

.memory-card.is-matched {
  background: linear-gradient(180deg, #f7fff5, #dff8d4);
  box-shadow: 0 0 0 2px rgba(123, 211, 137, 0.65), 0 14px 28px rgba(123, 211, 137, 0.25);
}

.memory-card.tail-start {
  grid-column: 2;
}

.memory-card.tail-end {
  grid-column: 3;
}

.memory-card:focus-visible {
  outline: 3px solid rgba(255, 209, 102, 0.9);
  outline-offset: 4px;
  border-radius: 22px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(6, 10, 24, 0.62);
  z-index: 30;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(540px, 100%);
  padding: 2rem;
  border-radius: 28px;
  background: linear-gradient(180deg, #fffdf7, #fff2d8);
  color: #1f2342;
  box-shadow: 0 20px 70px rgba(8, 15, 38, 0.36);
}

.modal-badge {
  margin: 0 0 0.6rem;
  color: #7a5b0a;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
}

.modal-card h2 {
  margin: 0;
}

.modal-message {
  margin: 0.8rem 0 1.25rem;
  color: #4f5578;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.modal-stat {
  padding: 1rem;
  border-radius: 18px;
  background: rgba(31, 35, 66, 0.08);
}

.modal-stat-label {
  color: #5a607f;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.modal-actions .secondary-button {
  background: rgba(31, 35, 66, 0.1);
  color: #1f2342;
  border: 1px solid rgba(31, 35, 66, 0.14);
  font-weight: 600;
}

.modal-actions .secondary-button:hover {
  background: rgba(31, 35, 66, 0.16);
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 1rem, 100%);
    padding-top: 1rem;
  }

  .hero,
  .controls-panel,
  .board-panel,
  .modal-card {
    border-radius: 20px;
  }

  .hero-topbar {
    margin-bottom: 0.85rem;
  }

  .game-board {
    gap: 0.65rem;
  }
}

@media (max-width: 560px) {
  .modal {
    padding: 0.5rem;
  }

  .theme-toggle-button {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.05rem;
  }

  .modal-card {
    width: min(360px, 100%);
    padding: 1.2rem;
    border-radius: 18px;
  }

  .modal-card h2 {
    font-size: 1.8rem;
  }

  .modal-message {
    margin: 0.65rem 0 1rem;
  }

  .game-board {
    grid-template-columns: repeat(var(--columns-mobile, 4), clamp(60px, 18vw, 76px));
  }

  .modal-stats {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .modal-stat {
    padding: 0.8rem;
  }

  .modal-actions {
    gap: 0.6rem;
    margin-top: 1.1rem;
  }

  .modal-actions button {
    width: 100%;
    padding: 0.75rem 1rem;
  }
}
