.game-root {
  min-height: 36rem;
  display: flex;
  flex-direction: column;
}

/* Toolbar stays on top; the sheet sits in the middle of the remaining felt. */
.game-root > .sdk-sheet { margin: auto; }

.sdk {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.sdk-sheet {
  --sdk-paper: #fffdf7;
  --sdk-box: #f1e8d3;
  --sdk-ink: #1d2433;
  --sdk-line: #a08b68;
  --sdk-entry: #1d6b44;
  --sdk-note: #6e6558;
  --sdk-muted: #5e584e;
  /* Pigments. Cell states mix these into the paper or box tint so the rules stay visible. */
  --sdk-peer: #3f6e52;
  --sdk-note-match: #b8923a;
  --sdk-match: #c6a03a;
  --sdk-selected: #efd88f;
  --sdk-conflict: #c4544e;
  --sdk-conflict-ink: #8d2e2b;
  --sdk-key: #fffdf8;
  width: min(100%, 32rem);
  background: var(--sdk-paper);
  color: var(--sdk-ink);
  border-radius: 12px;
  border-top: 3px solid var(--gold);
  padding: 0.75rem 0.75rem 0.85rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

[data-theme="dark"] .sdk-sheet {
  --sdk-paper: #24302c;
  --sdk-box: #2c3a35;
  --sdk-ink: #e7eee9;
  --sdk-line: #6e8c82;
  --sdk-entry: #8dceb0;
  --sdk-note: #b7c2bb;
  --sdk-muted: #c5d0c9;
  --sdk-peer: #c8e4d4;
  --sdk-note-match: #e4c56a;
  --sdk-match: #f0d48a;
  --sdk-selected: #5a4e32;
  --sdk-conflict: #e8a29c;
  --sdk-conflict-ink: #f0b4b0;
  --sdk-key: #1c2622;
}

.sdk-status {
  min-height: 3.2rem;
  margin: 0 0 0.55rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--sdk-muted);
}

.sdk-stage { position: relative; }

.sdk-board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--sdk-paper);
  border: 2px solid var(--sdk-ink);
  border-radius: 2px;
  /* Gold frame, like the home-page thumbnail. */
  box-shadow: 0 0 0 4px var(--gold);
  touch-action: manipulation;
  user-select: none;
}

.sdk-cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--sdk-line);
  border-bottom: 1px solid var(--sdk-line);
  background: var(--cell-tint, transparent);
  color: var(--sdk-entry);
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.sdk-row { display: contents; }

.sdk-cell:nth-child(3),
.sdk-cell:nth-child(6) {
  border-right: 2px solid var(--sdk-ink);
}

.sdk-cell:nth-child(9) { border-right: none; }

.sdk-row:nth-child(3) .sdk-cell,
.sdk-row:nth-child(6) .sdk-cell {
  border-bottom: 2px solid var(--sdk-ink);
}

.sdk-row:nth-child(9) .sdk-cell { border-bottom: none; }

/* Alternate 3 x 3 boxes get a soft tint. :where() keeps state colours below in charge. */
:where(.sdk-row:nth-child(-n+3) .sdk-cell:nth-child(n+4):nth-child(-n+6)),
:where(.sdk-row:nth-child(n+4):nth-child(-n+6) .sdk-cell:nth-child(-n+3)),
:where(.sdk-row:nth-child(n+4):nth-child(-n+6) .sdk-cell:nth-child(n+7)),
:where(.sdk-row:nth-child(n+7) .sdk-cell:nth-child(n+4):nth-child(-n+6)) {
  --cell-tint: var(--sdk-box);
}

/* Tint the cell's own paper or box colour so the hairlines and 3×3 shading stay visible. */
.sdk-cell.is-peer { background: color-mix(in srgb, var(--sdk-peer) 16%, var(--cell-tint, var(--sdk-paper))); }
.sdk-cell.is-note-match { background: color-mix(in srgb, var(--sdk-note-match) 24%, var(--cell-tint, var(--sdk-paper))); }
.sdk-cell.is-match { background: color-mix(in srgb, var(--sdk-match) 34%, var(--cell-tint, var(--sdk-paper))); }
.sdk-cell.is-selected { background: color-mix(in srgb, var(--sdk-selected) 72%, var(--cell-tint, var(--sdk-paper))); z-index: 1; }
.sdk-cell.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px var(--gold);
  pointer-events: none;
}
.sdk-cell.is-conflict { background: color-mix(in srgb, var(--sdk-conflict) 36%, var(--cell-tint, var(--sdk-paper))); color: var(--sdk-conflict-ink); }
.sdk-cell.is-wrong::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid var(--danger);
  border-radius: 2px;
  pointer-events: none;
}

.sdk-value {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 4.4vw, 1.7rem);
  font-weight: 600;
}

.sdk-cell.is-given .sdk-value {
  color: var(--sdk-ink);
  font-weight: 700;
}

.sdk-cell.is-entry .sdk-value { color: var(--sdk-entry); }
.sdk-cell.is-conflict .sdk-value { color: var(--sdk-conflict-ink); }

.sdk-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
  font-family: var(--font-sans);
  font-size: clamp(0.45rem, 1.55vw, 0.68rem);
  font-weight: 600;
  color: var(--sdk-note);
  font-style: normal;
}

.sdk-notes i {
  display: grid;
  place-items: center;
  font-style: normal;
}

.sdk-notes i.is-on { color: var(--sdk-ink); }

.sdk-pad,
.sdk-actions {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.sdk-pad { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.sdk-actions { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.sdk-digit {
  position: relative;
  touch-action: manipulation;
  min-height: var(--tap-min);
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--sdk-line);
  background: var(--sdk-key);
  color: var(--sdk-ink);
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}

.sdk-digit:hover:not(:disabled) { border-color: var(--gold); }

.sdk-digit.is-on {
  border-color: var(--gold);
  background: var(--sdk-selected);
  box-shadow: inset 0 0 0 1px var(--gold);
}

/* The chosen digit stays fully marked when its ninth copy is placed. */
.sdk-digit.is-on.is-complete {
  color: var(--sdk-entry);
}

.sdk-digit.is-on.is-complete::before {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--sdk-entry);
  border-bottom: 2px solid var(--sdk-entry);
  transform: rotate(-45deg);
}

.sdk-digit.has-note::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--sdk-entry);
}

.sdk-digit:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.sdk-digit.is-on:disabled {
  opacity: 1;
  color: var(--sdk-entry);
  border-color: var(--gold);
  background: var(--sdk-selected);
  box-shadow: inset 0 0 0 1px var(--gold);
  -webkit-text-fill-color: var(--sdk-entry);
}

.sdk-actions .btn {
  padding-inline: 0.35rem;
  width: 100%;
}

.sdk-pause {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.35rem;
  padding: 1rem;
  background: color-mix(in srgb, var(--sdk-paper) 94%, var(--sdk-ink));
  border-radius: 2px;
  text-align: center;
}

.sdk-stage.is-paused .sdk-board,
.sdk-stage.is-paused .sdk-pad,
.sdk-stage.is-paused .sdk-actions {
  visibility: hidden;
}

.sdk-pause p {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.6rem;
  color: var(--sdk-ink);
}

.sdk-pause span {
  color: var(--sdk-muted);
  margin-bottom: 0.6rem;
}

@media (max-width: 560px) {
  .sdk-sheet { padding: 0.55rem; }
  .sdk-pad { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sdk-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sdk-digit { min-height: 3rem; font-size: 1.45rem; }
}

@media (max-width: 380px) {
  .sdk-actions .btn { font-size: 0.85rem; }
}
