* { box-sizing: border-box; }
html { color: #283d32; background: #faf7ef; }
body { margin: 0; font-family: Arial, "Noto Sans TC", sans-serif; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button { color: #283d32; background: #fffdf7; font: inherit; cursor: pointer; border: 2px solid #45654e; border-radius: 10px; min-height: 46px; touch-action: manipulation; }
button:disabled { color: #68726b; border-color: #acb5a9; cursor: default; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px dashed #111; outline-offset: 3px; }
[hidden] { display: none !important; }
.app { max-width: 920px; margin: 0 auto; padding: 6px 12px; }
.brand { display: flex; align-items: center; justify-content: center; min-width: 48px; min-height: 46px; color: #315a47; font-size: 24px; font-weight: 700; white-space: nowrap; margin-left: auto; padding: 0 4px; }
.heading { display: flex; gap: 8px; align-items: center; margin: 0 0 2px; }
.app .heading #language-toggle { font-size: 18px; }
h1 { margin: 0; font-size: 30px; line-height: 1.15; color: #254f39; }
.outlined { padding: 6px 10px; font-size: 20px; font-weight: 700; }
.board-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; justify-content: space-between; font-size: 18px; line-height: 1.3; margin-bottom: 4px; }
.puzzle-meta { display: flex; align-items: center; gap: 10px; }
#difficulty-label { font-weight: 700; border: 1px solid #8a6b35; border-radius: 5px; padding: 1px 6px; color: #674c21; background: #f7e8ba; }
#mode-label { font-weight: 700; }
#board { width: 100%; table-layout: fixed; border-collapse: collapse; border: 3px solid #605443; }
#board td { padding: 0; border: 1px solid #b5a389; width: 11.111%; }
#board td:nth-child(3n) { border-right: 3px solid #605443; }
#board tr:nth-child(3n) td { border-bottom: 3px solid #605443; }
.cell { display: block; position: relative; width: 100%; min-height: 0; height: auto; border: 0; border-radius: 0; padding: 0; color: #21633f; background: #fff9ed; font-size: 32px; font-size: 7.5vw; line-height: 1; font-weight: 400; }
/* The spacer follows the cell width, including on browsers without aspect-ratio. */
.cell::before { content: ""; display: block; padding-top: 100%; }
/* Keep full-size digits distinct from notes, including without CSS clamp(). */
@media (min-width: 960px) { .cell { font-size: 72px; } }
.cell .value { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.cell.given { color: #111; font-weight: 700; }
.cell.selected { background: #d8eadc; box-shadow: inset 0 0 0 3px #254532; }
.cell.conflict .value { text-decoration: underline double; }
.cell.conflict::after { content: "!"; position: absolute; top: 1px; right: 2px; font-size: 13px; font-weight: 700; }
.cell:focus { outline: 3px solid #254532; outline-offset: -3px; }
.cell.selected:focus { outline: 2px dashed #254532; outline-offset: -6px; }
.pencil { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-wrap: wrap; padding: 3px; color: #1756a9; font-size: 18px; font-size: 3vw; font-weight: 400; line-height: 1; text-decoration: none; }
.pencil span { display: flex; align-items: center; justify-content: center; width: 33.333%; height: 33.333%; text-align: center; }
/* Keep notes proportional until the board reaches its maximum width. */
@media (min-width: 934px) { .pencil { font-size: 28px; } }
.game-status { margin: 4px 0; min-height: 25px; font-size: 18px; line-height: 1.35; overflow-wrap: break-word; }
.game-status.complete { font-weight: 700; }
.keypad { display: flex; gap: 5px; }
.keypad button { flex: 1; min-width: 0; min-height: 46px; padding: 0; font-size: 27px; font-weight: 700; background: #e7efdf; }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.actions button { flex: 1; padding: 6px 3px; font-size: 20px; }
.actions button[aria-pressed="true"], .primary, #new-game { background: #315a47; color: #fffdf7; border-color: #254532; }
.text-button { font-size: 20px; padding: 6px 12px; white-space: nowrap; }
footer { margin-top: 6px; font-size: 18px; line-height: 1.4; }
footer p { margin: 0; overflow-wrap: break-word; }
.status-line { display: flex; flex-wrap: wrap; gap: 0 14px; }
.status-line p { min-width: 0; }
.footer-tools { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; }
.footer-tools details { flex: 1; min-width: 0; font-size: 20px; }
.footer-tools details[open] { flex-basis: 100%; }
summary { cursor: pointer; min-height: 46px; padding: 9px 0; }
details p { margin: 8px 0; }
.notice { padding: 12px; border: 2px solid #45654e; border-radius: 10px; background: #fffdf7; }
.overlay { position: fixed; z-index: 10; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(255,255,255,.94); }
.dialog { width: 100%; max-width: 440px; max-height: 100%; overflow-y: auto; padding: 24px; border: 3px solid #45654e; border-radius: 14px; background: #fffdf7; }
.dialog h2 { margin: 0 0 14px; font-size: 25px; }
.dialog p { font-size: 20px; line-height: 1.4; }
#difficulty-options { border: 0; padding: 0; margin: 18px 0 0; min-width: 0; }
#difficulty-options legend { padding: 0; margin-bottom: 9px; font-size: 20px; font-weight: 700; }
#difficulty-options label { display: flex; align-items: center; gap: 12px; padding: 12px; border: 2px solid #45654e; border-radius: 10px; margin: 8px 0; cursor: pointer; }
#difficulty-options input { width: 22px; height: 22px; flex-shrink: 0; margin: 0; accent-color: #315a47; }
#difficulty-options input:focus-visible { outline: 3px dashed #111; outline-offset: 3px; }
#difficulty-options strong { font-size: 20px; }
#difficulty-options small { display: block; margin-top: 3px; font-size: 18px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dialog-actions button { flex: 1; padding: 9px 6px; font-size: 20px; }
@media (max-width: 419px) {
  .app { padding: 6px 8px; }
  .heading { gap: 8px; }
  h1 { font-size: 26px; }
  .pencil { padding: 1px; }
  .keypad { gap: 3px; }
  .keypad button { font-size: 22px; }
  .actions { gap: 5px; }
  /* English needs two compact rows: title/language, then Home/new game. */
  html[lang="en"] .heading { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 6px; }
  html[lang="en"] .heading h1 { grid-column: 1; grid-row: 1; }
  html[lang="en"] .heading #language-toggle { grid-column: 2; grid-row: 1; justify-self: end; }
  html[lang="en"] .heading .brand { grid-column: 1; grid-row: 2; margin-left: 0; }
  html[lang="en"] .heading #new-game { grid-column: 2; grid-row: 2; }
  .dialog { padding: 16px; }
  #difficulty-options label { padding: 8px; }
}
/* Keep all four text actions inside very narrow viewports without shrinking type. */
@media (max-width: 319px) {
  .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Without flexbox gap (see interface.css), the keys, actions, board labels and difficulty choices get the same spacing
   from margins. Below 320px the actions are a grid, whose gap such browsers support. */
@supports not (aspect-ratio: 1 / 1) {
  html:not(.readerplay-kobo) .keypad, html:not(.readerplay-kobo) .puzzle-meta, html:not(.readerplay-kobo) #difficulty-options label { gap: 0; }
  html:not(.readerplay-kobo) .keypad > * + * { margin-left: 5px; }
  html:not(.readerplay-kobo) .puzzle-meta > * + * { margin-left: 10px; }
  html:not(.readerplay-kobo) #difficulty-options input { margin-right: 12px; }
  html:not(.readerplay-kobo) .board-meta { gap: 0; margin: -1px -5px 3px; }
  html:not(.readerplay-kobo) .board-meta > * { margin: 1px 5px; }
  @media (min-width: 320px) {
    html:not(.readerplay-kobo) .actions { gap: 0; }
    html:not(.readerplay-kobo) .actions > * + * { margin-left: 8px; }
  }
  @media (max-width: 419px) {
    html:not(.readerplay-kobo) .keypad > * + * { margin-left: 3px; }
  }
  @media (min-width: 320px) and (max-width: 419px) {
    html:not(.readerplay-kobo) .actions > * + * { margin-left: 5px; }
  }
}
