:root {
  color-scheme: dark;
  background: #060c18;
  color: #eee4ce;
  font: 16px/1.4 "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
.game { width: 100%; height: 100vh; height: 100dvh; position: relative; isolation: isolate; }
.viewport { position: absolute; inset: 0; overflow: hidden; }
#sleep-shade {
  position: absolute; inset: 0; z-index: 2; visibility: hidden; opacity: 0;
  background: #030509; transition: opacity 1.7s ease-in;
}
.game[data-asleep] #sleep-shade { visibility: visible; opacity: 1; }
@media (prefers-reduced-motion: reduce) { #sleep-shade { transition: none; } }
.scene {
  position: absolute; inset: 50% auto auto 50%;
  width: min(100vw, 150vh); aspect-ratio: 3 / 2; transform: translate(-50%, -50%);
  user-select: none; -webkit-user-select: none;
}
.scene img, .scene canvas { display: block; width: 100%; height: 100%; }
.scene canvas { position: absolute; inset: 0; touch-action: none; outline: none; }
.scene canvas:focus-visible { outline: 1px solid #94aebf; outline-offset: -2px; }
.lamp-dimmer {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background:
    radial-gradient(ellipse 34% 49% at 73% 48%, #111c3db0, #111c3d72 25%, #1018272e 50%, #10182700),
    radial-gradient(ellipse 72% 89% at 23% 27%, #f2f4f8 18%, #dde3ec 34%, #a4afc0 65%, #707c90);
  mix-blend-mode: multiply; transition: opacity .18s ease-out;
}
/* The bulb opening is painted into the room art. */
.lamp-dimmer::after {
  content: ""; position: absolute; inset: 0; background: #303944;
  clip-path: polygon(72.6% 38.9%, 73.2% 38.4%, 75.3% 37.6%, 75.4% 38%,
    74.7% 38.6%, 73.4% 39.2%, 72.6% 39.3%);
}
.scene[data-lamp-off] .lamp-dimmer { opacity: 1; }
#use-stereo { left: 63%; top: 38.5%; }
#switch-lamp { left: 73%; top: 38%; }
.room-prop {
  width: min(590px, 94vw); max-height: 88dvh; margin: auto; padding: 0;
  border: 2px solid #817055; border-radius: 3px; box-shadow: 0 14px 44px #02060cbf;
  background: #201c1a; color: #efdfb8; font-family: Consolas, "Courier New", monospace;
}
.room-prop::backdrop { background: #040811a3; }
.prop-heading {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 17px; color: #f5e7c3; background: #3c3028; border-bottom: 1px solid #88724e;
}
.prop-heading h2 { margin: 0; font: 600 1.35rem Georgia, serif; }
.room-prop button { display: inline-grid; width: auto; height: auto; min-height: 36px; padding: 5px 10px; font: inherit; }
#room-library[data-reading][open] {
  display: grid; grid-template-rows: auto minmax(0, 1fr); width: min(680px, 94vw);
  height: min(760px, 90dvh);
}
#shelf-reader:not([hidden]) {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px;
  padding: clamp(8px, 2vw, 14px);
}
.reader-controls { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
.reader-controls button, .reader-controls select {
  padding: 5px 9px; min-height: 44px;
  border: 1px solid #817055; color: #f5e7c3; background: #302824;
  font: inherit; font-size: .875rem; line-height: 1.25;
}
.reader-controls select { min-width: 0; }
.reader-controls button:disabled { opacity: .45; cursor: default; }
.reader-pages:not([hidden]) { display: flex; justify-content: space-between; }
#network-book, #saved-modem-file {
  overflow: auto; padding: clamp(16px, 5vw, 34px);
  background: #efe1bd; color: #2e241f; font: 1.06rem/1.62 Georgia, serif;
  scrollbar-color: #9e8057 #efe1bd; scrollbar-gutter: stable;
}
.book-title { margin-bottom: 1.25rem; padding-bottom: .85rem; border-bottom: 1px solid #bca67d; }
.book-title h3 { margin: 0; font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.08; }
.book-title p { margin: .5rem 0 0; color: #644739; }
#network-book h4 { margin: 0 0 .65em; font-size: 1.22rem; line-height: 1.23; }
#network-book h5 { margin: 1.2em 0 .45em; font-size: 1rem; line-height: 1.25; }
#network-book section p { margin: 0 0 .85em; }
.book-transcript {
  margin: 0 0 1em; padding: 10px 12px; border: 1px solid #bca67d; background: #e4d5b0;
  white-space: pre-wrap; overflow-wrap: anywhere; font: .95rem/1.5 Consolas, monospace;
}
.book-transcript samp { font: inherit; }
@media (prefers-reduced-motion: reduce) { .lamp-dimmer { transition: none; } }
header, footer {
  position: absolute; z-index: 1; left: max(clamp(18px, 3vw, 54px), env(safe-area-inset-left));
  pointer-events: none;
}
header { top: max(clamp(16px, 3.2vh, 42px), env(safe-area-inset-top)); }
h1 { font: normal clamp(24px, 3.3vw, 46px)/1.06 Georgia, serif; letter-spacing: -.045em; margin: 0; }
header p { margin: .5rem 0 0; color: #a0abb9; font: .75rem/1.4 Consolas, monospace; letter-spacing: .11em; text-transform: uppercase; }
header p span { color: #c89361; margin: 0 .23em; }
footer {
  bottom: max(clamp(12px, 2.5vh, 28px), env(safe-area-inset-bottom));
  right: max(clamp(15px, 2.6vw, 48px), env(safe-area-inset-right));
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
footer p { margin: 0; color: #acb5c0; font-size: .86rem; text-shadow: 0 1px 4px #030713; }
kbd { color: #e1d8c6; font: .86rem/1.5 Consolas, monospace; letter-spacing: .06em; }
.divider { margin: 0 .65rem; color: #a27a58; }
.touch-help { display: none; }
button {
  pointer-events: auto; width: 44px; height: 44px; cursor: pointer;
  display: grid; place-items: center; color: #aeb6c0;
  background: #09101b88; border: 1px solid #717f9244; border-radius: 5px;
}
button:hover, button:focus-visible { color: #f0dfbd; border-color: #9f8c73; }
button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.35; }
#open-backpack {
  position: absolute; transform: translate(-50%, -50%);
  width: max(44px, 4.6%); height: max(44px, 6.5%); padding: 0;
  background: transparent; border: 0; touch-action: manipulation;
}
#open-backpack:focus-visible { outline: 2px solid #eee4ce; outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
#backpack {
  width: min(58rem, 94vw, 129dvh); max-width: none; max-height: none;
  padding: 0; color: #25202b; background: #132025; border: 0;
  box-shadow: 0 14px 65px #01050dc7, 0 0 0 1px #e5d6af51;
}
#backpack::backdrop { background: #050914ca; }
.pack-spread { position: relative; overflow: hidden; aspect-ratio: 3/2; isolation: isolate; }
#notebook-page { position: absolute; inset: 0; }
.prop-scene { position: absolute; height: 100%; aspect-ratio: 3/2; left: 50%; transform: translateX(-50%); }
.prop-art { display: block; width: 100%; height: 100%; user-select: none; pointer-events: none; }
.name-tape, #close-pack, .speech-name {
  font: bold 1rem/1.1 "Courier New", monospace;
}
.name-tape {
  position: absolute; z-index: 1; left: 2.5%; top: 4%; margin: 0;
  color: #29282a; background: #e9d6a4; padding: .45em .84em .38em;
  font-size: clamp(15px, 2vw, 24px); letter-spacing: -.055em; transform: rotate(-4deg);
  clip-path: polygon(1% 0,99% 2%,98% 19%,100% 38%,99% 56%,100% 78%,99% 100%,0 96%,1% 75%,0 54%,2% 32%,0 17%);
}
#back-to-pack { width: auto; height: auto; min-height: 44px; display: block; border: 0; border-radius: 0; }
#close-pack {
  position: absolute; z-index: 2; right: 2.2%; top: 3%; width: 44px; height: 44px;
  color: #fff2d2; background: #202b32; border: 2px solid #c9b890; border-radius: 50%;
  box-shadow: 2px 3px 0 #141623; font-size: 27px; line-height: 1;
}
#close-pack:focus-visible { outline: 3px solid white; outline-offset: 3px; }
#back-to-pack:is(:hover,:focus-visible) { color: #29282a; background: #fff0bd; text-decoration: underline; }
#close-pack:is(:hover,:focus-visible) { background: #455153; }
#handwriting {
  position: absolute; left: 32%; top: 18%; width: 57%; height: auto;
  pointer-events: none; mix-blend-mode: multiply;
}
.antenna-waves {
  position: absolute; left: 77.4%; bottom: 35.7%; width: 3.2%; aspect-ratio: 1;
  color: #263e8b; transform: rotate(-9deg);
}
.antenna-waves::before, .antenna-waves::after {
  content: ""; position: absolute; left: 0; bottom: 0; width: 45%; height: 45%;
  border: solid currentColor; border-width: 2px 2px 0 0; border-radius: 0 100% 0 0;
  animation: broadcast .72s steps(1) 2.6s 3 both;
}
.antenna-waves::after { width: 85%; height: 85%; animation-delay: 2.78s; }
@keyframes broadcast { 0%, 80%, 100% { opacity: 0; } 18% { opacity: 1; } }
#notebook-page { transform-origin: 20% 50%; animation: flip-open .38s cubic-bezier(.2,.8,.2,1) both; }
@keyframes flip-open {
  from { transform: perspective(950px) rotateY(-32deg) scale(.87); opacity: .2; }
  to { transform: perspective(950px) rotateY(0) scale(1); opacity: 1; }
}
#room-speech {
  --ink: #272331; --paper: #fff0cd; --tail-x: 50%;
  position: absolute; z-index: 1; left: var(--speaker-x); top: var(--speaker-y);
  transform: translate(-50%, -100%); width: max-content; max-width: min(72%, 17em);
  padding: .52em .95em .65em; background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 49% 45% 38% 32% / 24% 32% 29% 35%;
  box-shadow: 2px 3px 0 #231d2bd6; pointer-events: none;
  font: 700 clamp(15px, 1.65vw, 22px)/1.18 "Trebuchet MS", "Segoe UI", sans-serif;
  animation: speak .16s ease-out;
}
#room-speech::after {
  content: ""; position: absolute; width: 13px; height: 14px; left: var(--tail-x); bottom: -9px;
  background: var(--paper); border: solid var(--ink); border-width: 0 2px 2px 0;
  transform: skew(15deg) rotate(40deg);
}
#room-speech[data-speaker="mom"] {
  --paper: #ffe2aa; left: auto; right: max(12px, 2vw); top: 45%;
  transform: none; border-radius: 32% 39% 28% 30% / 25% 31% 26% 29%;
}
#room-speech[data-speaker="mom"]::after {
  left: auto; bottom: 27%; right: -9px; transform: skew(18deg,12deg) rotate(-39deg);
}
.speech-name {
  display: block; margin: 0 0 .24em .1em; color: #825037;
  font-size: .58em; letter-spacing: .12em; text-transform: uppercase;
}
@keyframes speak { from { scale: .94; } }
@media (max-aspect-ratio: 4/5) {
  #backpack { width: min(96vw, 87dvh); }
  .pack-spread { aspect-ratio: 1 / 1; }
  #notebook-page .prop-scene { left: auto; right: -8%; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #room-speech, #notebook-page, .antenna-waves::before, .antenna-waves::after { animation: none; }
}
.status, noscript {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: .55rem 1rem; width: max-content; max-width: 90vw;
  background: #070c18eb; color: #e7ddc7; font-family: Consolas, monospace;
}
[hidden] { display: none !important; }
@media (pointer: coarse) {
  .keyboard, .mouse-help { display: none; }
  .touch-help { display: inline; }
}
@media (max-aspect-ratio: 4/5) {
  .viewport { top: max(85px, 12dvh); bottom: max(64px, 8dvh); }
  header { top: max(22px, env(safe-area-inset-top)); }
  h1 { font-size: 31px; }
  footer { bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (max-height: 500px) and (orientation: landscape) {
  header { top: 10px; } h1 { font-size: 23px; } header p { margin-top: 3px; font-size: .66rem; }
  footer { bottom: 6px; } button { width: 36px; height: 36px; }
}

/* The next morning opens a fresh leaf of the notebook. */
.prop-scene[data-morning]::before {
  content: ''; position: absolute; z-index: 1; inset: 7.3% 11.3% 8% 20.2%; border-radius: 1px 8px 9px 1px;
  background: linear-gradient(90deg, transparent 15%, #c67d7166 15.1% 15.3%, transparent 15.4%),
    linear-gradient(100deg, #b8a48430, transparent 10% 90%, #b8a48430),
    repeating-linear-gradient(#e9dfc9 0 2.85%, #b5b9b1 2.9% 3.05%);
  box-shadow: -3px 0 5px #766a5140, inset 5px 0 12px #74655024;
}
.prop-scene[data-morning] #handwriting { z-index: 2; }
