/* ==========================================================
   Sudoku Canvas — Cozy Theme
   ========================================================== */

:root {
  /* Palette */
  --cream: #FAF6F0;
  --cream-deep: #F0EAE0;
  --terracotta: #C97A5A;
  --terracotta-deep: #A85F40;
  --sage: #8FA68E;
  --sage-deep: #6B7F6A;
  --powder-blue: #A8B8C8;
  --gold: #E8C46B;
  --gold-soft: #F0D89A;
  --brown: #6B4F3A;
  --brown-soft: #8B6F5A;
  --rose: #E8B5A8;
  --ink: #3D5A80;
  --error: #B3362A;
  --error-bg: #F7D6CE;
  --shadow: rgba(107, 79, 58, 0.12);
  --shadow-strong: rgba(107, 79, 58, 0.20);

  /* Typo */
  --font-display: 'Fraunces', Georgia, serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* The hidden attribute always wins over component display rules (.tool-btn is inline-flex) */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  font-family: var(--font-ui);
  color: var(--brown);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  /* Disable iOS rubber-banding/bounce in webview */
  overscroll-behavior-y: none;
  /* Avoid blue text-selection highlight on tap */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* iPhone safe areas (notch / home indicator) */
.game-page,
.landing {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Cream band behind the iOS status bar, so content scrolled under it
   never collides with the clock (the web view runs edge to edge). */
.game-page::before,
.landing::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top, 0px);
  background: var(--cream);
  z-index: 20;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

/* ==========================================================
   Landing
   ========================================================== */

.landing {
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-deep) 100%);
  min-height: 100vh;
}

.hero {
  padding: var(--space-xl) var(--space-md);
  text-align: center;
}

.hero-inner {
  max-width: 480px;
  margin: 0 auto;
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  color: var(--brown);
  letter-spacing: -0.02em;
}

.logo em {
  font-style: italic;
  font-weight: 400;
  color: var(--terracotta);
}

.tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1rem, 4vw, 1.25rem);
  color: var(--brown-soft);
  margin-top: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.hero-art {
  margin: var(--space-lg) 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 40px var(--shadow);
  background: var(--cream);
  border: 1px solid rgba(107, 79, 58, 0.08);
}

.hero-svg {
  display: block;
  width: 100%;
  height: auto;
}

.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 16px 32px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1.05rem;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cta.primary {
  background: var(--terracotta);
  color: var(--cream);
  box-shadow: 0 8px 20px rgba(201, 122, 90, 0.35);
}

.cta.primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 28px rgba(201, 122, 90, 0.45);
}

.cta.primary:active {
  transform: translateY(0) scale(0.98);
}

.cta-icon {
  font-size: 1.2rem;
}

.cta-sub {
  margin-top: var(--space-md);
  font-size: 0.85rem;
  color: var(--brown-soft);
  font-style: italic;
}

/* Features */

.features {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  max-width: 480px;
  margin: var(--space-xl) auto;
  padding: 0 var(--space-md);
}

@media (min-width: 720px) {
  .features {
    grid-template-columns: repeat(3, 1fr);
    max-width: 960px;
  }
}

.feature {
  background: var(--cream);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid rgba(107, 79, 58, 0.08);
  box-shadow: 0 4px 12px var(--shadow);
}

.feature-icon {
  font-size: 2rem;
  margin-bottom: var(--space-sm);
}

.feature h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: var(--space-sm);
  color: var(--brown);
}

.feature p {
  font-size: 0.9rem;
  color: var(--brown-soft);
  line-height: 1.5;
}

.footer {
  padding: var(--space-xl) var(--space-md);
  text-align: center;
  font-size: 0.8rem;
  color: var(--brown-soft);
}

.footer-meta {
  margin-top: 4px;
  opacity: 0.7;
  font-style: italic;
}

/* ==========================================================
   Game Page
   ========================================================== */

.game-page {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-deep) 100%);
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--cream);
  border-bottom: 1px solid rgba(107, 79, 58, 0.08);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn {
  font-size: 1.4rem;
  color: var(--brown);
  padding: var(--space-sm);
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, opacity 0.2s;
}

.back-btn:hover { background: var(--cream-deep); }

.back-btn.hidden {
  visibility: hidden;
  pointer-events: none;
}

.settings-btn { font-size: 1.2rem; padding: 0; line-height: 1; margin: -12px -10px -12px 0; }
.settings-btn.hidden { display: none; }

.settings-dialog {
  width: min(360px, calc(100vw - 32px));
  margin: auto;
  border: none;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  background: var(--cream);
  color: var(--brown);
  box-shadow: 0 12px 40px var(--shadow-strong);
}

.settings-dialog::backdrop { background: rgba(59, 47, 42, 0.35); }

.settings-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0 0 var(--space-md);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 12px 0;
  border-bottom: 1px solid rgba(107, 79, 58, 0.10);
  font-family: var(--font-ui);
  cursor: pointer;
}

.setting-row small {
  display: block;
  font-size: 0.78rem;
  color: var(--brown-soft);
}

.setting-row input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: var(--cream-deep);
  border: 1px solid rgba(107, 79, 58, 0.18);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.setting-row input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px var(--shadow-strong);
  transition: transform 0.2s;
}

.setting-row input:checked { background: var(--sage); }
.setting-row input:checked::after { transform: translateX(18px); }

.settings-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.reminder-text {
  font-family: var(--font-ui);
  color: var(--brown-soft);
  line-height: 1.45;
  margin: 0;
}

.daily-done { text-align: center; }
.daily-done-icon { font-size: 2.4rem; line-height: 1; }
.daily-done .settings-title { margin: var(--space-sm) 0 var(--space-xs); }
.daily-done-sub,
.daily-done-line {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  margin: 0 0 6px;
}
.daily-done-sub { color: var(--brown-soft); font-size: 0.9rem; margin-bottom: var(--space-md); }
.daily-done-stats { display: flex; justify-content: space-around; margin-bottom: 14px; }
.daily-done-value { font-family: var(--font-display); font-size: 1.7rem; }
.daily-done-label { font-family: var(--font-ui); font-size: 0.75rem; color: var(--brown-soft); }
.daily-done-next { color: var(--sage-deep); }

.settings-link {
  color: var(--brown-soft);
  font-size: 0.85rem;
}

.game-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  color: var(--brown);
}

.game-stats {
  display: flex;
  gap: var(--space-md);
  font-size: 0.9rem;
  color: var(--brown-soft);
}

.game-stats span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================
   Diorama (canvas view)
   ========================================================== */

.diorama-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  gap: var(--space-lg);
}

.diorama-frame {
  width: 100%;
  max-width: 540px;
  background: var(--cream);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 40px var(--shadow);
  border: 1px solid rgba(107, 79, 58, 0.08);
  position: relative;
}

.diorama-svg {
  display: block;
  width: 100%;
  height: auto;
  /* Blank watercolor paper texture, awaiting first zones */
  background:
    radial-gradient(circle at 20% 30%, rgba(201, 122, 90, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(143, 166, 142, 0.04) 0%, transparent 40%),
    var(--cream-deep);
}

/* Hidden zones — gray silhouette + scintille for next */

.zone {
  transition: opacity 0.6s ease;
}

/* Unrevealed zones show as a faint sepia sketch of the whole painting */
.zone.hidden {
  opacity: 0.1;
  filter: grayscale(1) sepia(0.45);
  pointer-events: none;
}

.zone.revealing {
  animation: revealFlood 3.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes revealFlood {
  0% {
    opacity: 0;
    filter: blur(14px) brightness(1.9) saturate(1.4);
    transform: scale(0.85);
  }
  20% {
    opacity: 0.4;
    filter: blur(10px) brightness(1.7) saturate(1.3);
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    filter: blur(4px) brightness(1.35) saturate(1.15);
    transform: scale(1.04);
  }
  75% {
    opacity: 1;
    filter: blur(1.5px) brightness(1.15) saturate(1.05);
    transform: scale(1.015);
  }
  100% {
    opacity: 1;
    filter: blur(0) brightness(1) saturate(1);
    transform: scale(1);
  }
}

/* Reveal stage gets a subtle warm bloom while the zone fills in */
.reveal-stage.glowing::after {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(ellipse at center, rgba(232, 196, 107, 0.35) 0%, transparent 65%);
  pointer-events: none;
  animation: stageBloom 3.4s ease-out forwards;
  border-radius: var(--radius-lg);
}

@keyframes stageBloom {
  0%   { opacity: 0; transform: scale(0.8); }
  35%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.15); }
}

/* Particles — varied warm tones */
.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform, opacity;
}
.particle.gold       { background: #E8C46B; box-shadow: 0 0 10px #E8C46B; }
.particle.amber      { background: #F0A858; box-shadow: 0 0 10px #F0A858; }
.particle.cream      { background: #FFEAA8; box-shadow: 0 0 12px #FFEAA8; }
.particle.terracotta { background: #C97A5A; box-shadow: 0 0 8px #C97A5A; }

.diorama-info {
  text-align: center;
  width: 100%;
  max-width: 420px;
  min-width: 0;
}

.chapter-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--brown);
  margin-bottom: var(--space-xs);
}

.chapter-progress {
  font-size: 0.9rem;
  color: var(--brown-soft);
  font-style: italic;
}

/* ==========================================================
   Chapters List View ("Carnet de voyage" — home screen)
   ========================================================== */

.chapters-page {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-md);
}

.chapters-header {
  text-align: center;
  margin: var(--space-md) 0 var(--space-lg);
}

.chapters-page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 5vw, 2rem);
  color: var(--brown);
  letter-spacing: -0.01em;
}

.chapters-page-sub {
  font-size: 0.9rem;
  color: var(--brown-soft);
  font-style: italic;
  margin-top: 4px;
}

.chapters-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (min-width: 640px) {
  .chapters-list { grid-template-columns: repeat(4, 1fr); gap: var(--space-md); }
}

.chapter-list-card {
  background: var(--cream);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 20px var(--shadow);
  border: 2px solid transparent;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chapter-list-card:hover:not(.locked) {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px var(--shadow-strong);
}

.chapter-list-card.current {
  border-color: var(--terracotta);
  box-shadow: 0 8px 24px rgba(201, 122, 90, 0.30);
}

.chapter-list-card.completed {
  border-color: var(--gold);
  background: linear-gradient(180deg, var(--cream) 0%, rgba(232, 196, 107, 0.10) 100%);
}

.chapter-list-card.locked {
  cursor: not-allowed;
  background: var(--cream-deep);
  opacity: 0.85;
}

.chapter-list-card.locked .chapter-list-svg {
  filter: grayscale(0.85) brightness(0.92);
  opacity: 0.55;
}

.chapter-list-svg {
  background: var(--cream-deep);
  border-bottom: 1px solid rgba(107, 79, 58, 0.06);
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

.chapter-list-svg svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chapter-list-svg .lock-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  background: linear-gradient(135deg, rgba(107, 79, 58, 0.18), rgba(107, 79, 58, 0.05));
  pointer-events: none;
}

.chapter-list-meta {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.chapter-list-num {
  display: inline-block;
  align-self: flex-start;
  background: var(--gold-soft);
  color: var(--brown);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.7rem;
  padding: 2px 9px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.chapter-list-card.locked .chapter-list-num {
  background: rgba(107, 79, 58, 0.10);
  color: var(--brown-soft);
}

.chapter-list-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--brown);
  line-height: 1.3;
}

.chapter-list-card.locked .chapter-list-title {
  color: var(--brown-soft);
}

.chapter-list-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--brown-soft);
}

.chapter-list-status .status-badge {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chapter-list-card.completed .status-badge { color: var(--gold); }
.chapter-list-card.current   .status-badge { color: var(--terracotta); }
.chapter-list-card.locked    .status-badge { color: var(--brown-soft); }

.chapter-list-progress {
  height: 4px;
  background: rgba(107, 79, 58, 0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.chapter-list-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--terracotta), var(--gold));
  border-radius: 2px;
  transition: width 0.4s ease;
}

.chapter-list-card.completed .chapter-list-progress-bar {
  background: var(--gold);
}

/* 13 chapters don't fit on a phone: the row scrolls sideways and centres the current
   chapter (game.js). The auto margins centre the dots when they do fit. */
.chapter-dots {
  position: relative;
  display: flex;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px;
  margin-top: var(--space-md);
  /* Soft fade on both edges: dots cut by the edge read as "there is more, swipe". */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 20px, #000 calc(100% - 20px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 20px, #000 calc(100% - 20px), transparent);
}

.chapter-dots::-webkit-scrollbar { display: none; }
/* End spacers keep the first and last dots out of the fade once scrolled to an end. */
.chapter-dots::before,
.chapter-dots::after { content: ''; flex: 0 0 12px; }
.chapter-dots::before { margin-left: auto; }
.chapter-dots::after { margin-right: auto; }

.chapter-dot {
  flex: 0 0 auto;
  scroll-snap-align: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cream);
  border: 1.5px solid rgba(107, 79, 58, 0.18);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--brown-soft);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}

.chapter-dot:hover:not(.locked) {
  transform: scale(1.08);
  border-color: var(--terracotta);
}

.chapter-dot.current {
  background: var(--terracotta);
  color: var(--cream);
  border-color: var(--terracotta);
}

.chapter-dot.completed:not(.current) {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--brown);
}

.chapter-dot.locked {
  opacity: 0.4;
  cursor: not-allowed;
  font-size: 0.7rem;
}

.next-zone-hint {
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--cream);
  border-radius: var(--radius-md);
  border: 1px solid rgba(201, 122, 90, 0.15);
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: 0 4px 12px var(--shadow);
}

.next-zone-label {
  font-size: 0.85rem;
  color: var(--brown-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.next-zone-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--brown);
}

.start-puzzle-btn {
  margin-top: var(--space-md);
}

/* Short screens (iPhone SE, 667 pt): a smaller diorama and tighter spacing keep the
   "Résoudre la grille" button on screen. */
@media (max-height: 700px) {
  .diorama-wrap { gap: var(--space-md); padding-top: var(--space-sm); }
  .diorama-frame { max-width: 300px; }
  .chapter-dots { margin-top: var(--space-sm); }
  .next-zone-hint { margin-top: 0; }
  .start-puzzle-btn { margin-top: var(--space-sm); }
}

/* ----- Daily challenge card ----- */

.daily-card {
  margin-top: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(232, 196, 107, 0.18), rgba(201, 122, 90, 0.10));
  border: 1px solid rgba(232, 196, 107, 0.45);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 6px 18px var(--shadow);
}

.daily-card.done {
  background: var(--cream);
  border-color: rgba(107, 79, 58, 0.10);
  opacity: 0.85;
}

.daily-card-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.daily-card-body {
  flex: 1;
  min-width: 0;
}

.daily-card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--brown);
  margin-bottom: 2px;
}

.daily-card-meta {
  font-size: 0.78rem;
  color: var(--brown-soft);
  font-style: italic;
}

.daily-streak {
  font-size: 0.78rem;
  color: var(--terracotta);
  font-weight: 600;
  margin-top: 4px;
}

.daily-card-cta {
  flex-shrink: 0;
  min-height: 44px;
  padding: 8px 20px;
  background: var(--terracotta);
  color: var(--cream);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.85rem;
  transition: transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 4px 10px rgba(201, 122, 90, 0.25);
}

.daily-card-cta:hover {
  transform: translateY(-1px);
}

.daily-card-cta:active {
  transform: translateY(0) scale(0.96);
}

.daily-card.done .daily-card-cta {
  background: var(--cream-deep);
  color: var(--brown-soft);
  pointer-events: none;
  box-shadow: none;
}

/* ==========================================================
   Sudoku Grid
   ========================================================== */

.sudoku-page {
  background: var(--cream);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sudoku-progress {
  height: 4px;
  background: rgba(107, 79, 58, 0.08);
  position: relative;
}

.sudoku-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--terracotta), var(--gold));
  width: 0%;
  transition: width 0.4s ease;
}

.sudoku-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  gap: var(--space-md);
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  /* Fixed rows: without this, a row with no digits collapses to a thin strip */
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: 1px;
  background: var(--brown);
  padding: 3px;
  border-radius: var(--radius-md);
  box-shadow: 0 16px 32px var(--shadow);
  width: min(92vw, 480px);
  aspect-ratio: 1;
  position: relative;
}

.cell {
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.2rem, 4.5vw, 1.7rem);
  color: var(--brown);
  cursor: pointer;
  user-select: none;
  position: relative;
  min-width: 0;
  min-height: 0;
  transition: background 0.2s, transform 0.1s;
}

.cell.given {
  font-weight: 700;
  color: var(--brown);
}

.cell.user {
  color: var(--ink);
}

.cell.selected {
  background: #F4D88A;
}

.cell.highlight-related {
  background: #F8EAC4;
}

.cell.highlight-same {
  background: #F0D89A;
}

.cell.conflict {
  color: var(--error) !important;
  background: var(--error-bg);
  animation: cellShake 0.4s ease;
}

.cell.selected.conflict {
  box-shadow: inset 0 0 0 2px #E8B84A;
}

/* Pencil-mark notes — small 3x3 grid inside an empty cell */
.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: clamp(0.55rem, 1.6vw, 0.72rem);
  color: var(--brown-soft);
  opacity: 0.65;
  line-height: 1;
}

.cell-notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell-notes span:empty {
  visibility: hidden;
}

@keyframes cellShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* 3x3 box separators (thicker) */
.cell:nth-child(3n):not(:nth-child(9n)) {
  margin-right: 2px;
}
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
  margin-bottom: 2px;
}

/* Corner cells follow the grid's rounded frame (radius minus padding),
   otherwise their square corners cut through the border */
.cell:nth-child(1)  { border-top-left-radius: calc(var(--radius-md) - 3px); }
.cell:nth-child(9)  { border-top-right-radius: calc(var(--radius-md) - 3px); }
.cell:nth-child(73) { border-bottom-left-radius: calc(var(--radius-md) - 3px); }
.cell:nth-child(81) { border-bottom-right-radius: calc(var(--radius-md) - 3px); }

/* Number Pad */
.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: var(--space-xs);
  width: min(92vw, 480px);
  margin-top: var(--space-md);
}

.numpad-btn {
  /* 9 columns cannot be 44pt wide on an iPhone: make the keys taller instead */
  height: clamp(44px, 6vh, 52px);
  background: var(--cream);
  border: 1px solid rgba(107, 79, 58, 0.10);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.3rem;
  color: var(--brown);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
}

.numpad-btn:hover {
  background: var(--gold-soft);
}

.numpad-btn:active {
  transform: scale(0.92);
}

.numpad-btn.disabled {
  opacity: 0.25;
  pointer-events: none;
  background: var(--cream-deep);
  color: var(--brown-soft);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.tools {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--cream);
  border: 1px solid rgba(107, 79, 58, 0.10);
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--brown);
  transition: background 0.15s;
}

.tool-btn:hover {
  background: var(--cream-deep);
}

.tool-btn.disabled {
  opacity: 0.4;
}

.tool-btn.active {
  background: var(--gold-soft);
  border-color: var(--gold);
}

/* Temporary dev / test button — visually distinct so it's obvious it's not for release */
.dev-btn {
  margin-top: var(--space-md);
  background: repeating-linear-gradient(
    45deg,
    rgba(232, 196, 107, 0.20),
    rgba(232, 196, 107, 0.20) 6px,
    rgba(232, 196, 107, 0.10) 6px,
    rgba(232, 196, 107, 0.10) 12px
  );
  border-color: var(--gold);
  color: var(--brown);
  font-style: italic;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.dev-btn:hover {
  background: rgba(232, 196, 107, 0.30);
}

/* ==========================================================
   Reveal Animation Overlay
   ========================================================== */

.reveal-overlay {
  position: fixed;
  inset: 0;
  background: var(--cream);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
  gap: var(--space-lg);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.reveal-overlay.visible {
  display: flex;
  opacity: 1;
}

.reveal-stage {
  width: min(92vw, 600px);
  height: auto;
  position: relative;
}

.reveal-message {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.4rem;
  color: var(--brown);
  text-align: center;
  opacity: 0;
  animation: fadeInUp 1s ease 5s forwards;
}

.reveal-rewards {
  display: flex;
  gap: var(--space-lg);
  font-size: 1.1rem;
  color: var(--terracotta);
  font-weight: 600;
  opacity: 0;
  animation: fadeInUp 1s ease 5.5s forwards;
}

.reveal-continue {
  opacity: 0;
  animation: fadeInUp 1s ease 6s forwards;
  pointer-events: none; /* a tap before it shows skips the animation instead */
}

.reveal-overlay.done .reveal-continue {
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  .reveal-overlay { transition: none; }
  .reveal-message, .reveal-rewards, .reveal-continue { animation: none; opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Particles */
.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 8px var(--gold);
}

/* Win celebration on grid */
.cell.celebrating {
  animation: cellGlow 0.8s ease;
  background: var(--gold-soft);
}

@keyframes cellGlow {
  0% { background: var(--cream); transform: scale(1); }
  50% { background: var(--gold); transform: scale(1.1); }
  100% { background: var(--gold-soft); transform: scale(1); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--brown);
  color: var(--cream);
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 200;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* First-grid explanations */
.coach {
  position: fixed;
  inset: 0;
  z-index: 300;
}

.coach-hole {
  position: fixed;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 9999px rgba(61, 45, 33, 0.6);
  transition: all 0.3s;
  pointer-events: none;
}

.coach-bubble {
  position: fixed;
  left: var(--space-md);
  right: var(--space-md);
  max-width: 420px;
  margin: 0 auto;
  background: var(--cream);
  color: var(--brown);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: 0 8px 30px var(--shadow-strong);
  transition: top 0.3s;
}

.coach-step {
  font-size: 0.75rem;
  color: var(--brown-soft);
  letter-spacing: 0.08em;
}

.coach-text {
  margin: var(--space-xs) 0 var(--space-md);
  font-size: 1rem;
  line-height: 1.45;
}

.coach-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.coach-actions .cta {
  width: auto;
  min-height: 44px;
  padding: 0 var(--space-lg);
}

/* Difficulty selector */
.difficulty-modal {
  position: fixed;
  inset: 0;
  background: rgba(107, 79, 58, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--space-md);
}

.difficulty-modal.visible {
  display: flex;
}

.difficulty-card {
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  max-width: 360px;
  width: 100%;
  box-shadow: 0 24px 48px rgba(107, 79, 58, 0.3);
}

.difficulty-card h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: var(--space-md);
  text-align: center;
}

.difficulty-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.difficulty-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--cream-deep);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  font-size: 1rem;
  color: var(--brown);
  transition: border-color 0.15s, transform 0.1s;
  text-align: left;
  width: 100%;
}

.difficulty-option:hover {
  border-color: var(--terracotta);
}

.difficulty-option .label {
  font-family: var(--font-display);
  font-weight: 600;
}

.difficulty-option .meta {
  font-size: 0.8rem;
  color: var(--brown-soft);
}

/* Daily challenge clock */
.daily-timer {
  margin-top: 2px;
  font-size: 0.85rem;
  color: #8B6F5A;
  font-variant-numeric: tabular-nums;
}

/* Daily challenge card in the carnet, between the title and the chapters */
#view-chapters .daily-card {
  margin: 0 auto var(--space-lg);
}

/* Compact chapter tiles: the whole carnet fits on a couple of screens */
.chapters-list .chapter-list-card { border-radius: var(--radius-md); box-shadow: 0 4px 12px var(--shadow); }
.chapters-list .chapter-list-svg .lock-overlay { font-size: 1.4rem; }
.chapters-list .chapter-list-meta { padding: 6px 8px 8px; gap: 2px; }
.chapters-list .chapter-list-num { font-size: 0.6rem; padding: 1px 6px; margin-bottom: 0; }
.chapters-list .chapter-list-title { font-size: 0.74rem; line-height: 1.2; }
.chapters-list .chapter-list-status { margin-top: 2px; font-size: 0.68rem; flex-wrap: wrap; gap: 0 4px; }
.chapters-list .chapter-list-progress { margin-top: 4px; height: 3px; }
