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

.sudoku-wrap {
  max-width: 920px;
}

#game-stage {
  position: relative;
}

.sudoku-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 10px;
}

.sudoku-id {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.86rem;
  font-weight: 800;
  padding: 7px 12px;
}

.sudoku-game {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.sudoku-topbar,
.sudoku-options {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.sudoku-pad {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.sudoku-select-wrap,
.sudoku-stat,
.sudoku-toggle {
  align-items: center;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 3px 0 rgba(34, 49, 74, 0.12);
  color: var(--ink-soft);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  gap: 8px;
  min-height: 40px;
  padding: 7px 10px;
}

.sudoku-select-wrap select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  padding: 4px 8px;
}

.sudoku-stat strong {
  color: var(--pink-deep);
  font-family: var(--font-score);
  font-size: 1.05rem;
}

.sudoku-toggle input {
  accent-color: var(--teal);
}

.sudoku-status {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  min-height: 1.35em;
  text-align: center;
}

.sudoku-board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}

.sudoku-board {
  aspect-ratio: 1;
  background: var(--ink);
  border: 3px solid var(--ink);
  display: grid;
  gap: 0;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  max-width: min(78vh, 620px, 100%);
  width: 100%;
}

.sudoku-cell {
  align-items: center;
  background: #fff;
  border: 1px solid #cfd8e6;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 4.2vw, 2rem);
  font-weight: 800;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  position: relative;
}

.sudoku-cell:nth-child(3n) {
  border-right-width: 3px;
  border-right-color: var(--ink);
}
.sudoku-cell:nth-child(9n) {
  border-right-width: 1px;
  border-right-color: #cfd8e6;
}
.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom-width: 3px;
  border-bottom-color: var(--ink);
}

.sudoku-cell.given {
  background: #f0f5ff;
  color: var(--ink);
  cursor: default;
}
.sudoku-cell.selected {
  background: #fff1b8;
  box-shadow: inset 0 0 0 3px var(--yellow-deep);
  z-index: 1;
}
.sudoku-cell.peer {
  background: #edf9fb;
}
.sudoku-cell.same-number {
  background: #dcf4ef;
}
.sudoku-cell.wrong {
  background: #ffe4ec;
  color: var(--pink-deep);
}
.sudoku-cell.hint-related {
  background: #f7edff;
}
.sudoku-cell.hint-primary {
  background: #fff0a6;
  box-shadow: inset 0 0 0 3px #f4a259;
  z-index: 2;
}
.sudoku-cell.hint-eliminate {
  background: #ffe2d5;
  box-shadow: inset 0 0 0 3px #ff8a47;
  z-index: 2;
}

.candidate-grid {
  color: var(--ink-soft);
  display: grid;
  font-family: var(--font-body);
  font-size: clamp(0.48rem, 1.7vw, 0.72rem);
  font-weight: 800;
  grid-template-columns: repeat(3, 1fr);
  height: 100%;
  line-height: 1;
  opacity: 0.9;
  padding: 10%;
  width: 100%;
}
.candidate-grid span {
  align-items: center;
  display: flex;
  justify-content: center;
}

.pad-numbers {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(9, minmax(34px, 1fr));
  max-width: 520px;
  width: 100%;
}

.pad-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.sudoku-pad button,
.sudoku-topbar .primary {
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(34, 49, 74, 0.14);
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 800;
}

.pad-num {
  aspect-ratio: 1;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
}

.pad-num.active,
.pad-mode.active,
.sudoku-topbar .primary {
  background: var(--yellow);
}

.pad-mode,
.pad-erase,
.pad-undo,
.pad-check,
.pad-hint {
  background: var(--surface);
  color: var(--ink);
  min-height: 40px;
  padding: 8px 12px;
}

.pad-check {
  background: var(--teal);
}

.pad-hint {
  background: var(--yellow);
}

.pad-undo:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.sudoku-celebration {
  align-items: center;
  background: rgba(34, 49, 74, 0.22);
  display: flex;
  inset: 0;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  z-index: 35;
}
.sudoku-celebration[hidden] {
  display: none;
}
.sudoku-celebration-badge {
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 16px 0 rgba(34, 49, 74, 0.18);
  color: var(--ink);
  display: grid;
  gap: 6px;
  padding: 22px 28px;
  text-align: center;
  transform: scale(0.74);
  opacity: 0;
}
.sudoku-celebration-badge strong {
  color: var(--pink-deep);
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5vw, 2.2rem);
}
.sudoku-celebration-badge span {
  color: var(--ink-soft);
  font-weight: 800;
}
.sudoku-celebration.is-active .sudoku-celebration-badge {
  animation: sudoku-badge-pop 1.6s cubic-bezier(0.19, 1, 0.22, 1) both;
}
.sudoku-confetti {
  border: 1px solid rgba(34, 49, 74, 0.22);
  border-radius: 3px;
  height: 12px;
  left: var(--x);
  position: absolute;
  top: -22px;
  transform: translateX(-50%);
  width: 8px;
}
.sudoku-celebration.is-active .sudoku-confetti {
  animation: sudoku-confetti-fall 1.55s ease-in var(--delay) both;
}

@keyframes sudoku-badge-pop {
  0% { opacity: 0; transform: scale(0.74) translateY(20px); }
  22% { opacity: 1; transform: scale(1.08) translateY(0); }
  38% { transform: scale(1); }
  82% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95) translateY(-10px); }
}

@keyframes sudoku-confetti-fall {
  0% { opacity: 0; transform: translate(-50%, -20px) rotate(0deg); }
  14% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), 110vh) rotate(var(--spin)); }
}

@media (prefers-reduced-motion: reduce) {
  .sudoku-celebration.is-active .sudoku-celebration-badge,
  .sudoku-celebration.is-active .sudoku-confetti {
    animation-duration: 0.01ms;
  }
}

#game-stage:fullscreen,
#game-stage.is-ios-fullscreen {
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  justify-content: flex-start;
  margin: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#game-stage:fullscreen .sudoku-board,
#game-stage.is-ios-fullscreen .sudoku-board {
  max-width: min(72vh, 620px, 96vw);
  max-width: min(72dvh, 620px, 96vw);
}

@media (max-width: 640px) {
  #game-stage {
    padding-left: 8px;
    padding-right: 8px;
  }
  .sudoku-board {
    max-width: min(96vw, 540px);
  }
  .pad-numbers {
    grid-template-columns: repeat(9, minmax(28px, 1fr));
  }
  .pad-num {
    font-size: 0.95rem;
  }
}
