/* ===========================================================================
   Mini Crossword — layout on top of corner.css. 5x5, big cells, tap-to-select
   with the active clue shown in a bar, arrow-key + tap navigation, on-screen
   keyboard for touch. Colorblind-safe: the CURRENT cell is marked by a thick
   ring (shape), the active word by a fill — so selection never relies on hue
   alone; check/reveal use corner symbols. Sizes via --cell (set by fit()).
   =========================================================================== */
/* crossword-specific colors that read correctly in BOTH themes (the shared
   --ink flips light in dark mode, which would invert the grid). */
:root {
  --xw-cell-bg: #FFFFFF;    /* a fillable square */
  --xw-block:   #2A2622;    /* a blocked square */
  --xw-line:    #2A2622;    /* frame + gridlines */
}
:root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) {
  :root {
    --xw-cell-bg: #29251F;
    --xw-block:   #0B0A07;
    --xw-line:    #4A443A;
  }
}

.xw-main { --cell: 60px; --gap: 4px;
  max-width: 560px; margin: 0 auto; padding: 6px clamp(10px, 3vw, 20px) 24px;
  display: flex; flex-direction: column; align-items: center; }

.xw-head { width: 100%; text-align: center; margin: 2px 0 6px; }
.xw-head h1 { font-size: clamp(1.4rem, 5.2vw, 2rem); }
.xw-head .xw-sub { color: var(--ink-soft); font-weight: 700; font-size: .92rem; margin-top: 1px; }
.xw-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0 2px; width: 100%; }
.xw-controls .qc-iconbtn { min-height: 44px; min-width: 0; padding: 0 10px; font-size: .84rem; gap: .32em; box-shadow: var(--shadow-soft); }
.xw-controls .qc-iconbtn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }

.practice-banner {
  display: none; align-items: center; gap: .5em; justify-content: center;
  width: 100%; margin: 6px 0 0; padding: 8px 14px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-family: var(--font-display); font-weight: 600; font-size: .98rem;
}
body.xw.is-practice .practice-banner { display: flex; }

/* ---- active clue bar (tap ‹ ›, or tap it to switch direction) ---- */
.xw-cluebar { display: flex; align-items: stretch; width: 100%; max-width: 460px;
  margin: 8px 0 2px; background: var(--accent-soft); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--accent-line); }
.xw-clue-nav { flex: 0 0 auto; width: 46px; border: 0; background: transparent; cursor: pointer;
  font-size: 1.5rem; color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.xw-clue-nav:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.xw-clue-text { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center;
  padding: 8px 6px; cursor: pointer; min-height: 52px; text-align: center; }
.xw-clue-dir { font-family: var(--font-display); font-weight: 700; font-size: .72rem; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent-ink); }
.xw-clue-words { font-weight: 700; font-size: 1.04rem; color: var(--ink); line-height: 1.25; }

/* ---- grid ---- */
.xw-grid { display: grid; grid-template-columns: repeat(5, var(--cell)); grid-template-rows: repeat(5, var(--cell));
  gap: var(--gap); margin: 6px auto 0; background: var(--xw-line);
  padding: var(--gap); border-radius: 10px; }
.xw-cell { position: relative; background: var(--xw-cell-bg); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: calc(var(--cell) * 0.5); line-height: 1;
  color: var(--ink); text-transform: uppercase; cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent; }
.xw-cell.black { background: var(--xw-block); cursor: default; pointer-events: none; }
.xw-cell .num { position: absolute; top: 2px; left: 4px; font-family: var(--font-body);
  font-weight: 800; font-size: calc(var(--cell) * 0.22); color: var(--ink-soft); line-height: 1; }
.xw-cell.in-word { background: var(--accent-soft); }
.xw-cell.cursor { background: color-mix(in srgb, var(--accent) 30%, var(--surface)); }
/* the current cell also gets a thick ring — shape, not just color (colorblind) */
.xw-cell.cursor::before { content: ""; position: absolute; inset: 0; border: 3px solid var(--accent-ink);
  border-radius: 4px; pointer-events: none; }
/* checked-wrong: a corner ✗ + tint (symbol so it's not color-only) */
.xw-cell.wrong::after { content: "\2717"; position: absolute; bottom: 0; right: 3px;
  font-family: var(--font-body); font-weight: 800; font-size: calc(var(--cell) * 0.26); color: #C0392B; }
@media (prefers-color-scheme: dark) { .xw-cell.wrong::after { color: #FF7A6B; } }
.xw-cell.wrong { background: color-mix(in srgb, #C0392B 14%, var(--surface)); }
body.xw.is-practice .xw-cell.in-word, .xw-cell.in-word { }
/* revealed cell: small dot marker so it's clear it was given */
.xw-cell.revealed .num-dot { position: absolute; top: 2px; right: 3px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent-ink); }

/* ---- result ---- */
.xw-result { display: none; width: 100%; max-width: 460px; margin: 12px 0 2px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: center; }
body.xw.is-done .xw-result { display: block; }
/* when solved, the keyboard and clue bar aren't needed — hide them so the
   result banner fits without scrolling. */
body.xw.is-done .keyboard, body.xw.is-done .xw-cluebar { display: none; }
.xw-result h2 { font-size: 1.3rem; margin-bottom: .2em; }
.xw-result .streakline { color: var(--ink-soft); font-weight: 700; margin-top: 4px; }
.xw-result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }

/* ---- keyboard (letters + delete; no Enter needed) ---- */
.keyboard { width: 100%; max-width: 520px; margin: 10px auto 0; display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key { flex: 1 1 0; min-width: 0; height: var(--key-h, 52px); min-height: 0;
  display: flex; align-items: center; justify-content: center; position: relative;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  font-family: var(--font-display); font-weight: 600; font-size: clamp(1rem, calc(var(--key-h, 52px) * 0.42), 1.25rem);
  text-transform: uppercase; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, filter .1s ease; }
.key:active { transform: translateY(2px); }
.key.wide { flex: 1.6 1 0; font-size: .92rem; }

/* ---- clue list modal ---- */
.xw-cluelist { display: grid; grid-template-columns: 1fr; gap: 18px; }
.xw-cluelist h3 { font-size: 1.05rem; margin: 0 0 6px; color: var(--accent-ink); }
.xw-cluelist ol { list-style: none; margin: 0; padding: 0; }
.xw-cluelist li { display: flex; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.xw-cluelist li:hover { background: var(--accent-soft); }
.xw-cluelist li.active { background: var(--accent-soft); outline: 2px solid var(--accent-line); }
.xw-cluelist li .n { font-weight: 800; color: var(--ink-soft); min-width: 1.4em; }

@media (max-width: 460px) {
  .xw-controls .lbl { display: none; }
  .xw-controls .qc-iconbtn { padding: 0 13px; font-size: 1.2rem; }
}

.xw-print-clues { display: none; }

/* ---- print: black-and-white grid + two-column clue list for paper ---- */
@media print {
  .qc-nav, .qc-foot, .xw-controls, .practice-banner, .xw-cluebar, .keyboard, .xw-result, .xw-sub, .qc-sr, .qc-modal-overlay { display: none !important; }
  html, body, .xw-main { background: #fff !important; color: #000 !important; }
  .xw-main { --cell: 54px !important; --gap: 2px; max-width: none; padding: 0; }
  .xw-head h1 { color: #000 !important; }
  .xw-grid { background: #000 !important; border: 2px solid #000 !important; }
  .xw-cell { background: #fff !important; color: #000 !important; }
  .xw-cell.black { background: #000 !important; }
  .xw-cell .num { color: #000 !important; }
  .xw-cell.in-word, .xw-cell.cursor { background: #fff !important; }
  .xw-cell.cursor::before, .xw-cell.wrong::after, .xw-cell .num-dot { display: none !important; }
  .xw-cell.wrong { color: #000 !important; }
  .xw-print-clues { display: flex !important; gap: 24px; margin: 14px auto 0; max-width: 540px; text-align: left; }
  .xw-print-clues .xw-pc-col { flex: 1 1 0; }
  .xw-print-clues h4 { margin: 0 0 4px; font-family: var(--font-display); font-size: 1.02rem; color: #000; }
  .xw-print-clues ul { list-style: none; margin: 0; padding: 0; }
  .xw-print-clues li { font-size: .82rem; margin: 2px 0; color: #000; line-height: 1.3; }
  /* "Blank puzzle": print an empty grid (numbers only), not the player's letters */
  body.print-blank .xw-cell .ltr { visibility: hidden !important; }
}
