/* ─── Sudoku ──────────────────────────────────────────────────────────── */

/* ── Hub (difficulty cards) ─────────────────────────────────────────── */
.game-page-layout.max-board .sudoku-hub-pane {
  width: 100%;
  max-width: 720px;
  padding: 16px 8px;
  align-self: center;
  overflow-y: auto;
  max-height: 100%;
}
.game-page-layout.max-board .sudoku-hub-h1 {
  font-size: 24px;
  margin: 0 0 6px;
  font-weight: 700;
}
.game-page-layout.max-board .sudoku-hub-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.sudoku-tier-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.08s, border-color 0.12s, box-shadow 0.12s;
}
.sudoku-tier-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
.sudoku-tier-easy   { border-left-color: #fbbf24; }
.sudoku-tier-medium { border-left-color: #34d399; }
.sudoku-tier-hard   { border-left-color: #a78bfa; }

.sudoku-tier-head {
  display: flex; align-items: baseline; justify-content: space-between;
}
.sudoku-tier-label {
  font-size: 18px; font-weight: 700;
}
.sudoku-tier-clues {
  font-size: 13px;
}
.sudoku-tier-status {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 14px;
}
.sudoku-tier-bar {
  height: 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 999px;
  overflow: hidden;
}
.sudoku-tier-bar-fill {
  height: 100%;
  background: var(--accent, #7c3aed);
  transition: width 0.2s;
}
.sudoku-tier-easy   .sudoku-tier-bar-fill { background: #fbbf24; }
.sudoku-tier-medium .sudoku-tier-bar-fill { background: #34d399; }
.sudoku-tier-hard   .sudoku-tier-bar-fill { background: #a78bfa; }

.sudoku-tier-solved {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
}
.sudoku-tier-solved .muted { color: #047857; }
.sudoku-tier-active {
  background: rgba(124, 58, 237, 0.04);
}

/* ── Board ───────────────────────────────────────────────────────────── */
.sudoku-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 8px 8px 16px;
  align-self: stretch;
}
.sudoku-board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(94vw, 540px);
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border: 2px solid var(--ink, #111);
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
}
.sudoku-cell {
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  border-right: 1px solid rgba(0,0,0,0.12);
  border-bottom: 1px solid rgba(0,0,0,0.12);
  cursor: pointer;
  position: relative;
  transition: background 0.08s, color 0.08s;
  /* The big-digit value and the 3x3 notes mini-grid are stacked in the
     same cell — we toggle which is visible by emptying the other. */
  overflow: hidden;
}
.sudoku-cell-value {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  position: absolute; inset: 0;
}
/* 3x3 mini-grid of pencil-mark candidates. Each cell of the mini-grid
   reserves one of digits 1..9; an empty span = candidate not noted. The
   notes are hidden once a real value is placed (see .sudoku-cell:has-value
   override below). */
.sudoku-cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%; height: 100%;
  padding: 2px;
  pointer-events: none;
  font-size: clamp(8px, 1.7vw, 11px);
  font-weight: 500;
  color: rgba(0,0,0,0.55);
}
.sudoku-cell-note {
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
/* When the cell has a real value, the .sudoku-cell-value is shown (it's
   absolute-positioned over the notes grid). When it doesn't, the notes
   grid is the visible content. The Jinja initial render and the JS keep
   .sudoku-cell-value either filled or empty as appropriate. */
.sudoku-cell-value:not(:empty) {
  background: inherit;
  z-index: 1;
}
/* The grid's outer-right and outer-bottom edges already have the 2px
   board border, so the last column / last row drop their inner borders
   to avoid a doubled line. */
.sudoku-col-right { border-right: 0; }
.sudoku-row-bottom { border-bottom: 0; }
/* 3x3 box separators — every 3rd column / row gets a thicker left / top
   line. The first column/row borrows the board's outer border, so only
   the inner thirds need this. */
.sudoku-cell.sudoku-col-thick:not([data-c="0"]) { border-left: 2px solid var(--ink, #111); }
.sudoku-cell.sudoku-row-thick:not([data-r="0"]) { border-top: 2px solid var(--ink, #111); }

.sudoku-clue {
  background: rgba(0,0,0,0.04);
  color: var(--ink, #111);
  cursor: default;
}

.sudoku-cell.sudoku-peer {
  background: rgba(124, 58, 237, 0.06);
}
.sudoku-cell.sudoku-same {
  background: rgba(124, 58, 237, 0.18);
}
.sudoku-cell.sudoku-selected {
  background: rgba(124, 58, 237, 0.30);
  outline: 2px solid var(--accent, #7c3aed);
  outline-offset: -2px;
  z-index: 1;
}
.sudoku-cell.sudoku-bad {
  background: rgba(245, 34, 45, 0.18);
  color: #b91c1c;
}
.sudoku-cell.sudoku-bad.sudoku-selected {
  background: rgba(245, 34, 45, 0.32);
  outline-color: #dc2626;
}

.sudoku-board.sudoku-solved .sudoku-cell {
  background: rgba(34, 197, 94, 0.10);
  cursor: default;
}

/* ── Keypad ──────────────────────────────────────────────────────────── */
.sudoku-keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(94vw, 540px);
}
.sudoku-key {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.08s, border-color 0.08s, transform 0.06s, color 0.08s, opacity 0.08s;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
}
.sudoku-key-digit { font-size: 18px; line-height: 1; }
.sudoku-key-count { font-size: 10px; font-weight: 500; color: var(--muted); line-height: 1.1; }
.sudoku-key:hover {
  border-color: var(--accent, #7c3aed);
  background: rgba(124, 58, 237, 0.06);
}
.sudoku-key:active {
  transform: scale(0.96);
}
/* "All nine placed" = digit is finished — strike it through and gray it
   out so the player sees at a glance which digits are spent. The button
   is still tappable in notes mode (player might want to add a note for
   a digit that's elsewhere on the board), but big-digit placement is
   blocked by the JS guard. */
.sudoku-key-done {
  background: rgba(0,0,0,0.05);
  color: rgba(0,0,0,0.35);
  border-color: rgba(0,0,0,0.08);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.sudoku-key-done .sudoku-key-count { color: rgba(0,0,0,0.35); }
.sudoku-key-done:hover {
  border-color: rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.06);
}

/* Pencil-mark / notes mode toggle — when active, the button is visually
   "pressed" and the body gets a class so the cells can hint that taps
   will leave a note instead of placing a digit. */
.sudoku-key-erase,
.sudoku-key-notes {
  grid-column: span 2;
  font-size: 13px;
  flex-direction: row;
  gap: 6px;
  padding: 10px 0;
}
.sudoku-key-notes-active {
  background: var(--accent, #7c3aed);
  border-color: var(--accent, #7c3aed);
  color: #fff;
}
.sudoku-key-notes-active:hover {
  background: var(--accent, #7c3aed);
  color: #fff;
}
body.sudoku-notes-mode .sudoku-cell:not(.sudoku-clue):hover {
  background: rgba(124, 58, 237, 0.10);
}
@media (min-width: 600px) {
  .sudoku-keypad {
    grid-template-columns: repeat(11, 1fr);
  }
  .sudoku-key-erase,
  .sudoku-key-notes {
    grid-column: span 1;
  }
}

/* ── "Pick up where you left off" cards on the hub ──────────────────── */
.sudoku-resume-section {
  background: rgba(124, 58, 237, 0.06);
  border: 1px solid rgba(124, 58, 237, 0.18);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
}
.sudoku-resume-h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent, #7c3aed);
}
.sudoku-resume-sub { margin: 0 0 10px; font-size: 13px; }
.sudoku-resume-grid { display: grid; gap: 8px; }
.sudoku-resume-card {
  display: block;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.08s, border-color 0.12s;
}
.sudoku-resume-card.sudoku-tier-easy   { border-left-color: #fbbf24; }
.sudoku-resume-card.sudoku-tier-medium { border-left-color: #34d399; }
.sudoku-resume-card.sudoku-tier-hard   { border-left-color: #a78bfa; }
.sudoku-resume-card:hover { transform: translateY(-1px); }
.sudoku-resume-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 2px;
}
.sudoku-resume-tier { font-weight: 700; }
.sudoku-resume-date { font-size: 12px; }
.sudoku-resume-status { font-size: 13px; }

/* ── Prior-date banner on the board ──────────────────────────────────── */
.sudoku-prior-banner {
  width: min(94vw, 540px);
  padding: 8px 12px;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}
.sudoku-prior-banner a { color: inherit; text-decoration: underline; }

/* ── Hint button + wrong-cell highlight ──────────────────────────────── */
.sudoku-key-hint {
  grid-column: span 2;
  font-size: 13px;
  flex-direction: row;
  gap: 6px;
  padding: 10px 0;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.45);
  color: #92580a;
}
.sudoku-key-hint:hover {
  background: rgba(251, 191, 36, 0.25);
  border-color: rgba(251, 191, 36, 0.7);
  color: #5a3a06;
}
@media (min-width: 600px) {
  .sudoku-key-hint { grid-column: span 1; }
}
.sudoku-hint-msg {
  width: min(94vw, 540px);
  font-size: 13px;
  text-align: center;
}
/* Wrong-cell highlight kicks in when the player taps Hint. Stronger than
   the conflict glow (red bg + red ring) so it stands out as an explicit
   "fix this" signal. Cleared automatically when the cell value changes. */
.sudoku-cell.sudoku-wrong {
  background: rgba(245, 34, 45, 0.28);
  color: #b91c1c;
  box-shadow: inset 0 0 0 2px #dc2626;
  animation: sudoku-wrong-pulse 0.8s ease-out 2;
}
@keyframes sudoku-wrong-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px #dc2626; }
  50%      { box-shadow: inset 0 0 0 4px #dc2626; }
}

/* ── Action row + win banner ─────────────────────────────────────────── */
.sudoku-actions {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.sudoku-banner {
  width: min(94vw, 540px);
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
}
.sudoku-banner-win {
  background: linear-gradient(135deg, #d1f4d1 0%, #87e498 100%);
  color: #14532d;
  border: 2px solid #16a34a;
}

/* On mobile, .game-pane-center is `display: block` and the body scrolls,
   so the board + keypad sit naturally one above the other. On desktop
   we already get the inner pane scroll behaviour via .game-pane-center. */
@media (max-width: 900px) {
  .sudoku-game { padding-bottom: 24px; }
}

/* ── Celebration overlay (shown on real-time solve) ─────────────────── */
.sudoku-celebrate {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  padding: 20px;
  animation: sudoku-fade-in 0.3s ease-out;
}
.sudoku-celebrate-hidden { display: none !important; }
.sudoku-celebrate-card {
  position: relative;
  background: var(--surface, #fff);
  color: var(--ink, #111);
  border-radius: 18px;
  padding: 28px 26px 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: sudoku-pop-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.sudoku-celebrate-icon {
  width: 80px; height: 80px;
  margin: 0 auto 14px;
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4);
}
.sudoku-celebrate-icon .ti { color: #fff; stroke-width: 3; }
.sudoku-celebrate-title {
  font-size: 30px;
  font-weight: 800;
  margin: 4px 0 6px;
  color: var(--ink, #111);
  letter-spacing: -0.01em;
}
.sudoku-celebrate-sub {
  font-size: 15px;
  color: var(--muted, #6b7280);
  margin: 0 0 22px;
}
.sudoku-celebrate-actions {
  display: flex; flex-direction: column; gap: 10px;
}
.sudoku-celebrate-actions .btn-primary,
.sudoku-celebrate-actions .btn-outline {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  text-decoration: none;
  text-align: center;
  border-radius: 10px;
}
@keyframes sudoku-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes sudoku-pop-in {
  0%   { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

/* Confetti — colored squares dropping past the card. Pure CSS, no JS
   loop. 18 pieces with staggered delays + assorted colors. */
.sudoku-celebrate-confetti {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.sudoku-confetti {
  position: absolute;
  top: -20px;
  width: 10px; height: 14px;
  border-radius: 2px;
  opacity: 0;
}
.sudoku-celebrate-active .sudoku-confetti {
  animation: sudoku-confetti-fall 2.4s ease-in forwards;
}
@keyframes sudoku-confetti-fall {
  0%   { transform: translateY(-30px) rotate(0deg);    opacity: 0; }
  10%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg);  opacity: 0.4; }
}
.sudoku-confetti:nth-child(odd)  { background: #f59e0b; }
.sudoku-confetti:nth-child(even) { background: #10b981; }
.sudoku-confetti:nth-child(3n)   { background: #6366f1; }
.sudoku-confetti:nth-child(5n)   { background: #ec4899; }
.sudoku-confetti:nth-child(7n)   { background: #f5b800; }
.sudoku-confetti:nth-child(1)  { left:  4%; animation-delay: 0.00s; }
.sudoku-confetti:nth-child(2)  { left: 12%; animation-delay: 0.10s; }
.sudoku-confetti:nth-child(3)  { left: 20%; animation-delay: 0.20s; }
.sudoku-confetti:nth-child(4)  { left: 28%; animation-delay: 0.30s; }
.sudoku-confetti:nth-child(5)  { left: 36%; animation-delay: 0.05s; }
.sudoku-confetti:nth-child(6)  { left: 44%; animation-delay: 0.15s; }
.sudoku-confetti:nth-child(7)  { left: 52%; animation-delay: 0.25s; }
.sudoku-confetti:nth-child(8)  { left: 60%; animation-delay: 0.35s; }
.sudoku-confetti:nth-child(9)  { left: 68%; animation-delay: 0.45s; }
.sudoku-confetti:nth-child(10) { left: 76%; animation-delay: 0.00s; }
.sudoku-confetti:nth-child(11) { left: 84%; animation-delay: 0.10s; }
.sudoku-confetti:nth-child(12) { left: 92%; animation-delay: 0.20s; }
.sudoku-confetti:nth-child(13) { left:  8%; animation-delay: 0.50s; }
.sudoku-confetti:nth-child(14) { left: 24%; animation-delay: 0.55s; }
.sudoku-confetti:nth-child(15) { left: 40%; animation-delay: 0.60s; }
.sudoku-confetti:nth-child(16) { left: 56%; animation-delay: 0.65s; }
.sudoku-confetti:nth-child(17) { left: 72%; animation-delay: 0.70s; }
.sudoku-confetti:nth-child(18) { left: 88%; animation-delay: 0.75s; }
