:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #132033;
  --muted: #4c5a6d;
  --line: #a7b4c6;
  --line-strong: #1f304d;
  --given-bg: #e8effb;
  --conflict-bg: #ffdedd;
  --focus: #2c6cf5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #ffffff 0%, var(--bg) 65%);
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

button,
input {
  font-family: inherit;
}

.app {
  width: min(100%, 1120px);
  background: var(--panel);
  border: 1px solid #d6deea;
  border-radius: 14px;
  box-shadow: 0 10px 35px rgba(17, 33, 61, 0.08);
  padding: 20px;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
}

.subtitle {
  margin: 8px 0 16px;
  color: var(--muted);
}

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

button {
  border: 1px solid #bac8dc;
  background: #f2f6ff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

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

.mode {
  margin: 14px 0;
  font-weight: 700;
}

.digit-tracker {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 14px;
}

.digit-chip {
  border: 1px solid #c8d3e2;
  border-radius: 8px;
  background: #f5f8ff;
  color: #536175;
  text-align: center;
  font-size: 0.86rem;
  line-height: 1;
  padding: 7px 0;
}

.digit-chip.complete {
  background: #dff6e6;
  border-color: #8bb89a;
  color: #1f6a36;
  font-weight: 700;
}

.digit-chip.overfilled {
  background: #ffe7e7;
  border-color: #d98f8f;
  color: #a42828;
  font-weight: 700;
}

.board-wrap {
  overflow-x: auto;
}

.board {
  width: min(100%, 1008px, calc(100dvh - 280px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns:
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 6px
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 6px
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows:
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 6px
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 6px
    minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  border: 6px solid var(--line-strong);
  margin-inline: auto;
  user-select: none;
  position: relative;
}

.cell-wrap {
  position: relative;
  border: 0;
  background: #fff;
}

.cell-wrap:not([data-row="0"]) {
  border-top: 2px solid var(--line);
}

.cell-wrap:not([data-col="0"]) {
  border-left: 2px solid var(--line);
}

.cell-wrap[data-row="3"],
.cell-wrap[data-row="6"] {
  border-top: 0;
}

.cell-wrap[data-col="3"],
.cell-wrap[data-col="6"] {
  border-left: 0;
}

.board-divider {
  background: var(--line-strong);
  pointer-events: none;
  z-index: 4;
}

.cell {
  width: 100%;
  height: 100%;
  border: 0;
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: clamp(2rem, 4.6vw, 2.8rem);
  color: var(--text);
  background: transparent;
  caret-color: transparent;
  position: relative;
  z-index: 2;
}

.cell:focus {
  outline: none;
  box-shadow: inset 0 0 0 4px var(--focus);
}

.board.pointer-multi-select .cell:focus {
  outline: none;
  box-shadow: none;
}

.pencil-grid {
  position: absolute;
  inset: 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  font-size: clamp(1rem, 2.7vw, 1.44rem);
  color: #60708a;
  z-index: 1;
  pointer-events: none;
}

.pencil-note {
  line-height: 1;
}

.pencil-note.conflict {
  color: #c62828;
}

.cell-wrap.given {
  background: transparent;
}

.cell-wrap.conflict {
  background: var(--conflict-bg);
}

.cell-wrap.selected {
  background: #cfe0ff;
}

.cell-wrap.active-seen-cell {
  background: #e2ecff;
}

.cell-wrap.active-digit-value-match {
  background: #bdd4ff;
}

.cell-wrap.active-digit-pencil-match {
  background: #fff4d6;
}

.cell-wrap.active-digit-possible-cell {
  background: #e4f7e7;
}

.pencil-note.active-digit-pencil-note {
  color: #2f5fa8;
  font-weight: 700;
}
