:root {
  color-scheme: light;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  color: #23332f;
  background: #f5f2e9;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #23332f;
  --muted: #6b7770;
  --paper: #fffefa;
  --line: #c9cec4;
  --accent: #d65b3d;
  --green: #27725d;
}

.game-card-copy .daily-status {
  min-height: 1rem;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 650;
}

.game-card-actions {
  display: grid;
  min-width: 190px;
  gap: 0.6rem;
}

.game-card-actions > .button {
  width: 100%;
}

.freeplay-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 0.5rem;
}

.freeplay-actions .button {
  min-width: 4.3rem;
}

.game-card .button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 12% 0%, #e8e4d7 0, transparent 40rem),
    #f5f2e9;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.page {
  width: min(100% - 2rem, 1024px);
  margin: 0 auto;
  padding: 2rem 0 1.5rem;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid #dcd9cf;
}

.brand {
  display: block;
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 100%;
  height: 100%;
}

.eyebrow,
.control-label {
  margin: 0 0 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.masthead h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 4vw, 2.25rem);
  font-weight: 500;
  letter-spacing: -0.04em;
}

.edition {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: right;
}

.masthead .edition {
  max-width: 24rem;
  line-height: 1.45;
}

.home-menu,
.game-screen {
  margin: 2rem auto 0;
}

.section-heading {
  margin-bottom: 1rem;
}

.section-heading h2,
.game-intro h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 4vw, 2.15rem);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.game-card,
.leaderboard-card,
.solved-panel {
  border: 1px solid #e7e3d8;
  border-radius: 1rem;
  background: var(--paper);
  box-shadow: 0 1rem 2.5rem #363b300a;
}

.game-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
}

.game-card + .game-card {
  margin-top: 1rem;
}

.game-icon {
  display: grid;
  width: 4rem;
  height: 4rem;
  place-items: center;
  border-radius: 0.8rem;
  background: #eaf2ed;
  color: var(--green);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 700;
}

.game-icon svg {
  width: 2.8rem;
  height: 2.8rem;
}

.sudoku-icon svg {
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sudoku-icon svg .icon-heavy {
  stroke-width: 3;
}

.sudoku-icon svg circle {
  fill: var(--green);
  stroke: none;
}

.kemkem-icon {
  border-radius: 50%;
  background: var(--green);
}

.kemkem-icon svg {
  fill: none;
  stroke: #fffefa;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.kemkem-icon svg path:last-child {
  stroke-width: 2.5;
}

.game-card-copy h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  font-weight: 500;
}

.game-card-copy p:last-child {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.size-picker {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.size-picker select,
#username {
  min-height: 2.75rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid #d6d9d0;
  border-radius: 0.55rem;
  background: var(--paper);
  color: var(--ink);
}

.button {
  min-height: 2.8rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.button-secondary {
  border-color: #d6d9d0;
  background: var(--paper);
  color: var(--ink);
}

.button-primary {
  background: var(--green);
  color: white;
}

.button-primary:hover {
  background: #1d5e4b;
}

.button[aria-pressed="true"] {
  border-color: var(--green);
  background: #eaf2ed;
  color: var(--green);
}

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.back-button {
  padding: 0.3rem 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 700;
}

.game-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.instructions {
  max-width: 440px;
  margin: 0;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.55;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(260px, 560px) minmax(200px, 1fr);
  align-items: start;
  justify-content: center;
  gap: clamp(1.5rem, 5vw, 3.5rem);
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid #e7e3d8;
  border-radius: 1.25rem;
  background: var(--paper);
  box-shadow: 0 1.5rem 4rem #363b3010;
}

.board-wrap {
  width: 100%;
}

.board {
  display: grid;
  width: min(100%, 560px);
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: clamp(1rem, 3.6vw, 2rem);
  font-weight: 650;
  transition: background-color 120ms ease, color 120ms ease;
}

.cell.cage-right {
  border-right: 2px solid var(--ink);
}

.cell.cage-bottom {
  border-bottom: 2px solid var(--ink);
}

.cell.last-column {
  border-right: 0;
}

.cell.last-row {
  border-bottom: 0;
}

.sudoku-board .cell.box-right {
  border-right: 2px solid var(--ink);
}

.sudoku-board .cell.box-bottom {
  border-bottom: 2px solid var(--ink);
}

.sudoku-board .cell.given {
  background: #f0efe8;
  font-weight: 800;
}

.cell.selected {
  z-index: 1;
  background: #f7e9d8;
  box-shadow: inset 0 0 0 3px var(--accent);
}

.cell.duplicate {
  color: #b52e25;
}

.cell:focus-visible,
.button:focus-visible,
.back-button:focus-visible,
.brand:focus-visible,
.number-button:focus-visible {
  z-index: 2;
  outline: 3px solid #236f83;
  outline-offset: -3px;
}

.cage-label {
  position: absolute;
  top: 0.08rem;
  left: 0.1rem;
  z-index: 1;
  color: #42534c;
  font-size: clamp(0.48rem, 1.25vw, 0.76rem);
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

.cage-error-dot {
  display: inline-block;
  width: 0.38rem;
  height: 0.38rem;
  margin-left: 0.12rem;
  border-radius: 50%;
  background: #c7332b;
  vertical-align: 0.05rem;
}

.cage-error-dot[hidden] {
  display: none;
}

.cell-notes {
  position: absolute;
  inset: 20% 8% 5%;
  display: grid;
  overflow: hidden;
  align-content: center;
  color: #6b7770;
  font-size: clamp(0.43rem, 1vw, 0.68rem);
  font-weight: 500;
  line-height: 1.25;
  overflow-wrap: anywhere;
  pointer-events: none;
}

.cell-value {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.keyboard-hint {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
  text-align: center;
}

.controls {
  min-width: 0;
  align-self: center;
}

.timer-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e7e3d8;
}

.control-label {
  margin-bottom: 0.65rem;
}

.timer-row .control-label {
  margin: 0;
}

.timer {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  font-weight: 700;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), minmax(36px, 1fr));
  gap: 0.4rem;
}

.number-button {
  min-width: 0;
  min-height: 2.8rem;
  border: 1px solid #d6d9d0;
  border-radius: 0.55rem;
  background: #f8f7f1;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
}

.number-button:hover {
  border-color: var(--green);
  background: #eaf2ed;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.action-buttons .button {
  padding-inline: 0.45rem;
  font-size: 0.82rem;
}

.feedback {
  min-height: 2.8rem;
  margin: 0.85rem 0 0;
  color: var(--green);
  font-size: 0.86rem;
  font-weight: 650;
  line-height: 1.45;
}

.feedback.error {
  color: #a53d2a;
}

.rule-note,
.local-note {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.5;
}

.rule-note strong {
  color: var(--ink);
}

.personal-best {
  min-height: 1.2rem;
  margin: 0.65rem 0;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 700;
}

.leaderboard-card {
  margin-top: 1rem;
  padding: 1rem;
  box-shadow: none;
}

.leaderboard-card h3,
.solved-panel h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  font-weight: 500;
}

.leaderboard-card ol {
  display: grid;
  gap: 0.4rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard-card li:not(.leaderboard-empty) {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
}

.leaderboard-card time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.leaderboard-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.solved-panel {
  margin-top: 1rem;
  padding: 1.25rem;
}

.solved-panel > p {
  margin: 0.5rem 0 1rem;
  color: var(--muted);
}

#username-form label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.86rem;
  font-weight: 650;
}

.username-row {
  display: flex;
  gap: 0.5rem;
}

#username {
  flex: 1;
}

footer {
  padding: 1.5rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

footer p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .page {
    width: min(100% - 1.25rem, 560px);
    padding-top: 1rem;
  }

  .home-menu,
  .game-screen {
    margin-top: 1.2rem;
  }

  .game-card {
    grid-template-columns: auto 1fr;
    gap: 0.8rem;
    padding: 1rem;
  }

  .game-card-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .game-icon {
    width: 3.25rem;
    height: 3.25rem;
  }

  .edition {
    font-size: 0.75rem;
  }

  .game-intro {
    display: block;
    margin-bottom: 1rem;
  }

  .instructions {
    margin-top: 0.55rem;
  }

  .play-area {
    grid-template-columns: 1fr;
    gap: 1.2rem;
    padding: 0.85rem;
  }

  .board-wrap {
    width: min(100%, 560px);
    margin: 0 auto;
  }

  .controls {
    width: min(100%, 560px);
    margin: 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
