/* Sudoku – only what's specific to this game.
   Header, segmented buttons and the rest come from /css/style.css. */

.sd-layout {
  gap: 16px;
}

.sd-modes button {
  min-width: 0;
}

/* ---------- Status line ---------- */

.sd-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  width: min(100%, 520px);
  font-size: 14px;
  font-weight: 600;
}

.sd-level {
  font-family: var(--font-display);
  font-size: 17px;
}

.sd-mistakes,
.sd-best {
  color: var(--text-muted);
}

.sd-mistakes[data-tone="bad"] {
  color: var(--danger);
}

.sd-clock {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.sd-pause {
  height: 36px;
  padding: 0 12px;
}

/* ---------- Board (grid + tools + numbers) ---------- */

.sd-board {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 520px);
}

.sd-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  border: 2px solid var(--text-muted);
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
}

.sd-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: clamp(18px, 5.4vw, 28px);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sd-cell:nth-child(9n) {
  border-right: 0;
}

.sd-cell:nth-last-child(-n + 9) {
  border-bottom: 0;
}

/* The thicker lines between the 3×3 boxes */
.sd-cell.edge-r {
  border-right: 2px solid var(--text-muted);
}

.sd-cell.edge-b {
  border-bottom: 2px solid var(--text-muted);
}

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

.sd-cell.is-related {
  background: color-mix(in srgb, var(--accent-fill) 7%, var(--surface));
}

.sd-cell.is-same {
  background: color-mix(in srgb, var(--accent-fill) 22%, var(--surface));
}

.sd-cell.is-selected {
  background: color-mix(in srgb, var(--accent-fill) 38%, var(--surface));
}

.sd-cell.is-wrong {
  color: var(--danger);
}

.sd-cell.is-wrong.is-selected,
.sd-cell.is-wrong.is-same {
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
}

.sd-cell.is-hinted {
  animation: sd-hint 0.7s ease-out;
}

.sd-cell.is-shake .sd-value {
  animation: sd-shake 0.3s;
}

.sd-cell.is-done {
  animation: sd-done 0.6s ease-out both;
}

/* Pencil marks: a little 3×3 of numbers */
.sd-notes {
  position: absolute;
  inset: 2px;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  font-family: var(--font-body);
  font-size: clamp(8px, 1.9vw, 11px);
  font-weight: 600;
  line-height: 1;
  color: var(--text-muted);
}

.sd-cell.has-notes .sd-notes {
  display: grid;
}

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

.sd-notes i.on {
  visibility: visible;
}

.sd-notes i.is-match {
  border-radius: 3px;
  background: var(--accent-fill);
  color: var(--accent-text);
}

/* Paused: the grid is hidden */
.sd-grid.is-hidden .sd-cell {
  color: transparent;
  background: var(--surface);
}

.sd-grid.is-hidden .sd-notes {
  display: none;
}

.sd-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: var(--overlay);
  text-align: center;
}

.sd-overlay p {
  margin: 0;
}

.sd-overlay .game-actions {
  margin-top: 8px;
}

/* ---------- Tools ---------- */

.sd-tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 8px;
}

.sd-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.sd-tool[hidden] {
  display: none;
}

.sd-tool:hover {
  background: var(--hover-tint);
  color: var(--text);
}

.sd-tool svg {
  width: 22px;
  height: 22px;
}

.sd-tool b {
  font-weight: 700;
}

.sd-tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Number pad ---------- */

.sd-pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.sd-num {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 0.8;
  max-height: 64px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: clamp(20px, 5.6vw, 28px);
  font-weight: 700;
  cursor: pointer;
}

.sd-num:hover {
  border-color: var(--accent-fill);
}

.sd-num small {
  position: absolute;
  right: 5px;
  bottom: 3px;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
}

.sd-num.is-complete {
  color: var(--text-faint);
  opacity: 0.45;
}

.sd-tool:focus-visible,
.sd-num:focus-visible,
.sd-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- Options + keys ---------- */

.sd-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(100%, 520px);
}

.sd-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}

.sd-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.sd-toggle:has(input:disabled) {
  opacity: 0.6;
  cursor: default;
}

.game-status[data-tone="bad"] {
  color: var(--danger);
}

.sd-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-fill);
}

.sd-keys {
  max-width: 560px;
  margin: 0;
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 1px;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Online race ---------- */

.sd-race-setup,
.sd-race {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.sd-race-setup > p {
  margin: 0;
}

.sd-setup-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.sd-standings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(100%, 520px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.sd-standings li {
  display: grid;
  grid-template-columns: minmax(0, 130px) 1fr 70px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.sd-standings .sd-s-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sd-standings li.is-me .sd-s-name {
  color: var(--accent);
}

.sd-standings .sd-s-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.sd-standings .sd-s-bar span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--text-muted);
  transition: width 0.3s;
}

.sd-standings li.is-me .sd-s-bar span {
  background: var(--accent-fill);
}

.sd-standings .sd-s-status {
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sd-standings li.is-done .sd-s-status {
  color: var(--accent);
  font-weight: 700;
}

/* ---------- Animations ---------- */

@keyframes sd-shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@keyframes sd-hint {
  from { background: var(--accent-fill); }
}

@keyframes sd-done {
  50% { background: var(--accent-soft); transform: scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
  .sd-cell.is-done,
  .sd-cell.is-hinted,
  .sd-cell.is-shake .sd-value {
    animation: none;
  }
}

/* ---------- Phones ---------- */

@media (max-width: 480px) {
  .sd-pad {
    gap: 4px;
  }
  .sd-modes button {
    padding: 0 8px;
    font-size: 13px;
  }
  .sd-best {
    display: none;
  }
}

/* ---------- Wide screens: numbers beside the grid ---------- */

@media (min-width: 900px) {
  .sd-status,
  .sd-options {
    width: min(100%, 800px);
  }
  .sd-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 230px;
    grid-template-areas: "grid tools" "grid pad";
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 14px 22px;
    /* The grid never gets taller than the window */
    width: min(100%, 800px, calc(100svh - 250px + 252px));
  }
  .sd-board > .sd-grid {
    grid-area: grid;
  }
  .sd-board > .sd-tools {
    grid-area: tools;
    grid-template-columns: repeat(2, 1fr);
  }
  .sd-board > .sd-pad {
    grid-area: pad;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .sd-board .sd-num {
    aspect-ratio: 1;
    max-height: none;
    font-size: 28px;
  }
}

/* Phone held sideways: grid on the right at full height, numbers beside it */
@media (orientation: landscape) and (max-height: 540px) {
  .sd-board {
    display: grid;
    grid-template-columns: min(var(--play-h), calc(var(--play-w) - 128px)) minmax(116px, 1fr);
    grid-template-areas: "grid tools" "grid pad";
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 8px 12px;
    width: min(var(--play-w), calc(var(--play-h) + 220px));
  }
  .sd-board > .sd-grid { grid-area: grid; }
  .sd-board > .sd-tools { grid-area: tools; grid-template-columns: repeat(2, 1fr); }
  .sd-board > .sd-pad { grid-area: pad; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .sd-board .sd-num { aspect-ratio: 1; max-height: none; font-size: 20px; }
  .sd-status, .sd-options { width: 100%; flex-wrap: wrap; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .sd-grid { grid-template-rows: repeat(9, minmax(0, 1fr)); }
  .sd-cell { font-size: clamp(14px, calc(var(--play-h) / 13), 26px); line-height: 1; }
}
/* With friends, phone held sideways */
@media (orientation: landscape) and (max-height: 540px) {
  .sd-race { --play-h: calc(100dvh - 176px); gap: 8px; }
}
/* Sideways: number pad sized so all nine fit beside the grid */
@media (orientation: landscape) and (max-height: 540px) {
  .sd-board {
    grid-template-columns: min(var(--play-h), calc(var(--play-w) - 128px)) minmax(116px, 190px);
    width: auto;
    justify-content: center;
  }
  .sd-board > .sd-tools { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .sd-board .sd-tool { padding: 4px 2px; font-size: 10px; }
  .sd-board .sd-tool svg { height: 18px; }
  .sd-board .sd-num {
    aspect-ratio: auto;
    height: max(34px, calc((var(--play-h) - 76px) / 3 - 6px));
    font-size: 18px;
  }
}
