/* FunWords Puzzles. Colours and fonts follow www.funwords.eu. Fonts: Fredoka and Atkinson Hyperlegible (OFL); the
   text font is the books' copy with a plain zero (kdp/fonts/make-plain-zero.py), since the slashed one reads as Ø. */
@font-face { font-family: 'Fredoka'; src: url('fonts/fredoka-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('fonts/fredoka-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Atkinson'; src: url('fonts/funwords-text-400.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson'; src: url('fonts/funwords-text-700.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  --ink: #1d2433; --subtle: #5b6475; --line: #eadfce; --bg: #fffaf3; --card: #ffffff; --soft: #fff1dd;
  --red: #d94841; --green: #2f9e5b; --orange: #f28c28; --purple: #6c4bb6; --blue: #2b6cb0; --yellow: #ffd23f;
  --sel: #ffe08a; --peer: #fff4d6; --same: #ffd9a8; --clash: #c62828; --given: #1d2433; --entered: #2b6cb0;
  --radius: 16px; --shadow: 0 6px 24px rgba(60, 40, 10, .10), 0 1px 3px rgba(60, 40, 10, .08);
  --fs: 17px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eef1f6; --subtle: #a5adbd; --line: #2e3646; --bg: #151a24; --card: #1e2532; --soft: #27303f;
    --sel: #6b5a1e; --peer: #2d3850; --same: #5a4322; --clash: #ff7a70; --given: #eef1f6; --entered: #8cb8ff;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #eef1f6; --subtle: #a5adbd; --line: #2e3646; --bg: #151a24; --card: #1e2532; --soft: #27303f;
  --sel: #6b5a1e; --peer: #2d3850; --same: #5a4322; --clash: #ff7a70; --given: #eef1f6; --entered: #8cb8ff;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
}
:root[data-size="large"] { --fs: 21px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 400 var(--fs)/1.45 'Atkinson', system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
h1, h2, h3, .brand, .btn, .tile b, .chip { font-family: 'Fredoka', 'Atkinson', system-ui, sans-serif; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.3em; margin: 0; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--subtle); margin: .2em 0; }
.center { text-align: center; }
.loading { text-align: center; margin-top: 40vh; font-family: 'Fredoka'; font-size: 2rem; color: var(--red); }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.ok { color: var(--green); stroke-width: 3; }
main { max-width: 720px; margin: 0 auto; padding: 0 16px 28px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

/* Top bar */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: 8px 10px; background: var(--bg); max-width: 720px; margin: 0 auto; }
.bar-title { flex: 1; font-size: 1.15em; margin: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; text-decoration: none; }
.icon-btn:active { background: var(--soft); }
.timer { font-variant-numeric: tabular-nums; color: var(--subtle); padding: 0 6px; font-size: .95em; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.5rem; padding-left: 6px; }
.brand .tiles { display: flex; gap: 3px; }
.brand .tiles b { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: #fff; font-size: 1.05rem; box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.brand .tiles b:nth-child(1) { background: var(--red); transform: rotate(-6deg); }
.brand .tiles b:nth-child(2) { background: var(--green); transform: rotate(4deg); }
.brand .tiles b:nth-child(3) { background: var(--orange); transform: rotate(-3deg); }

/* Home */
.daily { margin-top: 4px; }
.daily-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.streak { display: flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 99px; background: var(--soft); color: var(--subtle); }
.streak.on { color: var(--orange); }
.streak.on .icon { fill: currentColor; }
.streak b { font-family: 'Fredoka'; font-size: 1.2em; }
.daily-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.daily-btn { display: flex; align-items: center; gap: 8px; padding: 10px; min-width: 0; border-radius: 14px; background: var(--soft); text-decoration: none; min-height: 72px; }
.daily-btn > span:not(.art) { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.daily-btn small { color: var(--subtle); }
.daily-btn.done { outline: 2px solid var(--green); }
.daily-btn .art { width: 44px; height: 44px; border-radius: 12px; background: var(--red); padding: 3px; flex: none; }
.daily-btn:nth-child(2) .art { background: var(--blue); }
.art svg { width: 100%; height: 100%; display: block; }
.section { margin: 22px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); color: #fff; text-decoration: none; box-shadow: var(--shadow); min-height: 150px; }
.tile .art { width: 64px; height: 64px; margin-bottom: auto; }
.tile b { font-size: 1.15em; margin-top: 10px; hyphens: manual; line-height: 1.15; }
.tile small { opacity: .9; }
.tile.red { background: var(--red); } .tile.blue { background: var(--blue); } .tile.orange { background: #d9741a; } .tile.purple { background: var(--purple); } .tile.green { background: var(--green); }
.badge { position: absolute; top: 12px; right: 12px; font-style: normal; font-size: .75em; background: rgba(255,255,255,.92); color: #1d2433; padding: 2px 8px; border-radius: 99px; }
.unlock-card { display: flex; gap: 12px; align-items: center; width: 100%; margin-top: 18px; border: 2px dashed var(--orange); text-align: left; cursor: pointer; }
.unlock-card .icon { color: var(--orange); fill: currentColor; width: 32px; height: 32px; }
.unlock-card span { display: flex; flex-direction: column; }
.unlock-card small { color: var(--subtle); }

/* Puzzle list */
.note { background: var(--soft); border-radius: 12px; padding: 10px 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-weight: 600; min-height: 40px; display: flex; align-items: center; }
.chip.on { background: var(--ink); color: var(--bg); }
.pz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; margin-top: 10px; }
.pz-grid.titled { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pz { position: relative; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 64px; padding: 10px 12px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); text-decoration: none; cursor: pointer; }
.pz:not(.titled .pz) { align-items: center; }
.pz b { font-family: 'Fredoka'; font-size: 1.15em; }
.pz span { font-size: .9em; line-height: 1.25; }
.pz .icon { position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; }
.pz.done { background: var(--soft); }
.pz.locked { opacity: .55; }
.pz .started { position: absolute; top: 6px; right: 8px; font-size: .7em; color: var(--orange); }

/* Playing */
/* Puzzles sit in the middle of tall phones instead of leaving the bottom half empty. */
.play { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100vh - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding-bottom: 20px; }
.pz-title { margin: 0 0 8px; font-family: 'Fredoka'; font-weight: 600; color: var(--subtle); text-align: center; }
.stage { width: 100%; display: flex; flex-direction: column; align-items: center; }
.tools { display: flex; justify-content: center; gap: 8px; margin: 10px 0 6px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 72px; padding: 8px 10px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; font-size: .8em; color: var(--subtle); }
.tool:active, .tool[aria-pressed="true"] { background: var(--soft); color: var(--ink); }
.tool[aria-pressed="true"] .icon { color: var(--orange); }

/* Word search */
.ws { width: 100%; display: flex; flex-direction: column; align-items: center; }
.ws-board-wrap { width: min(100%, 62vh); container-type: inline-size; }
.ws-board { position: relative; display: grid; grid-template-rows: repeat(var(--n), 1fr); aspect-ratio: 1; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); touch-action: none; user-select: none; -webkit-user-select: none; padding: 0; }
.ws-row { display: grid; grid-template-columns: repeat(var(--n), 1fr); }
.ws-cell { display: grid; place-items: center; font-family: 'Fredoka'; font-weight: 600; font-size: calc(100cqw / var(--n) * .58); line-height: 1; position: relative; z-index: 1; }
.ws-cell.hint { animation: hint 1.6s ease-out; border-radius: 50%; }
@keyframes hint { 0%, 60% { background: var(--yellow); color: #1d2433; } 100% { background: transparent; } }
.ws-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ws-band { opacity: .32; }
.ws-live { stroke: var(--orange); opacity: .45; }
.ws-count { color: var(--subtle); margin: 10px 0 4px; }
.ws-words { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; padding: 0 4px; margin: 0; max-width: 620px; }
.ws-word { font-weight: 700; position: relative; }
.ws-word.found { color: var(--subtle); text-decoration: line-through; text-decoration-color: var(--band); text-decoration-thickness: 3px; }

/* Sudoku */
.su { width: 100%; display: flex; flex-direction: column; align-items: center; }
.su-board-wrap { width: min(100%, 56vh); container-type: inline-size; }
.su-board { display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 8px; overflow: hidden; background: var(--card); }
.su-cell { border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--card); padding: 0; display: grid; place-items: center; font-family: 'Fredoka'; font-weight: 600; font-size: calc(100cqw / 9 * .56); color: var(--entered); cursor: pointer; aspect-ratio: 1; }
.su-cell.br { border-right: 2px solid var(--ink); }
.su-cell.bb { border-bottom: 2px solid var(--ink); }
.su-cell.given { color: var(--given); font-weight: 700; }
.su-cell.peer { background: var(--peer); }
.su-cell.same { background: var(--same); }
.su-cell.sel { background: var(--sel); }
.su-cell.clash { color: var(--clash); }
.su-notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; padding: 2px; }
.su-notes i { font-style: normal; font-size: calc(100cqw / 9 * .24); line-height: 1; display: grid; place-items: center; color: var(--subtle); font-family: 'Atkinson'; }
.su-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; width: min(100%, 56vh); min-width: 300px; }
.su-digit { position: relative; display: flex; flex-direction: column; align-items: center; padding: clamp(8px, 2vh, 18px) 0 clamp(4px, 1vh, 10px); border: 0; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); cursor: pointer; }
.su-digit b { font-family: 'Fredoka'; font-size: 1.6em; line-height: 1.1; color: var(--entered); }
.su-digit small { font-size: .65em; color: var(--subtle); min-height: 1.2em; }
.su-digit.used { opacity: .35; }

/* Crossword */
.cw { width: 100%; display: flex; flex-direction: column; align-items: center; }
.cw-board-wrap { width: min(100%, 50vh); container-type: inline-size; }
.cw-board { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 2px; }
.cw-block { aspect-ratio: 1; }
.cw-cell { position: relative; aspect-ratio: 1; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--card); padding: 0; cursor: pointer; display: grid; place-items: center; }
.cw-cell small { position: absolute; top: 1px; left: 2px; font-size: max(8px, calc(100cqw / var(--cols) * .26)); line-height: 1; color: var(--subtle); }
.cw-cell b { font-family: 'Fredoka'; font-size: calc(100cqw / var(--cols) * .55); line-height: 1; }
.cw-cell.word { background: var(--peer); }
.cw-cell.sel { background: var(--sel); }
.cw-cell.wrong b { color: var(--clash); }
.cw-cell.done { background: var(--soft); }
.cw-clue { width: 100%; max-width: 620px; margin-top: 10px; padding: 10px 14px; border: 0; border-radius: 12px; background: var(--soft); text-align: left; min-height: 3.2em; cursor: pointer; }
.cw-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 720px; margin-top: 14px; }
.cw-list h3 { margin: 0 0 6px; font-size: 1em; }
.cw-list ol { list-style: none; padding: 0; margin: 0; }
.cw-list li { padding: 5px 6px; border-radius: 8px; cursor: pointer; font-size: .92em; }
.cw-list li.cur { background: var(--sel); }
@media (max-width: 520px) { .cw-lists { grid-template-columns: 1fr; } }

/* On-screen keyboard */
.kb { width: 100%; max-width: 560px; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: flex; justify-content: center; gap: 4px; }
.kb-key { flex: 1; max-width: 48px; min-height: 48px; border: 0; border-radius: 8px; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.2); font-family: 'Fredoka'; font-weight: 600; font-size: 1.1em; cursor: pointer; padding: 0; display: grid; place-items: center; }
.kb-key:active { background: var(--sel); }
.kb-key.used { color: var(--subtle); background: var(--soft); }
.kb-wide { max-width: 70px; flex: 1.5; }

/* Cryptogram */
.cg { width: 100%; display: flex; flex-direction: column; align-items: center; }
.cg-phrase { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 18px; max-width: 640px; margin: 8px 0; }
.cg-word { display: flex; gap: 3px; align-items: flex-end; }
.cg-slot { display: flex; flex-direction: column; align-items: center; width: 30px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.cg-slot b { display: grid; place-items: center; width: 30px; height: 34px; border-bottom: 2.5px solid var(--ink); font-family: 'Fredoka'; font-size: 1.25em; color: var(--entered); border-radius: 4px 4px 0 0; }
.cg-slot small { font-size: .78em; color: var(--subtle); font-weight: 700; }
.cg-slot.sel b { background: var(--sel); }
.cg-slot.given b { color: var(--given); }
.cg-slot.clash b { color: var(--clash); }
.cg-slot.done b { border-color: var(--green); }
.cg-punct { font-size: 1.3em; padding-bottom: 20px; }
.cg-help { color: var(--subtle); text-align: center; font-size: .9em; max-width: 520px; }
:root[data-size="large"] .cg-slot, :root[data-size="large"] .cg-slot b { width: 36px; }

/* Maze */
.mz { width: 100%; display: flex; flex-direction: column; align-items: center; }
.mz-board-wrap { width: min(100%, 66vh * var(--ratio, .72)); }
.mz-board { width: 100%; display: block; touch-action: none; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.mz-walls { stroke: var(--ink); }
.mz-trail { stroke: var(--orange); opacity: .85; }
.mz-head { fill: var(--red); }
.mz-goal { fill: var(--green); opacity: .45; }
.mz-board.done .mz-trail { stroke: var(--green); }
.mz-help { color: var(--subtle); text-align: center; }

/* Sheets (dialogs) */
dialog.sheet { border: 0; border-radius: 22px; padding: 22px; width: min(92vw, 440px); background: var(--card); color: var(--ink); box-shadow: var(--shadow); text-align: center; overflow: hidden; }
dialog.sheet::backdrop { background: rgba(10, 14, 22, .5); }
.sheet-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.btn { display: block; width: 100%; padding: 13px 18px; border-radius: 14px; border: 0; background: var(--soft); cursor: pointer; font-size: 1.05em; text-decoration: none; text-align: center; }
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--subtle); margin-top: 6px; }
.perks { text-align: left; padding-left: 1.2em; }
.perks li { margin: 6px 0; }
.solved h2 { font-size: 1.8em; color: var(--green); margin-top: 6px; }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -10px; left: calc(var(--k) * 5.5%); width: 8px; height: 14px; border-radius: 2px; background: var(--red); animation: fall 1.8s ease-in calc(var(--k) * 40ms) forwards; opacity: 0; }
.confetti i:nth-child(3n) { background: var(--green); } .confetti i:nth-child(3n+1) { background: var(--orange); } .confetti i:nth-child(4n) { background: var(--blue); }
@keyframes fall { 0% { opacity: 1; transform: translateY(0) rotate(0); } 100% { opacity: 0; transform: translateY(260px) rotate(540deg); } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } .ws-cell.hint { animation-duration: .01s; } }

/* Settings */
.settings section { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; }
.field select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-width: 140px; }
.field input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--red); }
.about p { margin: 0; }
.error { padding-top: 30vh; text-align: center; }

/* Unlock code */
.code-form { text-align: left; margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.code-form label { font-weight: 700; font-size: .95em; }
.code-row { display: flex; gap: 8px; }
.code-input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-family: ui-monospace, monospace; font-size: .85em; }
.code-row .btn { width: auto; flex: none; }
