/* Layout: a one-screen puzzle app, built phone-first. Red title bar on top,
   the grid fills whatever space is left, the current clue sits right under
   it and a Persian keyboard is docked at the bottom. Clues and settings open
   as bottom sheets. Wide screens get the clue list beside the grid; phones
   held sideways put the keyboard next to the grid. */
:root {
  --paper: #f3f4f1;        /* app ground, cool newsprint */
  --sheet: #ffffff;        /* sheets, clue bar */
  --cell: #ffffff;         /* letter cells */
  --ink: #151515;          /* text, grid lines */
  --ink-soft: #5b5f5c;
  --rule: #d4d7d2;
  --rule-soft: #e7e9e5;
  --band: #e3232b;         /* the title bar red */
  --band-ink: #ffffff;
  --yellow: #ffc61a;       /* badge, accents */
  --ink-on-yellow: #151515;
  --block: #151515;        /* black cells */
  --grid-line: #151515;
  --hl-word: #fff0b8;
  --hl-cell: #ffd23f;
  --hl-cell-ink: #151515;
  --wrong: #c92a2a;
  --wrong-bg: #ffd6d6;     /* a square holding a wrong letter */
  --wrong-on-cur: #b3201b; /* wrong letter on the yellow selected square */
  --toast: #151515;
  --toast-ink: #ffffff;
  --toast-bad: #b42323;
  --revealed: #1864ab;
  --focus: #1864ab;
  --kb-bg: #d9dcd7;        /* keyboard tray */
  --key: #ffffff;
  --key-ink: #151515;
  --key-alt: #bfc4bd;
  --key-shadow: #8f958d;
  --backdrop: rgba(10, 12, 11, .5);

  --font-display: "Lalezar", "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --font-body: "Vazirmatn", Tahoma, "Segoe UI", "Noto Sans Arabic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121413;
    --sheet: #1d201f;
    --cell: #2b2f2d;
    --ink: #ecedea;
    --ink-soft: #a4a8a5;
    --rule: #383c3a;
    --rule-soft: #2a2e2c;
    --band: #c81f27;
    --band-ink: #ffffff;
    --yellow: #f5b800;
    --ink-on-yellow: #121413;
    --block: #040404;
    --grid-line: #4b504d;
    --hl-word: #403616;
    --hl-cell: #e0aa00;
    --hl-cell-ink: #121413;
    --wrong: #ff8787;
    --wrong-bg: #5c2424;
    --wrong-on-cur: #6e0b0b;
    --toast: #ecedea;
    --toast-ink: #121413;
    --toast-bad: #e03131;
    --revealed: #74c0fc;
    --focus: #74c0fc;
    --kb-bg: #0b0c0c;
    --key: #2f3331;
    --key-ink: #ecedea;
    --key-alt: #1f2221;
    --key-shadow: #000000;
    --backdrop: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121413;
  --sheet: #1d201f;
  --cell: #2b2f2d;
  --ink: #ecedea;
  --ink-soft: #a4a8a5;
  --rule: #383c3a;
  --rule-soft: #2a2e2c;
  --band: #c81f27;
  --band-ink: #ffffff;
  --yellow: #f5b800;
  --ink-on-yellow: #121413;
  --block: #040404;
  --grid-line: #4b504d;
  --hl-word: #403616;
  --hl-cell: #e0aa00;
  --hl-cell-ink: #121413;
  --wrong: #ff8787;
  --wrong-bg: #5c2424;
  --wrong-on-cur: #6e0b0b;
  --toast: #ecedea;
  --toast-ink: #121413;
  --toast-bad: #e03131;
  --revealed: #74c0fc;
  --focus: #74c0fc;
  --kb-bg: #0b0c0c;
  --key: #2f3331;
  --key-ink: #ecedea;
  --key-alt: #1f2221;
  --key-shadow: #000000;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  /* Keep clear of notches and the home indicator; the strips show the bar
     red on top and the keyboard tray at the bottom. */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: linear-gradient(to bottom, var(--band) 50%, var(--kb-bg) 50%);
  -webkit-text-size-adjust: 100%;
}
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ----------------------------------------------------------------- bar */

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding-inline: 12px 4px;
  background: var(--band);
  color: var(--band-ink);
}
.badge { width: 30px; height: 30px; flex: none; }
.title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.55rem;
  line-height: 1;
  white-space: nowrap;
  padding-top: 3px;
}
.timer {
  margin-inline-start: auto;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .16);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: .9rem;
  line-height: 1.5;
}
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-btn:active { background: rgba(0, 0, 0, .14); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }

/* --------------------------------------------------------------- stage */

.stage { flex: 1; min-height: 0; display: flex; }
.side { display: none; }
.play {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
}

/* --------------------------------------------------------------- board */

/* The grid and the clue bar under it form one group, centred in the space
   left between the title bar and the keyboard. */
.board-zone {
  --clue-h: 80px; /* clue bar plus gap, taken off the height the grid can use */
  position: relative;
  flex: 1;
  min-height: 0;
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 6px;
}
.board-frame {
  --cols: 13;
  --rows: 13;
  --g: 1.05;   /* width of the row-number column, in cells */
  --gt: .62;   /* height of the column-number row, in cells */
  --cs: min(48px, calc(100cqw / (var(--cols) + var(--g))), calc((100cqh - var(--clue-h)) / (var(--rows) + var(--gt))));
  flex: none;
  position: relative;
  display: grid;
  grid-template-columns: calc(var(--cs) * var(--g)) calc(var(--cs) * var(--cols));
  grid-template-rows: calc(var(--cs) * var(--gt)) calc(var(--cs) * var(--rows));
}
.corner { grid-row: 1; grid-column: 1; }
.colnums {
  grid-row: 1; grid-column: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  align-items: center;
  padding-inline: 2px;
  font-size: max(9px, calc(var(--cs) * .32));
  color: var(--ink-soft);
  text-align: center;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.rownums {
  grid-row: 2; grid-column: 1;
  display: grid;
  grid-template-rows: repeat(var(--rows), 1fr);
  padding-block: 2px;
  padding-inline-end: 12%;
  font-family: var(--font-display);
  font-size: max(11px, calc(var(--cs) * .52));
  line-height: 1;
}
.rownums span {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--ink);
  padding-top: .12em;
}
.rownums span:last-child { border-bottom: 0; }

.board {
  grid-row: 2; grid-column: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 1px;
  background: var(--grid-line);
  border: 2px solid var(--grid-line);
  outline: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
.board:focus-visible { box-shadow: 0 0 0 3px var(--focus); }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: var(--cell);
  font-weight: 700;
  font-size: calc(var(--cs) * .58);
  line-height: 1;
  cursor: pointer;
}
.cell .ch { padding-top: .08em; }
.cell.black { background: var(--block); cursor: default; }
.cell.in-word { background: var(--hl-word); }
.cell.is-cur { background: var(--hl-cell); color: var(--hl-cell-ink); }
/* A wrong letter: red square and red letter; on the selected square the
   yellow stays and a red ring marks the mistake. */
.cell.wrong { background: var(--wrong-bg); color: var(--wrong); }
.cell.wrong.is-cur { background: var(--hl-cell); color: var(--wrong-on-cur); box-shadow: inset 0 0 0 2px var(--wrong-on-cur); }
.cell.wrong::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 1px), var(--wrong) calc(50% - 1px), var(--wrong) calc(50% + 1px), transparent calc(50% + 1px));
  opacity: .35;
  pointer-events: none;
}
.cell.wrong.just-wrong { animation: nudge .28s ease-out; }
@keyframes nudge {
  0%, 100% { transform: none; }
  30% { transform: translateX(-2px); }
  65% { transform: translateX(2px); }
}
.cell.revealed { color: var(--revealed); }
.cell.revealed::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 26%;
  height: 26%;
  background: var(--revealed);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.board.solved .cell:not(.black) { animation: settle .6s ease-out both; }
@keyframes settle {
  from { background: var(--hl-cell); }
  to { background: var(--cell); }
}

.veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  font-weight: 700;
  z-index: 2;
}
.veil span {
  background: var(--sheet);
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 60px);
  left: 50%;
  z-index: 3;
  max-width: calc(100% - 24px);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--toast);
  color: var(--toast-ink);
  font-size: .9rem;
  font-weight: 500;
  line-height: 1.6;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--toast-bad); color: #fff; }

/* ------------------------------------------------------------ clue bar */

.cluebar {
  flex: none;
  display: flex;
  align-items: stretch;
  width: min(100%, 720px);
  min-height: 66px;
  background: var(--sheet);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
  overflow: hidden;
  touch-action: pan-y;
}
.cluebar .nav {
  flex: none;
  width: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.cluebar .nav:active { background: var(--hl-word); }
.cluebar .nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.clue-now {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 6px 4px;
  border: 0;
  border-inline: 1px solid var(--rule-soft);
  background: transparent;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
}
.clue-tag {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: .82rem;
  font-weight: 700;
  color: var(--band);
  line-height: 1.4;
}
.clue-len { color: var(--ink-soft); font-weight: 500; }
.clue-text {
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------------------ keyboard */

.keyboard {
  flex: none;
  display: grid;
  gap: 7px;
  padding: 8px 4px 10px;
  background: var(--kb-bg);
}
.kb-row { display: flex; justify-content: center; gap: 4px; }
.kb-key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 54px;
  height: clamp(40px, 6.3vh, 54px);
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--key);
  color: var(--key-ink);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  box-shadow: 0 1px 0 var(--key-shadow);
  cursor: pointer;
  touch-action: manipulation;
}
.kb-key.wide { flex-grow: 1.55; max-width: 86px; background: var(--key-alt); font-size: 1.15rem; }
.kb-key svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.kb-key.down, .kb-key:active { background: var(--hl-cell); color: var(--hl-cell-ink); }

/* -------------------------------------------------------------- quick */

.only-wide { display: none !important; }
.quick { flex: none; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 0 12px 14px; }

.btn {
  min-height: 44px;
  padding: 6px 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--sheet);
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { background: var(--hl-word); }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }
.btn-primary:active { opacity: .85; background: var(--ink); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-quiet[aria-pressed="true"] { color: var(--ink); border-color: var(--rule); background: var(--sheet); }
.btn-block { display: block; width: 100%; min-height: 50px; }

/* --------------------------------------------------------------- clues */

.clue-panel { padding-bottom: 8px; }
.clue-head {
  margin: 6px 0 2px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.45rem;
  color: var(--ink-soft);
}
.clue-list { list-style: none; margin: 0 0 6px; padding: 0; }
.clue-list li {
  padding: 7px 0;
  border-bottom: 1px solid var(--rule-soft);
  line-height: 2;
}
.clue-list li:last-child { border-bottom: 0; }
.clue-list .num { font-weight: 800; font-variant-numeric: tabular-nums; margin-inline-end: 4px; }
.clue-list li.is-line .num { color: var(--band); }
.clue {
  padding: 3px 4px;
  border-radius: 5px;
  cursor: pointer;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.clue.is-active { background: var(--hl-word); }
.clue.done { color: var(--ink-soft); }
.clue.has-wrong { color: var(--wrong); }
.sep { color: var(--ink-soft); }
.dots { display: flex; gap: 4px; margin: 8px 0 10px; }
.dots i { width: 14px; height: 8px; background: var(--yellow); }

/* -------------------------------------------------------------- sheets */

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: min(88%, 760px);
  margin: auto auto 0;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .28);
  overflow: hidden;
  flex-direction: column;
}
dialog.sheet[open] { display: flex; animation: sheet-up .24s cubic-bezier(.2, .8, .3, 1); }
dialog.sheet::backdrop { background: var(--backdrop); }
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: .4; }
  to { transform: none; opacity: 1; }
}
.sheet-head {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 6px;
}
.sheet-head::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: var(--rule);
}
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.5rem; line-height: 1.2; }
.sheet-head .close { color: var(--ink-soft); }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 20px;
  -webkit-user-select: text;
  user-select: text;
}

.menu { display: grid; gap: 18px; }
.group { display: grid; gap: 10px; }
.group h3 { margin: 0; font-size: .85rem; font-weight: 700; color: var(--ink-soft); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  min-height: 52px;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  font-size: .92rem;
  line-height: 1.4;
  cursor: pointer;
}
.tile:active { background: var(--hl-word); }
.tile.is-confirm { background: var(--toast-bad); border-color: var(--toast-bad); color: #fff; }

.seg {
  display: flex;
  padding: 3px;
  gap: 3px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
}
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 9px;
  font-weight: 700;
  font-size: .95rem;
  color: var(--ink-soft);
}
.seg input:checked + span { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.by-number { display: flex; align-items: center; gap: 8px; }
.by-number label { flex: none; font-size: .9rem; color: var(--ink-soft); }
.by-number input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}
.switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--rule);
  position: relative;
  cursor: pointer;
  transition: background .15s;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.switch input:checked { background: var(--band); }
.switch input:checked::after { transform: translateX(-20px); }

.custom summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.custom p { margin: 0; font-size: .92rem; }
.custom textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.9;
  resize: vertical;
}
.custom code { font-family: var(--font-body); background: var(--paper); padding: 0 4px; border-radius: 4px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { width: 20px; height: 20px; }
.custom-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.custom-msg { font-size: .85rem; color: var(--ink-soft); }
.note { color: var(--ink-soft); }
.credits { font-size: .8rem; color: var(--ink-soft); border-top: 1px solid var(--rule-soft); padding-top: 12px; }
.credits p { margin: 0 0 4px; }
.credits a { word-break: break-all; }

.done-body { display: grid; justify-items: center; gap: 6px; padding: 28px 20px 24px; text-align: center; }
.done-mark { width: 56px; height: 56px; }
.done-body h2 { margin: 6px 0 0; font-family: var(--font-display); font-weight: 400; font-size: 2rem; line-height: 1.2; }
.done-body p { margin: 0 0 12px; font-size: 1.05rem; }
.done-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.done-actions .btn { min-width: 130px; min-height: 48px; }

.solution { display: none; }

/* ------------------------------------------------------ narrow phones */

@media (max-width: 350px) {
  .title { font-size: 1.3rem; }
  .badge { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kb-row { gap: 3px; }
  .kb-key { font-size: 1.1rem; }
}

/* ------------------------------------------------ phone held sideways */

@media (orientation: landscape) and (max-height: 540px) {
  .bar { height: 42px; }
  .title { font-size: 1.25rem; }
  .badge { width: 24px; height: 24px; }
  .play {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "board bar" "board kb";
  }
  .board-zone { grid-area: board; padding: 4px; --clue-h: 0px; }
  .cluebar { grid-area: bar; align-self: end; width: auto; margin: 6px 8px; }
  .keyboard { grid-area: kb; border-radius: 12px 12px 0 0; gap: 5px; padding: 6px 4px; }
  .kb-key { height: clamp(32px, 10vh, 44px); font-size: 1.1rem; }
}

/* -------------------------------------------------------- wide screens */

@media (min-width: 900px) and (min-height: 560px) {
  body { font-size: 16px; }
  .only-narrow { display: none !important; }
  .only-wide { display: flex !important; }
  /* With the on-screen keyboard out, the menu holds these and the grid gets the room. */
  .kb-on .quick { display: none !important; }
  .bar { height: 60px; padding-inline: 20px 10px; gap: 12px; }
  .badge { width: 38px; height: 38px; }
  .title { font-size: 2rem; }
  .side {
    display: block;
    flex: 0 0 min(40%, 500px);
    overflow: auto;
    padding: 16px 24px 24px;
    background: var(--sheet);
    border-inline-end: 1px solid var(--rule);
  }
  .board-zone { padding: 20px; gap: 14px; --clue-h: 84px; }
  .board-frame { --cs: min(52px, calc(100cqw / (var(--cols) + var(--g))), calc((100cqh - var(--clue-h)) / (var(--rows) + var(--gt)))); }
  .keyboard { width: min(100%, 600px); margin: 0 auto 12px; border-radius: 14px; }
  dialog.sheet { margin: auto; border-radius: 16px; padding-bottom: 0; }
  .sheet-head::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .board.solved .cell:not(.black), dialog.sheet[open], .cell.wrong.just-wrong { animation: none; }
  .toast { transition: none; }
}

/* --------------------------------------------------------------- print */

@media print {
  @page { size: A4; margin: 12mm; }
  :root {
    --paper: #fff; --sheet: #fff; --cell: #fff; --ink: #000; --ink-soft: #333; --rule: #999; --rule-soft: #ddd;
    --block: #000; --grid-line: #000; --hl-word: #fff; --hl-cell: #fff; --hl-cell-ink: #000;
    --band: #e3232b; --band-ink: #fff;
    color-scheme: light;
  }
  html, body { height: auto; overflow: visible; background: #fff; padding: 0; }
  body { font-size: 10.5pt; line-height: 1.6; }
  .app { height: auto; display: block; padding: 0; }
  .bar { height: auto; padding: 8px 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .icon-btn, .timer, .cluebar, .quick, .keyboard, .toast, .veil, dialog { display: none !important; }
  .stage { display: grid; grid-template-columns: .95fr 1.15fr; gap: 16px; margin-top: 10px; }
  .side { display: block; grid-column: 1; grid-row: 1; overflow: visible; padding: 0; border: 0; background: none; }
  .play { grid-column: 2; grid-row: 1; display: block; }
  .board-zone { container-type: normal; display: block; padding: 0; }
  .board-frame { --cs: calc(102mm / (var(--cols) + var(--g))); }
  .badge, .cell.black, .dots i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cell { color: #000 !important; }
  .cell.wrong, .cell.in-word, .cell.is-cur { background: #fff; box-shadow: none; }
  .cell::before, .cell::after { display: none; }
  body.print-blank .cell .ch { visibility: hidden; }
  .clue.is-active { background: none; }
  .clue-list li { padding: 2px 0; border: 0; line-height: 1.6; }
  .clue-list li.is-line .num { color: inherit; }
  .solution {
    display: block;
    break-inside: avoid;
    width: 42%;
    margin-inline-start: auto;
    margin-top: 12px;
    border: 1.5px solid #ffc61a;
    padding: 6px 8px 8px;
  }
  .solution-head { margin: 0 0 4px; font-family: var(--font-display); font-weight: 400; font-size: 12pt; }
  .solution-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    border-top: 1px solid #000;
    border-right: 1px solid #000;
    font-size: 7.5pt;
    font-weight: 700;
    line-height: 1;
  }
  .solution-grid span {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-left: 1px solid #000;
    border-bottom: 1px solid #000;
  }
  .solution-grid span.b { background: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
