.sudoku-page {
  --board-size: min(520px, calc(100svh - 148px), 46vw);
  background:
    linear-gradient(90deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
    linear-gradient(135deg, #fbf7ed 0%, #edf4ee 54%, #f8efe2 100%);
  background-size: 34px 34px, 34px 34px, auto;
}

.sudoku-page .site-header {
  width: min(1160px, calc(100% - 32px));
  padding: 14px 0 8px;
}

.sudoku-page .brand-mark {
  width: 34px;
  height: 34px;
  box-shadow: 3px 3px 0 var(--ink);
}

.sudoku-page .brand strong {
  font-size: 0.95rem;
}

.sudoku-page .brand small {
  font-size: 0.72rem;
}

.sudoku-page .top-nav a {
  padding: 7px 12px;
}

.sudoku-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(1160px, calc(100% - 32px));
  min-height: calc(100svh - 62px);
  padding-bottom: 32px;
}

.game-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  padding: 0 0 8px;
}

.game-intro h1 {
  margin-bottom: 0;
  font-size: 1.85rem;
  line-height: 1;
}

.game-intro .eyebrow,
.game-intro p:not(.eyebrow) {
  display: none;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.status-strip span {
  display: grid;
  gap: 4px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fffdf7;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 160ms var(--ease-out-quart), box-shadow 160ms var(--ease-out-quart);
}

.status-strip span:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.status-strip strong {
  font-size: 1.35rem;
}

.status-strip small {
  color: var(--muted);
  font-weight: 800;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(360px, calc(var(--board-size) + 28px)) minmax(320px, 400px);
  gap: 24px;
  align-items: start;
  min-width: 0;
}

.board-panel,
.side-panel {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(250, 245, 234, 0.94));
  box-shadow: 8px 8px 0 var(--ink);
  animation: sudoku-panel-in 420ms var(--ease-out-quint) both;
}

.board-panel {
  position: relative;
  display: grid;
  gap: 8px;
  width: fit-content;
  padding: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .segmented {
  flex: 1 1 176px;
  min-width: 176px;
  width: auto;
}

.toolbar .tool-button {
  flex: 0 0 auto;
}

.number-pad button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.sudoku-board {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, minmax(0, 1fr));
  width: var(--board-size);
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 253, 247, 0.42);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-right: 1px solid #c6bba8;
  border-bottom: 1px solid #c6bba8;
  background:
    linear-gradient(145deg, rgba(255, 253, 247, 0.86), rgba(255, 253, 247, 0) 58%),
    #fffdf7;
  color: #22312b;
  font: inherit;
  font-size: 1.8rem;
  font-weight: 850;
  cursor: pointer;
  transform: translateZ(0);
  transition:
    background 120ms var(--ease-out-quart),
    color 120ms var(--ease-out-quart),
    outline-color 120ms var(--ease-out-quart),
    filter 120ms var(--ease-out-quart);
}

.cell:hover:not(.selected) {
  filter: brightness(0.985);
}

.cell:nth-child(3n) {
  border-right: 3px solid var(--ink);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 3px solid var(--ink);
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 73) {
  border-bottom: 0;
}

.cell.given {
  background: #f1ead9;
  color: #1e2a25;
}

.cell.user {
  color: #2f7a5a;
}

.cell.peer {
  background: #edf5ec;
}

.cell.same-number {
  background: #fae8c2;
}

.cell.selected {
  z-index: 2;
  background: #dceccf;
  outline: 3px solid var(--leaf);
  outline-offset: -3px;
}

.cell.conflict {
  background: #f8d1c8;
  color: #8f2c1b;
}

.cell.entered {
  animation: sudoku-enter 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.cell.error-shake {
  animation: sudoku-error 260ms cubic-bezier(0.25, 1, 0.5, 1);
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 5px;
  color: #6f7b75;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.notes span {
  display: grid;
  place-items: center;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: 100%;
  gap: 6px;
  margin-bottom: 16px;
}

.number-pad button {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #fffdf7;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 1rem;
  transition:
    transform 130ms var(--ease-out-quart),
    box-shadow 130ms var(--ease-out-quart),
    background 130ms var(--ease-out-quart);
}

.number-pad button:hover {
  transform: translate(-1px, -1px);
  background: #fff7e6;
  box-shadow: 4px 4px 0 var(--ink);
}

.number-pad button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

.number-pad button:last-child {
  grid-column: span 1;
  background: #f7f0df;
  font-size: 0.9rem;
}

.game-message {
  min-height: 22px;
  max-width: var(--board-size);
  margin-bottom: 0;
  color: #4d5c55;
  font-size: 0.92rem;
  font-weight: 800;
}

.side-panel {
  align-self: start;
  max-width: 470px;
  padding: 16px;
  animation-delay: 80ms;
}

.leaderboard-head {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 12px;
}

.leaderboard-head h2 {
  font-size: 1.55rem;
}

.leaderboard-head select {
  min-height: 38px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(34, 49, 43, 0.18);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fbf7ed;
}

.rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: var(--ink);
  color: #fffdf7;
  font-size: 0.8rem;
  font-weight: 900;
}

.leaderboard-list strong {
  display: block;
}

.leaderboard-list small {
  color: var(--muted);
}

.empty-board-note {
  grid-template-columns: 1fr !important;
  color: var(--muted);
}

.sudoku-rules {
  padding-top: 40px;
  padding-bottom: 28px;
}

@media (max-width: 960px) {
  .sudoku-page {
    --board-size: min(calc(100vw - 60px), 520px);
  }

  .game-intro,
  .play-layout {
    grid-template-columns: 1fr;
  }

  .game-intro h1 {
    font-size: 1.85rem;
  }

  .status-strip {
    width: 100%;
  }

  .board-panel {
    width: 100%;
    justify-items: center;
  }

  .toolbar,
  .game-message {
    width: var(--board-size);
  }

  .side-panel {
    max-width: none;
  }
}

@media (max-width: 620px) {
  .sudoku-page {
    --board-size: min(calc(100vw - 84px), 330px);
  }

  .sudoku-page .site-header {
    width: min(100% - 28px, 1160px);
    position: sticky;
    z-index: 30;
    top: 0;
    padding: 10px 0 6px;
    background:
      linear-gradient(90deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
      linear-gradient(0deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
      linear-gradient(135deg, rgba(251, 247, 237, 0.96), rgba(237, 244, 238, 0.96));
    background-size: 34px 34px, 34px 34px, auto;
  }

  .sudoku-page .brand strong {
    font-size: 0.9rem;
  }

  .sudoku-page .brand small {
    display: none;
  }

  .sudoku-shell {
    width: min(100% - 28px, 1160px);
    min-height: auto;
    padding-bottom: 20px;
  }

  .game-intro {
    padding: 4px 0 8px;
  }

  .number-pad {
    border: 2px solid var(--ink);
    border-radius: 8px;
    padding: 8px;
    background: rgba(255, 253, 247, 0.74);
    box-shadow: 2px 2px 0 rgba(34, 49, 43, 0.9);
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-bottom: 12px;
  }

  .toolbar {
    width: 100%;
    gap: 6px;
  }

  .toolbar .segmented {
    flex-basis: 100%;
    min-width: 0;
  }

  .segmented button,
  .tool-button {
    min-height: 44px;
    padding: 0 8px;
  }

  .number-pad button:last-child {
    grid-column: span 5;
  }

  .number-pad button {
    min-height: 42px;
    box-shadow: 2px 2px 0 var(--ink);
  }

  .status-strip {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
  }

  .status-strip span {
    min-height: 52px;
    padding: 8px 7px;
    box-shadow: 2px 2px 0 var(--ink);
  }

  .status-strip strong {
    font-size: 1.08rem;
  }

  .status-strip small {
    font-size: 0.78rem;
  }

  .game-intro h1 {
    font-size: clamp(1.55rem, 8vw, 1.75rem);
  }

  .board-panel,
  .side-panel {
    box-shadow: 5px 5px 0 var(--ink);
  }

  .board-panel {
    padding: 7px;
  }

  .cell {
    font-size: 1.35rem;
  }

  .notes {
    font-size: 0.54rem;
    padding: 3px;
  }

  .side-panel {
    padding: 12px;
  }

  .leaderboard-head {
    align-items: center;
    gap: 8px;
  }

  .leaderboard-head h2 {
    font-size: 1.2rem;
  }
}

@media (max-width: 380px) {
  .sudoku-page {
    --board-size: min(calc(100vw - 76px), 312px);
  }

  .cell {
    font-size: 1.18rem;
  }
}

@keyframes sudoku-enter {
  0% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

@keyframes sudoku-error {
  0% { transform: translateX(0); }
  30% { transform: translateX(-3px); }
  65% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

@keyframes sudoku-panel-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell {
    animation: none !important;
    transition: none !important;
  }
}
