/* The room fills the window. All text sits on things that belong in it:
   a shop sign, paper tags, the CRT, a name card, a pinned note, a sketchbook. */
:root {
  --night: #0a0b12;
  --sign-red: #9e211b;
  --sign-red-hi: #b8291f;
  --gold: #e7bd62;
  --paper: #f1e9d6;
  --paper-ink: #2a1c13;
  --ink-soft: #6f5b47;
  --chop: #b3261e;
  --phosphor: #8dffb0;
  --crt-bg: #07140c;
  --cloth: #2b2f3a;
  --ming: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --serif: "Noto Serif", Georgia, serif;
  --hand: "Kalam", "Segoe Print", cursive;
  --crt: "VT323", "Courier New", monospace;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--night); color: var(--paper); font-family: var(--serif); overflow: hidden; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px dashed var(--gold); outline-offset: 3px; }

canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
canvas#view.hot { cursor: pointer; }

/* ---------- sign, tags, index ---------- */
.bar {
  position: fixed; left: 0; right: 0; z-index: 5;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.top { top: 0; padding-top: calc(14px + env(safe-area-inset-top, 0px)); align-items: flex-start; }
.bottom { bottom: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); align-items: flex-end; }

.sign {
  display: flex; align-items: center; gap: 10px; padding: 5px 14px 5px 6px;
  background: linear-gradient(180deg, var(--sign-red-hi), var(--sign-red));
  border: 2px solid var(--gold);
  box-shadow: inset 0 0 0 3px var(--sign-red), inset 0 0 0 4px rgba(231, 189, 98, 0.5), 0 6px 18px rgba(0, 0, 0, 0.5);
  color: var(--gold); text-decoration: none;
}
.sign .zh { font: 900 30px/1 var(--ming); padding: 4px 6px; }
.sign .en { font: 700 12px/1.2 var(--serif); letter-spacing: 0.24em; }

.tagbtn {
  display: inline-flex; align-items: baseline; gap: 8px; cursor: pointer;
  padding: 8px 14px; min-height: 40px; border: 0;
  background: var(--paper); color: var(--paper-ink); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  text-decoration: none;
}
.tagbtn .zh { font: 900 15px var(--ming); }
.tagbtn .en { font: 700 11px var(--serif); letter-spacing: 0.18em; }
.tagbtn:disabled { opacity: 0.45; cursor: default; }
.first-hint { font: 400 17px var(--hand); color: #e9dcc0; text-shadow: 0 1px 3px #000; transition: opacity 1s; }
.first-hint.gone { opacity: 0; }

#index {
  position: fixed; z-index: 7;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  width: min(300px, calc(100vw - 32px)); max-height: calc(100vh - 140px); overflow: auto;
  padding: 8px 0 10px; background: var(--paper); color: var(--paper-ink); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#index h2 { margin: 8px 16px 4px; font: 900 13px var(--ming); color: var(--chop); letter-spacing: 0.1em; }
#index button, #index a {
  display: flex; align-items: baseline; gap: 10px; width: 100%; padding: 8px 16px; min-height: 38px;
  background: none; border: 0; cursor: pointer; text-align: left; color: inherit; text-decoration: none;
}
#index button:hover, #index a:hover { background: rgba(179, 38, 30, 0.08); }
#index .zh { font: 900 16px var(--ming); min-width: 3em; }
#index .en { font: 700 11px var(--serif); letter-spacing: 0.16em; }
#index a .t { font: 500 14px var(--serif); }
#index a .t small { color: var(--ink-soft); }
#index .mail { margin: 6px 16px 0; font: 500 13px var(--serif); user-select: all; }

#tip {
  position: fixed; z-index: 6; pointer-events: none; display: flex; align-items: baseline; gap: 8px;
  padding: 5px 10px 5px 9px; background: var(--paper); color: var(--paper-ink);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); transform: translate(16px, 14px) rotate(-2deg);
}
#tip .zh { font: 900 16px var(--ming); }
#tip .en { font: 700 10px var(--serif); letter-spacing: 0.18em; }

/* ---------- picked-up objects ---------- */
#held {
  position: fixed; inset: 0; z-index: 6; display: grid; place-items: center;
  padding: 60px max(16px, env(safe-area-inset-right, 0px)) 76px max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at center, rgba(6, 6, 10, 0.35), rgba(6, 6, 10, 0.84));
  opacity: 0; transition: opacity 0.35s;
}
#held.on { opacity: 1; }
#held.clear { background: none; pointer-events: none; padding: 0; }
#held.clear > * { pointer-events: auto; }
.obj { transform: rotate(var(--r, 0deg)); animation: lift 0.5s cubic-bezier(.2, .9, .3, 1.06); }
@keyframes lift { from { opacity: 0; transform: translateY(40px) rotate(var(--r, 0deg)) scale(0.96); } }
.putdown { position: fixed; z-index: 8; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }

#full { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; background: rgba(4, 4, 6, 0.95); cursor: zoom-out; padding: 3vh 3vw 6vh; }
#full img { max-width: 100%; max-height: 86vh; width: auto; height: auto; }
#full p { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); left: 0; right: 0; margin: 0; text-align: center; font: 500 13px var(--serif); letter-spacing: 0.12em; color: #b9ae98; }

/* CRT: an HTML screen pinned onto the 3D monitor glass every frame */
.crt {
  position: fixed; container-type: inline-size; overflow: hidden; border-radius: 4% / 5%;
  background: radial-gradient(ellipse at 50% 45%, #0f2a19, var(--crt-bg) 78%);
  color: var(--phosphor); font-family: var(--crt);
  text-shadow: 0 0 0.5cqw rgba(120, 255, 170, 0.55); box-shadow: inset 0 0 6cqw rgba(0, 0, 0, 0.75);
}
.crt::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px); }
.crt .inner { position: absolute; inset: 4.5cqw 5cqw; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 1.6cqw; font-size: 3.2cqw; line-height: 1.05; }
.crt p { margin: 0; }
.crt .cols { display: grid; grid-template-columns: 30% minmax(0, 1fr); gap: 3cqw; min-height: 0; }
.crt ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6cqw; }
.crt li button { width: 100%; text-align: left; background: none; border: 0; padding: 0.4cqw 1cqw; cursor: pointer; font: inherit; color: inherit; text-shadow: inherit; }
.crt li button[aria-current="true"] { background: var(--phosphor); color: var(--crt-bg); text-shadow: none; }
.crt li button:hover:not([aria-current="true"]) { background: rgba(141, 255, 176, 0.15); }
.crt .detail { min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 1.4cqw; scrollbar-width: none; }
.crt h3 { margin: 0; font: inherit; font-size: 4.6cqw; line-height: 1; }
.crt .meta { opacity: 0.7; }
.crt .shot { position: relative; aspect-ratio: 2 / 1; flex: none; }
.crt .shot img, .crt .shot canvas { display: block; width: 100%; height: 100%; object-fit: cover; filter: saturate(0.85) contrast(1.05); }
.crt .shot .none { display: grid; place-items: center; height: 100%; border: 0.3cqw dashed rgba(141, 255, 176, 0.5); text-align: center; padding: 2cqw; }
.crt .shot::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px); }
.crt .links { display: flex; flex-wrap: wrap; gap: 2cqw; }
.crt a { color: inherit; }
.crt .foot { opacity: 0.6; }

/* name card */
.cardwrap { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.card {
  position: relative; width: min(540px, 88vw); aspect-ratio: 1.75; padding: 6% 7%;
  background: #f6f1e4; color: var(--paper-ink); box-shadow: 0 24px 50px rgba(0, 0, 0, 0.6);
  display: grid; grid-template-columns: auto 1fr; column-gap: 7%; align-content: center;
}
.chop {
  grid-row: span 3; align-self: start; width: clamp(56px, 13vw, 84px); aspect-ratio: 1; display: grid; place-items: center;
  background: var(--chop); color: #f6f1e4; font: 900 clamp(32px, 7.5vw, 50px)/1 var(--ming);
  border-radius: 6px; box-shadow: inset 0 0 0 3px #f6f1e4, inset 0 0 0 5px var(--chop);
}
.card .cname { margin: 0; font: 700 clamp(20px, 4.4vw, 30px)/1.1 var(--serif); letter-spacing: 0.16em; }
.card .crole { margin: 4px 0 0; font: 500 clamp(12px, 2.2vw, 15px)/1.4 var(--serif); color: var(--ink-soft); }
.card dl { grid-column: 2; margin: 8% 0 0; display: grid; gap: 4px; font: 500 clamp(12px, 2.3vw, 15px)/1.4 var(--serif); }
.card dl div { display: flex; gap: 12px; flex-wrap: wrap; }
.card dt { font-family: var(--ming); font-weight: 900; color: var(--chop); min-width: 3.4em; }
.card dd { margin: 0; user-select: all; }
.card a { color: inherit; }

/* pinned note + polaroid */
.noteobj { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; justify-content: center; max-width: 94vw; }
.polaroid { background: #fbf8f0; padding: 10px 10px 34px; box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55); transform: rotate(-4deg); }
.polaroid .ph { width: min(220px, 50vw); aspect-ratio: 4 / 5; background: #3a4a52; display: grid; place-items: center; overflow: hidden; }
.polaroid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaroid .ph span { font: 900 48px var(--ming); color: #cfd8da; }
.polaroid figcaption { margin-top: 8px; text-align: center; font: 400 16px var(--hand); color: var(--paper-ink); }
.note {
  position: relative; width: min(420px, 88vw); padding: 34px 30px 26px;
  background: #f5efdc repeating-linear-gradient(to bottom, transparent 0 29px, rgba(70, 110, 160, 0.28) 29px 30px);
  color: #26313f; font: 400 21px/30px var(--hand); box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55);
}
.note p { margin: 0 0 30px; }
.note p:last-child { margin: 0; }
.pinhead { position: absolute; top: 10px; left: 50%; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ff6a5c, #a51d16); box-shadow: 0 3px 4px rgba(0, 0, 0, 0.4); }

.wintag {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) rotate(-1deg);
  padding: 10px 16px; background: var(--paper); color: var(--paper-ink); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5); text-align: center; max-width: 88vw;
}
.wintag b { display: block; font: 900 18px var(--ming); }
.wintag span { font: 400 17px var(--hand); }

/* ---------- sketchbook (page-flip) ---------- */
.bookwrap { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.bookstage { width: min(1080px, 94vw, calc((100vh - 230px) * 1.5)); aspect-ratio: 3 / 2; filter: drop-shadow(0 24px 40px rgba(0, 0, 0, 0.55)); }
.book { width: 100%; height: 100%; }
.bookctl { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.pg {
  background: var(--paper) radial-gradient(rgba(80, 60, 30, 0.05) 1px, transparent 1.4px) 0 0 / 5px 5px;
  color: var(--paper-ink); overflow: hidden;
}
.pg .in { position: relative; width: 100%; height: 100%; }
/* the spine: every page darkens slightly toward the fold */
.pg.l:not(.cover) { box-shadow: inset -26px 0 30px -20px rgba(60, 40, 20, 0.45); }
.pg.r:not(.cover) { box-shadow: inset 26px 0 30px -20px rgba(60, 40, 20, 0.45); }
.pg.cover { background: var(--cloth) repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 5px); color: var(--paper); }
.pg.cover .in { display: grid; place-items: center; }
.cover .label { padding: 18px 26px; background: var(--paper); color: var(--paper-ink); text-align: center; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); transform: rotate(-1.5deg); }
.cover .label b { display: block; font: 900 clamp(26px, 4vw, 44px)/1.1 var(--ming); }
.cover .label span { font: 400 clamp(14px, 1.6vw, 20px) var(--hand); }

.pg .text { position: absolute; inset: 9% 10%; display: flex; flex-direction: column; gap: 10px; }
.pg h3 { margin: 0; font: 700 clamp(20px, 2.6vw, 34px)/1.1 var(--hand); }
.pg h3 .zh { font-family: var(--ming); font-weight: 900; margin-right: 0.3em; }
.pg .medium { margin: 0; font: 500 clamp(12px, 1.2vw, 15px)/1.4 var(--serif); color: var(--ink-soft); letter-spacing: 0.04em; }
.pg .notes { margin: 0; font: 400 clamp(14px, 1.4vw, 19px)/1.45 var(--hand); }
.pg .num { position: absolute; bottom: 4%; left: 0; right: 0; text-align: center; font: 500 12px var(--serif); color: var(--ink-soft); }
.pg .contents { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.pg .contents button { display: flex; gap: 10px; align-items: baseline; width: 100%; padding: 5px 0; background: none; border: 0; border-bottom: 1px dashed rgba(42, 28, 19, 0.25); cursor: pointer; text-align: left; font: 400 clamp(14px, 1.4vw, 19px) var(--hand); }
.pg .contents button:hover { color: var(--chop); }
.pg .contents i { font-style: normal; margin-left: auto; color: var(--ink-soft); font-family: var(--serif); font-size: 12px; }
.pg .viewfull { align-self: flex-start; margin-top: auto; }

/* how a piece sits on its page */
.pg .art { position: absolute; overflow: hidden; }
.pg .art img { display: block; width: 100%; height: 100%; }
.pg.bleed .art { inset: 0; }
.pg.bleed .art img { object-fit: cover; }
.pg.plate .art { inset: 9% 9% 14%; display: grid; place-items: center; overflow: visible; }
.pg.plate .art img { width: auto; height: auto; max-width: 100%; max-height: 100%; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.pg.spread .art { inset: 0; }
.pg.spread .art img { position: absolute; top: 0; width: 200%; height: 100%; max-width: none; object-fit: cover; }
.pg.spread.l .art img { left: 0; }
.pg.spread.r .art img { left: -100%; }
.pg.spread .caption { position: absolute; left: 6%; bottom: 6%; padding: 8px 12px; background: var(--paper); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; gap: 4px; max-width: 80%; }
.pg .missing { position: absolute; inset: 9%; display: grid; place-items: center; text-align: center; border: 2px dashed rgba(42, 28, 19, 0.3); font: 400 15px var(--hand); color: var(--ink-soft); padding: 10px; }
/* gutter shading over art so bleed pages still read as a bound book */
.pg.bleed .in::after, .pg.spread .in::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.pg.bleed.r .in::after, .pg.spread.r .in::after { background: linear-gradient(90deg, rgba(0, 0, 0, 0.28), transparent 7%); }
.pg.spread.l .in::after { background: linear-gradient(270deg, rgba(0, 0, 0, 0.28), transparent 7%); }

/* ---------- loading / fallback ---------- */
#loading { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: var(--night); font: 400 20px var(--hand); color: #b9ae98; text-align: center; padding: 0 16px; transition: opacity 0.6s; }
#loading.gone { opacity: 0; pointer-events: none; }

@media (max-width: 560px) {
  .sign .en { display: none; }
  .first-hint { display: none; }
  .bookstage { width: min(94vw, calc((100vh - 230px) * 0.75)); aspect-ratio: 3 / 4; }
}
@media (prefers-reduced-motion: reduce) {
  .obj { animation: none; }
  #held, #loading, .first-hint { transition: none; }
}
