/* ===== Memory Path =====
   Style: Claymorphism (matches PTV Games)
   Fonts: Baloo 2 + Comic Neue
   Brand: #01311F / #BF9E69 / #F4F2EE
   ========================= */

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

:root {
  /* Brand */
  --primary: #01311F;
  --primary-mid: #0A5438;
  --primary-light: #3D8B6B;
  --primary-bg: #E2EDE7;
  --accent: #BF9E69;
  --accent-light: #D4BC8E;
  --accent-bg: #F5F0E5;
  --cream: #F4F2EE;

  /* Game colors */
  --gold: #D4A84B;
  --gold-light: #E8CC8A;
  --gold-glow: rgba(212, 168, 75, 0.5);
  --trail: rgba(212, 168, 75, 0.25);

  /* Feedback */
  --success: #3D8B6B;
  --success-light: #7ABF9E;
  --error: #C45B5B;
  --error-light: #E8A0A0;

  /* Text */
  --text: #1A2A22;
  --text-muted: #5E6E64;
  --bg: var(--cream);
  --white: #FFFFFF;

  /* Tokens */
  --radius: 20px;
  --radius-sm: 12px;
  --shadow-clay: 6px 6px 12px rgba(1, 49, 31, 0.06), -2px -2px 8px rgba(255, 255, 255, 0.9);
  --shadow-clay-hover: 8px 8px 16px rgba(1, 49, 31, 0.10), -3px -3px 10px rgba(255, 255, 255, 0.95);
  --shadow-clay-inset: inset 2px 2px 4px rgba(1, 49, 31, 0.05), inset -1px -1px 3px rgba(255, 255, 255, 0.7);
  --font-display: 'Baloo 2', cursive, sans-serif;
  --font-body: 'Comic Neue', cursive, sans-serif;
  --transition: 250ms ease;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* --- Page container --- */
.page {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
  position: relative;
}

/* --- Back Link --- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 8px 0;
  margin-bottom: 8px;
  cursor: pointer;
  transition: color var(--transition);
}

.back-link:hover {
  color: var(--primary);
}

/* ==================
   INTRO SCREEN
   ================== */
.intro-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 3px solid rgba(1, 49, 31, 0.06);
  box-shadow: var(--shadow-clay);
  padding: 40px 28px 32px;
  text-align: center;
}

.intro-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  border-radius: 50%;
  margin: 0 auto 16px;
  box-shadow: var(--shadow-clay-inset);
}

.eyebrow {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 4px;
}

.intro-card h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.lead {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto 28px;
}

/* Mode picker */
.mode-picker {
  margin-bottom: 24px;
}

.mode-picker h2 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.mode-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 2px solid rgba(1, 49, 31, 0.06);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-clay-inset);
}

.mode-btn:hover {
  border-color: var(--accent-light);
  background: var(--accent-bg);
}

.mode-btn.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  box-shadow: var(--shadow-clay);
}

.mode-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
}

.mode-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 12px 28px;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.btn:focus-visible {
  outline: 3px solid var(--accent-light);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--primary);
  color: var(--white);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: var(--shadow-clay), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  width: 100%;
}

.btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-clay-hover), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  background: #024A2E;
}

.btn--primary:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-clay-inset);
}

.btn--ghost {
  background: var(--bg);
  color: var(--text);
  border-color: rgba(1, 49, 31, 0.08);
  box-shadow: var(--shadow-clay);
}

.btn--ghost:hover {
  background: var(--white);
  transform: translateY(-1px);
}

/* ==================
   GAME SCREEN
   ================== */

/* HUD */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.hud__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--white);
  border-radius: var(--radius-sm);
  border: 2px solid rgba(1, 49, 31, 0.05);
  box-shadow: var(--shadow-clay-inset);
  padding: 8px 16px;
  min-width: 72px;
}

.hud__item--status {
  flex: 1;
  min-width: 100px;
}

.hud__label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.hud__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--text);
  line-height: 1.1;
}

.hud__status {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  text-align: center;
}

.hud__status.watching {
  color: var(--accent);
}

.hud__status.your-turn {
  color: var(--success);
}

.hud__status.wrong {
  color: var(--error);
}

/* --- Grid --- */
.grid-container {
  display: grid;
  gap: 6px;
  margin-bottom: 20px;
  touch-action: none;
}

.grid-container[data-size="3"] { grid-template-columns: repeat(3, 1fr); }
.grid-container[data-size="4"] { grid-template-columns: repeat(4, 1fr); }
.grid-container[data-size="5"] { grid-template-columns: repeat(5, 1fr); }
.grid-container[data-size="6"] { grid-template-columns: repeat(6, 1fr); gap: 4px; }
.grid-container[data-size="7"] { grid-template-columns: repeat(7, 1fr); gap: 3px; }

.cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 3px solid rgba(1, 49, 31, 0.08);
  background: var(--white);
  cursor: pointer;
  position: relative;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  box-shadow: var(--shadow-clay);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0;
  color: transparent;
}

.cell:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}

.cell.disabled {
  cursor: default;
  pointer-events: none;
}

/* Lit cell during watch phase */
.cell.lit {
  background: var(--gold);
  border-color: var(--gold);
  transform: scale(1.05);
  box-shadow: 0 0 16px 4px var(--gold-glow), var(--shadow-clay);
  font-size: 1rem;
  color: var(--white);
}

/* Trail of previously lit cells */
.cell.trail {
  background: var(--trail);
  border-color: rgba(212, 168, 75, 0.3);
}

/* Start hint pulsing */
.cell.start-hint {
  animation: startPulse 800ms ease infinite alternate;
}

@keyframes startPulse {
  from {
    box-shadow: 0 0 0 0 var(--gold-glow), var(--shadow-clay);
    background: var(--accent-bg);
  }
  to {
    box-shadow: 0 0 12px 6px var(--gold-glow), var(--shadow-clay);
    background: var(--gold-light);
  }
}

/* Correct tap */
.cell.correct {
  background: var(--success);
  border-color: var(--success);
  transform: scale(0.95);
  box-shadow: var(--shadow-clay-inset);
  font-size: 1rem;
  color: var(--white);
}

/* Wrong tap */
.cell.wrong {
  background: var(--error);
  border-color: var(--error);
  animation: wrongShake 400ms ease;
}

/* Reveal remaining path after wrong */
.cell.reveal {
  background: var(--error-light);
  border-color: var(--error);
  opacity: 0.7;
  font-size: 0.85rem;
  color: var(--error);
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Fog transition */
.cell.fog-out {
  animation: fogOut 400ms ease forwards;
}

@keyframes fogOut {
  from { background: var(--trail); border-color: rgba(212, 168, 75, 0.3); }
  to { background: var(--white); border-color: rgba(1, 49, 31, 0.08); }
}

/* Smaller cells for larger grids */
.grid-container[data-size="6"] .cell,
.grid-container[data-size="7"] .cell {
  border-radius: 8px;
  border-width: 2px;
}

.grid-container[data-size="6"] .cell.lit,
.grid-container[data-size="7"] .cell.lit {
  font-size: 0.8rem;
}

.grid-container[data-size="6"] .cell.correct,
.grid-container[data-size="7"] .cell.correct {
  font-size: 0.8rem;
}

.grid-container[data-size="6"] .cell.reveal,
.grid-container[data-size="7"] .cell.reveal {
  font-size: 0.7rem;
}

/* --- Progress Dots --- */
.progress-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  min-height: 18px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #D8D4CE;
  border: 2px solid rgba(1, 49, 31, 0.06);
  transition: background var(--transition), transform var(--transition);
}

.dot.done {
  background: var(--success);
  transform: scale(1.15);
}

.dot.active {
  background: var(--accent-light);
  animation: dotPulse 600ms ease infinite alternate;
}

.dot.wrong {
  background: var(--error);
}

@keyframes dotPulse {
  from { transform: scale(1); }
  to { transform: scale(1.3); }
}

/* --- Game Controls --- */
.game-controls {
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--white);
  border: 2px solid rgba(1, 49, 31, 0.06);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-clay-inset);
}

.ctrl-btn:hover {
  color: var(--primary);
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

/* ==================
   OVERLAY (Game Over)
   ================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 42, 34, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 16px;
}

.overlay__card {
  background: var(--white);
  border-radius: var(--radius);
  border: 3px solid rgba(1, 49, 31, 0.06);
  box-shadow: var(--shadow-clay-hover);
  padding: 36px 32px 28px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  animation: popIn 300ms ease;
}

@keyframes popIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay__icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  border-radius: 50%;
  margin: 0 auto 16px;
}

.overlay__card h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.overlay__score {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 4px;
}

.overlay__detail {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.overlay__actions {
  display: flex;
  gap: 10px;
}

.overlay__actions .btn {
  flex: 1;
}

/* ==================
   TOAST
   ================== */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--white);
  background: var(--success);
  padding: 10px 24px;
  border-radius: 50px;
  box-shadow: 0 4px 16px rgba(1, 49, 31, 0.25);
  animation: toastIn 300ms ease, toastOut 300ms ease 1.2s forwards;
}

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ==================
   FULLSCREEN MODE
   ================== */
.is-fullscreen {
  background: var(--bg);
}

.is-fullscreen .page {
  max-width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
}

.is-fullscreen .screen--game {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.is-fullscreen .grid-container {
  flex: 1;
  min-height: 0;
  margin-bottom: 16px;
}

.is-fullscreen .cell {
  aspect-ratio: auto;
  height: 100%;
  min-height: 0;
}

.is-fullscreen .back-link {
  display: none;
}

/* ==================
   RESPONSIVE
   ================== */
@media (max-width: 480px) {
  .page {
    padding: 12px;
  }

  .intro-card {
    padding: 28px 20px 24px;
  }

  .intro-card h1 {
    font-size: 1.6rem;
  }

  .hud__item {
    padding: 6px 10px;
    min-width: 60px;
  }

  .hud__value {
    font-size: 1.1rem;
  }

  .grid-container {
    gap: 4px;
  }

  .grid-container[data-size="6"],
  .grid-container[data-size="7"] {
    gap: 3px;
  }

  .cell {
    border-radius: 8px;
  }

  .mode-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .mode-btn {
    padding: 10px 8px;
  }

  .mode-label {
    font-size: 0.9rem;
  }

  .mode-desc {
    font-size: 0.7rem;
  }

  .ctrl-btn {
    padding: 8px 10px;
    font-size: 0.78rem;
    gap: 4px;
  }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .cell,
  .dot,
  .toast,
  .overlay__card {
    animation: none;
    transition: none;
  }

  .cell.lit {
    transform: none;
    outline: 4px solid var(--gold);
  }

  .cell.start-hint {
    animation: none;
    background: var(--gold-light);
  }
}
