:root {
  color-scheme: light;
  --paper: #f2eee6;
  --paper-deep: #e7dfd2;
  --ink: #1f2520;
  --muted: #666a62;
  --line: #bbb5aa;
  --line-strong: #29332b;
  --moss: #315b47;
  --moss-dark: #234234;
  --moss-soft: #dce7df;
  --amber: #d88c36;
  --danger: #a13d32;
  --danger-soft: #f6ddd7;
  --focus: #1b6fa8;
  --shadow: 0 22px 70px rgb(49 43 35 / 12%);
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 6%, rgb(255 255 255 / 72%), transparent 31rem),
    linear-gradient(145deg, var(--paper) 0%, #eee8de 55%, var(--paper-deep) 100%);
  font-size: 1rem;
  line-height: 1.55;
}

button,
select {
  font: inherit;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.page-frame {
  width: min(100% - 2rem, 74rem);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 5rem;
  border-bottom: 1px solid rgb(31 37 32 / 18%);
}

.brand {
  display: inline-flex;
  gap: 0.7rem;
  align-items: center;
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.4rem;
  height: 2.4rem;
  place-items: center;
  border: 1px solid currentColor;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.85rem;
}

.eyebrow,
.section-index,
.panel-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow {
  display: none;
}

.intro {
  display: grid;
  gap: 1.5rem;
  padding: 3.5rem 0 2.5rem;
}

.intro h1 {
  max-width: 13ch;
  margin: 0.45rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 13vw, 5.8rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.94;
}

.intro-copy {
  max-width: 32rem;
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.game-panel {
  margin-inline: -0.5rem;
  padding: 1.25rem 0.5rem 1.5rem;
  border: 1px solid rgb(31 37 32 / 12%);
  background: rgb(250 248 243 / 72%);
  box-shadow: var(--shadow);
}

.game-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
}

.game-toolbar h2,
.keyboard-help h2,
.dialog h2 {
  margin: 0.25rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  line-height: 1.1;
}

.game-toolbar h2 {
  font-size: 1.8rem;
}

.timer-block {
  display: grid;
  text-align: right;
}

.timer-block span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.timer-block time {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.game-controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: center;
  padding: 1rem 0.5rem 0;
}

.game-controls label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.game-controls select {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--ink);
  background: #faf8f3;
  padding: 0 0.7rem;
}

.game-controls .button {
  grid-column: 1 / -1;
}

.game-status {
  min-height: 1.6rem;
  margin: 0;
  padding: 0.85rem 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.play-area {
  display: grid;
  gap: 1.4rem;
}

.board-shell {
  position: relative;
  width: 100%;
  max-width: 35rem;
  margin-inline: auto;
  padding: 0.5rem;
  background: var(--line-strong);
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1;
  background: var(--line-strong);
  gap: 1px;
}

.sudoku-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  color: var(--moss);
  background: #faf8f3;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1rem, 6vw, 1.65rem);
  font-weight: 650;
  line-height: 1;
}

.sudoku-cell:nth-child(3n):not(:nth-child(9n)) {
  box-shadow: 2px 0 0 var(--line-strong);
}

.sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
  box-shadow: inset 0 -2px 0 var(--line-strong);
}

.sudoku-cell:nth-child(3n):not(:nth-child(9n)):nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(3n):not(:nth-child(9n)):nth-child(n + 46):nth-child(-n + 54) {
  box-shadow: 2px 0 0 var(--line-strong), inset 0 -2px 0 var(--line-strong);
}

.sudoku-cell.is-given {
  color: var(--ink);
  font-weight: 800;
}

.sudoku-cell.is-related {
  background: #ece9df;
}

.sudoku-cell.is-same {
  background: var(--moss-soft);
}

.sudoku-cell.is-selected {
  z-index: 1;
  background: #d4e1d8;
  outline: 3px solid var(--moss);
  outline-offset: -3px;
}

.sudoku-cell.is-conflict {
  color: var(--danger);
  background: var(--danger-soft);
}

.conflict-marker {
  position: absolute;
  top: 2px;
  right: 3px;
  display: grid;
  width: 0.9rem;
  height: 0.9rem;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--danger);
  font-family: sans-serif;
  font-size: 0.65rem;
  font-weight: 900;
}

.pause-cover {
  position: absolute;
  inset: 0.5rem;
  z-index: 4;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.8rem;
  color: #f8f4ec;
  background: rgb(35 66 52 / 96%);
  text-align: center;
}

.pause-cover[hidden] {
  display: none;
}

.pause-cover > span {
  font-family: Georgia, serif;
  font-size: 3rem;
}

.input-panel {
  display: grid;
  gap: 1rem;
  padding: 0 0.5rem;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 0.55rem;
}

.number-key {
  min-height: 48px;
  border: 1px solid var(--line);
  color: var(--moss-dark);
  background: #faf8f3;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 700;
}

.number-key:hover,
.number-key:active {
  border-color: var(--moss);
  background: var(--moss-soft);
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  padding: 0.65rem 1rem;
  font-weight: 750;
}

.button-primary {
  color: #fff;
  background: var(--moss);
}

.button-primary:hover {
  background: var(--moss-dark);
}

.button-secondary {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #faf8f3;
}

.button-quiet {
  color: var(--muted);
  background: transparent;
}

.button-danger {
  color: #fff;
  background: var(--danger);
}

.button-wide {
  width: 100%;
  margin-top: 0.55rem;
}

.session-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot,
.legend-alert {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
}

.legend-given {
  background: var(--ink);
}

.legend-entry {
  background: var(--moss);
}

.legend-alert {
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--danger);
  font-size: 0.6rem;
  font-style: normal;
  font-weight: 900;
}

.keyboard-help {
  padding: 4rem 0;
}

.keyboard-help h2 {
  max-width: 18ch;
  margin-top: 0.5rem;
  font-size: clamp(2rem, 9vw, 3.7rem);
  letter-spacing: -0.035em;
}

.keyboard-help > p:last-child {
  max-width: 38rem;
  color: var(--muted);
}

footer {
  padding: 1.5rem 0 2.5rem;
  border-top: 1px solid rgb(31 37 32 / 18%);
  color: var(--muted);
  font-size: 0.82rem;
}

.dialog {
  width: min(32rem, calc(100% - 2rem));
  border: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgb(24 31 26 / 68%);
  backdrop-filter: blur(3px);
}

.dialog form {
  padding: 1.5rem;
}

.dialog h2 {
  margin-top: 0.5rem;
  font-size: 2rem;
}

.dialog p:not(.section-index) {
  color: var(--muted);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 1.5rem;
}

.complete-dialog {
  text-align: center;
}

.completion-mark {
  display: grid;
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1rem;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--moss);
  font-size: 2rem;
}

@media (min-width: 40rem) {
  .page-frame {
    width: min(100% - 4rem, 74rem);
  }

  .eyebrow {
    display: block;
  }

  .intro {
    grid-template-columns: 1.5fr 1fr;
    align-items: end;
    padding: 5rem 0 3.5rem;
  }

  .game-panel {
    margin-inline: 0;
    padding: 1.75rem;
  }

  .game-controls {
    grid-template-columns: auto 10rem 1fr;
    padding-inline: 0;
  }

  .game-controls .button {
    grid-column: auto;
    justify-self: end;
  }

  .game-toolbar,
  .game-status,
  .input-panel {
    padding-inline: 0;
  }

  .number-pad {
    grid-template-columns: repeat(9, 1fr);
  }
}

@media (min-width: 60rem) {
  .play-area {
    grid-template-columns: minmax(30rem, 35rem) minmax(15rem, 1fr);
    align-items: start;
    gap: 2.5rem;
  }

  .input-panel {
    position: sticky;
    top: 1rem;
    align-content: start;
    padding-top: 0.5rem;
  }

  .number-pad {
    grid-template-columns: repeat(3, 1fr);
  }

  .number-key {
    min-height: 4rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .button,
  .number-key,
  .sudoku-cell {
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
  }
}
