:root {
  --bg: #f6f3ec;
  --fg: #23211d;
  --line: #6b665c;
  --thick: #2b2823;
  --given: #23211d;
  --manual: #1a56c4;
  --selected: #ffe08a;
  --peer: #e7dbc0;
  --match: #cfe4ff;
  --conflict: #ffb3b3;
  --button: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  width: min(92vw, 560px);
  text-align: center;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1rem;
  font-size: 0.85rem;
  opacity: 0.8;
}

main {
  width: min(92vw, 560px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 3px solid var(--thick);
  background: var(--button);
  touch-action: manipulation;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--given);
  font: inherit;
  font-size: clamp(1rem, 4.4vw, 1.7rem);
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.cell.br {
  border-right: 3px solid var(--thick);
}

.cell.bb {
  border-bottom: 3px solid var(--thick);
}

.cell.given {
  font-weight: 700;
}

.cell.manual {
  color: var(--manual);
}

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

.cell.match {
  background: var(--match);
}

.cell.selected {
  background: var(--selected);
  outline: 2px solid var(--thick);
  outline-offset: -2px;
}

.cell.conflict {
  animation: flash 0.6s ease-out;
}

@keyframes flash {
  0%,
  60% {
    background: var(--conflict);
  }
  100% {
    background: transparent;
  }
}

.dots {
  position: absolute;
  inset: 5%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.dot {
  display: grid;
  place-items: center;
}

.dot.visible::after {
  content: "";
  width: 52%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
}

.dot.visible.manual::after {
  background: var(--manual);
  opacity: 0.6;
}

.cell.filled .dots {
  display: none;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.35rem;
}

.numbers button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0.1rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.numbers button.active {
  background: var(--selected);
  outline: 2px solid var(--thick);
  outline-offset: -2px;
}

.numbers .digit {
  font-size: clamp(1rem, 3.8vw, 1.35rem);
  line-height: 1;
}

.marks button {
  justify-content: center;
  padding: 0.6rem 0.1rem;
}

.counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  width: 60%;
}

.counts i {
  aspect-ratio: 1;
  border-radius: 1px;
  background: #ddd8cc;
}

.counts i.on {
  background: var(--manual);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.actions button,
.panel button {
  flex: 1 1 auto;
  min-width: 6.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.status {
  min-height: 1.2em;
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  color: #8a2b2b;
}

.panel {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(92vw, 460px);
  max-height: 80vh;
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.saved-list button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  text-align: left;
}

.saved-list small {
  opacity: 0.75;
}
