:root {
  --paper: #eef1ee;
  --surface: #fbfcfb;
  --cell: #ffffff;
  --ink: #16211e;
  --muted: #5a6964;
  --line: #c6d0cb;
  --block: #16211e;
  --word: #fff1b3;
  --cursor: #ffd84d;
  --accent: #0b6e5f;
  --on-accent: #ffffff;
  --warn: #a8321f;
  --wrong-bg: #fbd9d2;
  --display: "Frank Ruhl Libre", "David", "Times New Roman", serif;
  --body: "Assistant", "Arial Hebrew", Arial, sans-serif;
}
/* Deliberately light-only: a crossword reads best as black ink on white paper. */
:root { color-scheme: light; }

* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 17px; line-height: 1.5; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.page { --gutter: 16px; max-width: 1120px; margin: 0 auto; padding: 20px var(--gutter) 48px; }
@media (max-width: 480px) { .page { --gutter: 10px; padding-top: 14px; } }

header { display: flex; flex-direction: column; gap: 4px; border-bottom: 3px double var(--ink); padding-bottom: 12px; min-width: 0; }
h1 { font-family: var(--display); font-weight: 900; font-size: clamp(28px, 6vw, 44px); line-height: 1.1; margin: 0; }
header p { margin: 0; max-width: 62ch; }
.save { color: var(--muted); font-size: 14px; min-height: 1.5em; }
.save.warn { color: var(--warn); font-weight: 700; }
h2 { font-family: var(--display); font-weight: 700; font-size: 22px; margin: 0; }

.install {
  width: 100%; font-weight: 700; background: var(--accent); color: var(--on-accent);
  border: 0; border-radius: 6px; padding: 8px 16px; min-height: 48px; cursor: pointer;
}
.save { text-align: center; margin: 0; }
.install[hidden] { display: none; }

.done { background: var(--surface); border: 2px solid var(--accent); border-radius: 6px; padding: 16px 20px; text-align: center; }
.done[hidden] { display: none; }
.done h2 { font-size: 34px; }
.done p { margin: 4px 0 0; font-family: var(--display); font-size: 22px; font-weight: 700; }

/* Desktop: grid on the right (RTL first column), clues beside it. */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px 32px; align-items: start;
  grid-template-areas: "install install" "done done" "play clues";
}
.layout > .install { grid-area: install; }
.layout > .done { grid-area: done; }
.layout > .play { grid-area: play; }
.layout > .clues { grid-area: clues; }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; grid-template-areas: "install" "done" "play" "clues"; }
}

.play { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 10px; }
@media (max-width: 860px) { .play { position: static; } }

/* Desktop: the dock dissolves; the keyboard sits below the grid. The clue is read from the lists
   beside the grid, so there is no clue box above the puzzle. */
.dock { display: contents; }
@media (min-width: 861px) { .dock .cluebar { display: none; } }
/* Phones: clue + keyboard pinned to the bottom of the screen while the grid scrolls above. */
@media (max-width: 860px) {
  .dock {
    display: flex; flex-direction: column; gap: 6px; position: sticky; bottom: 0; z-index: 2;
    background: var(--paper); margin: 0 calc(-1 * var(--gutter)); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0, 0, 0, .08);
  }
  .dock .cluebar { order: 0; min-height: 0; padding: 6px 10px; font-size: 16px; }
  /* No clue selected: the dock steps aside so the whole grid can be seen. */
  .play.idle .dock { display: none; }
  .key { min-height: 44px; }
}
.cluebar {
  background: var(--surface); border: 1.5px solid var(--ink); border-radius: 4px; padding: 8px 12px;
  min-height: 3.2em; display: flex; gap: 10px; align-items: baseline;
}
.cluebar .tag { font-family: var(--display); font-weight: 700; white-space: nowrap; }
.cluebar .text { min-width: 0; }
.cluebar .text.none { color: var(--muted); }
.cluebar .close {
  flex: none; align-self: center; margin: -6px 0; margin-inline-start: auto; width: 40px; height: 40px; padding: 0;
  background: none; border: 0; border-radius: 4px; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
}
.cluebar .close:hover { color: var(--ink); background: var(--word); }
.enum { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.boardwrap { container-type: inline-size; width: 100%; max-width: 600px; margin: 0 auto; }
.board {
  --n: 15; display: grid; grid-template-columns: repeat(var(--n), 1fr);
  background: var(--block); border: 2px solid var(--block); gap: 1px; direction: rtl;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.c { aspect-ratio: 1; position: relative; background: var(--block); }
.c.l {
  background: var(--cell); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 700; font-size: calc(100cqi / var(--n) * 0.6); line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.c.inword { background: var(--word); }
.c.cursor { background: var(--cursor); box-shadow: inset 0 0 0 2px var(--ink); }
.c.wrong { background: var(--wrong-bg); color: var(--warn); }
.c.cursor.wrong { background: var(--cursor); }
.c.revealed::after {
  content: ""; position: absolute; bottom: 0; left: 0; border: calc(100cqi / var(--n) * 0.13) solid transparent;
  border-bottom-color: var(--accent); border-left-color: var(--accent);
}
.c .n {
  position: absolute; top: 3%; right: 6%; font-family: var(--body); font-weight: 700;
  font-size: calc(100cqi / var(--n) * 0.28); line-height: 1; color: var(--ink);
}

.keyboard { display: flex; flex-direction: column; gap: 6px; max-width: 600px; width: 100%; margin: 0 auto; direction: rtl; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; max-width: 58px; min-height: 46px; padding: 0; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-family: var(--display); font-weight: 700; font-size: 22px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.key:active { background: var(--cursor); }
.key.wide { flex-grow: 1.6; max-width: 90px; font-family: var(--body); font-size: 18px; }
@media (hover: hover) and (pointer: fine) { .key { min-height: 38px; font-size: 19px; } }

.tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tools button {
  font-weight: 600; background: var(--surface); border: 1.5px solid var(--ink); border-radius: 4px;
  padding: 6px 14px; cursor: pointer; min-height: 40px;
}
.tools button:hover { background: var(--word); }
.tools button:disabled { opacity: .45; cursor: default; background: var(--surface); }
.tools button.quiet { border-color: var(--line); color: var(--muted); }
.tools button.armed { background: var(--warn); border-color: var(--warn); color: var(--on-accent); }
.status { margin: 0; text-align: center; color: var(--muted); min-height: 1.5em; }
.status.good { color: var(--accent); font-weight: 700; }
.status.warn { color: var(--warn); font-weight: 700; }

.clues { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.cluegroup h2 { border-bottom: 1px solid var(--ink); padding-bottom: 4px; margin-bottom: 6px; }
.clues ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.clues li button {
  width: 100%; text-align: start; background: none; border: 0; border-radius: 4px; padding: 6px 8px; cursor: pointer;
  display: grid; grid-template-columns: 2em minmax(0, 1fr); gap: 6px; align-items: baseline;
}
.clues li button:hover { background: var(--surface); }
.clues .num { font-family: var(--display); font-weight: 700; font-size: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.clues li.active button { background: var(--word); }
.clues li.cross button { box-shadow: inset -3px 0 0 var(--cursor); }
.clues li.filled .text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
