:root {
  --paper: #fbf5e9;
  --card: #fffaf0;
  --ink: #3b3a36;
  --ink-soft: #6b6559;
  --line: #e4d9c2;
  --accent: #e07b39;      /* found-cat orange */
  --accent-ink: #9a4614;  /* accent text on paper, 4.5:1+ */
  --hint: #3f8f8a;
  --radius: 14px;
  --font: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 17px/1.5 var(--font); }
a { color: var(--accent-ink); }
img { max-width: 100%; display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  font: 600 16px var(--font); text-decoration: none; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--hint); outline-offset: 3px; }
.btn.primary { background: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn[hidden] { display: none; }

/* ---------- homepage ---------- */
.site { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }
.site-head { display: flex; align-items: center; gap: 10px; padding: 18px 0; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 26px; color: var(--ink); text-decoration: none; }
.logo svg { width: 36px; height: 36px; }
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.1; margin: 0 0 10px; }
.hero p { margin: 0; color: var(--ink-soft); font-size: 19px; max-width: 36ch; }

.shelf { font-size: 28px; margin: 32px 0 0; }
.shelf-sub { margin: 4px 0 0; color: var(--ink-soft); }
.puzzles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; margin: 18px 0 40px; }
.card { position: relative; background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.card .btn::after { content: ""; position: absolute; inset: 0; } /* whole card is the tap target */
.card:hover { transform: translateY(-3px); box-shadow: 0 5px 0 var(--ink); }
.card:has(.btn:focus-visible) { outline: 3px solid var(--hint); outline-offset: 3px; }
.card img { width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; border-bottom: 2px solid var(--ink); }
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { margin: 0; font-size: 22px; }
.card p { margin: 0 0 8px; color: var(--ink-soft); }
.card .btn { align-self: flex-start; margin-top: auto; }
.card.soon { border-style: dashed; border-color: var(--ink-soft); align-items: center; justify-content: center; text-align: center; padding: 28px; color: var(--ink-soft); min-height: 200px; }
.badge { display: inline-block; align-self: flex-start; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--line); }

.how h2 { font-size: 26px; margin: 0 0 12px; }
.how ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.how li { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.how b { display: block; font-size: 18px; }
.site-foot { margin-top: 56px; padding-top: 20px; border-top: 2px solid var(--line); color: var(--ink-soft); font-size: 15px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 24px; }
.site-foot nav { display: flex; gap: 4px 20px; flex-wrap: wrap; }
.site-foot a { color: var(--ink-soft); display: inline-block; padding: 10px 0; } /* 44px tap height with line-height */
.site-foot a:hover { color: var(--ink); }

/* ---------- text pages (about, privacy) ---------- */
.prose { max-width: 68ch; }
.prose h1 { font-size: clamp(30px, 5vw, 42px); line-height: 1.15; margin: 16px 0 12px; }
.prose h2 { font-size: 22px; margin: 28px 0 6px; }
.prose p, .prose li { color: var(--ink); }
.prose ul { padding-left: 1.2em; }
.prose li { margin-bottom: 8px; }
.prose .updated { color: var(--ink-soft); font-size: 15px; }

/* ---------- game page ---------- */
body.game { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
#game { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hud { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 2px solid var(--ink); background: var(--card); flex-wrap: wrap; }
.hud .back { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); text-decoration: none; font-size: 22px; }
.hud .back:focus-visible { outline: 3px solid var(--hint); }
.hud h1 { font-size: 19px; margin: 0; line-height: 1.2; }
.hud .sub { font-size: 14px; color: var(--ink-soft); }
.hud .title { flex: 1; min-width: 120px; }
.progress { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.progress [data-count] { font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.progress.bump { animation: bump .35s; }
.dots { display: flex; gap: 3px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); }
.dots i.on { background: var(--accent); }
.hud .actions { display: flex; gap: 8px; }
.hud .btn { min-height: 40px; padding: 0 14px; font-size: 15px; }
[data-hint][data-wait]::after { content: " " attr(data-wait) "s"; font-variant-numeric: tabular-nums; }

.viewport { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; background: #efe6d3; }
.viewport:active { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage.animating { transition: transform .35s ease; }
.scene { width: 100%; height: 100%; pointer-events: none; -webkit-user-drag: none; }
.cats, .fx { position: absolute; inset: 0; pointer-events: none; }

.cat { position: absolute; aspect-ratio: 1; transform: translate(-50%, -50%) rotate(var(--rot)) scaleX(var(--flip)); }
.cat svg { width: 100%; height: 100%; overflow: visible; clip-path: var(--clip, none); }
.cat path, .cat ellipse { fill: #fffaf0; stroke: var(--ink); stroke-width: var(--sw, 3.5); stroke-linejoin: round; stroke-linecap: round; transition: fill .3s; }
.cat .line { fill: none; }
.cat .eye { fill: var(--ink); stroke: none; }
.cat.ghost:not(.found) path, .cat.ghost:not(.found) ellipse { fill: transparent; } /* background texture shows through */
.cat.found path:not(.line), .cat.found ellipse { fill: var(--accent); }
.cat.found svg { animation: hop .5s; }
.cat.painted { border-radius: 50%; }
.cat.painted.found { box-shadow: 0 0 0 calc(3px / var(--s, 1)) var(--accent), 0 0 0 calc(5px / var(--s, 1)) #fff; }

/* rings live in scene space; divide by --s so they stay a constant size on screen */
.pop, .miss, .hint-ring { position: absolute; border-radius: 50%; transform: translate(-50%, -50%); }
.pop { width: calc(70px / var(--s, 1)); aspect-ratio: 1; border: calc(4px / var(--s, 1)) solid var(--accent); animation: ring .7s ease-out forwards; }
.miss { width: calc(26px / var(--s, 1)); aspect-ratio: 1; border: calc(3px / var(--s, 1)) solid var(--ink-soft); animation: ring .45s ease-out forwards; }
.hint-ring { width: 13%; aspect-ratio: 1; border: 4px dashed var(--hint); background: rgb(63 143 138 / .12); animation: hint 3.2s ease-in-out forwards; }

.hud .zoom { display: flex; gap: 6px; }
.hud .zoom .btn { width: 40px; padding: 0; font-size: 20px; }

dialog.done { border: 2px solid var(--ink); border-radius: 20px; background: var(--card); color: var(--ink); padding: 28px 24px; width: min(380px, calc(100% - 32px)); text-align: center; }
dialog.done::backdrop { background: rgb(59 58 54 / .45); }
dialog.done h2 { margin: 8px 0 4px; font-size: 26px; }
dialog.done p { margin: 0 0 18px; color: var(--ink-soft); }
dialog.done .row { display: flex; flex-direction: column; gap: 10px; }
dialog.done .cat-hero { width: 96px; margin: 0 auto; }
dialog.done .cat-hero path:not(.line), dialog.done .cat-hero ellipse { fill: var(--accent); stroke: var(--ink); stroke-width: 3.5; stroke-linejoin: round; }
dialog.done .cat-hero .line { fill: none; stroke: var(--ink); stroke-width: 3.5; }
dialog.done .cat-hero .eye { fill: var(--ink); stroke: none; }

@keyframes ring { from { opacity: 1; scale: .4; } to { opacity: 0; scale: 1.4; } }
@keyframes hop { 40% { transform: translateY(-14%); } }
@keyframes bump { 50% { transform: scale(1.18); } }
@keyframes hint { 0% { opacity: 0; scale: 1.6; } 15%, 75% { opacity: 1; scale: 1; } 100% { opacity: 0; } }

@media (max-width: 560px) {
  .hud { padding: 6px 8px; gap: 6px; }
  .hud .sub { display: none; }
  .hud h1 { font-size: 17px; }
  .hud .btn { padding: 0 12px; }
  .hud .zoom .btn { width: 36px; padding: 0; }
  /* phone: title and score on the first row, all buttons on the second */
  .hud .title { min-width: 0; }
  .hud .zoom { order: 3; margin-right: auto; }
  .hud .actions { order: 4; }
  .hud .zoom, .hud .actions { flex: 0 0 auto; }
  .hud::after { content: ""; order: 2; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
