.topbar {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  letter-spacing: 0.22em;
  font-size: 28px;
}

.brand p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sudoku-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

.sudoku-panel {
  display: grid;
  gap: 16px;
  justify-items: center;
}

.sudoku-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.difficulty-btn {
  min-width: 96px;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.difficulty-btn:hover {
  transform: translateY(-1px);
  color: var(--fg);
  border-color: var(--border);
  background: rgba(255,255,255,.04);
}

html[data-theme="light"] .difficulty-btn:hover {
  background: rgba(16,17,20,.04);
}

.difficulty-btn.active {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
  box-shadow: none;
}

.sudoku-meta {
  display: grid;
  gap: 4px;
  text-align: center;
}

.check-info {
  color: var(--muted);
  min-height: 24px;
}

.sudoku-board {
  width: min(92vw, 540px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--fg);
  background: var(--bg);
  margin: 0 auto;
  transition: opacity 180ms ease, filter 180ms ease, transform 180ms ease;
}

.sudoku-board.is-locked {
  opacity: 0.58;
  filter: grayscale(0.3);
  pointer-events: none;
}

.sudoku-cell {
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 2.8vw, 28px);
  font-weight: 700;
  background: color-mix(in srgb, var(--bg) 92%, var(--fg) 8%);
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  transition:
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease,
    filter 140ms ease;
  transform-origin: center;
  will-change: transform, box-shadow, background-color, filter;
}

.sudoku-cell:hover {
  background: color-mix(in srgb, var(--bg) 86%, var(--fg) 14%);
}

.sudoku-cell.selected {
  outline: 2px solid var(--tile-correct);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--bg) 72%, var(--tile-correct) 28%);
}

.sudoku-cell.given {
  background: color-mix(in srgb, var(--bg) 82%, var(--fg) 18%);
  color: var(--fg);
  font-weight: 800;
  cursor: default;
}

.sudoku-cell.user {
  color: var(--tile-correct);
}

.sudoku-cell.invalid {
  background: color-mix(in srgb, var(--bg) 60%, #b3261e 40%);
  color: #fff;
}

.sudoku-cell.row-complete,
.sudoku-cell.col-complete {
  background: var(--tile-correct);
  color: #fff;
  border-color: var(--border);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}

.sudoku-cell.border-right {
  border-right: 3px solid var(--fg);
}

.sudoku-cell.border-bottom {
  border-bottom: 3px solid var(--fg);
}

.sudoku-actions {
  width: min(92vw, 540px);
  display: grid;
  gap: 10px;
  justify-items: center;
}

.sudoku-actions-top {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sudoku-actions-top > .btn {
  min-width: 145px;
}

.number-tray {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
}

.tray-num {
  width: 100%;
  height: 46px;
  min-width: 0;
  min-height: 46px;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  box-shadow: none;
}

.tray-num:hover {
  transform: translateY(-1px);
  border-color: var(--border);
  background: rgba(255,255,255,.04);
}

html[data-theme="light"] .tray-num:hover {
  background: rgba(16,17,20,.04);
}

.btn-warning {
  background: var(--tile-present);
  color: #fff;
  border-color: var(--tile-present);
}

.btn-warning:hover {
  filter: brightness(1.05);
}

.sudoku-cell.pop {
  animation: sudokuPop 220ms cubic-bezier(.2,.8,.2,1);
}

.sudoku-cell.pulse {
  animation: sudokuPulse 1.1s ease-in-out infinite;
}

.sudoku-cell.spark {
  animation: sudokuSpark 700ms cubic-bezier(.16,1,.3,1);
}

.sudoku-board.board-win {
  animation: boardCelebrate 1400ms ease-in-out 2;
}

.sudoku-cell.board-dance {
  animation: cellDance 820ms cubic-bezier(.16,1,.3,1);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.icon-btn:focus-visible,
.modal-close:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  z-index: 1001;
  width: min(92vw, 460px);
  margin: 10vh auto 0;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 18px 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}

.modal-card h2 {
  margin: 0 32px 14px 0;
  font-size: 22px;
  text-align: center;
}

.modal-card p {
  margin: 10px 0;
  line-height: 1.45;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.help-example-sudoku {
  display: flex;
  justify-content: center;
  margin: 16px auto 14px;
}

.help-sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 28px);
  grid-template-rows: 28px;
  border: 2px solid var(--fg);
}

.help-sudoku-cell {
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  background: color-mix(in srgb, var(--bg) 92%, var(--fg) 8%);
  color: var(--fg);
}

.help-sudoku-cell.given {
  background: color-mix(in srgb, var(--bg) 82%, var(--fg) 18%);
  color: var(--fg);
  font-weight: 800;
}

.help-sudoku-cell.user {
  background: color-mix(in srgb, var(--bg) 72%, var(--tile-correct) 28%);
  color: #fff;
  outline: 2px solid var(--tile-correct);
  outline-offset: -2px;
}

.modal-credit {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.modal-credit p {
  margin: 4px 0;
  text-align: center;
}

body.modal-open {
  overflow: hidden;
}

@keyframes sudokuPop {
  0% {
    transform: scale(0.78);
    filter: brightness(1);
  }
  55% {
    transform: scale(1.18);
    filter: brightness(1.08);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes sudokuPulse {
  0% {
    transform: scale(1);
    box-shadow: inset 0 0 0 0 rgba(255,255,255,0);
  }
  50% {
    transform: scale(1.07);
    box-shadow: inset 0 0 0 999px rgba(255,255,255,0.08);
  }
  100% {
    transform: scale(1);
    box-shadow: inset 0 0 0 0 rgba(255,255,255,0);
  }
}

@keyframes sudokuSpark {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  20% {
    transform: scale(1.18);
    filter: brightness(1.35);
  }
  45% {
    transform: scale(0.94);
    filter: brightness(1.12);
  }
  70% {
    transform: scale(1.08);
    filter: brightness(1.2);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes boardCelebrate {
  0% {
    transform: scale(1) rotate(0deg);
    filter: brightness(1);
  }
  15% {
    transform: scale(1.02) rotate(-0.4deg);
    filter: brightness(1.08);
  }
  35% {
    transform: scale(1.035) rotate(0.4deg);
    filter: brightness(1.18);
  }
  55% {
    transform: scale(1.015) rotate(-0.25deg);
    filter: brightness(1.1);
  }
  75% {
    transform: scale(1.03) rotate(0.2deg);
    filter: brightness(1.14);
  }
  100% {
    transform: scale(1) rotate(0deg);
    filter: brightness(1);
  }
}

@keyframes cellDance {
  0% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
  20% {
    transform: translateY(-12px) scale(1.12) rotate(-2deg);
  }
  40% {
    transform: translateY(0) scale(0.96) rotate(2deg);
  }
  60% {
    transform: translateY(-7px) scale(1.08) rotate(-1deg);
  }
  80% {
    transform: translateY(0) scale(1.02) rotate(1deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@media (max-width: 640px) {
  .number-tray {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .sudoku-actions-top > .btn {
    min-width: 132px;
  }
}