:root {
  --bg: #1b1d23;
  --panel: #23262e;
  --line-soft: #3a3f4b;
  --line-strong: #d8dbe2;
  --text: #eceef2;
  --text-dim: #9aa0ac;
  --given: #d8dbe2;
  --user-num: #6fb1ff;
  --accent: #6fb1ff;
  --bad: #ff6b6b;
  --selected: #33465e;
  --peer: #2a2e37;
  --same-num: #3a4a5c;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.app {
  width: 100%;
  max-width: 520px;
}

header h1 {
  text-align: center;
  margin: 0 0 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

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

.toolbar label {
  color: var(--text-dim);
  font-size: 0.85rem;
}

select, button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

select:hover, button:hover {
  border-color: var(--accent);
}

button.toggle.active {
  background: var(--accent);
  color: #10131a;
  border-color: var(--accent);
}

.status {
  display: flex;
  justify-content: center;
  gap: 18px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-bottom: 14px;
  font-size: 0.9rem;
  min-height: 1.2em;
}

#mistakes.warn {
  color: var(--bad);
}

#message {
  color: var(--accent);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--line-strong);
  gap: 1px;
  border: 3px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}

.cell {
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: clamp(16px, 3.6vw, 26px);
  color: var(--user-num);
  cursor: pointer;
}

.cell.given {
  color: var(--given);
  font-weight: 600;
  cursor: default;
}

.cell.selected { background: var(--selected); }
.cell.peer { background: var(--peer); }
.cell.same-num { background: var(--same-num); }

.cell.error { color: var(--bad); }

.cell.border-right { border-right: 2px solid var(--line-strong); }
.cell.border-bottom { border-bottom: 2px solid var(--line-strong); }

.cell .notes {
  position: absolute;
  inset: 3px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(7px, 1.6vw, 10px);
  color: var(--text-dim);
  line-height: 1;
}

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

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  margin-top: 14px;
}

.numpad button {
  padding: 10px 0;
  font-size: 1.05rem;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden { display: none; }

.win-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
}

.win-card h2 { margin-top: 0; color: var(--accent); }

@media (max-width: 420px) {
  .toolbar button, .toolbar select { font-size: 0.8rem; padding: 6px 8px; }
}

.site-footer {
  text-align: center;
  margin-top: 18px;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.site-footer a:hover {
  text-decoration: underline;
}
