/* ============================================================================
   STYLE — game chrome in wood & parchment (Stardew-inspired).
   Rules of the look: chunky borders, hard offset shadows (no soft blurs on
   interactive things), square corners on the game window, paper for reading.
   ========================================================================= */

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

:root {
  --paper: #f7ecd2;
  --paper-deep: #efe0bb;
  --paper-edge: #d9c294;
  --ink: #3a2f28;
  --wood: #6b4a2f;
  --wood-dark: #46311d;
  --wood-light: #8a6544;
  --accent: #e07a5f;
  --accent-dark: #b5543c;
  --gold: #d9a83c;
  /* the toys' "written notes" voice: a warm storybook serif — characterful
     but crisp, unlike a cursive script */
  --font-note: "Iowan Old Style", "Palatino", Georgia, "Times New Roman", serif;
  /* game window width: capped by screen width AND height (ratio 384:240) */
  --game-w: min(1152px, 96vw);
  --game-w: min(1152px, 96vw, calc((100vh - 150px) * 1.6));
  --game-w: min(1152px, 96vw, calc((100dvh - 150px) * 1.6));
}

html, body {
  height: 100%;
  background:
    radial-gradient(ellipse at 50% 20%, #33261c 0%, #241d18 55%, #1c1613 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", Verdana, sans-serif;
  overflow: hidden;
}

#stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;                  /* clue ribbon hugs the game frame as one unit */
}

/* ---- the game window: canvas in a chunky wooden frame -------------------- */
#wrap {
  position: relative;
  line-height: 0;
  border: 4px solid var(--wood);
  outline: 4px solid var(--wood-dark);
  box-shadow:
    0 0 0 6px rgba(0, 0, 0, 0.35),
    0 18px 50px rgba(0, 0, 0, 0.6);
  background: #241d18;
}
canvas#game {
  width: var(--game-w);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}
/* soft vignette so the world feels lamplit */
#wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
    rgba(0, 0, 0, 0) 62%, rgba(20, 12, 6, 0.28) 100%);
}

/* ---- corner chips: progress, journal, settings ---------------------------- */
#hud-chips {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  line-height: 1.2;
  z-index: 5;
}
.chip {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 3px 0 var(--ink);
  color: var(--ink);
  font: 700 13px/1.2 "Avenir Next", "Trebuchet MS", sans-serif;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  white-space: nowrap;
}
button.chip { cursor: pointer; }
button.chip:hover { background: #fff6df; transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
button.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.chip.counter { background: var(--paper-deep); }

/* ---- clue ribbon under the game window ------------------------------------ */
#clue-bar {
  /* +16px: flush with the wooden frame's outer edge (border 4+4, outline 4+4) */
  width: calc(var(--game-w) + 16px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
  border: 3px solid var(--wood-dark);
  border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  padding: 8px 14px;
  min-height: 40px;
}
#clue-bar .scroll-icon { font-size: 17px; }
#clue-bar #hud-clue {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-note);
  font-style: italic;
  font-size: 16px;
  color: var(--ink);
}

/* ---- dialog box (in-world speech/inspect text) ----------------------------- */
#dialog {
  position: absolute;
  left: 50%;
  bottom: 9%;                 /* lower third, but off the floor edge (RPG norm) */
  transform: translateX(-50%);
  width: 78%;
  line-height: 1.45;
  background: var(--paper);
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.45), inset 0 0 0 2px var(--paper-deep);
  padding: 14px 18px 20px;
  font-size: 17px;
  display: none;
  z-index: 4;
}
#dialog.show { display: block; }
#dialog .who { font-weight: 700; color: var(--accent-dark); margin-bottom: 3px; font-size: 14px; }
#dialog .next-hint {
  position: absolute;
  right: 12px;
  bottom: 4px;
  font-size: 12px;
  color: var(--wood);
  animation: bounce-hint 0.9s ease-in-out infinite;
}
@keyframes bounce-hint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* ---- generic modal shell ---------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 11, 7, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.overlay.show { display: flex; }

.card {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow:
    0 0 0 3px var(--paper-edge),
    0 8px 0 rgba(0, 0, 0, 0.45),
    0 24px 70px rgba(0, 0, 0, 0.5);
  padding: 26px 30px;
  max-width: 560px;
  width: 92%;
  max-height: 88vh;
  overflow-y: auto;
  text-align: center;
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.card h1 { font-size: 30px; margin-bottom: 10px; letter-spacing: 0.02em; }
.card h2 { font-size: 21px; margin-bottom: 8px; }
.card p { font-size: 16px; line-height: 1.5; margin: 8px 0; }
.card .soft { opacity: 0.7; font-size: 14px; }

.btn {
  /* one standard button: fixed height, flex-centered content — emoji or not,
     every button lines up */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  vertical-align: middle;
  min-height: 46px;
  margin: 14px 5px 0;
  background: var(--accent);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 4px 0 var(--ink);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.2;
  padding: 0 22px;
  cursor: pointer;
}
.btn:hover { background: #ea8a70; transform: translateY(-1px); box-shadow: 0 5px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.ghost { background: var(--paper); color: var(--ink); font-weight: 600; }
.btn.ghost:hover { background: #fff6df; }
.btn.danger { background: var(--paper); color: #a93b30; font-weight: 600; }
.btn.danger:hover { background: #fbe4dc; }
.btn:focus-visible, button.chip:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---- polaroid (reveal card + journal cells) --------------------------------- */
.polaroid {
  display: inline-block;
  background: #fff;
  padding: 10px 10px 30px;
  border: 1px solid #d8d0be;
  border-radius: 3px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  transform: rotate(-2deg);
}
.polaroid img, .polaroid canvas {
  display: block;
  width: 170px;
  height: 170px;
  object-fit: contain;
  image-rendering: auto;
  background: #f4efe4;
}
.polaroid .label {
  margin-top: 8px;
  font-family: var(--font-note);
  font-style: italic;
  font-size: 17px;
  text-align: center;
}

#reveal .found-count { color: var(--accent-dark); font-weight: 700; letter-spacing: 0.06em; }

/* ---- clue note --------------------------------------------------------------- */
.note {
  background: #fdf6e0;
  border: 2px dashed #b9a468;
  border-radius: 8px;
  padding: 14px 16px;
  font-family: var(--font-note);
  font-style: italic;
  font-size: 18px;
  line-height: 1.5;
  margin: 12px 0;
  text-align: left;
}

/* ---- keypad (drawer code lock) ------------------------------------------------ */
#keypad .display {
  font-family: "Courier New", monospace;
  font-size: 34px;
  letter-spacing: 14px;
  white-space: nowrap;          /* the three digits stay on one line, always */
  text-align: center;
  background: #2b241e;
  color: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.6);
  padding: 8px 0 8px 14px;      /* left pad offsets the trailing letter-space */
  margin: 10px auto 16px;
  width: 232px;
  min-height: 58px;
}
#keypad .keys {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 8px;
  justify-content: center;
}
#keypad .keys button {
  font-size: 20px;
  font-weight: 700;
  padding: 12px 0;
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--ink);
  background: #fff;
  cursor: pointer;
}
#keypad .keys button:hover { background: #ffe9d6; }
#keypad .keys button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#keypad.shake .display { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ---- journal -------------------------------------------------------------------- */
#journal .card { max-width: 860px; text-align: left; }
#journal .card h2:first-child { text-align: center; }
#journal .grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin: 14px 0;
}
#journal .cell {
  width: 118px;
  background: #fff;
  padding: 6px 6px 20px;
  border: 1px solid #d8d0be;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
}
#journal .cell:nth-child(odd) { transform: rotate(-2deg); }
#journal .cell:nth-child(even) { transform: rotate(1.6deg); }
#journal .cell img, #journal .cell canvas {
  width: 106px;
  height: 106px;
  object-fit: contain;
  display: block;
  background: #f4efe4;
}
#journal .cell .mystery {
  width: 106px;
  height: 106px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-deep);
  color: #b9a468;
  font-size: 52px;
  font-weight: 800;
}
#journal .cell .name {
  font-family: var(--font-note);
  font-style: italic;
  font-size: 13px;
  text-align: center;
  margin-top: 4px;
  min-height: 16px;
}
#journal .hints { text-align: center; }
#journal .hints .btn { margin: 4px 6px; font-size: 14px; padding: 0 14px; min-height: 38px; }
#journal .cell.clickable { cursor: pointer; }
#journal .cell.clickable:hover { outline: 3px solid var(--gold); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3); }
#journal .hint-text { font-style: italic; margin-top: 6px; }

/* ---- settings --------------------------------------------------------------------- */
#settings .card { max-width: 460px; padding: 26px 30px 30px; }
#settings .btn { min-width: 250px; margin: 6px 0 0; }
#settings .settings-row { margin-bottom: 14px; }
#settings .controls { margin: 4px auto 8px; }
#settings .danger-zone {
  margin: 16px 0 4px;
  padding-top: 14px;
  border-top: 2px dashed var(--paper-edge);
}
#settings .danger-zone .btn { font-size: 14px; min-height: 42px; }

/* ---- title screen ------------------------------------------------------------------- */
#title .card { max-width: 620px; }
#title h1 {
  font-size: 34px;
  color: var(--accent-dark);
  margin-bottom: 2px;
  text-shadow: 2px 2px 0 rgba(58, 47, 40, 0.12);
}
.controls {
  display: inline-block;
  text-align: left;
  margin: 12px auto 4px;
  font-size: 15px;
  line-height: 2.1;
}
kbd {
  background: var(--paper-deep);
  border: 2px solid #b9a468;
  border-bottom-width: 4px;
  border-radius: 6px;
  padding: 1px 8px;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
}

/* ---- finale ---------------------------------------------------------------------------- */
#finale {
  background: linear-gradient(180deg, #2c2440 0%, #4d3350 55%, #7a4a58 100%);
  overflow: hidden;
}
#finale .inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;      /* fallback: top-anchored, scrollable */
  justify-content: safe center;     /* centered when it fits */
  overflow-y: auto;                 /* many toys must never clip the button */
  gap: 18px;
  padding: 4vh 4vw;
}
#confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#finale .toys-ring {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 1050px;
  z-index: 2;
}
#finale .toys-ring .polaroid {
  padding: 6px 6px 18px;
  opacity: 0;
  transform: scale(0.3) rotate(var(--tilt, -8deg));
  transition: all 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}
#finale .toys-ring .polaroid.in {
  opacity: 1;
  transform: scale(1) rotate(var(--tilt, 0deg));
}
#finale .toys-ring .polaroid img, #finale .toys-ring .polaroid canvas {
  width: 96px; height: 96px;
}
#finale .toys-ring .label { font-size: 12px; margin-top: 4px; }
#finale .cake-slot { z-index: 2; flex-shrink: 0; }
#finale .cake-slot canvas { image-rendering: pixelated; width: 150px; }
#finale #bday-msg {
  z-index: 2;
  max-width: 700px;
  color: #ffeeda;
  font-family: var(--font-note);
  font-style: italic;
  font-size: 21px;
  line-height: 1.6;
  text-align: center;
  min-height: 90px;
}
#finale #bday-from { color: #e8b7a0; font-size: 16px; z-index: 2; font-style: italic; }
#finale #bday-big {
  z-index: 2;
  color: #ffd97a;
  font-size: clamp(34px, 6vw, 62px);
  font-weight: 800;
  text-align: center;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.7s cubic-bezier(0.2, 1.5, 0.4, 1);
}
#finale #bday-big.in { opacity: 1; transform: scale(1); }
#finale .btn { z-index: 2; flex-shrink: 0; }

/* ---- toast (small notices) — a notification strip near the top of the
   game view, clear of the player, dialog, banner, and chips ---------------- */
#toast {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  line-height: 1.4;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  padding: 9px 20px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.3s, top 0.3s;
  pointer-events: none;
  z-index: 40;
}
#toast.show { opacity: 1; top: 13%; }

/* ---- accessibility -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
