:root {
  --ink: #e8e2d6;
  --dim: #8a8478;
  --font: 'Special Elite', Georgia, serif;
}

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

body {
  display: grid;
  place-items: center;
}

/* The stage keeps the art's 1408:768 shape and fits the window. */
#stage {
  position: relative;
  width: min(100vw, calc(100vh * 1408 / 768));
  aspect-ratio: 1408 / 768;
  overflow: hidden;
  user-select: none;
  container-type: inline-size;
}

#scene, #scene > * {
  position: absolute;
  inset: 0;
}

#scene img {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Patches cut from an "after" image, shown over the base image. */
.overlay {
  opacity: 0;
  transition: opacity 0.9s ease;
}
.overlay.on { opacity: 1; }
.overlay.instant { transition: none; }

#scene .hotspot {
  inset: auto;
  cursor: pointer;
}
#scene [hidden] { display: none !important; }

#scene .room-layer { pointer-events: none; }

/* Kitchen cupboard clip: feathered along its top and right edges so it melts
   into the still. */
#scene .cupboard-clip {
  position: absolute;
  object-fit: fill;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-mask-image: linear-gradient(to right, #000 90%, transparent), linear-gradient(to bottom, transparent, #000 10%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, #000 90%, transparent), linear-gradient(to bottom, transparent, #000 10%);
  mask-composite: intersect;
}
#scene .cupboard-clip.on { opacity: 1; }

/* Grandfather clock close-up: the dial you can grab, the engraved bob, and
   the bob held up close. */
#scene .clock-grab, #scene .clock-bob { position: absolute; border-radius: 50%; pointer-events: auto; }
#scene .clock-grab { cursor: grab; touch-action: none; }
#scene .clock-grab:active { cursor: grabbing; }
#scene .clock-bob { cursor: zoom-in; }
.lock-panel .bob-close {
  width: 34cqw;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 38% 32%, #d9b46a, #9a7434 55%, #5c4219 100%);
  box-shadow: inset 0 0 2cqw rgba(0, 0, 0, 0.6), 0 1cqw 3cqw #000;
  cursor: default;
}
.lock-panel .bob-close svg { width: 85%; }

/* The small padlock on the sitting-room door, across the hall. */
#scene .door-lock.sitting { left: 36.3%; top: 47.4%; width: 1.3%; transform: rotate(3deg); }

/* The computer's screen: dark green glass with a cursor. */
#scene .crt {
  position: absolute;
  box-sizing: border-box;
  padding: 1.2cqw 1.4cqw;
  border-radius: 6% / 9%;
  background: radial-gradient(ellipse at 50% 45%, rgba(30, 60, 40, 0.92), rgba(6, 16, 10, 0.97) 80%);
  box-shadow: inset 0 0 2cqw rgba(0, 0, 0, 0.9);
  font: 1.1cqw/1.3 'Courier New', monospace;
  color: #7dff9a;
  text-shadow: 0 0 0.5cqw rgba(125, 255, 154, 0.8);
}
#scene .crt p { margin: 0; min-height: 1em; }
#scene .crt .clues { font-size: 0.85cqw; line-height: 1.5; white-space: pre-wrap; }
#scene .crt .clue { white-space: nowrap; }
#scene .crt .cursor { animation: crt-blink 1.1s steps(1) infinite; }
@keyframes crt-blink { 50% { opacity: 0; } }

/* The supper glowing in its bowl on the jar shelf: a faint sickly light that
   breathes. Sits over the bowl's mouth. */
#scene .bowl-glow {
  position: absolute;
  left: 54%;
  top: 73.5%;
  width: 23%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(190, 255, 170, 0.55), rgba(120, 220, 140, 0.18) 55%, transparent 75%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 2s ease;
}
#scene .bowl-glow.on { opacity: 1; animation: bowl-glow 3.5s ease-in-out infinite alternate; }
@keyframes bowl-glow { from { filter: brightness(0.75); } to { filter: brightness(1.15); } }

/* Handwritten names on the jar labels (kitchen shelf close-up). */
#scene .jar-label {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font: 0.5cqw/1.5 'Homemade Apple', cursive;
  color: rgba(38, 24, 10, 0.82);
  transform: rotate(-2deg);
  mix-blend-mode: multiply;
}
#scene .cupboard-clip:not(.on) { transition-duration: 0.9s; }

/* Lights out. Background (with the switch's faint glow) is set per scene. */
#scene .dark {
  opacity: 0;
  pointer-events: none;
}
#scene .dark.on {
  opacity: 1;
  pointer-events: auto;
}

/* Light that survives the dark, like firelight. */
#scene .glow {
  opacity: 0;
  pointer-events: none;
}
#scene .glow.on {
  opacity: 1;
  animation: firelight 2.3s infinite;
}
/* Writing in the dark (the sitting room mirror). Fades in slowly, then
   flickers with the fire. Sized in cqw so it scales with the stage. */
#scene .dark-text {
  inset: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6cqw;
  font-family: 'Rock Salt', cursive;
  font-size: 1.15cqw;
  line-height: 1.1;
  color: rgba(236, 214, 190, 0.9);
  text-shadow: 0 0 0.35em rgba(255, 130, 50, 0.65), 0 0 0.1em rgba(255, 200, 150, 0.5);
  filter: blur(0.25px);
  opacity: 0;
  pointer-events: none;
}
/* Slow fade in only; gone instantly when the lights come back. */
#scene .dark-text.on {
  opacity: 1;
  transition: opacity 3.5s ease-in 1.2s;
}
#scene .dark-text.on span {
  animation: firelight 2.3s infinite;
}
#scene .dark-text span:nth-child(1) { transform: rotate(-4deg) translateX(-4%); }
#scene .dark-text span:nth-child(2) { transform: rotate(2deg) translateX(6%); }
#scene .dark-text span:nth-child(3) { transform: rotate(-2deg) translateX(-2%); }

@keyframes firelight {
  0%   { opacity: 0.86; }
  12%  { opacity: 0.97; }
  25%  { opacity: 0.80; }
  40%  { opacity: 1; }
  55%  { opacity: 0.88; }
  68%  { opacity: 0.95; }
  82%  { opacity: 0.78; }
  100% { opacity: 0.86; }
}

/* Bottom strip that takes you back where you came from. */
#scene .exit {
  inset: auto 0 0 0;
  height: 9%;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.6%;
  box-sizing: border-box;
  color: var(--ink);
  font-size: clamp(12px, 1.4vw, 20px);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  opacity: 0;
  transition: opacity 0.3s;
}
#scene .exit:hover { opacity: 1; }

#scene .placeholder {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--dim);
  font-size: clamp(14px, 2vw, 28px);
  background: #050505;
}

#fade {
  position: absolute;
  inset: 0;
  background: #000;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
#fade.clear { opacity: 0; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 11%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 0.5em 1em;
  background: rgba(0, 0, 0, 0.75);
  font-size: clamp(13px, 1.5vw, 22px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
#toast.show { opacity: 1; }
#toast.thought { color: #e8cf6a; font-style: italic; }

.shake { animation: shake 0.35s; }
@keyframes shake {
  20% { transform: translateX(-0.6%); }
  40% { transform: translateX(0.6%); }
  60% { transform: translateX(-0.4%); }
  80% { transform: translateX(0.3%); }
}

/* Name screen: plain black, plain boxes. */
#intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #000;
}
#intro[hidden] { display: none; }
#intro input::placeholder { color: var(--ink); opacity: 0.3; }

/* Opening story: plain black, each paragraph fading in after the last. */
#story {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2em;
  padding: 0 24px;
  background: #000;
  font-size: clamp(16px, 1.6vw, 22px);
  line-height: 1.6;
}
#story[hidden] { display: none; }
#story p { max-width: 36em; margin: 0; }
#story p, #story button { opacity: 0; animation: story-in 2.5s ease forwards; }
#story p:nth-of-type(1) { animation-delay: 0.6s; }
#story p:nth-of-type(2) { animation-delay: 4s; }
#story p:nth-of-type(3) { animation-delay: 7.5s; }
#story p:nth-of-type(4) { animation-delay: 10s; }
#story .knock { color: var(--dim); }
#story button {
  animation-delay: 12s;
  font: inherit;
  color: var(--dim);
  background: none;
  border: none;
  cursor: pointer;
  margin-top: 0.8em;
}
#story button:hover { color: var(--ink); }
@keyframes story-in { to { opacity: 1; } }
#intro label { font-size: 28px; }
#intro input, #intro button {
  font: 20px var(--font);
  color: var(--ink);
  background: #000;
  border: 1px solid var(--dim);
  padding: 8px 14px;
}
#intro input { width: min(320px, 80vw); text-align: center; }
#intro button { cursor: pointer; }
#intro input:focus, #intro button:hover { outline: none; border-color: var(--ink); }

/* Debug tools (temporary, while puzzles are stubbed). */
#debug {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 20;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  color: #ddd;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid #444;
  padding: 6px 8px;
}
#debug summary { cursor: pointer; color: #f88; }
#debug .row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
#debug select, #debug button { font: inherit; }
.show-hotspots #scene .hotspot {
  outline: 1px dashed rgba(255, 90, 90, 0.9);
  background: rgba(255, 0, 0, 0.1);
}
.show-hotspots #scene .hotspot::after {
  content: attr(data-label);
  position: absolute;
  left: 2px;
  top: 2px;
  font: 11px ui-monospace, Consolas, monospace;
  color: #fff;
  background: rgba(160, 0, 0, 0.8);
  padding: 0 3px;
}

/* Inventory: slots along the top, hidden while empty. */
#items {
  position: absolute;
  top: 1.2%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5cqw;
  padding: 0.4cqw;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(138, 132, 120, 0.4);
  z-index: 2;
}
#items:empty { display: none; }
#items .slot {
  width: 3.6cqw;
  height: 3.6cqw;
  padding: 0.3cqw;
  background: rgba(20, 16, 12, 0.85);
  border: 1px solid rgba(138, 132, 120, 0.5);
  cursor: pointer;
}
#items .slot:hover { border-color: var(--ink); }
#items .slot.held { opacity: 0.35; }
#items .slot.new { animation: pickup 0.6s ease-out; }
#items svg, #items img, #held svg, #held img { width: 100%; height: 100%; display: block; }
@keyframes pickup {
  0%   { transform: scale(1.8); box-shadow: 0 0 1.5cqw rgba(255, 220, 160, 0.8); }
  100% { transform: scale(1); box-shadow: none; }
}

/* The item you're holding follows the cursor. */
#held {
  position: absolute;
  width: 3.2cqw;
  height: 3.2cqw;
  transform: translate(-30%, -30%);
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 0 0.3cqw #000);
}
#held:empty { display: none; }

/* Looking at an item up close: its photo with the description under it. */
#examine {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5cqw;
  background: rgba(0, 0, 0, 0.88);
  cursor: pointer;
}
#examine[hidden] { display: none; }
#examine img { pointer-events: none; }
#examine .photo { width: 60%; box-shadow: 0 0 3cqw #000; filter: sepia(0.25) brightness(0.85); }
#examine .icon { width: 18%; }
#examine p {
  margin: 0;
  max-width: 60%;
  text-align: center;
  font-size: 1.5cqw;
}

/* A handwritten letter on the parchment. */
#letter {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
#letter[hidden] { display: none; }
#letter .paper {
  width: 50%;
  aspect-ratio: 800 / 576;
  box-sizing: border-box;
  padding: 6% 9%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.9cqw;
  background: url(../img/parchment.png) center / 100% 100% no-repeat;
  filter: drop-shadow(0 1cqw 2cqw rgba(0, 0, 0, 0.7));
  transform: rotate(-1.5deg);
  font-family: 'Homemade Apple', cursive;
  font-size: 1.05cqw;
  line-height: 1.8;
  color: #3a2614;
  animation: letter-in 0.5s ease-out;
}
#letter p { margin: 0; }
#letter p:last-child { text-align: right; }
/* Lists (recipe card, book pages) are puzzle text: a plainer hand, and no
   sign-off, so no right-aligned last line. */
#letter .paper.list {
  gap: 0.2cqw;
  font-family: 'Patrick Hand', cursive;
  font-size: 1.35cqw;
  line-height: 1.45;
}
#letter .list p:last-child { text-align: left; }
#letter .list p:empty { height: 0.8cqw; }
@keyframes letter-in {
  from { opacity: 0; transform: rotate(-4deg) translateY(4%); }
}

/* Front door padlock: a small one hanging on the door... */
#scene .door-lock {
  position: absolute;
  left: 52.4%;
  top: 46.5%;
  width: 6%;
  height: auto;
  transform: rotate(-4deg);
  filter: drop-shadow(0.15cqw 0.25cqw 0.2cqw rgba(0, 0, 0, 0.8)) brightness(0.6) saturate(0.8);
}

/* ...and the big one, with Ogham drawn on its wheels. */
#scene .lock-panel {
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.75);
  pointer-events: auto;
  cursor: pointer;
}
.lock-panel .lock { position: relative; width: 56cqw; cursor: default; }
#scene .lock-panel .lock img { position: static; display: block; width: 100%; height: auto; filter: drop-shadow(0 1cqw 2cqw #000); }
.lock-panel .lock.open { animation: lock-open 0.5s ease-out forwards; }
@keyframes lock-open {
  30% { transform: translateY(-1.5%) rotate(-1deg); }
  100% { transform: translateY(2%); }
}
.lock-panel .wheel { position: absolute; }
.lock-panel .face, .lock-panel .next {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}
.lock-panel .face svg { width: 92%; height: 92%; }
/* The next symbol, just coming round under the front face. */
.lock-panel .next { pointer-events: none; }
.lock-panel .next svg { width: 92%; height: 200%; align-self: start; transform: scaleY(0.5); transform-origin: top; opacity: 0.8; }
.lock-panel .roll-up svg { animation: roll-up 0.18s ease-out; }
.lock-panel .roll-down svg { animation: roll-down 0.18s ease-out; }
@keyframes roll-up { from { transform: translateY(35%) scaleY(0.6); opacity: 0.3; } }
@keyframes roll-down { from { transform: translateY(-35%) scaleY(0.6); opacity: 0.3; } }
.lock-panel .wheel button {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.8cqw;
  line-height: 1;
  padding: 0.3cqw 1cqw;
  color: rgba(232, 226, 214, 0.35);
  background: none;
  border: none;
  cursor: pointer;
}
.lock-panel .wheel .up { bottom: 104%; }
.lock-panel .wheel .down { top: 104%; }
.lock-panel .wheel button:hover { color: var(--ink); }

/* Dialogs that need an answer (stay and watch / move on). */
#dialog {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
}
#dialog[hidden] { display: none; }
#dialog .box {
  max-width: 60%;
  padding: 1.6cqw 2.2cqw;
  background: rgba(8, 6, 4, 0.92);
  border: 1px solid rgba(138, 132, 120, 0.5);
  text-align: center;
  font-size: 1.5cqw;
}
#dialog p { margin: 0 0 1.2cqw; }
#dialog .thought { color: #e8cf6a; font-style: italic; }
#dialog .copy {
  margin: 0 0 1.4cqw;
  padding: 0.8cqw 1cqw;
  min-height: 1.5em;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.4cqw;
  letter-spacing: 0.08em;
  word-spacing: 0.3em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(138, 132, 120, 0.3);
  user-select: text;
  cursor: text;
}
#dialog .buttons { display: flex; gap: 1cqw; justify-content: center; }
#dialog button {
  font: 1.3cqw var(--font);
  color: var(--ink);
  background: #000;
  border: 1px solid var(--dim);
  padding: 0.4cqw 1.2cqw;
  cursor: pointer;
}
#dialog button:hover { border-color: var(--ink); }

/* Printing never shows the game. At the computer, the page built at print
   time (computer-room.js) is the only thing on the paper. */
#printout { display: none; }
@media print {
  @page { margin: 0; }
  body { background: #fff !important; }
  body > * { display: none !important; }
  body > #printout {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: #000;
  }
  #printout .head { position: absolute; top: 1.2cm; font: 9pt 'Courier New', monospace; letter-spacing: 0.3em; }
  #printout .word { margin: 0; font: 72pt 'Rock Salt', cursive; letter-spacing: 0.15em; }
}
