/* Zupples: soft colours, big targets, calm feedback. */
:root {
  --bg: #fff7ec;
  --surface: #ffffff;
  --ink: #2b2d42;
  --muted: #555a70;
  --line: #e4d6c2;
  --grid-line: #6b5e4c;
  --accent: #4f6df5;
  --accent-ink: #ffffff;
  --good: #1f8a5b;
  --good-soft: #d7f5e6;
  --oops-soft: #ffe7c7;
  --oops-ink: #8a4b00;
  --path: #7cc69b;
  --path-line: #2f8f5b;
  --focus: #1f4fff;
  --radius: 18px;
  --text-scale: 1;
  --font: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: calc(18px * var(--text-scale));
  color-scheme: light;
}
.easy-font { --font: "Atkinson Hyperlegible", Verdana, system-ui, sans-serif; }
.easy-font body { letter-spacing: 0.03em; word-spacing: 0.08em; }
.contrast {
  --bg: #ffffff;
  --ink: #000000;
  --muted: #1a1a1a;
  --line: #000000;
  --grid-line: #000000;
  --accent: #0028b8;
  --path-line: #004d24;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 600;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, a, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 10px; }

.app { max-width: 40rem; margin: 0 auto; padding: 12px 16px 32px; }

/* ---- Header ---- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 2rem; font-weight: 800; margin: 8px 0; letter-spacing: -0.01em; }
.game-title { font-size: 1.4rem; margin: 0; text-align: center; flex: 1; font-weight: 800; }
.icon-btn {
  width: 56px; height: 56px; flex: none;
  display: grid; place-items: center;
  font-size: 1.6rem; text-decoration: none;
  background: var(--surface); border: 2px solid var(--line); border-radius: 50%;
}
.lead { font-size: 1.15rem; color: var(--muted); margin: 0 0 18px; }

/* ---- Home cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 16px; }
.card {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; column-gap: 14px;
  padding: 16px 18px; text-decoration: none;
  background: var(--tint); border: 3px solid transparent; border-radius: var(--radius);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.15s;
}
.contrast .card { border-color: #000; }
.card:hover { transform: translateY(-2px); }
.card-emoji { grid-row: 1 / 4; font-size: 3rem; align-self: center; }
.card-title { font-size: 1.3rem; font-weight: 800; }
.card-tag { color: var(--muted); font-size: 0.95rem; }
.foot { text-align: center; margin-top: 28px; }
.link-btn { background: none; border: none; text-decoration: underline; color: var(--muted); padding: 12px; }

/* ---- Game frame ---- */
.levels { display: flex; justify-content: center; gap: 8px; margin: 14px 0 6px; }
.level {
  min-height: 48px; padding: 6px 16px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px;
}
.level[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.play { display: flex; flex-direction: column; align-items: center; }
.board { width: min(100%, 30rem); display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 10px; }
.status {
  min-height: 3.2em; margin: 14px 0 0; padding: 10px 16px; width: min(100%, 30rem);
  text-align: center; font-size: 1.1rem; border-radius: 14px;
}
.status:empty { visibility: hidden; }
.status[data-kind="oops"] { background: var(--oops-soft); color: var(--oops-ink); }
.status[data-kind="good"], .status[data-kind="info"] { background: var(--good-soft); color: var(--good); }
.contrast .status[data-kind] { color: #000; border: 2px solid #000; }
.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }

.btn {
  min-height: 52px; padding: 8px 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px;
  text-decoration: none; font-weight: 800;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }

/* ---- Grids ---- */
.grid {
  container-type: inline-size;
  width: 100%;
  display: grid; grid-template-columns: repeat(var(--n), 1fr);
  gap: 4px; padding: 6px;
  background: var(--grid-line); border-radius: var(--radius);
  touch-action: manipulation;
}
.cell {
  aspect-ratio: 1; padding: 0; min-width: 0;
  display: grid; place-items: center;
  font-size: calc(100cqi / var(--n) * 0.5); line-height: 1;
  background: var(--surface); border: none; border-radius: 10px;
}
.cell.given { background: #f3ece1; }
.contrast .cell.given { background: #e6e6e6; }
.cell.selected { box-shadow: inset 0 0 0 5px var(--accent); }
.cell.bad { background: var(--oops-soft); box-shadow: inset 0 0 0 4px #f0a24b; }
.contrast .cell.bad { box-shadow: inset 0 0 0 5px #b35c00; }
.grid.boxes { grid-template-columns: repeat(var(--stacks), 1fr); gap: 10px; }
.box { display: grid; grid-template-columns: repeat(var(--bc), 1fr); gap: 4px; }

.palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.chip {
  min-width: 64px; min-height: 64px; padding: 6px 14px;
  font-size: 2rem; line-height: 1;
  background: var(--surface); border: 3px solid var(--line); border-radius: 16px;
}
.chip.tool { font-size: 1.1rem; }
.chip.tool span { font-size: 1.6rem; vertical-align: middle; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: #e6ebff; }
.chip.erase { font-size: 1.6rem; }

/* Crowns: colour regions with thick walls between them */
.grid.crowns { gap: 0; padding: 4px; }
/* Walls are inset shadows (not borders) so every square stays exactly the same size. */
.grid.crowns .cell {
  --wt: 0px; --wb: 0px; --wl: 0px; --wr: 0px;
  position: relative; background: var(--rc); border-radius: 0;
  box-shadow:
    inset 0 var(--wt) 0 var(--grid-line), inset 0 calc(-1 * var(--wb)) 0 var(--grid-line),
    inset var(--wl) 0 0 var(--grid-line), inset calc(-1 * var(--wr)) 0 0 var(--grid-line),
    inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.grid.crowns .cell.edge-t { --wt: 3px; }
.grid.crowns .cell.edge-b { --wb: 3px; }
.grid.crowns .cell.edge-l { --wl: 3px; }
.grid.crowns .cell.edge-r { --wr: 3px; }
.grid.crowns .cell.dot { color: #6b5e4c; font-size: calc(100cqi / var(--n) * 0.4); }
.grid.crowns .cell.bad::after {
  content: ""; position: absolute; inset: 6px; border: 4px dashed #d06a00; border-radius: 50%;
}

/* Dot path */
.path-wrap { position: relative; width: 100%; }
.grid.path { gap: 0; padding: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.grid.path .cell { border-radius: 0; border: 1px solid var(--line); background: var(--surface); }
.grid.path .cell.on { background: #e3f6ea; }
.path-line {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
.path-line polyline {
  fill: none; stroke: var(--path-line); stroke-width: 0.32; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85;
}
.dot-num {
  position: relative; z-index: 1;
  width: 62%; aspect-ratio: 1; display: grid; place-items: center;
  font-size: calc(100cqi / var(--n) * 0.32); font-weight: 800;
  background: var(--ink); color: #fff; border-radius: 50%;
}
.cell.next .dot-num { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.cell.head { background: #c3ecd3 !important; }

/* Picture clues */
.progress { display: flex; gap: 8px; }
.progress span { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.progress .now { background: var(--accent); }
.progress .done { background: var(--good); }
.clue-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.clue {
  aspect-ratio: 1; display: grid; place-items: center; font-size: 2.6rem;
  background: var(--surface); border: 3px solid var(--line); border-radius: 16px;
}
.clue.hidden { color: var(--muted); background: repeating-linear-gradient(45deg, #f6efe4, #f6efe4 8px, #efe5d6 8px, #efe5d6 16px); }
.question { font-size: 1.25rem; font-weight: 800; margin: 4px 0 0; text-align: center; }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 10px; width: 100%; }
.option {
  min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 10px 16px; text-align: left;
  font-size: 1.15rem; font-weight: 800;
  background: var(--surface); border: 3px solid var(--line); border-radius: 16px;
}
.option-icon { font-size: 1.8rem; }
.option.tried { opacity: 0.45; text-decoration: line-through; }
.option.right { border-color: var(--good); background: var(--good-soft); }

/* Word ladder */
.ladder { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 10px; }
.rung {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px 14px;
  padding: 10px 14px; background: var(--surface); border: 3px solid var(--line); border-radius: 18px;
}
.rung.active { border-color: var(--accent); box-shadow: 0 0 0 4px #e6ebff; }
.rung-pic { width: 64px; height: 64px; font-size: 2.4rem; background: var(--bg); border: none; border-radius: 14px; }
.tiles { display: flex; gap: 6px; }
.tile {
  width: 52px; height: 58px; display: grid; place-items: center;
  font-size: 1.8rem; font-weight: 800; background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
}
.tile.blank { border: 3px dashed var(--accent); background: var(--surface); }
.tile.new { background: var(--good-soft); border-color: var(--good); }
.letter-options { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip.letter { font-size: 1.8rem; font-weight: 800; min-width: 72px; }
.chip.letter:disabled { opacity: 0.35; text-decoration: line-through; cursor: default; }

/* Word wander */
.word-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.word-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 999px; font-weight: 800; letter-spacing: 0.08em;
}
.word-chip.found { background: var(--wc); border-color: transparent; }
.word-pic { width: 44px; height: 44px; font-size: 1.6rem; border: none; background: transparent; }
.letter-cell { font-size: calc(100cqi / var(--n) * 0.42) !important; font-weight: 800; position: relative; }
.grid.path .cell.letter-cell.on { background: #e6ebff; }
.grid.path .cell.letter-cell.head { background: #cdd8ff !important; }
.letter-cell.hinted::after {
  content: ""; position: absolute; inset: 8%; border: 3px dashed var(--accent); border-radius: 50%;
}
.word-lines polyline { stroke: var(--accent); stroke-width: 0.18; opacity: 0.35; }

/* Patchwork */
.grid.patches { gap: 0; padding: 4px; touch-action: none; user-select: none; -webkit-user-select: none; }
.grid.patches .cell {
  --wt: 0px; --wb: 0px; --wl: 0px; --wr: 0px;
  position: relative; border-radius: 0;
  box-shadow:
    inset 0 var(--wt) 0 var(--grid-line), inset 0 calc(-1 * var(--wb)) 0 var(--grid-line),
    inset var(--wl) 0 0 var(--grid-line), inset calc(-1 * var(--wr)) 0 0 var(--grid-line),
    inset 0 0 0 1px var(--line);
}
.grid.patches .cell.filled { background: #ece6dc; }
.grid.patches .cell.wrong {
  background: repeating-linear-gradient(45deg, var(--oops-soft), var(--oops-soft) 8px, #fff3e0 8px, #fff3e0 16px) !important;
}
.grid.patches .cell.preview { background: #dfe6ff !important; }
.grid.patches .cell.anchor { background: #c9d4ff !important; }
.patch-clue { display: grid; justify-items: center; gap: 4px; }
.patch-num {
  width: calc(100cqi / var(--n) * 0.52); aspect-ratio: 1; display: grid; place-items: center;
  font-size: calc(100cqi / var(--n) * 0.3); font-weight: 800;
  background: var(--surface); border: 3px solid var(--ink); border-radius: 50%;
}
.shape-icon { display: block; border: 3px solid var(--ink); border-radius: 3px; background: var(--surface); }
.shape-icon.square { width: 14px; height: 14px; }
.shape-icon.wide { width: 22px; height: 11px; }
.shape-icon.tall { width: 11px; height: 22px; }
.patch-size { min-height: 1.5em; margin: 0; font-weight: 800; color: var(--accent); }

/* ---- Dialogs ---- */
.dialog {
  width: min(92vw, 32rem); max-height: 90vh; padding: 0;
  border: none; border-radius: 22px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(43, 45, 66, 0.45); }
.dialog-body { padding: 22px; }
.dialog h2 { margin: 0 0 12px; font-size: 1.5rem; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.howto { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.howto li { display: flex; align-items: center; gap: 14px; font-size: 1.1rem; }
.howto-icon {
  flex: none; width: 52px; height: 52px; display: grid; place-items: center;
  font-size: 1.7rem; background: var(--bg); border-radius: 14px;
}
.plain { padding-left: 0; list-style: none; display: grid; gap: 8px; }

.switch { display: flex; align-items: center; gap: 14px; padding: 10px 0; cursor: pointer; border-bottom: 1px solid var(--line); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: none; width: 58px; height: 34px; border-radius: 999px; background: #cfc6b8; position: relative; transition: background 0.2s;
}
.switch-track::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff;
  transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.switch input:checked + .switch-track { background: var(--good); }
.switch input:checked + .switch-track::after { transform: translateX(24px); }
.switch input:focus-visible + .switch-track { outline: 4px solid var(--focus); outline-offset: 2px; }
.switch-text { display: grid; }
.switch-text small { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.sizes { border: none; padding: 10px 0 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.sizes legend { font-weight: 800; margin-bottom: 6px; }
.size-opt { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 12px; }
.size-opt input { width: 22px; height: 22px; }

/* ---- Win ---- */
.win {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(43, 45, 66, 0.45);
}
.win-card {
  width: min(100%, 26rem); padding: 26px; text-align: center;
  background: var(--surface); border-radius: 26px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: pop 0.4s ease-out;
}
.win-card h2 { font-size: 1.8rem; margin: 6px 0; }
.win-card .row { justify-content: center; }
.win-star { font-size: 4.5rem; animation: spin 1.2s ease-out; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px;
  animation: fall linear forwards;
}

/* ---- Motion (all removed in calm mode) ---- */
.flash { animation: flash 0.9s ease-out; }
@keyframes flash { 0%, 100% { filter: none; } 30% { filter: brightness(1.25) saturate(1.4); transform: scale(1.06); } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } }
@keyframes spin { from { transform: rotate(-180deg) scale(0.3); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

.calm *, .calm *::before, .calm *::after { animation: none !important; transition: none !important; }
.calm .flash { box-shadow: inset 0 0 0 5px var(--good); }

@media (max-width: 420px) {
  .game-title { font-size: 1.15rem; }
  .btn { padding: 8px 12px; }
}

/* ---- Streaks, install and mobile app polish ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.streak-banner {
  display: flex; align-items: center; gap: 14px; margin: 4px 0 14px; padding: 12px 16px;
  background: linear-gradient(135deg, #fff1d6, #ffe0e6); border-radius: var(--radius);
}
.streak-banner.done { background: linear-gradient(135deg, #e3f7ea, #e6f0ff); }
.contrast .streak-banner { background: #fff; border: 3px solid #000; }
.streak-flame { font-size: 2.6rem; line-height: 1; }
.streak-text { display: grid; }
.streak-text strong { font-size: 1.3rem; font-weight: 800; }
.streak-text small { color: var(--muted); font-size: 0.95rem; }
.btn.install { width: 100%; margin-bottom: 14px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card-emoji { position: relative; }
.card-done {
  position: absolute; right: -6px; bottom: -4px; width: 26px; height: 26px;
  display: grid; place-items: center; font-size: 0.95rem; font-weight: 800;
  color: #fff; background: var(--good); border: 2px solid #fff; border-radius: 50%;
}
.card-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.95rem; margin-top: 4px; }
.win-streak { display: grid; font-size: 1.3rem; font-weight: 800; margin: 10px 0 0; }
.win-streak small { font-size: 0.95rem; color: var(--muted); font-weight: 600; }

/* Respect phone notches and home bars when installed. */
.app {
  padding-top: max(12px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}
html, body { overscroll-behavior-y: none; }
button, a { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
@media (display-mode: standalone) {
  .foot { padding-bottom: 8px; }
}
