/* Fredoka (SIL OFL 1.1, see fonts/OFL.txt), bundled so the game makes no font requests. */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("fonts/fredoka-latin.woff2") format("woff2");
}
:root {
  --ink: #3b2340;
  --cream: #fff8ea;
  --wall: #fff1d6;
  --tomato: #ef5b4c;
  --butter: #ffcf5a;
  --mint: #8fd8c3;
  --teal: #2b857f;
  --cookie: #dfa45c;
  --choc: #5b3424;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--wall);
  overscroll-behavior: none;
}
body {
  font-family: Fredoka, "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
#game {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none; cursor: pointer;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.meter { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.progress {
  display: flex; gap: 5px; padding: 5px 9px;
  background: rgba(255, 248, 234, .92);
  border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 var(--ink);
}
.pip { width: 26px; height: 26px; display: block; }
.pip .ck { fill: rgba(59, 35, 64, .06); stroke: var(--ink); stroke-width: 2; stroke-dasharray: 3.2 2.6; }
.pip .chip { fill: rgba(59, 35, 64, .12); }
.pip.on .ck { fill: var(--cookie); stroke-dasharray: none; }
.pip.on .chip { fill: var(--choc); }
.pip.pop { animation: pop .55s cubic-bezier(.2, 1.8, .4, 1); }
.bones { display: flex; gap: 4px; padding: 3px 8px; background: rgba(255, 248, 234, .75); border-radius: 999px; }
.bone { width: 28px; height: 14px; display: block; }
.bone path, .res-bone path { fill: rgba(59, 35, 64, .1); stroke: rgba(59, 35, 64, .45); stroke-width: 1.8; stroke-dasharray: 2.5 2; }
.bone.on path, .res-bone.on path { fill: var(--cream); stroke: var(--ink); stroke-dasharray: none; }
.bone.on { animation: pop .55s cubic-bezier(.2, 1.8, .4, 1); }

.caught {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 6px;
  background: var(--butter); border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 var(--ink);
  font-size: 22px; font-weight: 700; line-height: 1;
}
.caught[hidden] { display: none; }
.caught svg { width: 26px; height: 26px; }
.caught.pop { animation: pop .35s cubic-bezier(.2, 1.8, .4, 1); }
.controls { display: flex; gap: 8px; }
.btn {
  position: relative; width: 48px; height: 48px; padding: 0;
  display: grid; place-items: center;
  border: 3px solid var(--ink); border-radius: 15px;
  background: var(--cream); color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer; transition: transform .08s, box-shadow .08s, background .2s;
}
.btn svg { width: 26px; height: 26px; fill: currentColor; }
.btn svg .ln { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.hint { background: var(--butter); position: relative; }
.sniff-n {
  position: absolute; right: -8px; top: -8px; min-width: 22px; height: 22px; padding: 0 5px;
  display: grid; place-items: center; font-size: 14px; line-height: 1; color: var(--cream);
  background: var(--tomato); border: 2.5px solid var(--ink); border-radius: 999px;
}
.btn.hint.invite, .btn.hint.free { animation: nudge 1.6s ease-in-out infinite; }
.btn.hint.free .sniff-n { background: var(--teal); }
.btn.hint.gain .sniff-n { animation: pop .55s cubic-bezier(.2, 1.8, .4, 1); }
.btn[hidden] { display: none; }
.btn.off { background: #ece3d4; color: rgba(59, 35, 64, .55); }
.btn.off::after {
  content: ""; position: absolute; width: 34px; height: 4px; border-radius: 2px;
  background: var(--tomato); transform: rotate(-45deg); box-shadow: 0 0 0 2px var(--cream);
}
.btn.confirm { background: var(--tomato); color: var(--cream); animation: wob .35s; }
.btn:focus-visible, .again:focus-visible { outline: 4px solid var(--teal); outline-offset: 3px; }

@media (max-width: 440px) {
  .btn { width: 42px; height: 42px; border-radius: 13px; }
  .btn svg { width: 22px; height: 22px; }
  .controls { gap: 6px; }
  .pip { width: 21px; height: 21px; }
  .progress { gap: 3px; padding: 4px 7px; }
  .bone { width: 24px; height: 12px; }
}

/* ---------- title flash ---------- */
.title {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  display: grid; place-content: center; text-align: center;
  animation: titleIn .8s cubic-bezier(.2, 1.6, .4, 1) both;
  transition: opacity .5s ease, transform .5s ease;
}
.title::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: min(620px, 92vw); height: min(300px, 50vw);
  transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 248, 234, .92), rgba(255, 248, 234, 0));
}
.title h1 {
  position: relative; margin: 0; font-weight: 700; line-height: .92;
  font-size: clamp(52px, 12vw, 128px); letter-spacing: .01em;
  text-shadow:
    -4px -4px 0 var(--ink), 4px -4px 0 var(--ink), -4px 4px 0 var(--ink), 4px 4px 0 var(--ink),
    0 -4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink), 4px 0 0 var(--ink),
    0 11px 0 var(--ink);
}
.title .t1 { color: var(--butter); display: inline-block; transform: rotate(-4deg); }
.title .t2 { color: var(--tomato); display: inline-block; transform: rotate(3deg); }
.title p {
  position: relative; justify-self: center; margin: 16px 0 0; padding: 6px 16px;
  font-size: clamp(16px, 3.4vw, 22px); font-weight: 600;
  color: var(--cream); background: var(--ink); border-radius: 999px;
}
.title.gone { animation: none; opacity: 0; transform: scale(1.12); }

/* ---------- results ---------- */
.results {
  position: fixed; inset: 0; z-index: 4; padding: 16px;
  display: grid; place-items: end center; padding-bottom: max(5vh, 24px);
  background: linear-gradient(to top, rgba(59, 35, 64, .38), rgba(59, 35, 64, 0) 70%);
  opacity: 0; transition: opacity .35s ease;
  pointer-events: none; /* the kitchen stays playable (munch the cookies!) */
}
.results .card { pointer-events: auto; }
.results[hidden] { display: none; }
.results.show { opacity: 1; }
.card {
  width: min(360px, 100%); padding: 18px 24px 24px; text-align: center;
  background: var(--cream); border: 4px solid var(--ink); border-radius: 28px;
  box-shadow: 0 9px 0 var(--ink);
  transform: scale(.75) rotate(-3deg);
  transition: transform .5s cubic-bezier(.2, 1.7, .4, 1);
}
.results.show .card { transform: scale(1) rotate(-1deg); }
.big-cookie { width: 74px; height: 74px; margin-top: -54px; filter: drop-shadow(0 4px 0 var(--ink)); animation: spin 6s linear infinite; }
.yum {
  margin: 2px 0 6px; font-size: 64px; line-height: 1; font-weight: 700; color: var(--tomato);
  text-shadow: -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 7px 0 var(--ink);
}
.the-end { margin: 0 0 2px; font-size: 17px; font-weight: 600; }
.stats { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 18px; margin: 10px 0 4px; }
.stat { display: inline-flex; align-items: center; gap: 6px; font-size: 28px; }
.stat svg { width: 30px; height: 30px; }
.stat .res-bone { width: 32px; height: 16px; }
.best { margin: 4px 0 0; min-height: 1.2em; font-weight: 600; color: var(--teal); font-size: 18px; }
.hint-line { margin: 2px 0 0; font-size: 16px; color: rgba(59, 35, 64, .75); }
.hint-line[hidden] { display: none; }
.again {
  margin-top: 14px; display: inline-flex; align-items: center; gap: 10px;
  font: inherit; font-size: 24px; font-weight: 700; color: var(--cream);
  background: var(--tomato); border: 4px solid var(--ink); border-radius: 18px;
  padding: 12px 26px 12px 20px; box-shadow: 0 5px 0 var(--ink); cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.again svg { width: 28px; height: 28px; }
.again[hidden] { display: none; }
.again.next { margin-right: 6px; padding: 12px 18px 12px 24px; }
.again.secondary { background: var(--cream); color: var(--ink); font-size: 20px; padding: 10px 18px 10px 14px; }
.res-stars { display: flex; justify-content: center; gap: 6px; margin: 2px 0 4px; }
.res-star { width: 40px; height: 40px; fill: rgba(59, 35, 64, .1); stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.res-star.on { fill: var(--butter); animation: pop .5s cubic-bezier(.2, 1.8, .4, 1) both; }
.res-star.on:nth-child(2) { animation-delay: .25s; }
.res-star.on:nth-child(3) { animation-delay: .5s; }
.genius { margin: 0 0 6px; font-size: 17px; font-weight: 600; color: var(--tealDark, #2b857f); }
.score-line { margin: 4px 0 0; font-size: 16px; font-weight: 600; }
.btn-row { display: flex; justify-content: center; align-items: center; gap: 10px; }
.btn-row .again { margin-top: 12px; }
.again.rooms { padding: 10px 12px; }
.again.rooms svg { width: 26px; height: 26px; }

/* ---------- panels: out of sniffs, room map ---------- */
.panel-wrap { position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; padding: 16px; background: rgba(59, 35, 64, .45); opacity: 0; transition: opacity .25s ease; }
.panel-wrap[hidden] { display: none; }
.panel-wrap.show { opacity: 1; }
.panel {
  width: min(380px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px 22px 22px; text-align: center;
  background: var(--cream); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink);
}
.panel h2 { margin: 0 0 4px; font-size: 30px; }
.panel-sub { margin: 4px 0 8px; font-size: 17px; }
.rooms { display: grid; gap: 8px; margin: 8px 0 4px; }
.room-card {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; text-align: left;
  font: inherit; font-size: 19px; font-weight: 600; color: var(--ink); cursor: pointer;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px 12px; box-shadow: 0 4px 0 var(--ink);
}
.room-card.here { background: var(--butter); }
.room-card.locked { opacity: .5; cursor: default; }
.room-card:focus-visible { outline: 4px solid var(--teal); outline-offset: 3px; }
.room-n { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--cream); font-size: 16px; }
.room-stars .star { font-size: 20px; color: rgba(59, 35, 64, .2); }
.room-stars .star.on { color: #f2a93b; }
/* map: one row per chapter, the big room as a card and its errands as small tiles */
.chapter { display: flex; gap: 6px; align-items: stretch; }
.chapter .room-card { flex: 1 1 auto; min-width: 0; grid-template-columns: 30px 1fr; grid-template-rows: auto auto; row-gap: 0; padding: 6px 10px; font-size: 17px; }
.chapter .room-card .room-n { grid-row: span 2; }
.chapter .room-card .room-stars { grid-column: 2; line-height: 1; }
.chapter .room-card .room-stars .star { font-size: 15px; }
.chapter .room-card .room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level-tile {
  flex: 0 0 52px; display: grid; justify-items: center; align-content: center; gap: 2px; padding: 5px 2px;
  font: inherit; color: var(--ink); cursor: pointer; background: #fff;
  border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink);
}
.level-tile .room-n { width: 26px; height: 26px; font-size: 14px; }
.level-tile .room-stars { line-height: 1; white-space: nowrap; }
.level-tile .room-stars .star { font-size: 11px; }
.level-tile.here { background: var(--butter); }
.level-tile.locked { opacity: .5; cursor: default; }
.level-tile:focus-visible { outline: 4px solid var(--teal); outline-offset: 3px; }
@media (max-width: 400px) { .level-tile { flex-basis: 46px; } .chapter .room-card { font-size: 15px; padding: 6px 8px; } }

/* level card: number, name and the mission line, shown for a few seconds at the start */
.lvl-card {
  position: fixed; left: max(12px, env(safe-area-inset-left)); top: 76px; z-index: 4; pointer-events: none;
  display: flex; align-items: center; gap: 10px; max-width: min(440px, calc(100vw - 24px)); padding: 7px 16px 7px 8px;
  background: rgba(255, 248, 234, .95); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 4px 0 var(--ink);
  opacity: 0; transform: translateY(-10px); transition: opacity .35s ease, transform .35s ease;
}
.lvl-card.show { opacity: 1; transform: none; }
.lvl-card b { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--cream); font-size: 17px; }
.lvl-text { display: grid; line-height: 1.15; }
.lvl-text span { font-size: 19px; font-weight: 700; }
.lvl-text small { font-size: 15px; font-weight: 500; }
.lvl-text small:empty { display: none; }

.fade { position: fixed; inset: 0; z-index: 8; background: var(--wall); opacity: 0; pointer-events: none; transition: opacity .3s ease; }
.fade.on { opacity: 1; }
.again:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- keyboard & screen-reader layer ---------- */
#targets { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.target {
  position: absolute; left: 0; top: 0; padding: 0; margin: 0;
  border: 0; border-radius: 50%; background: transparent; pointer-events: none;
}
.target:focus { outline: none; }
.target:focus-visible { outline: 5px solid var(--teal); outline-offset: 2px; box-shadow: 0 0 0 10px rgba(255, 255, 255, .65); }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 22px; background: var(--wall); }

@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes wob { 0%, 100% { transform: rotate(0); } 33% { transform: rotate(-8deg); } 66% { transform: rotate(8deg); } }
@keyframes titleIn { from { opacity: 0; transform: scale(.6) rotate(-6deg); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes nudge { 0%, 100% { transform: none; } 15% { transform: rotate(-10deg) scale(1.08); } 30% { transform: rotate(10deg) scale(1.08); } 45% { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .title, .pip.pop, .bone.on, .big-cookie, .btn.confirm, .btn.hint.invite, .btn.hint.free, .res-star.on { animation: none; }
  .lvl-card { transition: none; }
  .card, .results.show .card { transition: none; transform: none; }
}

/* ---------- story mode ---------- */
.story-line { margin: 2px 0 8px; font-size: 16px; font-weight: 600; color: var(--choc); }
.panel-sub.mission { font-weight: 600; color: var(--teal); }
