:root {
  --bg: #f3efe6;
  --panel: #fffdf8;
  --ink: #1f2a33;
  --muted: #6b7780;
  --grid: #1f2a33;
  --line: #c5ccd2;
  --given: #1f2a33;
  --user: #1f6f8b;
  --select: #d8ebf2;
  --peer: #eef3f5;
  --error: #c0392b;
  --error-bg: #f8e0dc;
  --accent: #c45c26;
  --notes: #7a8690;
  --btn: #e7ddd0;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(160deg, #f7f2e8 0%, #e8efe9 55%, #f3efe6 100%);
}

#game-container {
  max-width: 460px;
  margin: 56px auto 24px;
  padding: 16px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
}

.tagline {
  margin: 4px 0 14px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.diff-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

#difficulty {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--panel);
  color: var(--ink);
}

#timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(92vw, 420px);
  margin: 0 auto;
  border: 2px solid var(--grid);
  background: var(--panel);
  user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: clamp(1rem, 4.5vw, 1.45rem);
  font-weight: 700;
  cursor: pointer;
}

.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
.cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--grid); }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--grid); }

.cell.given { color: var(--given); }
.cell.user { color: var(--user); }
.cell.peer { background: var(--peer); }
.cell.selected { background: var(--select); }
.cell.error { background: var(--error-bg); color: var(--error); }
.cell.same { outline: 2px solid rgba(31, 111, 139, 0.35); outline-offset: -2px; }

.notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.45rem, 2vw, 0.65rem);
  font-weight: 600;
  color: var(--notes);
  line-height: 1;
  pointer-events: none;
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

#status {
  min-height: 1.35em;
  margin: 10px 0;
  color: var(--accent);
  font-weight: 600;
}

#numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  max-width: 420px;
  margin: 0 auto 12px;
}

#numpad button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}

#numpad button:hover { background: var(--select); }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.actions button {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

@media (max-width: 420px) {
  #game-container { margin-top: 48px; padding: 10px; }
  .actions button { padding: 8px 10px; font-size: 0.9rem; }
}
