html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
[hidden] { display: none !important; }
body { --talk-w: 0px; --talk-h: 0px; }
@media (min-width: 821px) { body.talking { --talk-w: min(400px, 38vw); } }
@media (max-width: 820px) { body.talking { --talk-h: 46dvh; } }

/* the scene, seen through the glass */
#stage {
  position: fixed; left: 0; top: 0; right: var(--talk-w); bottom: var(--talk-h);
  background: #0a0503; touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M25 25l11 11' stroke='%233a2212' stroke-width='7' stroke-linecap='round'/%3E%3Cpath d='M25 25l11 11' stroke='%23b8862c' stroke-width='3' stroke-linecap='round'/%3E%3Ccircle cx='16' cy='16' r='11' fill='%23cfe6ee' fill-opacity='.3' stroke='%23120a06' stroke-width='5'/%3E%3Ccircle cx='16' cy='16' r='11' fill='none' stroke='%23e8c878' stroke-width='2.5'/%3E%3C/svg%3E") 16 16, zoom-in;
}
#stage svg { display: block; width: 100%; height: 100%; }
#stage svg text { pointer-events: none; }
#stage [data-s] { transition: filter .15s; }
@media (hover: hover) { #stage [data-s]:hover { filter: brightness(1.18) drop-shadow(0 0 6px rgba(255,217,138,.5)); } }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .28s; z-index: 5; }
#fade.on { opacity: 1; }

#hud {
  position: fixed; top: 0; left: 0; right: var(--talk-w); z-index: 10; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 18px; pointer-events: none;
  background: linear-gradient(rgba(0,0,0,.7), transparent);
}
#hud > * { pointer-events: auto; }
#timer { font-family: var(--font-type); font-size: 1.25rem; color: var(--ember); text-shadow: 0 0 8px rgba(255,177,74,.5); }
#timer.hit { animation: hit 1.2s; }
@keyframes hit { 0%, 60% { color: #ff5a4a; transform: scale(1.25); } 100% { color: var(--ember); transform: none; } }
#guest { font-size: .85rem; color: var(--muted); }
#place { font-family: var(--font-display); color: var(--parchment); font-size: clamp(.8rem, 2.2vw, 1.05rem); text-align: center; padding-top: 4px; text-shadow: 0 2px 4px #000; flex: 1; }
.hud-right { display: flex; gap: 8px; }
.hud-btn { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 1px solid #b8862c; background: rgba(42,22,12,.9); font-size: 1.25rem; color: var(--bone); }
.hud-btn.pulse { animation: pulse 1s 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255,177,74,.45); } }
#pad-count { position: absolute; right: -4px; top: -4px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--blood); color: #fff; font: 12px/20px var(--font-type); padding: 0 5px; }
#pad-count:empty { display: none; }

#btn-back { position: fixed; left: 12px; bottom: calc(var(--talk-h) + var(--cap-h, 0px) + 12px); z-index: 12; }
#caption {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--talk-h) + 10px); z-index: 11;
  width: min(760px, calc(100vw - var(--talk-w) - 20px)); margin-left: calc(var(--talk-w) / -2);
  background: #e9dcb6; color: #2a1c10; border: 1px solid #7a5a32; border-radius: 6px; padding: 10px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.6); font-size: 1.08rem; line-height: 1.4; max-height: 38dvh; overflow: auto;
}
#cap-title { display: block; font-family: var(--font-display); font-weight: normal; font-size: .95rem; color: #6a2a14; margin-bottom: 2px; }
#toast {
  position: fixed; top: 64px; left: 50%; transform: translate(-50%, -20px); margin-left: calc(var(--talk-w) / -2); z-index: 30; opacity: 0; pointer-events: none;
  background: #f4ecd0; color: #2a2a5a; font-family: var(--font-hand); font-size: 1.35rem; padding: 4px 16px; border-radius: 4px; box-shadow: 0 4px 16px #000; transition: opacity .3s, transform .3s; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#tooltip { position: fixed; z-index: 20; pointer-events: none; background: rgba(22,11,6,.92); color: var(--parchment); border: 1px solid #7a5a32; border-radius: 4px; padding: 2px 8px; font-size: .9rem; opacity: 0; transition: opacity .12s; white-space: nowrap; }
#tooltip.show { opacity: 1; }

/* lock widget */
.lock { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.dial { display: flex; flex-direction: column; align-items: center; }
.dial button { width: 44px; height: 30px; border: 1px solid #7a5a32; background: #c9a55c; border-radius: 4px; font-size: .9rem; color: #2a1c10; }
.dial output { font: 1.7rem var(--font-type); width: 44px; text-align: center; background: #fbf6e4; border: 2px solid #3a240c; border-radius: 4px; margin: 3px 0; }

/* talking */
#talk {
  position: fixed; z-index: 15; background: linear-gradient(#2e1a0e, #1c0f08); border-left: 2px solid #7a5a32; display: flex; flex-direction: column;
  right: 0; top: 0; bottom: 0; width: var(--talk-w);
}
@media (max-width: 820px) { #talk { left: 0; top: auto; width: auto; height: var(--talk-h); border-left: 0; border-top: 2px solid #7a5a32; } }
.talk-head { padding: 12px 14px 8px; border-bottom: 1px solid #4a2c18; }
#talk-name { margin: 0; font: normal 1.2rem var(--font-display); color: var(--brass); }
#talk-role { color: var(--muted); font-style: italic; font-size: .92rem; }
#talk-log { flex: 1; overflow: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
#talk-log p { margin: 0; line-height: 1.4; max-width: 94%; padding: 7px 11px; border-radius: 10px; }
#talk-log .them { background: #e9dcb6; color: #2a1c10; align-self: flex-start; border-bottom-left-radius: 2px; }
#talk-log .you { background: #40502f; color: #eef0dc; align-self: flex-end; border-bottom-right-radius: 2px; font-style: italic; }
#talk-log .sys { align-self: center; color: var(--ember); font-size: .88rem; padding: 0; }
#talk-qs { padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid #4a2c18; max-height: 40%; overflow: auto; }
#talk-qs button { background: #3a2212; color: var(--parchment); border: 1px solid #7a5a32; border-radius: 14px; padding: 5px 11px; font-size: .95rem; text-align: left; }
#talk-qs button:hover { border-color: var(--ember); }
#talk-qs button.asked { opacity: .55; }
#talk-qs button.ev { border-color: var(--blood); background: #4a1a1e; }
#talk-form { display: flex; gap: 6px; padding: 8px 12px max(10px, env(safe-area-inset-bottom)); }
#talk-form input { flex: 1; }

/* notepad */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.72); display: grid; place-items: center; padding: 12px; }
.pad-book { position: relative; width: min(940px, 100%); max-height: 92dvh; display: grid; grid-template-columns: 1.25fr 1fr; background: #f4ecd0; color: #2a2438; border-radius: 6px; box-shadow: 0 0 0 8px #3a2212, 0 20px 60px #000; overflow: hidden;
  background-image: repeating-linear-gradient(transparent 0 31px, #b9c4d6 31px 32px); }
.pad-page { padding: 18px 22px; overflow: auto; max-height: 92dvh; }
.pad-page + .pad-page { border-left: 2px solid #c9b88a; }
.pad-page h2 { font: normal 1.3rem var(--font-display); margin: 0 0 10px; color: #6a2a14; }
#pad-clues { margin: 0; padding-left: 1.3em; font-family: var(--font-hand); font-size: 1.28rem; line-height: 1.25; }
#pad-clues li { margin-bottom: 9px; } #pad-clues b { color: #8a1c2a; }
#pad-clues:empty::after { content: 'Nothing yet. Put the glass on things.'; font-style: italic; opacity: .7; margin-left: -1.3em; }
.pad-page label { display: block; font-family: var(--font-display); font-size: .9rem; margin-bottom: 12px; color: #6a2a14; }
.pad-page select { display: block; width: 100%; margin-top: 4px; font: 1.3rem var(--font-hand); padding: 4px 6px; background: #fffaf0; border: 1px solid #8a7a5a; border-radius: 4px; color: #2a2438; }
.pad-page .fine { color: #6a5c48; }
#pad-msg { color: #8a1c2a; font-size: 1.05rem; min-height: 1.4em; }
.pad-x { position: absolute; right: 8px; top: 6px; z-index: 2; border: 0; background: none; font-size: 1.3rem; color: #6a2a14; }
@media (max-width: 700px) { .pad-book { grid-template-columns: 1fr; overflow: auto; } .pad-page { max-height: none; overflow: visible; } .pad-page + .pad-page { border-left: 0; border-top: 2px solid #c9b88a; } }

/* intro */
.screen { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; overflow: auto; padding: 16px; }
#intro { background: linear-gradient(#0c1428 0%, #1c1a30 45%, #3a2212 45.2%, #1c0f08 100%); }
#intro .street { position: absolute; inset: 0; background:
  radial-gradient(circle at 82% 14%, #f4eccb 0 26px, transparent 27px),
  radial-gradient(circle at 20% 12%, #fff 0 1.5px, transparent 2px), radial-gradient(circle at 36% 26%, #fff 0 1px, transparent 2px), radial-gradient(circle at 60% 9%, #fff 0 1.5px, transparent 2px), radial-gradient(circle at 8% 32%, #fff 0 1px, transparent 2px), radial-gradient(circle at 70% 30%, #fff 0 1px, transparent 2px),
  radial-gradient(ellipse at 50% 100%, rgba(255,177,74,.5), transparent 60%); }
.intro-card { position: relative; z-index: 3; max-width: 620px; width: 100%; text-align: center; padding: 22px 26px; background: rgba(28,15,8,.93); border: 2px solid #b8862c; border-radius: 10px; box-shadow: 0 0 0 6px #160b06, 0 20px 60px #000; transition: opacity .5s; }
.over { margin: 0; color: var(--muted); letter-spacing: .12em; font-size: .85rem; text-transform: uppercase; }
.title { font: normal clamp(1.8rem, 6.4vw, 3.1rem)/1.1 var(--font-display); color: var(--brass); margin: .25em 0 .4em; text-shadow: 0 3px 0 #3a1a08, 0 0 24px rgba(255,177,74,.35); }
.story { font-size: 1.08rem; line-height: 1.5; margin: 0 0 14px; }
.guestbook { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-bottom: 14px; }
.guestbook span { font-family: var(--font-display); color: var(--parchment); }
.guestbook input { width: min(320px, 100%); text-align: center; }
.batwings { position: absolute; inset: 0; z-index: 4; display: flex; pointer-events: none; perspective: 1400px; opacity: 0; }
.leaf { flex: 1; margin: 22vh 0 14vh; background: repeating-linear-gradient(#8a5630 0 16px, #4a2a12 16px 22px); border: 6px solid #2a160a; box-shadow: inset 0 0 60px #0008; }
.leaf.l { transform-origin: left center; border-radius: 0 40% 0 0 / 0 12% 0 0; } .leaf.r { transform-origin: right center; border-radius: 40% 0 0 0 / 12% 0 0 0; }
#intro.swing .intro-card { opacity: 0; }
#intro.swing .batwings { opacity: 1; }
#intro.swing .leaf.l { animation: swingL 1.9s cubic-bezier(.3,.6,.4,1) forwards; }
#intro.swing .leaf.r { animation: swingR 1.9s cubic-bezier(.3,.6,.4,1) forwards; }
@keyframes swingL { 0% { transform: rotateY(0); } 35% { transform: rotateY(-88deg); } 60% { transform: rotateY(-58deg); } 80% { transform: rotateY(-80deg); } 100% { transform: rotateY(-74deg); } }
@keyframes swingR { 0% { transform: rotateY(0); } 35% { transform: rotateY(88deg); } 60% { transform: rotateY(58deg); } 80% { transform: rotateY(80deg); } 100% { transform: rotateY(74deg); } }
#intro.gone { opacity: 0; transition: opacity .6s .9s; pointer-events: none; }

/* reveal + victory */
#reveal { position: fixed; inset: 0; z-index: 60; background: #0a0503; display: grid; place-items: center; padding: 24px; }
#reveal-text { max-width: 720px; font-size: clamp(1.2rem, 3.4vw, 1.9rem); line-height: 1.5; text-align: center; color: var(--bone); transition: opacity .6s; }
#victory { z-index: 70; background: radial-gradient(ellipse at 50% 20%, #5a3418, #160b06 70%); align-content: start; gap: 10px; }
.banner { font: normal clamp(2.4rem, 10vw, 6rem) var(--font-display); color: var(--brass); text-shadow: 0 4px 0 #3a1a08, 0 0 40px rgba(255,177,74,.6); text-align: center; animation: drop .9s cubic-bezier(.2,1.4,.4,1); }
@keyframes drop { from { transform: translateY(-120%) rotate(-6deg); opacity: 0; } }
.award-wrap { width: min(900px, 100%); text-align: center; }
#award { width: 100%; height: auto; border-radius: 6px; box-shadow: 0 10px 50px #000; }
.award-actions { display: flex; gap: 10px; justify-content: center; margin: 12px 0 6px; flex-wrap: wrap; }
