:root {
  --ink: #141414;
  --paper: #f4ead0;
  --paper-2: #fbf5e3;
  --blue: #1f5fbf;
  --yellow: #ffd23f;
  --red: #c8262b;
  --olive: #6f7240;
  --muted: #6b6253;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--paper);
  background-image: radial-gradient(#d9cba5 1.2px, transparent 1.3px);
  background-size: 9px 9px;
  color: var(--ink);
  font-family: "Comic Neue", "Comic Sans MS", system-ui, sans-serif;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 16px 16px;
  gap: 10px;
}

/* top bar */
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#chapter {
  font-family: "Bangers", Impact, sans-serif;
  font-weight: 400;
  letter-spacing: 1.5px;
  font-size: clamp(18px, 3.2vw, 28px);
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 2px 12px;
  transform: rotate(-1deg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbtns { display: flex; gap: 8px; flex-shrink: 0; }
.tbtn {
  background: var(--paper-2);
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 6px 12px;
  min-height: 44px; min-width: 44px;
  font-size: 16px;
}
.tbtn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }

/* stage */
#stage {
  position: relative;
  border: 5px solid var(--ink);
  box-shadow: 7px 7px 0 var(--ink);
  background: #fff;
  overflow: hidden;
}
#stage svg.room { display: block; width: 100%; height: auto; }
.hs { cursor: pointer; }
.hs:hover .hl, .hs:focus .hl { stroke: var(--yellow); stroke-width: 7; }
.hs .hl { fill: transparent; stroke: transparent; }
.hs:hover { filter: brightness(1.08); }
.selecting .hs { cursor: crosshair; }

/* comic panels (title, intro, cut-scenes) */
.page { padding: clamp(12px, 3vw, 28px); background: var(--paper-2); }
.panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.panel {
  position: relative;
  border: 4px solid var(--ink);
  background: #fff;
  box-shadow: 5px 5px 0 var(--ink);
  overflow: hidden;
  opacity: 0; transform: translateY(8px) rotate(var(--r, 0deg));
  animation: pop .45s ease forwards;
}
.panel svg { display: block; width: 100%; height: auto; }
.panel:nth-child(2) { animation-delay: .5s; --r: .6deg; }
.panel:nth-child(3) { animation-delay: 1s; --r: -.6deg; }
@keyframes pop { to { opacity: 1; transform: translateY(0) rotate(var(--r, 0deg)); } }
.caption {
  position: absolute; top: 8px; left: 8px; right: 8px;
  background: var(--yellow); border: 3px solid var(--ink);
  padding: 4px 8px; font-size: clamp(12px, 1.6vw, 15px); line-height: 1.25;
}
.caption.bottom { top: auto; bottom: 8px; }
.wide { grid-column: 1 / -1; }

h1.title {
  font-family: "Bangers", Impact, sans-serif; font-weight: 400;
  font-size: clamp(40px, 9vw, 104px); line-height: .92; letter-spacing: 2px;
  margin: 8px 0 6px; color: var(--yellow);
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-2deg);
}
.lede { font-size: clamp(16px, 2.2vw, 21px); max-width: 640px; line-height: 1.35; }
.small { font-weight: 400; font-size: 14px; color: var(--muted); max-width: 640px; line-height: 1.4; }
.btnrow { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.cbtn {
  font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1.5px;
  font-size: 24px; padding: 8px 22px; min-height: 48px;
  background: var(--blue); color: #fff;
  border: 4px solid var(--ink); box-shadow: 5px 5px 0 var(--ink);
}
.cbtn.alt { background: var(--yellow); color: var(--ink); }
.cbtn.ghost { background: var(--paper-2); color: var(--ink); }
.cbtn:active { transform: translate(3px,3px); box-shadow: 2px 2px 0 var(--ink); }
.cbtn:disabled { opacity: .45; cursor: not-allowed; }
.boom {
  font-family: "Bangers", Impact, sans-serif; font-weight: 400;
  color: var(--red); -webkit-text-stroke: 2px var(--ink);
  font-size: clamp(54px, 12vw, 140px); line-height: 1;
  transform: rotate(-6deg); display: inline-block;
  animation: shake .5s ease 2;
}
@keyframes shake { 25% { transform: rotate(-3deg) scale(1.05);} 75% { transform: rotate(-8deg) scale(.97);} }

/* dialog */
#dialog {
  position: relative;
  background: var(--paper-2);
  border: 4px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  border-radius: 18px;
  padding: 12px 44px 12px 16px;
  min-height: 74px;
  cursor: pointer;
  font-size: clamp(16px, 2vw, 19px);
  line-height: 1.35;
}
#dlgWho {
  position: absolute; top: -16px; left: 14px;
  font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1px;
  background: var(--blue); color: #fff; border: 3px solid var(--ink);
  padding: 0 10px; font-size: 17px;
}
#dlgWho.tv { background: var(--red); }
#dlgWho.cat { background: #e38b2c; }
#dlgWho.narr { background: var(--yellow); color: var(--ink); }
#dlgWho.guard { background: var(--olive); }
#dlgWho.phone { background: #444; }
#dlgMore { position: absolute; right: 14px; bottom: 8px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* inventory */
#invbar { display: flex; gap: 10px; align-items: stretch; }
#inv { display: flex; flex-wrap: wrap; gap: 10px; min-height: 70px; }
.slot {
  width: 70px; height: 70px; padding: 4px;
  background: var(--paper-2);
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1.05; text-align: center; position: relative;
}
.slot svg { width: 40px; height: 40px; }
.slot.sel { background: var(--yellow); transform: translate(-2px,-2px); box-shadow: 5px 5px 0 var(--ink); }
.slot.decoder { background: #ffe3e3; }
.slot .badge {
  position: absolute; top: -9px; right: -9px; background: var(--red); color: #fff;
  border: 2px solid var(--ink); border-radius: 12px; font-size: 11px; padding: 0 5px;
}
.invhint { align-self: center; font-weight: 400; color: var(--muted); font-size: 14px; }

/* modal */
#modal {
  position: fixed; inset: 0; background: #14141499;
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
#modalBox {
  background: var(--paper-2); border: 5px solid var(--ink); box-shadow: 8px 8px 0 var(--ink);
  width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px 18px 20px;
}
#modalBox h2 {
  font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1.5px;
  margin: 0 0 10px; font-size: 32px;
}
.x { float: right; background: none; border: 3px solid var(--ink); width: 40px; height: 40px; font-size: 18px; }

/* decoder */
.tvscreen {
  background: #2a0b0b; color: #fff; border: 4px solid var(--ink); border-radius: 10px;
  padding: 14px; font-size: 18px; line-height: 1.6; font-family: "Comic Neue", sans-serif;
}
.tvlogo { color: #ff6b6b; font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1.5px; font-size: 15px; margin-bottom: 6px; }
.term { border-bottom: 3px dashed var(--yellow); cursor: pointer; padding: 0 2px; }
.term.locked { border-bottom-color: #777; color: #bbb; cursor: help; }
.term.done { border: 0; cursor: default; }
.term.done s { color: #ff8a8a; }
.term.done ins { text-decoration: none; background: var(--yellow); color: var(--ink); padding: 0 4px; margin-left: 4px; display: inline-block; transform: rotate(-1.5deg); animation: pop .35s ease forwards; opacity: 0; }
.note { font-weight: 400; color: var(--muted); font-size: 14px; margin-top: 10px; }

/* keypad, radio */
.display {
  font-family: "Courier New", monospace; font-size: 40px; letter-spacing: 10px; text-align: center;
  background: #1d2b1d; color: #7dff7d; border: 4px solid var(--ink); padding: 6px; margin: 6px 0 12px;
}
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { font-size: 24px; min-height: 52px; background: #fff; border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.key:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }

/* choices */
.choices { display: grid; gap: 10px; }
.choice {
  text-align: left; padding: 10px 14px; min-height: 48px; background: #fff;
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); font-size: 17px;
}
.choice:hover { background: var(--yellow); }
.row { margin-bottom: 12px; }
.row .lbl { font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1px; font-size: 20px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.opt { padding: 6px 12px; min-height: 44px; background: #fff; border: 3px solid var(--ink); font-size: 15px; }
.opt.on { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.rebut { background: #2a0b0b; color: #fff; border: 3px solid var(--ink); padding: 10px 12px; margin-top: 12px; }
.rebut b { color: #ff8a8a; font-family: "Bangers", Impact, sans-serif; font-weight: 400; letter-spacing: 1px; }

/* fact file */
.facts { display: grid; gap: 10px; margin: 12px 0; }
.fact { background: #fff; border: 3px solid var(--ink); padding: 10px 12px; font-weight: 400; line-height: 1.4; }
.fact b { font-weight: 700; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0 4px; }
.stat { background: var(--yellow); border: 3px solid var(--ink); padding: 6px 12px; font-size: 16px; }

@media (max-width: 720px) {
  #app { padding: 8px 10px 14px; }
  .panels { grid-template-columns: 1fr; }
  .slot { width: 60px; height: 60px; }
  .slot svg { width: 32px; height: 32px; }
  #stage { box-shadow: 4px 4px 0 var(--ink); border-width: 4px; }
}

/* item feedback */
#toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 20; background: #2f9e44; color: #fff;
  border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  padding: 8px 16px; font-size: 18px; white-space: nowrap; max-width: calc(100vw - 32px);
  overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
#toast.show { animation: toastIn .3s ease; }
@keyframes toastIn { from { transform: translate(-50%, -20px); opacity: 0; } }
.slot.fresh { animation: fresh 1.2s ease; }
@keyframes fresh { 0% { transform: scale(1.35); background: #b8f0c4; } 60% { background: #b8f0c4; } 100% { transform: scale(1); } }
#usebar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  background: var(--yellow); border-bottom: 4px solid var(--ink);
  padding: 6px 10px; font-size: 17px;
}
#usebar svg { width: 30px; height: 30px; display: block; }
#usebar button { margin-left: auto; background: #fff; border: 3px solid var(--ink); padding: 4px 10px; min-height: 40px; }
.itemcard { display: flex; gap: 14px; align-items: center; }
.bigicon { width: 84px; height: 84px; flex-shrink: 0; background: #fff; border: 3px solid var(--ink); display: flex; align-items: center; justify-content: center; }
.bigicon svg { width: 64px; height: 64px; }
.reveal .hs .hl { stroke: var(--yellow); stroke-width: 7; stroke-dasharray: 14 8; fill: #ffd23f; fill-opacity: .28; animation: blink .6s infinite; }
@media (max-width: 720px) { #usebar { font-size: 14px; } .tbtn { padding: 6px 8px; font-size: 14px; } }

/* illustrated panels (generated art + text set in code) */
.artpanel { position: relative; container-type: inline-size; border: 4px solid var(--ink); box-shadow: 5px 5px 0 var(--ink); background: #000; }
.artpanel img { display: block; width: 100%; height: auto; }
.artbubble {
  position: absolute; display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: "Comic Neue", sans-serif; font-weight: 700; text-transform: uppercase;
  font-size: 3cqw; line-height: 1.12; color: var(--ink);
  animation: pop .4s ease .3s forwards; opacity: 0;
}

/* illustrated rooms */
.roomwrap { position: relative; container-type: inline-size; background: #111; }
.roomimg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
svg.hsl { position: absolute; inset: 0; width: 100%; height: 100%; }
.hsl .hl { fill: transparent; stroke: transparent; }
.hsl .hs:hover .hl { stroke: var(--yellow); stroke-width: 6; fill: #ffd23f; fill-opacity: .12; }
.ticker {
  position: absolute; overflow: hidden; white-space: nowrap; display: flex; align-items: center;
  background: var(--yellow); color: var(--ink); border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink);
  font-family: "Courier New", monospace; font-weight: 700; font-size: 1.3cqw; pointer-events: none;
}
.ticker span#tickerText { display: inline-block; padding-left: 100%; animation: tick 14s linear infinite; }
@keyframes tick { to { transform: translateX(-100%); } }
.stamp {
  position: absolute; transform: translate(-50%, -50%) rotate(var(--rot)); pointer-events: none;
  font-family: "Bangers", Impact, sans-serif; letter-spacing: 1.5px; font-size: 2.2cqw;
  color: #c8262b; border: .3cqw solid #c8262b; background: #fbf5e3; padding: 0 .7cqw; opacity: .92;
}
.covertitle {
  position: absolute; left: 0; right: 0; top: 4%; margin: 0; text-align: center;
  font-size: clamp(34px, 8.5cqw, 110px); color: var(--red); -webkit-text-stroke: 2px var(--ink); text-shadow: 5px 5px 0 var(--ink);
}
.boomover { position: absolute; left: 6%; top: 8%; font-size: 12cqw; }
#dlgPic {
  position: absolute; left: 10px; top: 10px; width: 64px; height: 64px; object-fit: cover;
  border: 3px solid var(--ink); background: #fff;
}
#dialog.withpic { padding-left: 88px; min-height: 92px; }
#dialog.withpic #dlgWho { left: 84px; }
@media (max-width: 720px) {
  #dlgPic { width: 52px; height: 52px; }
  #dialog.withpic { padding-left: 74px; }
  #dialog.withpic #dlgWho { left: 70px; }
  .ticker { font-size: 1.6cqw; }
}

/* ---------- fit the whole room on one screen (wide screens) ---------- */
.roomwrap { border: 5px solid var(--ink); box-shadow: 7px 7px 0 var(--ink); }
.fig { position: absolute; width: auto; pointer-events: none; user-select: none; filter: drop-shadow(0 6px 6px #000a); }
body.roommode #stage { border: 0; box-shadow: none; background: transparent; overflow: visible; }
@media (min-width: 721px) {
  body.roommode #app { height: 100dvh; min-height: 0; padding-bottom: 12px; }
  body.roommode #stage { flex: 1 1 auto; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; }
  body.roommode .roomwrap { width: min(100cqw - 8px, (100cqh - 8px) * 1672 / 941); }
  .roomwrap #dialog {
    position: absolute; left: 2%; right: 2%; bottom: 3%; z-index: 3; margin: 0;
    font-size: clamp(15px, 1.7cqw, 19px); min-height: 0; max-width: 1000px; margin-inline: auto;
  }
  body.roommode #invbar { flex: 0 0 auto; }
  body.roommode .slot { width: 64px; height: 64px; }
}
@media (min-width: 721px) and (max-height: 700px) {
  body.roommode #topbar .tbtn { min-height: 38px; padding: 3px 10px; }
  body.roommode .slot { width: 54px; height: 54px; font-size: 9px; }
  body.roommode .slot svg { width: 30px; height: 30px; }
}

/* ---------- decoder ---------- */
.tvquote { background: #2a0b0b; color: #fff; border: 4px solid var(--ink); padding: 10px 14px; font-size: 18px; line-height: 1.45; }
.tvquote b { color: #ffb3b3; }
.dechead { display: grid; grid-template-columns: 1fr 28px 1fr; gap: 8px; margin: 14px 0 4px; font-family: "Bangers", Impact, sans-serif; letter-spacing: 1px; font-size: 17px; color: var(--muted); }
.decrows { display: grid; gap: 8px; }
.decrow { display: grid; grid-template-columns: 1fr 28px 1fr; gap: 8px; align-items: stretch; }
.decrow .says { background: #ffe3e3; border: 3px solid var(--ink); padding: 8px 10px; font-size: 16px; display: flex; align-items: center; }
.decrow .arrow { display: flex; align-items: center; justify-content: center; font-size: 22px; }
.means { border: 3px solid var(--ink); padding: 8px 10px; font-size: 16px; display: flex; align-items: center; }
.means.decode { background: var(--blue); color: #fff; font-family: "Bangers", Impact, sans-serif; letter-spacing: 1.5px; font-size: 20px; justify-content: center; box-shadow: 3px 3px 0 var(--ink); min-height: 48px; animation: nudge 1.6s ease infinite; }
.means.decode:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
@keyframes nudge { 50% { transform: scale(1.03); } }
.means.done { background: var(--yellow); font-weight: 700; animation: pop .35s ease; }
.means.locked { background: #eee; color: #777; border-style: dashed; }
.plain { margin-top: 12px; background: #fff; border: 3px solid var(--ink); padding: 10px 12px; font-size: 18px; line-height: 1.45; }
.plain mark { background: var(--yellow); padding: 0 3px; }
@media (max-width: 520px) {
  .decrow, .dechead { grid-template-columns: 1fr; }
  .decrow .arrow, .dechead span:nth-child(2) { display: none; }
}

/* ---------- while someone talks: scene dims, objects go quiet, the dialog steps forward ---------- */
.roomimg, .fig, .stamp, .ticker { transition: filter .25s ease; }
body.talking .roomimg, body.talking .fig, body.talking .stamp, body.talking .ticker { filter: brightness(.5) saturate(.7); }
body.talking .hsl .hs, body.talking .roomwrap { cursor: default; }
body.talking .hsl .hs:hover .hl, body.talking.reveal .hs .hl, body.talking .reveal .hs .hl { stroke: transparent; fill: transparent; animation: none; }
body.talking #inv .slot { opacity: .35; filter: grayscale(1); }
#dialog { transform-origin: 50% 100%; transition: transform .22s ease, opacity .22s ease; }
#dialog.in { animation: dlgIn .25s ease; }
#dialog.closing { transform: translateY(24px) scale(.92); opacity: 0; }
@keyframes dlgIn { from { transform: translateY(24px) scale(.92); opacity: 0; } }
@media (min-width: 721px) {
  .roomwrap #dialog {
    font-size: clamp(18px, 2.2cqw, 26px); line-height: 1.35;
    left: 4%; right: 4%; bottom: 5%; padding: 20px 56px 20px 24px; border-width: 5px; box-shadow: 8px 8px 0 var(--ink);
  }
  .roomwrap #dialog.withpic { padding-left: clamp(110px, 12cqw, 150px); min-height: clamp(110px, 13cqw, 160px); }
  .roomwrap #dlgPic { width: clamp(86px, 10cqw, 128px); height: clamp(86px, 10cqw, 128px); left: 14px; top: 14px; border-width: 4px; }
  .roomwrap #dialog.withpic #dlgWho { left: clamp(104px, 11.5cqw, 144px); font-size: clamp(16px, 1.6cqw, 22px); }
}
#dialog.withpic { min-height: 96px; }
@media (max-width: 720px) {
  #dlgPic { width: 64px; height: 64px; }
  #dialog.withpic { padding-left: 86px; }
  #dialog.withpic #dlgWho { left: 82px; }
}

/* ---------- comic panel pages fit the screen too ---------- */
@media (min-width: 721px) {
  body.panelmode #app { height: 100dvh; min-height: 0; padding-bottom: 12px; }
  body.panelmode #stage { flex: 1 1 auto; min-height: 0; }
  body.panelmode .page { height: 100%; display: flex; flex-direction: column; }
  body.panelmode .page > :not(.panelfit) { flex: 0 0 auto; }
  body.panelmode .panelfit { flex: 1 1 auto; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; }
  body.panelmode .panelfit .artpanel { width: min(100cqw - 8px, (100cqh - 8px) * 1672 / 941); }
  body.panelmode .page .lede { margin: 12px 0 4px; }
  body.panelmode .page .btnrow { margin-top: 10px; }
}

/* cover title: one line inside the empty paper strip, clear of the hedgehog */
h1.title.covertitle { top: 5%; font-size: 9.5cqw; white-space: nowrap; line-height: 1; -webkit-text-stroke: .25cqw var(--ink); text-shadow: .45cqw .45cqw 0 var(--ink); }

/* end screen */
.endcards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.fact.support { background: #e6efff; }
.fact .btnrow { margin-top: 10px; }
a.cbtn { text-decoration: none; display: inline-flex; align-items: center; }
.note a { color: var(--ink); }
@media (max-width: 720px) { .endcards { grid-template-columns: 1fr; } }
