/* cozy placeholder palette — gets replaced by real pixel art later.
   Everything is sized in % of #stage so the whole game scales as one unit. */
:root {
  --dawn-1: #2b2440;
  --dawn-2: #4a3b66;
  --warm:   #f6d9a8;
  --ink:    #2b2440;
  --paper:  #fdf3e3;
  --accent: #e8a0a0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; background: #000; }
body {
  height: 100vh;
  height: 100svh;            /* visible viewport — excludes mobile URL bar */
  font-family: "Courier New", ui-monospace, monospace;
  overflow: hidden;
  -webkit-font-smoothing: none;
  background: #000;          /* top/bottom letterbox stays black */
}

/* Only when the screen is wider than the stage (side bars) do we dress
   the letterbox with the fantasy curtains. Narrower screens get plain
   black top/bottom bars. 367/200 = 1.835 = the stage aspect. */
@media (min-aspect-ratio: 367/200) {
  body {
    background-color: #241a22;
    background-image:
      url("../assets/bg/drape_l.jpg"),
      url("../assets/bg/drape_r.jpg");
    background-repeat: no-repeat, no-repeat;
    /* nudge the visible slice slightly inward (mirrored, so symmetric) */
    background-position: -22px center, calc(100% + 22px) center;
    background-size: auto 185%, auto 185%;   /* zoomed into the pattern */
    background-attachment: fixed;
  }
}

#game {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  height: 100svh;            /* fit the visible area, not behind the URL bar */
  display: grid;
  place-items: center;
}

/* fixed 1.835:1 stage, letterboxed; sized to the *visible* viewport so
   the dialogue at the bottom is never hidden under mobile browser chrome */
#stage {
  position: relative;
  width: min(100vw, 183.5vh);
  width: min(100vw, 183.5svh);
  height: min(54.5vw, 100vh);
  height: min(54.5vw, 100svh);
  background: #14101f;
  overflow: hidden;
  image-rendering: auto;          /* soft illustrated art, not pixel */
  cursor: pointer;
  user-select: none;
}

#scene { position: absolute; inset: 0; }

#art, #art svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* hotspots: invisible clickable regions placed by % coords from scene data.
   Invisible by default (real art shows through); gentle glow on hover. */
.hotspot {
  position: absolute;
  border: 0;
  background: transparent;
  outline: none;
  cursor: pointer;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.hotspot:hover {
  background: rgba(246, 217, 168, 0.16);
  box-shadow: 0 0 0 2px rgba(246, 217, 168, 0.55);
  border-radius: 4px;
}
.hotspot .tag {
  position: absolute;
  left: 50%; bottom: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: clamp(8px, 1.6vh, 14px);
  color: var(--paper);
  background: rgba(20, 16, 31, 0.85);
  padding: 2px 6px;
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.hotspot:hover .tag { opacity: 1; }
.hotspot.done { outline-color: rgba(160, 232, 160, 0.5); }

/* placeholder "art": a labelled colored block until the real sprite drops in */
.ph {
  position: absolute;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: clamp(9px, 1.8vh, 15px);
  color: var(--ink);
  border-radius: 4px;
  padding: 4px;
  line-height: 1.2;
}

/* BB the toad — extracted sprite, idle loop */
#bb {
  position: absolute;
  height: 15%;
  transform: translateX(-50%);   /* (x,y) marks where she stands */
  transition: left 0.7s ease, top 0.7s ease;
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 6px 5px rgba(20, 16, 31, 0.28));
}
#bb img {
  height: 100%;
  width: auto;
  image-rendering: auto;          /* smooth illustration, not pixel art */
  display: block;
}

/* dialogue / quip box */
#dialogue {
  position: absolute;
  left: 4%; right: 4%; bottom: 4%;
  min-height: 14%;
  background: rgba(20, 16, 31, 0.92);
  border: 2px solid var(--warm);
  border-radius: 6px;
  padding: 3% 4%;
  color: var(--paper);
  font-size: clamp(11px, 2.4vh, 20px);
  line-height: 1.5;
  cursor: pointer;
  z-index: 10;
}
#dialogue-cont {
  position: absolute;
  right: 3%; bottom: 4%;
  animation: bob 1s infinite ease-in-out;
}
@keyframes bob { 50% { transform: translateY(3px); } }

/* inventory bar */
#inventory {
  position: absolute;
  top: 3%; right: 3%;
  display: flex;
  gap: 6px;
  z-index: 10;
}
#inventory .slot {
  width: clamp(28px, 6vh, 52px);
  aspect-ratio: 1;
  background: rgba(20, 16, 31, 0.8);
  border: 2px solid var(--warm);
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-size: clamp(14px, 3.4vh, 28px);
}

/* keypad modal */
#keypad {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 16, 0.78);
  display: grid;
  place-items: center;
  z-index: 20;
}
.keypad-box {
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 4%;
  width: 46%;
  min-width: 240px;
  text-align: center;
}
.keypad-label { font-size: clamp(11px, 2.2vh, 18px); margin-bottom: 8px; }
#keypad-display {
  font-size: clamp(20px, 5vh, 40px);
  letter-spacing: 0.3em;
  margin: 8px 0 14px;
}
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.keypad-grid button, #keypad-close {
  font-family: inherit;
  font-size: clamp(14px, 3vh, 24px);
  padding: 10px 0;
  border: 2px solid var(--ink);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}
.keypad-grid button:active { background: var(--warm); }
#keypad-close {
  margin-top: 12px;
  font-size: clamp(10px, 2vh, 16px);
  background: transparent;
  border-style: dashed;
}

/* "turn your phone" — only on touch devices held in portrait */
#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #2b2440, #4a3b66);
    padding: 8vw;
  }
  #game { display: none; }
}
.rot-card {
  text-align: center;
  color: #fdf3e3;
  background: rgba(20, 16, 31, 0.55);
  border: 2px solid #f6d9a8;
  border-radius: 14px;
  padding: 9vw 7vw;
  font-family: "Courier New", monospace;
}
.rot-emoji {
  font-size: 18vw;
  animation: rot 2.4s ease-in-out infinite;
}
.rot-card p { font-size: 5.5vw; margin: 4vw 0 2vw; }
.rot-card small { font-size: 3.8vw; opacity: 0.85; }
@keyframes rot {
  0%, 55%  { transform: rotate(0deg); }
  80%,100% { transform: rotate(-90deg); }
}

/* mobile-only "add to home screen" gate (shown via JS) */
#install {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #2b2440, #4a3b66);
  padding: clamp(10px, 3vmin, 24px);
  overflow: auto;
}
/* sized in vmin so it fits both portrait and landscape phones */
.install-card {
  width: 100%;
  max-width: min(520px, 90vw);
  max-height: 94vh;
  overflow: auto;
  padding: clamp(16px, 5vmin, 34px);
  overflow-wrap: break-word;
}
.install-card .rot-emoji {
  animation: none;
  font-size: clamp(30px, 7vmin, 52px);
}
.install-card p { font-size: clamp(15px, 3.8vmin, 23px); margin: 1.4vmin 0; }
.install-card ol {
  text-align: left;
  margin: 2vmin auto;
  padding-left: 5vmin;
  font-size: clamp(13px, 3.2vmin, 18px);
  line-height: 1.6;
}
.install-card .scrollhint {
  font-size: clamp(11px, 2.8vmin, 15px);
  color: #ffd9a8;
  opacity: 0.85;
  margin: 0.6vmin 0 1.6vmin;
  animation: bob 1.3s ease-in-out infinite;
}
.install-card #install-msg {
  font-size: clamp(11px, 2.8vmin, 15px);
  opacity: 0.9;
  margin: 2vmin 0 0;
  color: #ffd9a8;
  min-height: 1px;
}
.install-card button {
  display: block;
  width: 100%;
  margin: 2.4vmin 0 0;
  padding: clamp(10px, 3vmin, 16px);
  font-family: "Courier New", monospace;
  font-size: clamp(14px, 3.4vmin, 19px);
  border-radius: 10px;
  border: 2px solid #f6d9a8;
  background: #f6d9a8;
  color: #2b2440;
  cursor: pointer;
}
.install-card #install-skip {
  background: transparent;
  color: #fdf3e3;
  border: none;
  font-size: clamp(12px, 2.8vmin, 16px);
  opacity: 0.75;
  text-decoration: underline;
}

/* the heartfelt finale: note pickup -> pause -> scrolling message */
#finale {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: radial-gradient(ellipse at center, #2a2036 0%, #140f1e 80%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#finale-intro {
  position: absolute;
  width: 80%;
  text-align: center;
  color: #f3e6cf;
  font-family: "Courier New", monospace;
  font-size: clamp(15px, 3.4vh, 30px);
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 1.6s ease;
}
#finale-intro.show { opacity: 1; }
#finale-scroll {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  /* soft fade at top & bottom edges */
  -webkit-mask-image: linear-gradient(180deg,
    transparent 0%, #000 16%, #000 84%, transparent 100%);
  mask-image: linear-gradient(180deg,
    transparent 0%, #000 16%, #000 84%, transparent 100%);
}
#finale-msg {
  width: min(80%, 60ch);
  text-align: center;
  color: #fbeed6;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 3.6vh, 32px);
  line-height: 2;
  white-space: pre-wrap;
  will-change: transform;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* the final heart that pops in once the scroll finishes */
#finale-heart {
  position: absolute;
  font-size: clamp(60px, 22vh, 180px);
  opacity: 0;
  transform: scale(0.2);
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}
#finale.done #finale-heart {
  animation: heartpop 1s cubic-bezier(.2,.8,.2,1.2) forwards,
             heartbeat 2.4s ease-in-out 1.1s infinite;
}
@keyframes heartpop {
  0%   { opacity: 0; transform: scale(0.2); }
  60%  { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

/* the sticky note hidden behind the photo */
#note {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 16, 0.45);
  cursor: pointer;
}
.note-paper {
  position: relative;
  width: 42%;
  min-width: 220px;
  background: #fff6a8;
  color: #5b4a2f;
  padding: 4% 4.5% 5%;
  border-radius: 3px;
  transform: rotate(-2.5deg);
  box-shadow: 0 14px 26px rgba(20, 16, 31, 0.5);
  font-family: "Comic Sans MS", "Segoe Script", cursive;
  animation: notepop 0.35s cubic-bezier(.2,.9,.3,1.2);
}
.note-paper::before {                 /* a piece of tape */
  content: "";
  position: absolute;
  top: -3%; left: 50%;
  width: 26%; height: 9%;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(214, 196, 160, 0.5);
  border: 1px solid rgba(170, 145, 105, 0.35);
}
#note-text {
  font-size: clamp(13px, 2.9vh, 24px);
  line-height: 1.55;
  white-space: pre-wrap;
}
.note-x {
  display: block;
  margin-top: 5%;
  text-align: right;
  font-size: clamp(9px, 1.7vh, 14px);
  opacity: 0.55;
}
@keyframes notepop {
  from { transform: rotate(-2.5deg) scale(0.7); opacity: 0; }
  to   { transform: rotate(-2.5deg) scale(1);   opacity: 1; }
}

.hidden { display: none !important; }

#stage.dark { filter: brightness(0.18); }

/* painted background image fills the scene */
#art {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* state patches composited over the base (legacy; unused by Scene 1) */
#patches { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.patch   { position: absolute; object-fit: fill; }

/* 🎒 cute packing checklist — a little note taped to the corner */
#checklist {
  position: absolute;
  top: 4%;
  left: 3%;
  z-index: 8;
  padding: 1.4% 1.8% 1.6%;
  background: repeating-linear-gradient(
      #fff8e9, #fff8e9 22px, #fdeccd 22px, #fdeccd 23px);
  color: #6e4b32;
  border: 2px solid #caa06a;
  border-radius: 7px;
  box-shadow: 0 6px 14px rgba(20, 16, 31, 0.35);
  transform: rotate(-3deg);
  font-family: "Comic Sans MS", "Courier New", monospace;
  font-size: clamp(10px, 1.9vh, 17px);
  line-height: 1.55;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
#checklist::before {            /* a little piece of tape */
  content: "";
  position: absolute;
  top: -10px; left: 50%;
  width: 46px; height: 18px;
  transform: translateX(-50%) rotate(4deg);
  background: rgba(214, 196, 160, 0.55);
  border: 1px solid rgba(180, 150, 110, 0.4);
}
#checklist .cl-head {
  font-weight: bold;
  margin-bottom: 4px;
  border-bottom: 2px dashed #d6b98a;
  padding-bottom: 3px;
}
#checklist ul { list-style: none; margin: 4px 0 0; padding: 0; }
#checklist li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  transition: color 0.3s ease;
}
#checklist .cl-bx { width: 1.3em; text-align: center; }
#checklist .cl-done { color: #8aa06a; text-decoration: line-through; }
#checklist .cl-cur  { color: #d07a6a; font-weight: bold; }
#checklist .cl-lock { color: #b9a48c; opacity: 0.7; }

#stage.night #checklist { opacity: 0; transform: rotate(-3deg) scale(0.9); }

@keyframes clpop {
  0%   { transform: rotate(-3deg) scale(1); }
  40%  { transform: rotate(-2deg) scale(1.07); }
  100% { transform: rotate(-3deg) scale(1); }
}
#checklist.pop { animation: clpop 0.45s ease; }

/* ---- cold open: dim sleeping room → warm wake ----------------------
   #nightveil is a full-bleed overlay. .night on #stage makes the room
   dark+cool; removing it (BB wakes) fades to the warm morning art. */
#nightveil {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse at 56% 35%, rgba(40,60,90,0) 0%, rgba(10,12,28,0.55) 70%),
    rgba(8,10,24,0.55);
  transition: opacity 3s ease;
}
#stage.night #nightveil { opacity: 1; }
#stage.night #art { filter: brightness(0.5) saturate(0.8) hue-rotate(-8deg); }
#art { transition: filter 3s ease; }

/* the alarm: a buzz burst, then a pause, repeating (BZZT … BZZT …) */
@keyframes ringshake {
  0%  { transform: translate(0, 0) rotate(0); }
  2%  { transform: translate(-0.7%, 0.4%) rotate(-0.7deg); }
  5%  { transform: translate(0.8%, -0.3%) rotate(0.7deg); }
  8%  { transform: translate(-0.7%, 0.3%) rotate(-0.6deg); }
  11% { transform: translate(0.7%, -0.2%) rotate(0.5deg); }
  14% { transform: translate(-0.5%, 0.1%) rotate(-0.4deg); }
  17% { transform: translate(0.4%, 0) rotate(0.2deg); }
  20% { transform: translate(0, 0) rotate(0); }
  /* pause — held still until the next buzz */
  100% { transform: translate(0, 0) rotate(0); }
}
#stage.ring #art { animation: ringshake 1.5s linear infinite; }
