/* „Pelkės žiburiai" — iPad-Safari-first. One stage, letterboxed, never scrolls.
   Everything inside #frame is laid out in 1600×1000 scene units; #frame is
   scaled to fit the viewport, so no CSS below needs media queries.

   The palette is the night the earlier games were lit by, taken out onto the
   bog: black-green water, moon-grey mist, birch bone and reed, and the cool
   klystžvakė teal that only living lights are allowed to carry — with one warm
   amber heart inside each of them. Paper and ink stay warm so every sentence
   the child has to READ keeps the daylight contrast a beginner needs. */

@font-face {
  font-family: 'Andika';
  src: url('/fonts/Andika-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Andika';
  src: url('/fonts/Andika-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --night: #101A22;
  --moon: #C8D8C0;
  --mist: #9FB8AC;
  --amber: #F5C86E;
  --paper: #F6EBD7;
  --paper-2: #E4D3B6;
  --ink: #3A2A1C;
  --bark: #4A3626;
  --bark-dark: #32241A;
  --moss: #7A8C5A;
  --dawn: #E9A6A0;
  /* the bog's own: the water it is made of, the alder and reed it grows, the
     marsh-tea pink — and the two colours of a klystžvakė, the cool light and
     the warm heart. Nothing that is not alive may use the wisp pair. */
  --bogwater: #0A1410;
  --wisp: #9FE8D8;
  --wisp-warm: #FFD9A0;
  --alder: #5A4632;
  --reed: #6B7A45;
  --gailis: #D8A0B8;
  --font: 'Andika', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  overscroll-behavior: none;
  background: #0B1114;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app { width: 100%; height: 100%; }

/* The letterbox is darker than any scene, so the stage reads as a window cut
   into the night rather than as a picture pasted on a background. */
#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 45%, #16232B00 0%, #070C0F 100%),
    #0B1114;
}

#frame {
  position: relative;
  width: 1600px;
  height: 1000px;
  flex: 0 0 auto;
  transform-origin: 50% 50%;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 0 90px rgba(0, 0, 0, 0.8);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: var(--font);
  color: var(--ink);
}

button {
  font-family: var(--font);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- hotspots ---------- */

.hs { cursor: pointer; }
.hitrect { fill: transparent; }

#scene.pulsing .hs { animation: hspulse 1.05s ease-in-out 2; }
@keyframes hspulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.shaking {
  transform-box: fill-box;
  transform-origin: center;
  animation: shake 0.6s ease-in-out;
}
@keyframes shake {
  10%, 90% { transform: translateX(-7px); }
  30%, 70% { transform: translateX(9px); }
  50% { transform: translateX(-9px); }
}

/* delight-only idle reactions */
.twitch { transform-box: fill-box; transform-origin: 50% 100%; animation: twitch 1.4s ease-in-out; }
@keyframes twitch { 20% { transform: rotate(-2.5deg); } 45% { transform: rotate(2deg); } 70% { transform: rotate(-1deg); } }

/* A tapped plant pivots where it is rooted: the base stays planted and the
   crown leans over. Anything that HANGS wants .sway-hang instead. */
.sway { transform-box: fill-box; transform-origin: 50% 100%; animation: sway 1.5s ease-in-out; }
@keyframes sway { 25% { transform: rotate(3deg); } 60% { transform: rotate(-2.4deg); } 85% { transform: rotate(1deg); } }

/* Hung from a rail, a cord or a branch: the tie is the pivot. */
.sway-hang { transform-box: fill-box; transform-origin: 50% 0%; animation: sway 1.5s ease-in-out; }

.shine { animation: shine 1.5s ease-in-out; }
@keyframes shine { 40% { filter: brightness(1.35); } }

.glow { animation: glow 4.2s ease-in-out; }
@keyframes glow { 10%, 90% { filter: brightness(1.25); } }

/* Žiburėlis idles as a floating light: the bob and the breath are ONE keyframe
   on `.g-body` (two transform animations on one element would fight), the
   halo's breathing is the art module's own, off-period. The dwellers' talking
   mouths reuse the same three class hooks inside their scene art. */
.guide .g-body {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: breathe 4.6s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scaleY(1.025) scaleX(0.99); } }

.guide.wisp .g-body { animation: wispFloat 5.4s ease-in-out infinite; }
@keyframes wispFloat {
  0%, 100% { transform: translateY(0) scaleY(1); }
  30% { transform: translateY(-14px) scaleY(1.02) scaleX(0.99); }
  50% { transform: translateY(-9px) scaleY(1.005); }
  75% { transform: translateY(-16px) scaleY(1.02) scaleX(0.99); }
}

.guide .g-eyes { transform-box: fill-box; transform-origin: 50% 50%; animation: blink 6.2s ease-in-out infinite; }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97.5% { transform: scaleY(0.08); } }

/* Unscoped to .guide on purpose: the dwellers are scene art (the Gurgis/Ūkė
   pattern) whose own groups take `.talking` while they speak. */
.talking .g-mouth { transform-box: fill-box; transform-origin: 50% 50%; animation: talk 0.34s ease-in-out infinite; }
@keyframes talk { 50% { transform: scaleY(2.1) scaleX(0.85); } }

/* The KEPT moment: the game puts `.flaring` on #guide for ~1.2 s and the
   hidden `zb-flare` ring inside the art module blooms once. The module only
   draws the ring; this file owns when and how it shows. */
.guide.wisp .zb-flare { opacity: 0; }
.guide.wisp.flaring .zb-flare {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: wispflare 1.2s ease-out 1;
}
@keyframes wispflare {
  0% { opacity: 0; transform: scale(0.4); }
  22% { opacity: 0.95; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.1); }
}

/* ---------- speech bubbles ---------- */

/* Explicit stacking, so DOM insertion order never decides who gets a tap:
   hud 5 < game layers 10 < tap catcher 50 < bubble 51 < sheets 60 < title 70. */
.tapcatch {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: auto;
}

.bubble {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 51;
  /* Narrow on purpose: short lines suit a reader who is still sounding words
     out, and a wide bubble lands on whatever just opened. */
  max-width: 640px;
  padding: 26px 36px;
  background: var(--paper);
  color: var(--ink);
  font-size: 38px;
  line-height: 1.34;
  border-radius: 30px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
/* The resting state is VISIBLE and the entrance animates away from hidden, so
   a browser that suppresses animations (reduced motion) still shows the text. */
.bubble.in { animation: bubblein 0.22s ease-out; }
@keyframes bubblein { from { opacity: 0; transform: translateY(10px); } }

.bubble::after {
  content: '';
  position: absolute;
  left: var(--tail-x, 50%);
  margin-left: -18px;
  border: 18px solid transparent;
}
.bubble.tail-down::after { top: 100%; border-top-color: var(--paper); border-bottom: 0; }
.bubble.tail-up::after { bottom: 100%; border-bottom-color: var(--paper); border-top: 0; }

/* Žiburėlis — the voice the child hears most: warm paper rimmed in his own
   cool light, lit from just inside the edge. The inner glow is an inset
   shadow rather than a filter — no SVG or CSS filters anywhere near a text
   box. */
.bubble-wisp {
  background: var(--paper);
  border: 5px solid var(--wisp);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.55),
    inset 0 0 22px rgba(159, 232, 216, 0.65),
    inset 0 0 6px rgba(159, 232, 216, 0.4);
}
.bubble-wisp.tail-down::after { border-top-color: var(--wisp); }
.bubble-wisp.tail-up::after { border-bottom-color: var(--wisp); }

/* the dwellers: Alksnė, Baublys, Gūbrys. Darker paper inside a bark border —
   heavier than Žiburėlis, so who is speaking is legible before a word of it
   is read. */
.bubble-stone {
  background: var(--paper-2);
  border: 5px solid var(--bark);
  color: #3B2A19;
  font-weight: 700;
}
.bubble-stone.tail-down::after { border-top-color: var(--paper-2); }
.bubble-stone.tail-up::after { border-bottom-color: var(--paper-2); }

/* the closing lines. Nobody's mouth moves and nothing is answered here, so
   the bubble steps back a little. */
.bubble-quiet {
  background: rgba(246, 235, 215, 0.92);
  font-style: italic;
}
.bubble-quiet.tail-down::after { border-top-color: rgba(246, 235, 215, 0.92); }
.bubble-quiet.tail-up::after { border-bottom-color: rgba(246, 235, 215, 0.92); }

/* ---------- paper overlays & panels ---------- */

.sheetwrap {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(6, 12, 14, 0.7);
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.paper, .panel {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.paper.in, .panel.in { animation: sheetin 0.2s ease-out; }
@keyframes sheetin { from { opacity: 0; transform: scale(0.96); } }

.paper {
  width: 900px;
  max-width: 90%;
  max-height: 88%;
  padding: 64px 74px 46px;
  overflow-y: auto;
  background-image: linear-gradient(rgba(140, 110, 70, 0.06) 1px, transparent 1px);
  background-size: 100% 56px;
}
.paper.wide { width: 1180px; }

/* A kept sentence handed back at the gate: the same paper, but carried by a
   wisp — a faint cool edge glow instead of ruled lines. */
.paper.word-card {
  border: 5px solid var(--wisp);
  background-image: none;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 44px rgba(159, 232, 216, 0.4),
    inset 0 0 26px rgba(159, 232, 216, 0.35);
}

.paper-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  background: var(--bark);
  color: var(--paper);
  font-size: 34px;
  line-height: 1;
}
.paper-close:active { background: var(--bark-dark); }

.paper-body p { font-size: 35px; line-height: 1.45; margin: 0 0 24px; }
.paper-body h2 { font-size: 46px; margin: 0 0 30px; text-align: center; letter-spacing: 1px; }
.paper-body .sign { text-align: right; font-style: italic; margin-bottom: 0; }

/* Writing kept by the bog: carved in the signpost and the stone, woven into
   the juosta. UPPERCASE, big, tracked out a little, and given the room a
   sentence a child is sounding out needs. It is the one text the whole
   encounter depends on, so nothing shares its sheet. */
.paper-body .mark {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.34;
  letter-spacing: 2px;
  text-align: center;
  margin: 0;
}

.panel {
  padding: 56px 64px 48px;
  text-align: center;
  max-width: 94%;
}
.panel-note { font-size: 32px; margin: 0 0 18px; }
.panel-task { font-size: 38px; font-weight: 700; line-height: 1.4; margin: 0 0 24px; }

.panel-body { display: block; }
.panel-actions { display: flex; align-items: center; justify-content: center; gap: 26px; }

.bigbutton {
  border: none;
  border-radius: 22px;
  background: var(--moss);
  color: var(--paper);
  font-size: 46px;
  font-weight: 700;
  padding: 22px 60px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
}
.bigbutton:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28); }
.bigbutton.ghost { background: var(--bark); }

/* ---------- the encounters ---------- */

/* The core verb of this game: a dweller's lines, and whole sentences the
   child can say. As wide as the widest paper because a sentence must never
   wrap in the middle — a beginner reading over two lines is reading two
   things. */
.encounter {
  width: 1180px;
  max-width: 94%;
  padding: 48px 64px 44px;
  text-align: left;
}
/* the dweller's own voice: two lines at most, and never a demand */
.encounter .enc-mood {
  font-size: 36px;
  line-height: 1.4;
  font-style: italic;
  color: #4A3626;
  margin: 0 auto 34px;
  max-width: 900px;
  text-align: center;
}
.encounter .enc-choices {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
/* Big sentences. 44px of text inside a 108px-tall target: the tap area is
   generous because a child reading aloud points at the words with the same
   finger they answer with. */
.encounter .enc-say {
  display: block;
  width: 100%;
  min-height: 108px;
  border: 4px solid var(--bark);
  border-radius: 20px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: 44px;
  line-height: 1.3;
  font-weight: 700;
  text-align: left;
  padding: 22px 34px;
}
.encounter .enc-say:active { background: var(--bark); color: var(--paper); }
/* finality: after a kept sentence is picked, the buttons die where they stand */
.encounter .enc-say[disabled] { opacity: 0.55; }

/* The panel sits low and dims lightly, so the dweller it is being said TO
   stays visible over its top edge while the child reads. */
.encounter-wrap {
  align-items: flex-end;
  padding-bottom: 26px;
  background: rgba(6, 12, 14, 0.45);
}

/* The kept tier wears its one UI-ism: a caption row — a small round wisp
   light and „Pelkė įsimins." — so the sentences that count are told apart
   from small talk before a word of them is read. game.js builds the row as
   `<div class="enc-caption">` holding an `.enc-wisp` icon and the text. */
.encounter.kept { border: 5px solid var(--wisp); }
.encounter.kept .enc-caption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 30px;
  font-style: italic;
  color: #4E5A50;
  margin: -8px 0 26px;
}
.encounter.kept .enc-wisp {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 0 6px rgba(159, 232, 216, 0.8));
}
.encounter.kept .enc-wisp svg { width: 100%; height: 100%; display: block; }
.encounter.kept .enc-wisp .w-halo { fill: rgba(159, 232, 216, 0.35); }
.encounter.kept .enc-wisp .w-core { fill: var(--wisp-warm); }

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  z-index: 5;
  left: 28px;
  top: 22px;
  display: flex;
  align-items: center;
  gap: 24px;
  pointer-events: none;
  padding: 10px 20px 10px 14px;
  border-radius: 20px;
  background: rgba(8, 16, 20, 0.42);
}
.hud[hidden] { display: none; }
/* steps aside while anyone is speaking — see Engine.say() */
.hud { transition: opacity 0.18s ease; }
.hud.dimmed { opacity: 0; }

/* The three wisp-lights. Unlit: a dim cool ring with the night inside it.
   Lit: the ring bright, a warm core kindled in it. It is a COUNT — three
   round lights and nothing else — so it can never be read as a word, a
   letter or a name. Which dweller kept which word is the child's to
   remember. */
.hud-lights { display: flex; gap: 12px; }
.hud-wisp svg { width: 56px; height: 56px; display: block; }
.hud-wisp .w-inside { fill: rgba(4, 10, 12, 0.62); }
.hud-wisp .w-ring { stroke: rgba(159, 232, 216, 0.3); }
.hud-wisp .w-core { fill: transparent; }
.hud-wisp.lit .w-inside { fill: rgba(20, 34, 30, 0.9); }
.hud-wisp.lit .w-ring { stroke: rgba(159, 232, 216, 0.9); }
.hud-wisp.lit .w-core {
  fill: var(--wisp-warm);
  filter: drop-shadow(0 0 7px rgba(159, 232, 216, 0.9));
}

/* ---------- title & ending ---------- */

.gamelayer { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.gamelayer > * { pointer-events: auto; }

.titlescreen {
  position: absolute;
  inset: 0;
  z-index: 70;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(9, 20, 24, 0.82);
}
.title-h1 {
  margin: 0;
  font-size: 124px;
  font-weight: 700;
  color: var(--wisp);
  text-shadow: 0 8px 26px rgba(0, 0, 0, 0.7);
  text-align: center;
}
.title-sub { margin: 0 0 26px; font-size: 46px; color: var(--moon); text-align: center; }
.title-buttons { display: flex; gap: 36px; }

.endingui {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 34px;
  padding-bottom: 64px;
}
/* The closing line lands on the busiest part of the picture — the grey-rose
   sky, the parted pines, whoever came. It carries its own light: a halo that
   hugs the letters, so the line is legible over every colour under it while
   the picture stays whole. A scrim panel would read as a caption bar and
   wipe out the art it sits on. */
.ending-quiet {
  margin: 0;
  font-size: 44px;
  color: var(--ink);
  text-align: center;
  text-shadow:
    0 0 10px rgba(233, 166, 160, 0.98),
    0 0 20px rgba(255, 217, 160, 0.95),
    0 0 34px rgba(159, 232, 216, 0.7),
    0 0 54px rgba(159, 232, 216, 0.5);
}

/* Reduced motion: floats, blooms and pulses become static states. Every
   reveal in the game is a display change (`st-*`), so nothing a child needs
   depends on an animation having run. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .guide.wisp .zb-flare { opacity: 0; }
  .guide.wisp.flaring .zb-flare { animation: none; opacity: 0.9; }
}
