:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel-2: #232c36;
  --line: #3a4654;
  --line-strong: #5b6b7c;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4c9aff;
  --accent-soft: #1d3a5f;
  --given: #c9d6e2;
  --user: #6cc0ff;
  --conflict: #ff5d5d;
  --conflict-bg: #3a1d22;
  --highlight: #1f2a36;
  --same: #2a3a4a;
  --good: #46d39a;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f6;
    --panel: #ffffff;
    --panel-2: #f1f5f9;
    --line: #c7d2dd;
    --line-strong: #6b7884;
    --text: #1a2129;
    --muted: #5b6b7c;
    --accent: #2f6fed;
    --accent-soft: #d8e6ff;
    --given: #1a2129;
    --user: #2f6fed;
    --conflict: #d61f1f;
    --conflict-bg: #ffe1e1;
    --highlight: #e7eef6;
    --same: #d6e4f2;
    --good: #1f9d6b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 800px at 50% -10%, var(--panel-2), var(--bg));
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  padding: 24px 16px 40px;
}

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

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

h1 {
  font-size: 1.9rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.stats {
  display: flex;
  gap: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.95rem;
}

.timer {
  font-weight: 600;
  color: var(--text);
}

.controls {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.difficulty {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
}

select {
  appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  cursor: pointer;
}

.board-wrap {
  position: relative;
}

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

.cell {
  position: relative;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.1rem, 5.5vw, 1.7rem);
  font-weight: 600;
  color: var(--user);
  cursor: pointer;
  transition: background 0.08s ease;
}

.cell.given {
  color: var(--given);
  font-weight: 700;
}

/* Thicker separators between 3x3 boxes. */
.cell[data-col="2"],
.cell[data-col="5"] {
  margin-right: 1px;
  box-shadow: 2px 0 0 0 var(--line-strong);
}
.cell[data-row="2"],
.cell[data-row="5"] {
  box-shadow: 0 2px 0 0 var(--line-strong);
}
.cell[data-col="2"][data-row="2"],
.cell[data-col="2"][data-row="5"],
.cell[data-col="5"][data-row="2"],
.cell[data-col="5"][data-row="5"] {
  box-shadow: 2px 0 0 0 var(--line-strong), 0 2px 0 0 var(--line-strong);
}

.cell.peer {
  background: var(--highlight);
}
.cell.same {
  background: var(--same);
}
.cell.selected {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 2;
}
.cell.conflict {
  color: var(--conflict);
  background: var(--conflict-bg);
}
.cell.flash-good {
  animation: flashGood 0.5s ease;
}
@keyframes flashGood {
  0%,
  100% {
    background: var(--panel);
  }
  50% {
    background: rgba(70, 211, 154, 0.3);
  }
}

.notes {
  position: absolute;
  inset: 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.45rem, 1.9vw, 0.62rem);
  font-weight: 500;
  color: var(--muted);
  pointer-events: none;
}
.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.pad {
  margin-top: 18px;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.num {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 600;
  padding: 14px 0;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.1s ease;
}
.num:hover {
  background: var(--panel-2);
}
.num:active {
  transform: scale(0.94);
}
.num.depleted {
  color: var(--muted);
  opacity: 0.4;
  pointer-events: none;
}

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

.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.95rem;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.06s ease;
  flex: 1;
  white-space: nowrap;
}
.btn:hover {
  background: var(--panel-2);
}
.btn:active {
  transform: scale(0.97);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
.btn.danger {
  border-color: #6b3030;
  color: var(--conflict);
}
.btn.toggle.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.btn.toggle .state {
  font-weight: 700;
}

.hint-line {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.2em;
  text-align: center;
}
.hint-line.error {
  color: var(--conflict);
}
.hint-line.success {
  color: var(--good);
}

.footer {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--radius);
  backdrop-filter: blur(2px);
}
.overlay.hidden {
  display: none;
}
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 80%;
}
.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}
.overlay-card p {
  margin: 0 0 18px;
  color: var(--muted);
}
.overlay-card .btn {
  flex: none;
  padding: 12px 28px;
}
