/* Valley Keeper in the Obrázky Play style (docs/game-style.md): text sits on things (parchment cards,
   tags, balloons), interactive things are tags with an ink border, a hand-drawn edge and a small
   ink shadow (G3), results land with a stamp (G8). The teacher page keeps style.css.
   Fonts are subsets of the brand fonts (Latin incl. Czech/Slovak, Playpen without contextual
   alternates), ~80 KB instead of 2 MB:
   pyftsubset (after varLib.instancer wght=500:800 for Playpen, wght=600 for Alegreya)
     --unicodes="U+0020-007E,U+00A0-017F,U+2010-2027,U+2030-203A,U+20AC,U+2190-2193,U+2212" --flavor=woff */
@font-face { font-family: "Playpen Sans"; src: url("fonts/playpen-game.woff") format("woff"); font-weight: 500 800; font-display: swap; }
@font-face { font-family: "Alegreya"; src: url("fonts/alegreya-game.woff") format("woff"); font-style: italic; font-weight: 600; font-display: swap; }

:root {
  --paper: #FBF7EE;
  --ink: #1C1712;
  --ink-soft: #5A5040;
  --parchment: #FFF4D6;
  --curl: #F3E2B8;
  --sun: #FFD84A;
  --yolk: #FFE89A;
  --ochre: #F2B45A;
  --vermilion: #E0352B;
  --leaf: #3F9A48;
  --meadow: #8DBA5A;
  --water: #8FC1E3;
  --grass: #3F9A48;
  --deer: #DC8E3C;
  --wolf: #5E86B0;
  --good: #3F9A48;
  --good-soft: #E1F2D6;
  --bad: #C2452F;
  --bad-soft: #FBE1D6;
  --bg: #E9E2D0;
  --on-bg: #1C1712;
  --edge: 255px 14px 225px 16px / 16px 225px 14px 255px;
  --edge-2: 16px 225px 14px 255px / 255px 14px 225px 16px;
  --line: 2.5px solid var(--ink);
  color-scheme: light;
}

/* Dark surroundings, same parchment: the drawings and cards stay as they are. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #2A241C; --on-bg: #F3E9D2; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #2A241C; --on-bg: #F3E9D2; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--on-bg);
  font: 500 17px/1.5 "Playpen Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--paper); color: var(--ink);
  border-bottom: var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  background: none; border: 0; color: inherit; padding: 2px 0; cursor: pointer;
  font: italic 600 22px/1 "Alegreya", Georgia, serif;
}
.brand img { border-radius: 8px; border: 2px solid var(--ink); }
.sync { font-size: 13px; font-weight: 700; }
.sync:not(:empty) { background: var(--parchment); border: 2px solid var(--ink); border-radius: var(--edge); padding: 0 8px; }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 56px; outline: none; }
.loading { text-align: center; margin-top: 30vh; font-weight: 700; }

h1, h2, h3 { font-family: "Alegreya", Georgia, serif; font-style: italic; font-weight: 600; line-height: 1.2; margin: 0 0 10px; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
a { color: inherit; font-weight: 700; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.center { text-align: center; }
.pic { display: inline-block; vertical-align: middle; flex: none; }

/* ---------- things text sits on ---------- */
.card {
  background: var(--parchment); color: var(--ink);
  border: var(--line); border-radius: var(--edge);
  padding: 14px 16px; margin-bottom: 14px;
  position: relative;
}
.card:nth-of-type(even) { border-radius: var(--edge-2); }
.card.note { background: var(--paper); }
.eyebrow { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 0 0 4px; }
.status { text-align: center; color: var(--on-bg); opacity: 0.8; margin: 16px 0 8px; }
.error { color: var(--bad); font-weight: 700; }
.error:empty { display: none; }

.scroll {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%) rotate(-1.2deg);
  font: italic 600 22px/1.25 "Alegreya", Georgia, serif; color: var(--ink);
  padding: 4px 26px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
  background: var(--parchment); border: var(--line); border-radius: 6px;
  box-shadow: inset 10px 0 0 -6px var(--curl), inset -10px 0 0 -6px var(--curl), 3px 3px 0 rgb(28 23 18 / 0.25);
}

.hero, .stage { position: relative; margin-bottom: 14px; border: var(--line); border-radius: 18px; overflow: hidden; background: #cfe3ef; }
.hero img { display: block; width: 100%; height: auto; aspect-ratio: 800 / 440; }
.tagline { display: flex; gap: 12px; align-items: center; transform: rotate(-0.4deg); }
.tagline p { font-weight: 700; }

/* ---------- the guide's balloon ---------- */
.say { display: flex; align-items: flex-end; gap: 6px; margin: 0 0 14px; color: var(--ink); }
.say-face { flex: none; width: 70px; height: auto; margin-bottom: -2px; filter: drop-shadow(2px 2px 0 rgb(28 23 18 / 0.18)); }
.balloon {
  position: relative; flex: 1; min-width: 0;
  background: #fff; border: var(--line); border-radius: 22px 22px 22px 6px;
  padding: 10px 14px; font-weight: 700; margin-bottom: 18px;
}
.balloon::before {
  content: ""; position: absolute; left: -13px; bottom: 6px;
  border: 7px solid transparent; border-right: 12px solid var(--ink); border-left: 0;
}
.balloon::after {
  content: ""; position: absolute; left: -8px; bottom: 8px;
  border: 5px solid transparent; border-right: 9px solid #fff; border-left: 0;
}
.balloon b { display: block; font-size: 19px; }
.balloon p { font-weight: 600; }
.say.big .balloon { font-weight: 600; }
.say.mini { margin: 0; }
.say.mini .say-face { width: 48px; }
.say.mini .balloon { padding: 6px 12px; margin-bottom: 10px; font-size: 15px; }
.card .say { margin-bottom: 10px; }

/* ---------- tags and buttons (G3) ---------- */
.btn, .act, .chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 8px 18px;
  font: 800 17px/1.2 "Playpen Sans", system-ui, sans-serif; color: var(--ink); text-decoration: none;
  background: var(--sun); border: var(--line); border-radius: var(--edge);
  box-shadow: 3px 3px 0 var(--ink); cursor: pointer;
  transform: rotate(-0.6deg);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active:not(:disabled), .act:active:not(:disabled), .chip:active { transform: translate(2px, 2px) rotate(-0.6deg); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled, .act:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn.block { display: flex; width: 100%; margin: 4px 0 12px; }
.btn.big { min-height: 56px; font-size: 19px; }
.btn.paper, .chip { background: var(--paper); transform: rotate(0.5deg); }
.btn.small { min-height: 42px; padding: 6px 14px; font-size: 15px; }
.btn svg, .act svg { flex: none; }
:focus-visible { outline: 3px solid var(--ultramarine, #2F5DB8); outline-offset: 3px; }

.pulse:not(:disabled) { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 3px 3px 0 var(--ink), 0 0 0 0 rgb(255 216 74 / 0.9); }
  50% { box-shadow: 3px 3px 0 var(--ink), 0 0 0 8px rgb(255 216 74 / 0); }
}

input[type="text"], textarea, select {
  width: 100%; padding: 12px 14px;
  border: var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600;
}
input.code-input { text-transform: uppercase; letter-spacing: 3px; font-size: 24px; text-align: center; font-weight: 800; }
textarea { min-height: 96px; resize: vertical; }
label { display: block; font-weight: 700; margin-bottom: 6px; }
.linkish { font: inherit; font-weight: 800; color: inherit; background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }

/* ---------- stamps (G8) ---------- */
.stamp {
  display: inline-block; color: var(--vermilion);
  border: 3px double var(--vermilion); border-radius: 6px;
  padding: 2px 12px; font: 800 20px/1.2 "Playpen Sans", sans-serif; letter-spacing: 3px; white-space: nowrap;
  transform: rotate(-8deg); mix-blend-mode: multiply;
  animation: stamp 0.45s cubic-bezier(.3,1.6,.5,1) both;
}
.stamp.good { color: var(--leaf); border-color: var(--leaf); }
@keyframes stamp { from { transform: scale(2.4) rotate(-14deg); opacity: 0; } to { transform: scale(1) rotate(-8deg); opacity: 1; } }

/* ---------- home ---------- */
.home-head { margin-bottom: 6px; }
.home-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin: -4px 0 14px; }
.rank {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--parchment); color: var(--ink); border: var(--line); border-radius: var(--edge-2); padding: 4px 12px;
}
.rank b { margin-left: 6px; }
.chip { min-height: 44px; padding: 4px 14px; font-size: 16px; }
.banner { display: flex; gap: 12px; align-items: center; background: var(--yolk); }

.trail { position: relative; width: 100%; max-width: 480px; margin: 0 auto 8px; border: var(--line); border-radius: 18px; overflow: hidden; background: var(--meadow); }
.trail-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.stop {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); width: 46%; font: inherit;
}
.stop .medal { position: relative; display: block; width: 96px; height: 96px; border-radius: 50%; transition: transform 0.12s; filter: drop-shadow(3px 4px 0 rgb(28 23 18 / 0.35)); }
.stop .medal img { width: 100%; height: 100%; display: block; }
.stop:hover:not(:disabled) .medal, .stop:focus-visible .medal { transform: scale(1.06) rotate(-3deg); }
.stop .num {
  position: absolute; left: -4px; top: -2px; width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--sun); border: var(--line); border-radius: 50% 46% 52% 48%; font-weight: 800;
}
.stop .mark { position: absolute; right: -6px; bottom: -2px; width: 36px; height: 36px; display: grid; place-items: center; background: var(--paper); border: var(--line); border-radius: 50%; }
.stop .mark.ok { background: var(--leaf); color: #fff; }
.stop-title {
  background: var(--parchment); border: var(--line); border-radius: var(--edge);
  padding: 2px 10px; font-weight: 800; font-size: 15px; line-height: 1.25; text-align: center;
  box-shadow: 2px 2px 0 rgb(28 23 18 / 0.3);
}
.stop.locked { cursor: not-allowed; }
.stop.locked .medal img { filter: grayscale(0.9) brightness(0.92); }
.stop.locked .stop-title { opacity: 0.75; }
.stop.next .medal { animation: bob 1.6s ease-in-out infinite; }
.stop.next .stop-title { background: var(--sun); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ---------- journal ---------- */
.screen-title { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; color: var(--on-bg); }
.screen-title h1 { margin: 0; }
.pages { display: grid; gap: 14px; margin-bottom: 14px; }
.page {
  background: var(--paper); color: var(--ink); border: var(--line); border-radius: 6px 14px 14px 6px;
  padding: 14px 16px; position: relative;
  box-shadow: inset 8px 0 0 -4px var(--curl), 4px 4px 0 rgb(28 23 18 / 0.2);
  background-image: repeating-linear-gradient(transparent 0 27px, rgb(94 134 176 / 0.14) 27px 28px);
}
.page header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.page header div { flex: 1; min-width: 0; }
.page header small { font-weight: 700; color: var(--ink-soft); }
.page header h3 { margin: 0; }
.page > .stamp { position: absolute; right: 12px; bottom: 12px; font-size: 14px; letter-spacing: 2px; padding: 1px 8px; }
.page.locked { display: flex; align-items: center; gap: 12px; background: var(--curl); color: var(--ink-soft); font-weight: 700; }
.page.reveal { animation: reveal 0.6s ease-out both; margin-bottom: 14px; }
@keyframes reveal { from { transform: translateY(24px) rotate(3deg); opacity: 0; } to { transform: none; opacity: 1; } }
.rankup { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; background: var(--yolk); }
.rankup p { margin-left: 8px; font-size: 19px; }

/* ---------- mission steps ---------- */
.stepper { display: flex; align-items: center; gap: 5px; margin-bottom: 12px; color: var(--on-bg); }
.stepper img { margin-right: 4px; }
.stepper i { flex: 1; height: 10px; border: 2px solid var(--ink); border-radius: 6px; background: var(--paper); }
.stepper i.on { background: var(--leaf); }
.stepper i.now { background: var(--sun); }

canvas.valley { display: block; width: 100%; height: auto; aspect-ratio: 800 / 440; }

.probe h2 { font-size: 22px; margin-top: 4px; }
.context { background: var(--paper); border: 2px dashed var(--ink-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.chain { display: flex; align-items: flex-start; justify-content: center; gap: 4px; flex-wrap: wrap; margin: 0 0 12px; }
.chain .link { display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: 13px; min-width: 64px; }
.chain .link img { background: var(--paper); border: 2px solid var(--ink); border-radius: 50%; padding: 4px; width: 60px; height: 60px; }
.chain .eats { display: flex; flex-direction: column; align-items: center; padding-top: 16px; font-weight: 700; color: var(--ink-soft); }

.options { display: grid; gap: 10px; margin: 12px 0; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 10px 12px; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  background: var(--paper); border: var(--line); border-radius: var(--edge);
  box-shadow: 2px 2px 0 rgb(28 23 18 / 0.35);
  transition: transform 0.08s, background 0.12s;
}
.option:nth-child(even) { border-radius: var(--edge-2); }
.option:active { transform: translate(1px, 1px); }
.option[aria-pressed="true"] { background: var(--yolk); box-shadow: 3px 3px 0 var(--ink); transform: rotate(-0.5deg) scale(1.01); }
.option.correct { background: var(--good-soft); border-color: var(--good); box-shadow: 3px 3px 0 var(--good); }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); }
.locked .option { cursor: default; }
.option .o-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.option .letter {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--parchment); border: var(--line); border-radius: 50% 46% 52% 48%; font-weight: 800; font-size: 15px;
}
.option svg.spark { color: var(--ink); }
.opic { display: flex; gap: 12px; flex-wrap: wrap; }
.opic-item { display: inline-flex; align-items: center; gap: 2px; }
.opic .many { display: inline-flex; }
.opic .many img { margin-right: -12px; }
.opic .many img:last-child { margin-right: 0; }
.trend { color: var(--ink); }

.conf-q { margin-top: 6px; }
.confidence { display: flex; gap: 8px; margin: 6px 0 14px; }
.confidence .option { flex: 1 1 0; flex-direction: column; gap: 2px; justify-content: center; text-align: center; padding: 8px 4px; font-size: 14px; font-weight: 700; }

.feedback { margin: 12px 0; position: relative; }
.feedback .stamp { position: absolute; right: 6px; top: -6px; }

.explain h2 { font-size: 26px; }
.explain p strong { background: linear-gradient(transparent 55%, var(--sun) 55%); }

/* explanation diagrams */
.dia { margin: 6px 0 12px; color: var(--ink); }
.dia-row { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 2px solid var(--ink); border-radius: var(--edge); padding: 4px 12px; font-weight: 700; }
.tumble { display: flex; justify-content: center; color: var(--vermilion); margin: 2px 0; }
.pyramid { display: grid; gap: 4px; justify-items: center; }
.tier { display: flex; flex-direction: column; align-items: center; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 4px 8px; font-weight: 700; font-size: 14px; }
.tier-0 { width: 40%; background: #E3ECF6; }
.tier-1 { width: 68%; background: #FBE6CF; }
.tier-2 { width: 100%; background: #E1F2D6; }
.tier-pics { display: flex; flex-wrap: wrap; justify-content: center; }
.capacity, .cycles { position: relative; background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 8px; }
.capacity svg, .cycles svg { display: block; width: 100%; height: auto; }
.dia-pic { position: absolute; top: 6px; left: 52px; }
.dia-note { display: block; font-size: 14px; font-weight: 700; }
.dia-key { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; font-weight: 700; }
.dia-key span { display: inline-flex; align-items: center; gap: 4px; }

/* compare */
.compare { position: relative; display: grid; gap: 12px; margin-bottom: 12px; }
.compare .card { margin: 0; }
.side.good { background: var(--good-soft); }
.side.bad { background: var(--bad-soft); }
.side .visual { margin-bottom: 6px; }
.side > .stamp { position: absolute; right: 10px; top: 10px; font-size: 14px; letter-spacing: 2px; padding: 1px 8px; }

/* ---------- the simulation ---------- */
.hud { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.tag {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--parchment); color: var(--ink); border: 2px solid var(--ink); border-radius: var(--edge);
  padding: 0 9px 0 4px; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums;
}
.tag.year { margin-left: auto; padding-left: 9px; }
.scale-note { margin: -8px 0 10px; color: var(--on-bg); opacity: 0.85; text-align: right; }

.pops { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; }
.pop {
  grid-area: 1 / 1; display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border: var(--line); border-radius: 999px; padding: 2px 12px; font-weight: 800; font-size: 20px;
  animation: pop 1.6s ease-out forwards;
}
.pop.plus { color: var(--leaf); }
.pop.minus { color: var(--vermilion); }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 15% { transform: scale(1.1); opacity: 1; } 70% { opacity: 1; } 100% { transform: translateY(-60px); opacity: 0; } }

.observe { position: absolute; left: 8px; bottom: 4px; right: 22%; pointer-events: none; opacity: 0; }
.observe.show { animation: observe 3.2s ease-in-out forwards; }
@keyframes observe { 0% { opacity: 0; transform: translateY(-8px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.track { position: relative; height: 30px; border: var(--line); border-radius: 999px; background: var(--paper); overflow: hidden; margin-bottom: 12px; }
.track-fill { height: 100%; width: 0; background: repeating-linear-gradient(-45deg, var(--meadow) 0 10px, var(--leaf) 10px 20px); transition: width 0.15s; }
.track-label { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: var(--ink); text-shadow: 0 0 4px var(--paper), 0 0 2px var(--paper); }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-bottom: 12px; }
.act { justify-content: flex-start; background: var(--paper); padding: 6px 12px 6px 6px; font-size: 15px; text-align: left; transform: rotate(0.4deg); }
.act:nth-child(even) { transform: rotate(-0.5deg); border-radius: var(--edge-2); }
.act-pic { position: relative; flex: none; width: 46px; height: 46px; display: grid; place-items: center; background: var(--parchment); border: 2px solid var(--ink); border-radius: 50%; }
.act-pic.glyph { color: var(--ink); }
.act-tag { position: absolute; right: -10px; top: -8px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; font-size: 12px; padding: 0 5px; line-height: 1.4; }
.act-tag.plus { color: var(--leaf); }
.act-tag.minus { color: var(--vermilion); }
.act.pulse:not(:disabled) { background: var(--sun); }
.controls { display: flex; gap: 10px; margin-bottom: 12px; }
.controls .btn { flex: 1 1 auto; }
.controls #play { flex: 2 1 auto; }

.bet { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--yolk); color: var(--ink); border: 2px dashed var(--ink); border-radius: 12px; padding: 6px 12px; margin-bottom: 12px; font-weight: 700; font-size: 15px; }
.chart-card { padding: 10px; }
.chart-card > .stamp { position: absolute; right: 14px; top: 10px; background: rgb(255 255 255 / 0.55); }
canvas.chart { display: block; width: 100%; height: 220px; }
canvas.chart.small { height: 170px; }
.done-card { background: var(--good-soft); }

.checkup h1 { margin-top: 6px; }

/* celebration */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border: 1.5px solid var(--ink); border-radius: 0 80% 0 80%; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(var(--r)); opacity: 0.4; } }

@media (min-width: 560px) {
  .compare { grid-template-columns: 1fr 1fr; }
  .say-face { width: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .observe.show { opacity: 1; }
}
