/* Sudoku (sudoku.js): the size and level picker, then the board with its number pad and tools.
   Smartboard and landscape: the board fills the height at the left, the pad and tools stand beside it. Portrait phone:
   the board fills the width and the pad sits under it, within thumb reach. The board sizes itself to its box with
   container queries, and its digits to the board. Errors carry a dashed outline, never colour alone. */

#arenaDialog[data-arena-layout~="card"] > #arenaBody > #arenaPlay.sd-game {
  flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 16px;
}
.sd-game p { margin: 0; }

/* ---------- Picker ---------- */
.sd-picker { display: flex; flex-direction: column; gap: 14px; width: min(100%, 760px); margin: auto; overflow: auto; }
.sd-picker__rule { font-size: clamp(16px, 1.4vw, 20px); line-height: 1.4; color: var(--ink-2); }
.sd-choices { margin: 0; padding: 0; border: 0; min-width: 0; }
.sd-choices > legend { padding: 0; margin-bottom: 8px; font-family: var(--font-title); font-size: 18px; font-weight: 700; color: var(--ink); }
.sd-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sd-option {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 76px; padding: 8px 10px;
  border: 2px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--ink);
  font: inherit; cursor: pointer; transition: transform 120ms ease-out, border-color 120ms ease-out;
}
.sd-option strong { font-family: var(--font-title); font-size: clamp(22px, 2vw, 30px); line-height: 1.1; font-variant-numeric: tabular-nums; }
.sd-option small { font-size: 14px; color: var(--ink-2); }
.sd-option.is-selected { border-color: var(--brand); background: var(--brand-tint); box-shadow: inset 0 0 0 2px var(--brand); }
.sd-option:active { transform: scale(.97); }
.sd-picker__foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.sd-picker__best { flex: 1 1 200px; color: var(--ink-2); }
.sd-picker__best:empty { display: none; }
.sd-picker__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-left: auto; }
.sd-switch {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 6px; border: 0; background: none;
  color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.sd-switch__track { position: relative; flex: none; width: 46px; height: 26px; border: 2px solid var(--line-strong); border-radius: 999px; background: var(--surface-2); transition: background-color 150ms ease-out, border-color 150ms ease-out; }
.sd-switch__track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink-3); transition: transform 150ms ease-out, background-color 150ms ease-out; }
.sd-switch[aria-pressed="true"] .sd-switch__track { border-color: var(--brand); background: var(--brand); }
.sd-switch[aria-pressed="true"] .sd-switch__track::after { transform: translateX(20px); background: var(--on-brand); }

/* ---------- Status line ---------- */
.sd-status { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sd-chip {
  display: inline-flex; align-items: center; min-height: 34px; padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font-size: 15px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.sd-chip[hidden] { display: none; }
.sd-chip--time { background: var(--brand-tint); color: var(--brand-ink); }
.sd-status__new { margin-left: auto; }

/* ---------- Board and panel ---------- */
.sd-stage { flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 26vw, 360px); gap: 16px; }
.sd-board-box { min-width: 0; min-height: 0; display: grid; place-items: center; container-type: size; }
.sd-board {
  --line-thin: var(--line-strong); --line-thick: var(--ink);
  container-type: inline-size; box-sizing: border-box; width: min(100cqw, 100cqh); aspect-ratio: 1;
  display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  border: 3px solid var(--line-thick); border-radius: 10px; overflow: hidden; background: var(--surface);
}
.sd-cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 0; margin: 0;
  border: 0; border-right: 1px solid var(--line-thin); border-bottom: 1px solid var(--line-thin); border-radius: 0;
  background: var(--surface); color: var(--brand-ink); font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  font-size: calc(100cqw / var(--n) * .56); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
}
.sd-cell.edge-r { border-right: 3px solid var(--line-thick); }
.sd-cell.edge-b { border-bottom: 3px solid var(--line-thick); }
.sd-cell.is-given { color: var(--ink); font-weight: 800; }
.sd-cell.is-hinted { color: var(--green-ink); }
.sd-cell.is-peer { background: var(--surface-2); }
.sd-cell.is-hint-unit { background: var(--green-tint); }
.sd-cell.is-same { background: var(--gold-tint); }
.sd-cell.is-selected { background: var(--brand-tint-2); box-shadow: inset 0 0 0 3px var(--brand); }
.sd-cell.is-hint { box-shadow: inset 0 0 0 3px var(--green-ink); }
.sd-cell.is-selected.is-hint { box-shadow: inset 0 0 0 3px var(--green-ink), inset 0 0 0 6px var(--brand); }
.sd-cell.is-conflict { background: var(--red-tint); color: var(--red-ink); outline: 2px dashed var(--red-ink); outline-offset: -6px; }
.sd-cell:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; z-index: 1; }
.sd-value { pointer-events: none; }
.sd-notes {
  display: grid; width: 100%; height: 100%; padding: 6%; box-sizing: border-box; pointer-events: none;
  color: var(--ink-2); font-weight: 600; line-height: 1; font-size: calc(100cqw / var(--n) * .24);
}
.sd-notes--4 { grid-template-columns: repeat(2, 1fr); font-size: calc(100cqw / var(--n) * .28); }
.sd-notes--6 { grid-template-columns: repeat(3, 1fr); }
.sd-notes--9 { grid-template-columns: repeat(3, 1fr); }
.sd-notes > i { display: grid; place-items: center; font-style: normal; }

.sd-side { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.sd-pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sd-pad--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sd-key--erase { grid-column: 1 / -1; }
.sd-key {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: clamp(48px, 7.5vh, 72px); padding: 4px;
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  font-family: var(--font-title); font-size: clamp(24px, 2.4vw, 34px); font-weight: 700; font-variant-numeric: tabular-nums;
  cursor: pointer; touch-action: manipulation; transition: transform 100ms ease-out;
}
.sd-key:active { transform: scale(.95); }
.sd-key.is-same { border-color: var(--brand); box-shadow: inset 0 0 0 2px var(--brand); }
.sd-key.is-done { color: var(--ink-3); border-style: dashed; }
.sd-key--erase { font-family: inherit; font-size: 17px; }
.sd-key--erase svg { width: 24px; height: 24px; }
.sd-game.is-notes .sd-key[data-value] { border-color: var(--gold-line); background: var(--gold-tint); color: var(--gold-ink); }
.sd-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sd-tools .uk-btn { flex-direction: column; justify-content: center; gap: 2px; width: 100%; min-height: 64px; padding: 6px 4px; font-size: 14px; }
.sd-tools [data-sd="notes"][aria-pressed="true"] { border-color: var(--gold-line); background: var(--gold-tint); color: var(--gold-ink); }
.sd-message { min-height: 2.8em; padding: 8px 12px; border-radius: var(--radius-sm); font-size: clamp(15px, 1.3vw, 19px); line-height: 1.35; color: var(--ink); }
.sd-message:empty { visibility: hidden; }
.sd-message.is-hint { background: var(--green-tint); color: var(--green-ink); font-weight: 700; }

@media (hover: hover) and (pointer: fine) {
  .sd-option:hover, .sd-key:hover { border-color: var(--brand); }
  .sd-cell:not(.is-selected):hover { background: var(--brand-tint); }
}

body.high-contrast .sd-cell.is-peer { background: var(--surface-3); }
body.high-contrast .sd-cell.is-selected { box-shadow: inset 0 0 0 4px var(--ink); }

/* Portrait phone: the board takes the width, then the pad (five keys a row) and the tools in one row. */
@media (max-width: 680px) and (orientation: portrait) {
  #arenaDialog[data-arena-layout~="card"] > #arenaBody > #arenaPlay.sd-game { gap: 8px; padding: 8px 4px; }
  .sd-status { gap: 4px; }
  .sd-chip { min-height: 30px; padding: 2px 9px; font-size: 13.5px; }
  .sd-stage { display: flex; flex-direction: column; gap: 8px; }
  .sd-board-box { flex: 1 1 auto; }
  .sd-side { flex: none; gap: 8px; }
  .sd-pad, .sd-pad--4 { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .sd-key--erase { grid-column: auto; }
  .sd-pad--6 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .sd-key { min-height: 50px; font-size: 26px; }
  .sd-key--erase span { display: none; }
  .sd-tools { gap: 6px; }
  .sd-tools .uk-btn { flex-direction: row; gap: 6px; min-height: 48px; padding-inline: 6px; }
  .sd-message { min-height: 0; padding: 6px 10px; font-size: 15px; }
  .sd-message:empty { display: none; }
  .sd-options { gap: 8px; }
  .sd-option { min-height: 64px; padding: 6px; }
  .sd-option small { font-size: 12.5px; }
}
/* A tall phone keeps two lines free for the message, so a hint does not push the board up. */
@media (max-width: 680px) and (orientation: portrait) and (min-height: 760px) {
  .sd-message { min-height: calc(2 * 1.35em + 12px); }
  .sd-message:empty { display: block; }
}

/* Short landscape phone: a narrower panel, smaller keys. */
@media (orientation: landscape) and (max-height: 500px) {
  #arenaDialog[data-arena-layout~="card"] > #arenaBody > #arenaPlay.sd-game { gap: 6px; padding: 6px 10px; }
  .sd-picker { gap: 8px; }
  .sd-choices > legend { margin-bottom: 4px; font-size: 16px; }
  .sd-options { gap: 8px; }
  .sd-option { min-height: 56px; padding: 4px 8px; }
  .sd-stage { grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: 10px; }
  .sd-side { gap: 6px; }
  .sd-pad { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .sd-pad--6 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sd-key--erase { grid-column: auto; }
  .sd-key { min-height: 44px; font-size: 22px; }
  .sd-key--erase span { display: none; }
  .sd-tools { gap: 5px; }
  .sd-tools .uk-btn { min-height: 52px; padding: 2px; font-size: 13px; }
  .sd-message { min-height: 0; padding: 4px 8px; font-size: 14px; }
  .sd-chip { min-height: 28px; padding: 2px 8px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .sd-option, .sd-key, .sd-switch__track, .sd-switch__track::after { transition: none; }
}
