:root {
  --bg-1: #f8efe2;
  --bg-2: #ecdcc6;
  --paper: #fffaf1;
  --paper-glass: rgba(255, 250, 241, 0.84);
  --ink: #2b211c;
  --muted: #6f5f55;
  --line: rgba(74, 46, 27, 0.12);
  --accent: #b4583a;
  --accent-hover: #9e4b31;
  --accent-ink: #fff7ee;
  --marigold: #d9a43a;
  --rust: #a8552f;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 12px 32px -14px rgba(90, 54, 28, 0.35);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --font-d: "Fraunces", Georgia, serif;
  --font-b: "Outfit", system-ui, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font: 400 16px/1.55 var(--font-b);
  background: radial-gradient(120% 90% at 50% 20%, var(--bg-1) 0%, var(--bg-2) 100%);
  -webkit-font-smoothing: antialiased;
  transition: color 0.8s;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---------- loader: tiny me looking for my keys ---------- */
#loader {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-content: center; justify-items: center;
  background: radial-gradient(120% 90% at 50% 20%, var(--bg-1) 0%, var(--bg-2) 100%);
  transition: opacity 0.6s var(--ease-out), visibility 0.6s;
}
.pre-night #loader { background: radial-gradient(120% 90% at 50% 20%, #2a3560 0%, #151c36 100%); }
.pre-night .l-caption { color: #e9e0f2; }
/* appears only if loading takes a moment, so a cached visit skips it */
.l-stage { display: grid; justify-items: center; gap: 6px; opacity: 0; animation: stageIn 0.45s var(--ease-out) 0.3s forwards; }
@keyframes stageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.l-scene { width: min(340px, 78vw); height: auto; overflow: visible; }
.l-caption { margin: 0; font: italic 500 19px/1.3 var(--font-d); color: var(--ink); }
.l-scene g { transform-box: fill-box; }
.l-head { transform-origin: 50% 100%; animation: peek 1.6s ease-in-out infinite; }
@keyframes peek { 0%, 100% { transform: rotate(7deg) translateY(1px); } 50% { transform: rotate(11deg) translateY(2px); } }
.l-arm { transform-origin: 30% 0%; animation: rummage 0.5s ease-in-out infinite alternate; }
@keyframes rummage { from { transform: rotate(-4deg); } to { transform: rotate(6deg) translateY(1px); } }
.l-arm-l { animation-delay: -0.25s; } /* patting both pockets, out of step */
@keyframes jiggle { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
.l-item { transform-box: fill-box; transform-origin: 50% 100%; opacity: 0; animation: pop 1.8s var(--ease-out) infinite; }
.l-item.i2 { animation-delay: 0.6s; }
.l-item.i3 { animation-delay: 1.2s; }
@keyframes pop { 0%, 34%, 100% { opacity: 0; transform: translateY(0); } 10% { opacity: 1; transform: translateY(-17px) rotate(-14deg); } 22% { opacity: 1; transform: translateY(-12px) rotate(10deg); } }
.l-key { opacity: 0; transform-origin: 50% 100%; }
.l-eyes-up, .l-mouth-smile { opacity: 0; }
.l-door { transform-origin: 0% 50%; transition: transform 0.75s var(--ease-drawer) 0.55s; }
.l-keyhole { transition: fill 0.2s 0.4s; }
/* found them: key up, look up, smile, unlock, door swings open */
.unlocking .l-item { animation: none; opacity: 0; }
.unlocking .l-arm { animation: none; }
.unlocking .l-head { animation: none; transform: rotate(-4deg); transition: transform 0.35s var(--ease-out); }
.unlocking .l-eyes-down, .unlocking .l-mouth-o { opacity: 0; }
.unlocking .l-eyes-up, .unlocking .l-mouth-smile { opacity: 1; }
.unlocking .l-key { animation: keyUp 0.6s var(--ease-out) forwards; }
@keyframes keyUp { 0% { opacity: 0; transform: translateY(0); } 60% { opacity: 1; transform: translateY(-26px) rotate(-12deg); } 100% { opacity: 1; transform: translateY(-22px) rotate(0deg); } }
.unlocking .l-keyhole { fill: #ffd98a; }
.unlocking .l-door { transform: scaleX(0.12); }
body.ready #loader { opacity: 0; visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  .l-stage, .l-head, .l-arm, .l-item { animation: none; }
  .l-stage { opacity: 1; }
}

/* ---------- top HUD ---------- */
.hud-top {
  position: fixed; z-index: 10;
  top: max(14px, env(safe-area-inset-top)); left: var(--gutter); right: max(16px, env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.wordmark {
  position: relative;
  border: 1px solid #d9c3a2; background: #f8eedc; padding: 8px 14px 7px 24px; cursor: pointer;
  border-radius: 8px;
  font: 400 17px/1 var(--font-d); letter-spacing: 0.01em; color: #3a2b22;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 6px 14px -8px rgba(90, 55, 25, 0.45);
  transform: rotate(-1.2deg);
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s;
}
/* the little nail hole, like a door sign */
.wordmark::before {
  content: ''; position: absolute; left: 10px; top: 50%; width: 6px; height: 6px; margin-top: -3px;
  border-radius: 50%; background: #b48a5e; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.wordmark:hover { transform: rotate(0deg) translateY(-1px); }
.wordmark:active { transform: rotate(0deg) scale(0.98); }
.hud-actions { display: flex; align-items: center; gap: 14px; }
.quiet { font-size: 14px; color: var(--muted); text-decoration: none; }
.quiet:hover { color: var(--ink); }
.resume {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px 9px 12px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 14px; text-decoration: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 10px 24px -12px rgba(120, 52, 26, 0.6);
  transition: transform 0.16s var(--ease-out), background-color 0.2s;
}
.resume svg { width: 17px; height: 17px; }
.resume:hover { background: var(--accent-hover); }
.resume:active { transform: scale(0.97); }
.coffee {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px 8px 11px; border-radius: 999px; cursor: pointer;
  background: var(--paper-glass); border: 1px solid var(--line); color: var(--ink);
  font-weight: 600; font-size: 14px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform 0.16s var(--ease-out), background-color 0.2s;
}
.coffee svg { width: 18px; height: 18px; color: var(--rust); }
.coffee:hover { background: #fff6ea; }
.coffee:active { transform: scale(0.97); }
.coffee .short { display: none; }

/* ---------- caption ---------- */
#caption {
  position: fixed; z-index: 5;
  left: var(--gutter); bottom: 92px;
  max-width: 400px;
  padding: 16px 18px 15px;
  border-radius: 18px;
  background: var(--paper-glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  transition: opacity 0.22s var(--ease-out), transform 0.22s var(--ease-out);
}
#caption.swap { opacity: 0; transform: translateY(6px); transition-duration: 0.14s; }
.kicker { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rust); }
#caption .cap-title { margin: 0 0 6px; font: 600 26px/1.15 var(--font-d); letter-spacing: -0.015em; }
#caption .sub { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
#caption .sub:empty { display: none; }
#caption .cap-title:has(+ .sub:empty) { margin-bottom: 0; }

/* ---------- nav ---------- */
#nav {
  position: fixed; z-index: 10;
  left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: var(--paper-glass);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#nav > button {
  width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: transparent; cursor: pointer;
  transition: background-color 0.18s, transform 0.16s var(--ease-out), opacity 0.2s;
}
#nav > button svg { width: 18px; height: 18px; }
#nav > button:hover { background: rgba(74, 46, 27, 0.07); }
#nav > button:active { transform: scale(0.94); }
#nav > button:disabled { opacity: 0.3; cursor: default; background: transparent; }
#dots { list-style: none; display: flex; align-items: center; gap: 2px; margin: 0; padding: 0 4px; }
#dots button {
  position: relative; display: block; width: 22px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer;
}
#dots button::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; border-radius: 99px;
  background: rgba(74, 46, 27, 0.25);
  transform: translate(-50%, -50%);
  transition: width 0.3s var(--ease-out), background-color 0.2s;
}
#dots button:hover::before { background: rgba(74, 46, 27, 0.5); }
#dots button[aria-current="step"]::before { width: 18px; background: var(--accent); }
#dots button::after {
  content: attr(aria-label);
  position: absolute; left: 50%; bottom: calc(100% + 10px);
  padding: 5px 9px; border-radius: 8px; white-space: nowrap;
  background: var(--ink); color: var(--paper); font-size: 12px;
  opacity: 0; transform: translate(-50%, 4px); pointer-events: none;
  transition: opacity 0.14s var(--ease-out), transform 0.14s var(--ease-out);
}
@media (hover: hover) { #dots button:hover::after { opacity: 1; transform: translate(-50%, 0); } }
#count { display: none; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 44px; text-align: center; }

/* ---------- hint ---------- */
#hint {
  position: fixed; z-index: 4; left: 50%; bottom: 84px; margin: 0;
  transform: translateX(-50%);
  display: none; align-items: center; gap: 10px;
  font-size: 13px; color: var(--muted);
  transition: opacity 0.4s var(--ease-out);
}
.mouse { width: 16px; height: 24px; border: 1.5px solid currentColor; border-radius: 10px; position: relative; }
.mouse::after { content: ""; position: absolute; left: 50%; top: 5px; width: 2px; height: 5px; margin-left: -1px; border-radius: 2px; background: currentColor; animation: nudge 2.4s var(--ease-out) infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: translateY(0); opacity: 1; } 30% { transform: translateY(5px); opacity: 0.3; } }
body.moved #hint { opacity: 0; pointer-events: none; }

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none;
  max-width: 260px; padding: 7px 11px; border-radius: 10px;
  background: var(--ink); color: var(--paper);
  font-size: 13px; line-height: 1.35;
  opacity: 0; transition: opacity 0.12s var(--ease-out);
}
#tooltip.show { opacity: 1; }

/* ---------- speech bubble ---------- */
#bubble {
  position: fixed; z-index: 8; left: 0; top: 0;
  width: max-content; max-width: min(280px, calc(100vw - 32px));
  padding: 12px 14px 12px;
  border-radius: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - 12px)) scale(0.96);
  transform-origin: 50% 100%;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
#bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; width: 14px; height: 14px;
  background: var(--paper); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
#bubble.show { opacity: 1; transform: translate(-50%, calc(-100% - 12px)) scale(1); pointer-events: auto; }
#bubble p { margin: 0; font: italic 500 18px/1.3 var(--font-d); }
#bubble .bubble-actions { margin-top: 10px; }
.bubble-actions { display: flex; gap: 6px; }
.bubble-actions button {
  border: 1px solid var(--line); background: #f5ecdc; border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: transform 0.16s var(--ease-out), background-color 0.2s;
}
.bubble-actions button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.bubble-actions[hidden] { display: none; }
.bubble-actions button:active { transform: scale(0.97); }

/* ---------- panel ---------- */
#panel {
  position: fixed; z-index: 15;
  top: 72px; right: max(16px, env(safe-area-inset-right)); bottom: 84px;
  width: min(420px, calc(100vw - 32px));
  display: flex; flex-direction: column;
  border-radius: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 30px 60px -24px rgba(90, 54, 28, 0.45);
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  transition: transform 0.26s cubic-bezier(0.4, 0, 1, 1), visibility 0s linear 0.26s;
}
#panel.open {
  transform: translateX(0); visibility: visible;
  transition: transform 0.45s var(--ease-drawer), visibility 0s;
}
#panelClose {
  position: absolute; top: 12px; right: 12px; z-index: 1;
  width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: #f3e9d8; cursor: pointer;
  transition: background-color 0.18s, transform 0.16s var(--ease-out);
}
#panelClose svg { width: 18px; height: 18px; }
#panelClose:hover { background: #ebdcc5; }
#panelClose:active { transform: scale(0.94); }
#panelBody { overflow-y: auto; padding: 26px 26px 28px; overscroll-behavior: contain; }
#panelBody h2 { margin: 2px 44px 12px 0; font: 600 28px/1.15 var(--font-d); letter-spacing: -0.015em; text-wrap: balance; }
#panelBody p { margin: 0 0 12px; color: #4a3b33; max-width: 60ch; }
#panelBody .tag { color: var(--muted); font-size: 14px; margin-top: -6px; }
#panelBody .muted, .muted { color: var(--muted); font-size: 14px; }
blockquote { margin: 8px 0 22px; padding: 0 0 0 16px; border-left: 3px solid var(--marigold); font: italic 500 22px/1.4 var(--font-d); color: var(--ink); }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.row.split { justify-content: space-between; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: #f6eddf;
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer;
  transition: transform 0.16s var(--ease-out), background-color 0.2s;
}
.btn:hover { background: #efe2cd; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.link { border: 0; background: none; padding: 0; color: var(--rust); font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.link::before { content: "\2190\00a0"; }

.tabs { display: grid; gap: 6px; margin: 4px 0 20px; }
.tabs button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  font-size: 14px; cursor: pointer; transition: background-color 0.18s, border-color 0.18s;
}
.tabs button span { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
.tabs button:hover { background: #f6eddf; }
.tabs button[aria-selected="true"] { background: #f8eadc; border-color: rgba(180, 88, 58, 0.4); }
.tabs button[aria-selected="true"] span { color: var(--accent); font-weight: 600; }
.pbl { margin: 8px 0 0; }
.pbl dt { margin-top: 14px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.pbl dd { margin: 4px 0 0; color: #4a3b33; }

.essays { list-style: none; padding: 0; margin: 8px 0 14px; display: grid; gap: 8px; }
.essays button {
  display: grid; gap: 2px; width: 100%; text-align: left; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: #fbf3e6; cursor: pointer;
  transition: background-color 0.18s, transform 0.16s var(--ease-out);
}
.essays button:hover { background: #f5e9d6; }
.essays button:active { transform: scale(0.99); }
.essays strong { font: italic 600 19px/1.3 var(--font-d); }
.essays span { font-size: 14px; color: var(--muted); }
.essay p:first-child::first-letter { font: 600 2.6em/0.9 var(--font-d); float: left; margin: 4px 8px 0 0; color: var(--rust); }

.contact { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.contact li { display: flex; align-items: center; gap: 8px; }
.contact a {
  flex: 1; min-width: 0; display: grid; gap: 1px; padding: 12px 14px; border-radius: 14px; text-decoration: none;
  border: 1px solid var(--line); background: #fbf3e6; transition: background-color 0.18s;
}
.contact a:hover { background: #f5e9d6; }
.contact span { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rust); }
.contact strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- book cover ---------- */
.cover { margin: 8px auto 6px; width: min(240px, 70%); aspect-ratio: 2 / 3; perspective: 800px; }
.cover-face {
  height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 14px;
  padding: 26px 22px; border-radius: 4px 10px 10px 4px;
  background: var(--c); color: var(--ink);
  box-shadow: inset 7px 0 0 rgba(0, 0, 0, 0.08), inset 9px 0 0 rgba(255, 255, 255, 0.12), 0 22px 40px -18px rgba(70, 40, 20, 0.55);
  animation: cover-in 0.42s var(--ease-out) both;
}
.cover-face strong { font: 600 26px/1.15 var(--font-d); letter-spacing: -0.01em; text-wrap: balance; }
.cover-author { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.8; }
.cover-rule { width: 36px; height: 3px; border-radius: 2px; background: currentColor; opacity: 0.55; }
@keyframes cover-in { from { opacity: 0; transform: translateY(8px) rotateY(-8deg); } to { opacity: 1; transform: none; } }

/* ---------- diary ---------- */
#panel[data-kind="diary"] { background: #fbf4e6; }
.diary-page {
  margin: 4px -6px 0; padding: 6px 10px 10px 30px;
  background-image: linear-gradient(90deg, transparent 18px, rgba(196, 112, 79, 0.35) 18px, rgba(196, 112, 79, 0.35) 19.5px, transparent 19.5px),
    repeating-linear-gradient(transparent 0 31px, rgba(110, 140, 170, 0.22) 31px 32px);
  background-position: 0 6px;
  font: 500 22px/32px "Caveat", "Segoe Print", cursive;
  color: #2f3a52;
}
#panelBody .diary-page p { margin: 0 0 32px; color: inherit; max-width: none; }
#panelBody .diary-page p:last-child { margin-bottom: 0; }
.diary-date { font-weight: 600; font-size: 24px; color: var(--rust) !important; }

/* ---------- note form ---------- */
.note { display: grid; gap: 14px; margin-top: 6px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field input, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid rgba(74, 46, 27, 0.18); background: #fffdf8; color: var(--ink);
  font: 400 15px/1.45 var(--font-b);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; min-height: 110px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(180, 88, 58, 0.15); }
#panelBody .help { margin: 0; font-size: 13px; color: var(--muted); }
#panelBody .error { margin: 0; min-height: 0; font-size: 14px; color: #a3321f; }
#panelBody .error:empty { display: none; }
.note .row { margin-top: 2px; }
.note-sent h3 { margin: 18px 0 4px; font: italic 600 22px/1.3 var(--font-d); }

/* ---------- toast ---------- */
#toast {
  position: fixed; z-index: 25; left: 50%; bottom: 84px;
  padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 14px;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 701px) { body[data-stop="outside"] #hint { display: flex; } }

/* ---------- phones ---------- */
@media (max-width: 700px) {
  #caption { left: 12px; right: 12px; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px); max-width: none; padding: 13px 15px 12px; }
  #caption .cap-title { font-size: 21px; }
  #caption .sub { font-size: 14px; }
  #nav { bottom: max(14px, env(safe-area-inset-bottom)); }
  #dots { display: none; }
  #count { display: block; }
  #nav > button { width: 44px; height: 44px; }
  .quiet { display: none; }
  .coffee .long { display: none; }
  .coffee .short { display: none; }
  .coffee { padding: 0; width: 36px; height: 36px; justify-content: center; }
  .resume { padding: 8px 12px 8px 10px; }
  .night-toggle { width: 48px; height: 28px; }
  .night-toggle .knob { width: 22px; height: 22px; }
  body.night .night-toggle .knob { transform: translateX(20px); }
  .hud-actions { gap: 8px; }
  .wordmark { font-size: 15px; padding: 7px 11px 6px 21px; }
  .wordmark::before { left: 8px; }
  #panel {
    top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 76dvh;
    border-radius: 22px;
    transform: translateY(calc(100% + 16px));
  }
  #panel.open { transform: translateY(0); }
  #panelBody { padding: 22px 20px 26px; }
  #panelBody h2 { font-size: 24px; }
  body.panel-open #caption { opacity: 0; pointer-events: none; }
  #toast { bottom: 140px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.12s !important; }
}

/* ---------- plain version ---------- */
body.plain-mode { overflow: auto; }
body.plain-mode #scene, body.plain-mode .hud-top, body.plain-mode #caption, body.plain-mode #nav,
body.plain-mode #about, body.plain-mode #hint, body.plain-mode #loader, body.plain-mode #bubble, body.plain-mode #panel { display: none; }
#plain { padding: 48px 16px 80px; }
.plain-inner { max-width: 680px; margin: 0 auto; }
.plain-inner h1 { font: 600 40px/1.1 var(--font-d); letter-spacing: -0.02em; margin: 6px 0 14px; }
.plain-inner h2 { font: 600 26px/1.2 var(--font-d); margin: 56px 0 8px; padding-top: 20px; border-top: 1px solid var(--line); }
.plain-inner h3 { font: italic 600 19px/1.3 var(--font-d); margin: 22px 0 6px; }
.plain-inner p, .plain-inner dd { color: #4a3b33; }
.books { list-style: none; padding: 0; display: grid; gap: 12px; }
.books li { display: grid; gap: 2px; }
.books span { color: #4a3b33; }


/* ---------- night sky (fades in under the canvas) ---------- */
#sky {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 15%, #2c3a6b 0%, #18213f 55%, #10162b 100%);
  opacity: 0; transition: opacity 1.2s ease;
}
body.night #sky { opacity: 1; }
#stars i {
  position: absolute; border-radius: 50%; background: #fff6dc; opacity: 0.8;
  animation: twinkle 3.6s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.85; } 50% { opacity: 0.35; } }
.moon {
  position: absolute; top: 9%; right: 14%; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fff8e4 0%, #f3e3b5 60%, #e6d19a 100%);
  box-shadow: 0 0 40px 8px rgba(255, 238, 190, 0.25);
}
.moon::after { content: ""; position: absolute; left: 18px; top: 26px; width: 10px; height: 10px; border-radius: 50%; background: rgba(200, 180, 130, 0.35); box-shadow: 16px -8px 0 -2px rgba(200, 180, 130, 0.3); }

/* ---------- sound toggle ---------- */
.sound-toggle {
  width: 32px; height: 32px; padding: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--paper-glass); color: var(--muted);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform 0.16s var(--ease-out), color 0.2s, background-color 0.2s;
}
.sound-toggle svg { width: 17px; height: 17px; }
.sound-toggle .waves { display: none; }
.sound-toggle.on { color: var(--rust); }
.sound-toggle.on .waves { display: inline; }
.sound-toggle.on .mute { display: none; }
.sound-toggle:hover { background: #fff6ea; color: var(--ink); }
.sound-toggle:active { transform: scale(0.94); }
body.night .sound-toggle { background: rgba(29, 38, 71, 0.75); border-color: rgba(255, 255, 255, 0.12); color: #cfc6e0; }
body.night .sound-toggle.on { color: #f3e3b5; }

/* ---------- day/night switch ---------- */
.night-toggle {
  position: relative; width: 54px; height: 30px; border-radius: 999px; cursor: pointer; padding: 0;
  border: 1px solid var(--line); background: #f6e7cf;
  transition: background-color 0.6s ease;
}
.night-toggle .knob {
  position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; background: #fffaf1; color: #d9a43a;
  box-shadow: 0 2px 6px rgba(90, 54, 28, 0.25);
  transition: transform 0.45s var(--ease-drawer), color 0.4s;
}
.night-toggle svg { width: 16px; height: 16px; grid-area: 1 / 1; transition: opacity 0.3s, transform 0.45s var(--ease-drawer); }
.night-toggle .moon-i { opacity: 0; transform: rotate(-40deg); }
body.night .night-toggle { background: #2d3a66; border-color: rgba(255, 255, 255, 0.12); }
body.night .night-toggle .knob { transform: translateX(24px); color: #f3e3b5; background: #1d2647; }
body.night .night-toggle .sun { opacity: 0; transform: rotate(40deg); }
body.night .night-toggle .moon-i { opacity: 1; transform: none; }
body.night .wordmark { color: #3a2b22; background: #f8eedc; box-shadow: 0 0 0 1px rgba(255, 220, 160, 0.25), 0 8px 22px -8px rgba(255, 196, 120, 0.45); }
body.night #hint { color: #cfc6e0; }

/* ---------- navigation: back + room menu ---------- */
#nav { gap: 4px; padding: 5px; }
#roomMenu { list-style: none; display: flex; gap: 2px; margin: 0; padding: 0; }
#roomMenu button {
  position: relative; width: 38px; height: 38px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; background: transparent; color: var(--muted); cursor: pointer;
  transition: background-color 0.18s, color 0.18s, transform 0.16s var(--ease-out);
}
#roomMenu svg { width: 20px; height: 20px; }
#roomMenu button:hover { background: rgba(74, 46, 27, 0.07); color: var(--ink); }
#roomMenu button:active { transform: scale(0.94); }
#roomMenu button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
#roomMenu .tip {
  position: absolute; left: 50%; bottom: calc(100% + 10px); padding: 5px 9px; border-radius: 8px; white-space: nowrap;
  background: var(--ink); color: var(--paper); font-size: 12px;
  opacity: 0; transform: translate(-50%, 4px); pointer-events: none;
  transition: opacity 0.14s var(--ease-out), transform 0.14s var(--ease-out);
}
@media (hover: hover) { #roomMenu button:hover .tip { opacity: 1; transform: translate(-50%, 0); } }
#nav > .back {
  display: none; width: auto; align-items: center; gap: 4px; height: 38px; padding: 0 14px 0 8px; border-radius: 999px; border: 0;
  background: #f3e4cc; color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background-color 0.18s, transform 0.16s var(--ease-out);
}
#nav > .back svg { width: 18px; height: 18px; }
#nav > .back:hover { background: #ecd8ba; }
#nav > .back:active { transform: scale(0.97); }
body.in-room #nav > .back { display: inline-flex; }
body[data-stop="outside"] #nav { opacity: 0; pointer-events: none; transform: translate(-50%, 8px); }
#nav { transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out); }
@media (min-width: 701px) { body[data-stop="outside"] #hint { display: flex; } }
@media (max-width: 700px) {
  #nav { left: 12px; right: 12px; transform: none; max-width: none; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
  #nav::-webkit-scrollbar { display: none; }
  body[data-stop="outside"] #nav { transform: translateY(8px); }
  #roomMenu button { width: 40px; height: 40px; flex: 0 0 auto; }
  #nav > .back { flex: 0 0 auto; }
  body[data-stop="outside"] #hint { display: flex; bottom: 120px; }
}

/* ---------- projects: a large centred panel ---------- */
#scrim { position: fixed; inset: 0; z-index: 14; background: rgba(43, 33, 28, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.3s var(--ease-out); }
body.panel-open[data-panel="projects"] #scrim { opacity: 1; pointer-events: auto; }
#panel[data-kind="projects"] {
  top: 50%; left: 50%; right: auto; bottom: auto;
  width: min(760px, calc(100vw - 32px)); max-height: min(86dvh, 820px);
  transform: translate(-50%, -46%) scale(0.98); opacity: 0;
  transition: transform 0.22s ease-in, opacity 0.18s ease-in, visibility 0s linear 0.22s;
}
#panel[data-kind="projects"].open {
  transform: translate(-50%, -50%); opacity: 1;
  transition: transform 0.4s var(--ease-drawer), opacity 0.25s var(--ease-out), visibility 0s;
}
.proj { padding: 10px 14px 4px; }
#panelBody .proj h2 { font-size: clamp(28px, 4vw, 38px); margin-bottom: 8px; }
.proj-tag { margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: #f6e7d6; color: var(--muted); letter-spacing: 0.04em; text-transform: none; font-weight: 500; }
#panelBody .proj-summary { font: italic 500 21px/1.45 var(--font-d); color: var(--ink); margin: 0 0 22px; max-width: 54ch; }
.proj section { padding: 16px 0 4px; border-top: 1px solid var(--line); }
/* before/after impact line, the visual, and tool chips */
#panelBody .proj-impact {
  margin: 0 0 18px; padding: 14px 18px; border-radius: 14px;
  background: #fbefe0; border-left: 4px solid var(--accent);
  font-size: 18px; line-height: 1.55; color: #3f322b; max-width: 62ch;
}
.proj-impact span { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rust); }
.proj-visual { margin: 0 0 16px; padding: 12px; border-radius: 16px; background: #f7ecdc; }
.proj-visual svg { display: block; width: 100%; height: auto; }
.proj-visual .v-cap { font: 600 15px var(--font-b); fill: #6f5f55; }
.proj-visual .v-chip { font: 700 11px var(--font-b); fill: #2b211c; }
.proj-visual.shot { padding: 8px; background: #fff; border: 1px solid var(--line); }
.proj-visual.shot img { display: block; width: 100%; height: auto; border-radius: 10px; }
.proj-visual figcaption { margin-top: 8px; font-size: 14px; }
.proj-visual figcaption a { color: var(--rust); }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 18px; padding: 0; list-style: none; }
.tools li { padding: 5px 12px; border-radius: 999px; background: #fffaf1; border: 1px solid #e3cfb3; font-size: 14px; font-weight: 500; color: var(--ink); }
.tools li.tools-label { padding: 0 4px 0 0; border: 0; background: none; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
#panelBody .story-label { margin-top: 14px; font: 600 26px/1 "Caveat", cursive; color: #2f3a52; transform: rotate(-2deg); display: inline-block; }
.proj h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--rust); }
#panelBody .proj section p { font-size: 18px; line-height: 1.6; color: #3f322b; max-width: 62ch; }
.proj-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.arrow {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: #f6eddf; cursor: pointer;
  display: grid; place-items: center; transition: background-color 0.18s, transform 0.16s var(--ease-out);
}
.arrow svg { width: 22px; height: 22px; }
.arrow:hover { background: #efe2cd; }
.arrow:active { transform: scale(0.95); }
.proj-dots { display: flex; gap: 8px; }
.proj-dots i { width: 8px; height: 8px; border-radius: 99px; background: rgba(74, 46, 27, 0.2); transition: width 0.3s var(--ease-out), background-color 0.2s; }
.proj-dots i.on { width: 22px; background: var(--accent); }
@media (max-width: 700px) {
  #panel[data-kind="projects"] { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 88dvh; transform: translateY(calc(100% + 16px)); opacity: 1; }
  #panel[data-kind="projects"].open { transform: translateY(0); }
  .proj { padding: 4px 2px; }
  #panelBody .proj-summary { font-size: 19px; }
  #panelBody .proj section p { font-size: 17px; }
}

/* ---------- book cover caption ---------- */
.cover figcaption { margin-top: 14px; text-align: center; font-size: 15px; color: var(--muted); }
.cover figcaption strong { color: var(--ink); font-weight: 600; }
.cover { margin-bottom: 24px; }

/* ---------- diary pen ---------- */
.diary-page .pen { display: inline-block; width: 22px; height: 22px; margin-left: 2px; vertical-align: -2px; animation: scribble 0.35s ease-in-out infinite alternate; }
.diary-page .pen svg { width: 100%; height: 100%; }
@keyframes scribble { from { transform: translate(0, 0) rotate(-6deg); } to { transform: translate(1px, -2px) rotate(4deg); } }
.diary-page p.later { opacity: 0; transform: translateY(4px); transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out); }
.diary-page p.later.shown { opacity: 1; transform: none; }
.diary-head { display: flex; align-items: baseline; gap: 14px; margin-right: 44px; }
.skip { font-size: 13px; }
.skip[hidden] { display: none; }
.skip::before { content: none; }

/* narrow phones: five things in the top bar, so everything tightens a little */
@media (max-width: 420px) {
  .hud-actions { gap: 5px; }
  .wordmark { font-size: 14px; padding: 6px 9px 5px 18px; }
  .wordmark::before { left: 7px; width: 5px; height: 5px; margin-top: -2.5px; }
  .sound-toggle { width: 30px; height: 30px; }
  .sound-toggle svg { width: 15px; height: 15px; }
  .night-toggle { width: 44px; height: 26px; }
  .night-toggle .knob { width: 20px; height: 20px; }
  body.night .night-toggle .knob { transform: translateX(18px); }
  .coffee { width: 32px; height: 32px; }
  .resume { padding: 7px 10px 7px 8px; font-size: 13px; gap: 4px; }
  .resume svg { width: 15px; height: 15px; }
}
