/* ===== Heti Skandi — look & feel ===== */
:root {
  --red: #e40c1d; --red-dark: #b60a18; --red-soft: #fde7e9;
  --ink: #1c1a17; --muted: #6b655c; --line: #2b2825; --line-soft: #d9d2c4;
  --bg: #f3ede2; --paper: #fffdf8; --card: #fff;
  --clue-bg: #f1ebdf; --hl: #ffe88a; --hl-word: #f4d85a; --word: #e6eefb; --sel: #2b6fe9;
  --radius: 14px; --shadow: 0 2px 6px rgba(40, 30, 10, .08), 0 12px 32px rgba(40, 30, 10, .08);
  --font-ui: "Nunito", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-grid: "Roboto Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --W: 12;
  font-family: var(--font-ui); color: var(--ink); font-size: 16px; line-height: 1.4;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg) radial-gradient(circle at 50% -20%, #fff8ea 0, var(--bg) 60%); min-height: 100vh; }

/* --- masthead: banner-lo.png (2170x725, content ends at row ~484) over a straight red band, main controls to its right.
   Sizes are in image-pixel units scaled to --bw; the image's empty bottom third is cropped by the fixed .brand height. --- */
.masthead { background: #fdfdfd; overflow: hidden; padding: 8px 16px 0; }
.masthead-inner { --bw: min(560px, 94vw); --band-top: calc(var(--bw) * 461 / 2170); display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: center;
  gap: 0 36px; max-width: 1180px; margin: 0 auto; }
.brand { position: relative; width: var(--bw); height: calc(var(--bw) * 575 / 2170); flex: none; }
.brand img { position: absolute; z-index: 1; left: 0; top: 0; display: block; width: 100%; height: auto; }
.brand .band { position: absolute; z-index: 0; left: 50%; top: var(--band-top); width: 600vw; height: calc(var(--bw) * 96 / 2170);
  background: var(--red); transform: translateX(-50%); }
.masthead-controls { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 10px; min-height: var(--band-top); padding: 4px 0; }
.masthead-controls .group { flex-wrap: wrap; }
@media (max-width: 1023px) {
  .masthead-inner { --bw: min(600px, 94vw); }
  .masthead-controls { width: 100%; align-items: center; min-height: 0; padding: 12px 0 10px; }
  .masthead-controls .group { justify-content: center; }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- toolbar --- */
.controls { background: var(--card); border-bottom: 1px solid var(--line-soft); box-shadow: 0 4px 18px rgba(40, 30, 10, .06);
  padding: 14px 16px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; position: relative; z-index: 2; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 10px; }
.controls .toolbar { font-size: 15px; gap: 10px 8px; }
.controls .toolbar button, .controls .toolbar .chip { padding-left: 11px; padding-right: 11px; }
.group { display: flex; align-items: center; gap: 8px; }
.group-label { font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sep { width: 1px; height: 26px; background: var(--line-soft); }
.controls { padding-top: 10px; }

button { font: inherit; font-weight: 700; color: var(--ink); padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--line-soft);
  background: #fff; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; line-height: 1.2;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s; }
button:hover { border-color: #b9b1a1; background: #fbf8f1; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 3px solid rgba(43, 111, 233, .35); outline-offset: 1px; }
button svg { width: 16px; height: 16px; flex: none; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 3px 10px rgba(228, 12, 29, .3); }
button.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }

.levels, .lang-switch { display: inline-flex; background: #f1ece2; border-radius: 999px; padding: 4px; gap: 2px; }
.levels button, .lang-switch button { border: none; background: transparent; padding: 6px 16px; color: var(--muted); }
.levels button:hover, .lang-switch button:hover { background: #fff; color: var(--ink); }
.levels button.active, .lang-switch button.active { background: var(--ink); color: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.levels button.active[data-level="1"] { background: #2e8b57; }
.levels button.active[data-level="2"] { background: #d98b00; }
.levels button.active[data-level="3"] { background: var(--red); }

label.code { display: inline-flex; align-items: stretch; }
label.code input { width: 110px; font: inherit; font-weight: 700; padding: 6px 12px; border: 1.5px solid var(--line-soft); border-right: none;
  border-radius: 999px 0 0 999px; background: #fff; color: var(--ink); -moz-appearance: textfield; }
label.code input::-webkit-outer-spin-button, label.code input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
label.code input:focus { outline: none; border-color: #b9b1a1; }
label.code button { border-radius: 0 999px 999px 0; }

.chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px 7px 10px; border-radius: 999px; border: 1.5px solid var(--line-soft);
  background: #fff; font-weight: 600; cursor: pointer; user-select: none; transition: background .15s, border-color .15s; }
.chip:hover { border-color: #b9b1a1; }
.chip input { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 0; border-radius: 6px; border: 2px solid #b9b1a1; background: #fff;
  display: grid; place-content: center; cursor: pointer; transition: background .15s, border-color .15s; }
.chip input::before { content: ""; width: 10px; height: 10px; clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%); background: #fff; transform: scale(0); transition: transform .12s; }
.chip input:checked { background: var(--red); border-color: var(--red); }
.chip input:checked::before { transform: scale(1); }
.chip:has(input:checked) { background: var(--red-soft); border-color: #f3b6bb; }

.lang-switch button { padding: 6px 12px; font-size: 14px; letter-spacing: .04em; }
#status { font-size: 13px; white-space: nowrap; color: var(--muted); max-width: 100%; overflow-wrap: anywhere; }
#status:not(:empty) { padding-left: 14px; border-left: 1px solid var(--line-soft); }
#status.ok { color: #1f7a3f; font-weight: 700; }
#status.bad { color: var(--red-dark); font-weight: 700; }

/* --- puzzle sheet --- */
main { padding: 28px 16px 48px; display: flex; flex-direction: column; align-items: center; gap: 28px; }
.sheet { --cell: min(58px, calc((100vw - 76px) / var(--W))); background: var(--paper); padding: 22px 22px 20px; border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 100%; border: 1px solid #ece5d6; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 3px solid var(--red); }
.sheet-title { font-weight: 900; font-size: 24px; letter-spacing: .06em; text-transform: uppercase; color: var(--red); }
.sheet-meta { font-size: 14px; font-weight: 600; color: var(--muted); }
.sheet-head .mascot { display: none; }
.solution-sheet { display: none; }
body.show-solution-sheet .solution-sheet { display: block; }

.grid-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
.grid { display: grid; grid-template-columns: repeat(var(--W), var(--cell)); grid-auto-rows: var(--cell); border: 2.5px solid var(--line);
  width: max-content; margin: 0 auto; font-family: var(--font-grid); background: var(--line); gap: 1px; }
.cell { position: relative; overflow: hidden; background: #fff; }
.cell.letter { cursor: text; }
.cell.letter.quote { background: var(--hl); }
.cell.letter.sel { box-shadow: inset 0 0 0 3px var(--sel); z-index: 1; }
.cell.letter.word { background: var(--word); }
.cell.letter.quote.word { background: var(--hl-word); }
.cell.letter.wrong .l { color: var(--red); }
.cell.letter.wrong::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: 10%; height: 3px; border-radius: 2px; background: var(--red); }
.cell .l { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--font-ui); font-weight: 800;
  font-size: calc(var(--cell) * .52); line-height: 1; letter-spacing: -.01em; }
.cell .l.two { font-size: calc(var(--cell) * .4); }
.cell .l.three { font-size: calc(var(--cell) * .31); }
.cell .l.sol { color: #1b7a3a; }
.cell svg.arrow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; color: var(--line); }
.cell.clue { background: var(--clue-bg); display: flex; flex-direction: column; }
.cell.clue .ct { flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 1px 2px; line-height: 1.04;
  font-size: calc(var(--cell) * .2); font-weight: 700; color: var(--ink); hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere; }
.cell.clue .ct .t { display: block; max-width: 100%; }
.cell.clue .ct + .ct { border-top: 1px solid var(--line); }
.cell.clue .ct.fixed { font-weight: 700; text-transform: uppercase; color: var(--red-dark); font-size: calc(var(--cell) * .14) !important; letter-spacing: .02em; }
.cell.empty { background: var(--line); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 4px, transparent 4px 8px); }

.answer { margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 15px; font-weight: 700; }
.answer .aw { display: inline-flex; gap: 3px; }
.answer .ab { width: calc(var(--cell) * .55); height: calc(var(--cell) * .62); border: 1.5px solid var(--line); border-radius: 5px; background: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: calc(var(--cell) * .34); }
.legend { font-size: 13px; color: var(--muted); margin: 14px 0 0; max-width: 72ch; line-height: 1.45; }

footer.site { text-align: center; font-size: 13px; color: var(--muted); padding: 0 16px 28px; }

@media (max-width: 600px) {
  .controls { padding: 12px 10px 10px; }
  .toolbar { gap: 8px 10px; }
  button { padding: 7px 13px; }
  .sheet { padding: 14px 10px 14px; }
  .sheet-title { font-size: 20px; }
  .sep { display: none; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: #fff; }
  .controls, .masthead, footer.site, .screen-only { display: none; }
  main { padding: 0; gap: 0; }
  .sheet { box-shadow: none; border: none; border-radius: 0; padding: 0; width: 100%; background: #fff; }
  .sheet { --cell: calc(186mm / var(--W)); }
  .sheet-head { border-bottom-color: #000; align-items: flex-end; flex-wrap: nowrap; padding-bottom: 0; margin-bottom: 4mm; }
  .sheet-head .sheet-meta { flex: 1 1 auto; text-align: right; padding-bottom: 3mm; }
  .sheet-head .mascot { display: block; height: 27mm; width: auto; flex: none; margin-bottom: -0.5mm; }
  .sheet-title { color: #000; padding-bottom: 2mm; }
  .grid-wrap { overflow: visible; display: flex; justify-content: center; }
  .cell.letter.sel, .cell.letter.word { box-shadow: none; background: #fff; }
  .cell.letter.quote, .cell.letter.quote.word { background: #e8e8e8; }
  .cell.letter.wrong::after { display: none; }
  .cell.empty { background: #777; background-image: none; }
  .grid, .cell, .cell.clue, .cell.letter.quote { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .solution-sheet { display: none; page-break-before: always; }
  body.print-solution .solution-sheet { display: block; }
  body.print-hide-entries .cell .l.ent { visibility: hidden; }
}
