/* ── COZZY TOWN UI ─ frosted-sticker system ───────────────────────────── */
:root {
  --ink: #6b4f3f;
  --ink-soft: #8a6f5c;
  --cream: #fff8ec;
  --cream-2: #f7ecd9;
  --strawberry: #f6a9b8;
  --butter: #f9e29c;
  --lavender: #cdb4eb;
  --sage: #bbddc0;
  --peach: #ffcba4;
  --coral: #ff8b7b;
  --honey: #ffc96b;
  --card-shadow: 0 10px 24px rgba(107, 79, 63, 0.22), 0 2px 0 rgba(255,255,255,.65) inset;
  --font: "Baloo 2", "Comic Sans MS", "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { font-family: var(--font); color: var(--ink); background: #aecbfa; }

#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background:
    radial-gradient(ellipse 120% 100% at 50% 42%, transparent 58%, rgba(96, 60, 24, 0.18) 100%),
    linear-gradient(rgba(255, 214, 150, 0.06), rgba(255, 214, 150, 0.06));
  mix-blend-mode: multiply;
}

.hidden { display: none !important; }

/* ── HUD ── */
/* z-index sits ABOVE the panel scrim (#panel-root, z 40) so the coin chip
   stays crisp while a panel's backdrop-filter blurs the world behind it,
   but below #fx-layer (z 50) so confetti still falls over everything. */
/* The notch eats this row in landscape. env() only started resolving once
   viewport-fit=cover landed in index.html, so these insets were inert before
   and the bug was invisible rather than absent. */
#hud {
  position: fixed; z-index: 45; display: flex; gap: 10px; align-items: center;
  top: calc(18px + env(safe-area-inset-top, 0px));
  left: calc(18px + env(safe-area-inset-left, 0px));
}
.pill {
  background: var(--cream);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 7px 18px 8px;
  font-size: 22px; font-weight: 800;
  box-shadow: var(--card-shadow);
}
#coin-pill { display: flex; align-items: center; gap: 8px; transition: transform .18s cubic-bezier(.34,1.56,.64,1); }
#coin-pill.bump { transform: scale(1.18) rotate(-3deg); }
.coin-icon { font-size: 22px; filter: drop-shadow(0 1px 0 rgba(107,79,63,.3)); }
#save-toast { font-size: 15px; font-weight: 700; color: var(--ink-soft); background: var(--cream-2); animation: toast-in .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px);} to { opacity: 1; transform: none; } }

/* ── Interaction prompt ── */
#interact-prompt {
  position: fixed; z-index: 15; transform: translate(-50%, -100%);
  display: flex; align-items: center; gap: 8px;
  background: var(--cream); border: 3px solid #fff; border-radius: 999px;
  padding: 6px 14px 7px; font-size: 16px; font-weight: 800;
  box-shadow: var(--card-shadow); pointer-events: none;
  animation: prompt-pop .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes prompt-pop { from { opacity: 0; transform: translate(-50%,-80%) scale(.7);} to { opacity: 1; transform: translate(-50%,-100%) scale(1);} }
.key-chip {
  background: var(--honey); border-radius: 8px; border-bottom: 3px solid #d9a24b;
  padding: 1px 9px 2px; font-size: 15px; font-weight: 800; color: #7a5a20;
}

/* ── Dialogue ── */
#dialogue { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
#dialogue-card {
  pointer-events: auto; position: relative;
  width: min(680px, calc(100vw - 48px)); margin-bottom: 34px;
  background: var(--cream); border: 4px solid #fff; border-radius: 26px;
  padding: 26px 28px 20px; box-shadow: var(--card-shadow);
  animation: card-up .28s cubic-bezier(.34,1.56,.64,1);
}
@keyframes card-up { from { opacity: 0; transform: translateY(26px) scale(.96);} to { opacity: 1; transform: none; } }
#dialogue-name-chip {
  position: absolute; top: -20px; left: 22px;
  display: flex; align-items: center; gap: 8px;
  background: var(--coral); color: #fff; border: 3px solid #fff;
  border-radius: 999px; padding: 4px 16px 5px; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 10px rgba(107,79,63,.25);
}
#dialogue-portrait { font-size: 18px; line-height: 1; }
#dialogue-text { font-size: 20px; font-weight: 600; line-height: 1.45; min-height: 58px; }
#dialogue-next { text-align: right; font-size: 15px; font-weight: 800; color: var(--ink-soft); animation: bob 1.1s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0);} 50% { transform: translateY(3px);} }
#dialogue-choices { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
/* The keyboard can now answer a question (arrows/WASD to move, Enter/E/Space to
   pick), so the CURRENT answer has to be obvious at a glance — the default
   focus ring is far too quiet against a honey button on a cream card. */
#dialogue-choices button:focus-visible,
#dialogue-choices button:focus {
  outline: none;
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 0 0 4px #fff, 0 0 0 8px var(--honey, #ffd166);
}
@media (prefers-reduced-motion: reduce) {
  #dialogue-choices button:focus, #dialogue-choices button:focus-visible { transform: none; }
}

/* ── Buttons ── */
button {
  font-family: var(--font); cursor: pointer; border: none;
  background: var(--honey); color: #7a5a20;
  border-radius: 16px; border-bottom: 4px solid #d9a24b;
  padding: 9px 22px 10px; font-size: 18px; font-weight: 800;
  transition: transform .12s cubic-bezier(.34,1.56,.64,1), filter .12s;
}
button:hover { transform: translateY(-2px) scale(1.04); filter: brightness(1.05); }
button:active { transform: translateY(1px) scale(.98); }
button:focus-visible { outline: 3px solid var(--coral); outline-offset: 2px; }
button.secondary { background: var(--cream-2); color: var(--ink-soft); border-bottom-color: #d8c8b2; }

/* ── Panels (shop / wardrobe / minigames) ── */
#panel-root {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(107, 79, 63, 0.28); backdrop-filter: blur(3px);
}
.panel {
  width: min(760px, calc(100vw - 40px)); max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--cream); border: 4px solid #fff; border-radius: 30px;
  padding: 28px 30px; box-shadow: var(--card-shadow);
  animation: card-up .3s cubic-bezier(.34,1.56,.64,1);
}
.panel h2 { font-size: 30px; font-weight: 800; margin-bottom: 4px; }
.panel .panel-sub { color: var(--ink-soft); font-weight: 600; margin-bottom: 18px; }

/* ── FX layer ── */
#fx-layer { position: fixed; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; }
/* Floating status text. --flt-dur is set per-message by economy.js from the
   text length: these are often whole sentences ("follow the star to Hazel's
   Books") and the old flat 1.3s, which began fading at 15%, left a child well
   under a second to read one. It now HOLDS at full opacity for most of its
   life and only fades at the very end. */
.floaty {
  position: absolute; font-size: 26px; font-weight: 800; color: #b8860b;
  text-shadow: 0 2px 0 #fff, 0 3px 8px rgba(107,79,63,.3);
  /* centred on its x rather than left-anchored: now that long sentences wrap
     inside a max-width, a left-anchored box would run off the right edge */
  max-width: min(560px, 86vw); text-align: center; transform-origin: 50% 100%;
  animation: floaty-up var(--flt-dur, 2.6s) cubic-bezier(.22,.61,.36,1) forwards;
}
@keyframes floaty-up {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(.6); }
  8%   { opacity: 1; transform: translate(-50%, 0) scale(1.14); }
  16%  { opacity: 1; transform: translate(-50%, -4px) scale(1); }
  78%  { opacity: 1; transform: translate(-50%, -38px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -64px) scale(.98); }
}
.confetti { position: absolute; width: 10px; height: 14px; border-radius: 3px; animation: confetti-fall 1.6s ease-in forwards; }
@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(-10px) rotate(0deg); }
  100% { opacity: 0; transform: translateY(220px) rotate(540deg); }
}

/* ── Title screen ──
   The COZZY TOWN landing screen (markup, logo, live 3D diorama) is owned by
   src/ui/title.js; its CSS lives in the <style id="ttl-css"> block in the
   document head so the first paint is already dressed. Nothing here. */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; transition-duration: .01s !important; }
}

/* ── grown-up gate ──────────────────────────────────────────────────────────
   Guards the few things aimed at a parent rather than a child: leaving the
   app, and anything whose loss cannot be undone. */
.gate-scrim { position: fixed; inset: 0; z-index: 210; display: grid; place-items: center;
  background: rgba(107,79,63,.42); padding: 24px; }
.gate-card { max-width: 360px; text-align: center; background: #fffaf0; color: #6b4f3f;
  border: 5px solid #ffeccd; border-radius: 26px; padding: 24px;
  box-shadow: 0 14px 40px rgba(107,79,63,.28);
  font-family: 'Baloo 2', system-ui, sans-serif; }
.gate-emoji { font-size: 38px; line-height: 1; }
.gate-card h2 { margin: 6px 0 8px; font-size: 21px; font-weight: 800; }
.gate-q { margin: 0 0 14px; font-size: 19px; font-weight: 700; }
.gate-input { font: inherit; font-size: 20px; font-weight: 700; text-align: center;
  width: 130px; padding: 9px; color: #6b4f3f; background: #fff6e8;
  border: 3px solid #ffeccd; border-radius: 14px; }
.gate-row { display: flex; gap: 10px; justify-content: center; margin-top: 16px;
  flex-wrap: wrap; }
.gate-row button { font: inherit; font-weight: 800; font-size: 16px; color: #6b4f3f;
  border: 4px solid #fff3dc; border-radius: 999px; padding: 9px 20px; cursor: pointer; }
.gate-ok { background: #ffd79a; }
.gate-ok:hover { background: #ffc978; }
.gate-cancel { background: #f0e6da; }
.gate-row button:focus-visible,
.gate-input:focus-visible { outline: 3px solid #f6a9b8; outline-offset: 3px; }

/* ── suggestion panel — an address, never a form ── */
.sug-card { max-width: 400px; }
.sug-body { margin: 0 0 12px; font-size: 15px; font-weight: 600; line-height: 1.45; }
.sug-addr { display: block; font-size: 18px; font-weight: 800; color: #6b4f3f;
  background: #fff6e8; border: 3px dashed #ffd79a; border-radius: 14px;
  padding: 11px 10px; margin-bottom: 12px; word-break: break-all;
  user-select: all; -webkit-user-select: all; }
.sug-note { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.45; opacity: .85; }

/* ── title-screen entry point, deliberately quiet ── */
.ttl-grownup { margin-top: 10px; text-align: center; }
#ttl-suggest { font: inherit; font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 700; font-size: 12px; color: #6b4f3f;
  background: rgba(255,250,240,.72); border: 2px solid rgba(255,236,205,.9);
  border-radius: 999px; padding: 5px 14px; cursor: pointer; opacity: .82; }
#ttl-suggest:hover { opacity: 1; background: rgba(255,250,240,.95); }
#ttl-suggest:focus-visible { outline: 3px solid #f6a9b8; outline-offset: 3px; }

/* ── recovery notice — only when a town could not be opened normally ── */
.rcv-card { max-width: 420px; }
.rcv-body { margin: 0 0 4px; font-size: 15px; font-weight: 600; line-height: 1.5; }

/* ── erase, inside the grown-up panel — quiet, and asks twice ── */
.sug-rule { border: none; border-top: 2px dashed #ffeccd; margin: 16px 0 12px; }
.sug-erase {
  font: inherit; font-family: 'Baloo 2', system-ui, sans-serif; font-weight: 700;
  font-size: 13px; color: #a8766a; background: none; border: none;
  text-decoration: underline; cursor: pointer; padding: 4px;
}
.sug-erase:hover { color: #8a5348; }
.ers-yes {
  font: inherit; font-weight: 800; font-size: 16px; color: #7a3b36;
  background: #f6c9c2; border: 4px solid #fdeae7; border-radius: 999px;
  padding: 9px 20px; cursor: pointer;
}
.ers-yes:hover { background: #f0b3aa; }
.sug-erase:focus-visible, .ers-yes:focus-visible { outline: 3px solid #f6a9b8; outline-offset: 3px; }

/* the title screen's second small button, matching #ttl-suggest */
#ttl-keys {
  font: inherit; font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 700; font-size: 12px; color: #6b4f3f;
  background: rgba(255,250,240,.72); border: 2px solid rgba(255,236,205,.9);
  border-radius: 999px; padding: 5px 14px; cursor: pointer; opacity: .82;
  margin-right: 6px;
}
#ttl-keys:hover { opacity: 1; background: rgba(255,250,240,.95); }
#ttl-keys:focus-visible { outline: 3px solid #f6a9b8; outline-offset: 3px; }
