/* The Dark Room — UI layer over the 3D scene */
:root {
  --paper: #ece2c8;
  --ink: #241a12;
  --string: #b8323a;
  --torch: #f6d48b;
  --lume: #b9ffcf;
  --f-type: "Special Elite", "Courier New", monospace;
  --f-hand: "Caveat", "Segoe Print", cursive;
  --f-body: "Newsreader", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #000; color: var(--paper); font-family: var(--f-body);
  overflow: hidden; -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
button { font: inherit; }
.noscript { color: #eee; padding: 2rem; }
.noscript a { color: var(--torch); }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ------------------------------------------------------------ crosshair */
#crosshair {
  position: fixed; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; z-index: 5;
  pointer-events: none; border-radius: 50%; border: 1.5px solid transparent;
  transition: border-color .2s, transform .2s, opacity .3s; opacity: 0;
}
#crosshair .dot { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: rgba(255, 240, 210, .75); box-shadow: 0 0 4px #000; }
body.exploring #crosshair { opacity: 1; }
#crosshair.aim { border-color: rgba(246, 212, 139, .9); transform: scale(1.1); }
body.touch #crosshair { display: none; }
#prompt {
  position: fixed; left: 50%; top: calc(50% + 30px); transform: translateX(-50%); z-index: 5; pointer-events: none;
  font: 15px var(--f-type); color: var(--torch); text-shadow: 0 1px 6px #000, 0 0 2px #000; white-space: nowrap;
  opacity: 0; transition: opacity .2s;
}
#prompt.show { opacity: 1; }
#prompt kbd { font: 12px var(--f-type); border: 1px solid rgba(246, 212, 139, .5); border-radius: 3px; padding: 0 5px; margin-right: 6px; }

/* ------------------------------------------------------------------ HUD */
.hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 18px 0; pointer-events: none;
  opacity: 0; transition: opacity .8s .4s;
}
body.started .hud { opacity: 1; }
.hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 2px; font-family: var(--f-type); text-shadow: 0 1px 6px #000; }
.hud-name { font-size: 17px; letter-spacing: .5px; }
.hud-count { font-size: 13px; color: rgba(236, 226, 200, .6); }
.hud-count #found-n { color: var(--torch); }
.hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.hud-btn {
  appearance: none; border: 1px solid rgba(236, 226, 200, .25); background: rgba(0,0,0,.55); color: var(--paper);
  font: 14px var(--f-type); padding: 8px 14px; border-radius: 999px; text-decoration: none; cursor: pointer;
  backdrop-filter: blur(4px); display: inline-flex; align-items: center; gap: 6px; transition: border-color .2s, color .2s;
}
.hud-btn:hover { border-color: var(--torch); color: var(--torch); }
.hud-btn:focus-visible { outline: 2px solid var(--torch); outline-offset: 2px; }
.hud-btn.icon { padding: 8px 10px; }
.hud-btn[aria-pressed="false"] .waves { opacity: 0; }
#btn-lights[aria-pressed="true"] { background: var(--torch); color: #000; border-color: var(--torch); }

.hint {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 10px); z-index: 11; pointer-events: none;
  font: 15px/1.5 var(--f-type); color: var(--paper); text-align: center; max-width: calc(100% - 40px);
  text-shadow: 0 1px 8px #000; opacity: 0; transition: opacity .6s, transform .6s;
}
.hint.show { opacity: .92; transform: translate(-50%, 0); }
body.touch .hint { bottom: 190px; }

.toast {
  position: fixed; left: 50%; top: 76px; z-index: 30; transform: translate(-50%, -12px);
  max-width: min(440px, calc(100% - 32px)); padding: 14px 18px; border-radius: 6px;
  background: var(--paper); color: var(--ink); font: 16px/1.4 var(--f-body);
  box-shadow: 0 16px 40px rgba(0,0,0,.6); opacity: 0; pointer-events: none; transition: opacity .4s, transform .4s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .btn-ink { margin: 10px 8px 0 0; }

/* -------------------------------------------------------------- joystick */
#joystick {
  position: fixed; left: max(28px, env(safe-area-inset-left)); bottom: max(34px, env(safe-area-inset-bottom)); z-index: 9;
  width: 124px; height: 124px; border-radius: 50%; display: none;
  border: 1.5px solid rgba(236, 226, 200, .25); background: radial-gradient(circle, rgba(255,255,255,.05), rgba(0,0,0,.25));
}
body.touch.exploring #joystick { display: block; }
#joystick .knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(246, 212, 139, .25); border: 1.5px solid rgba(246, 212, 139, .6); }

/* ----------------------------------------------------------------- intro */
#intro {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px;
  background: #000; transition: opacity 1.4s ease;
}
#intro.gone { opacity: 0; pointer-events: none; }
.intro-inner { max-width: 36rem; text-align: center; }
.intro-inner h1 { font: 400 clamp(40px, 7vw, 76px)/1 var(--f-type); margin: 26px 0 14px; color: #4a4538; letter-spacing: 1px; }
.intro-inner p { font: 18px/1.55 var(--f-body); color: #7a7362; margin: 0 auto; max-width: 30rem; }
.controls { margin-top: 22px !important; font: 14px/2.2 var(--f-type) !important; color: #6b6455 !important; }
.controls kbd { font: 12px var(--f-type); border: 1px solid #4a4538; border-bottom-width: 3px; border-radius: 4px; padding: 1px 6px; margin: 0 2px; color: #a59d88; }
.controls .sep { display: inline-block; width: 14px; }
.controls-touch { display: none; }
.classic-link { margin-top: 18px !important; font: 15px var(--f-type) !important; }
.classic-link a { color: #a59d88; text-underline-offset: 4px; }
.classic-link a:hover, .classic-link a:focus-visible { color: var(--torch); }
body.touch .controls-desktop { display: none; }
body.touch .controls-touch { display: block; }
.torch-btn {
  appearance: none; background: none; border: 0; cursor: pointer; padding: 10px; color: inherit;
  display: inline-flex; flex-direction: column; align-items: center; gap: 12px; border-radius: 12px;
}
.torch-btn:disabled { cursor: progress; }
.torch-btn:focus-visible { outline: 2px dashed var(--lume); outline-offset: 6px; }
.torch-art { width: min(300px, 70vw); height: auto; transform: rotate(-8deg); transition: transform .4s ease; }
.torch-btn:not(:disabled):hover .torch-art { transform: rotate(-4deg) translateY(-4px); }
.glowband { filter: drop-shadow(0 0 6px #b9ffcf); animation: breathe 3s ease-in-out infinite; }
.torch-cta { font: 18px var(--f-type); color: var(--lume); text-shadow: 0 0 10px rgba(185, 255, 207, .55); }
.torch-btn:disabled .torch-cta { color: #4d6b57; text-shadow: none; }
@keyframes breathe { 50% { opacity: .35; } }

/* ---------------------------------------------------------------- paused */
#paused { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
#paused[hidden] { display: none; }
.paused-inner { text-align: center; padding: 24px; }
.paused-title { font: 26px var(--f-type); margin: 0 0 18px; }
.paused-sub { font: 16px var(--f-body); color: rgba(236, 226, 200, .7); margin-top: 16px; }
.btn-big { appearance: none; border: 0; background: var(--torch); color: #1a1408; font: 18px var(--f-type); padding: 14px 26px; border-radius: 999px; cursor: pointer; box-shadow: 0 0 40px rgba(246, 212, 139, .35); }
.btn-big:hover, .btn-big:focus-visible { background: #fff0c8; outline: none; }
.linkish { appearance: none; background: none; border: 0; color: var(--torch); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; font: inherit; padding: 0; }

/* -------------------------------------------------------- inspect panel */
#inspect, #notebook {
  position: fixed; z-index: 30; top: 0; bottom: 0; right: 0; width: min(520px, 46vw);
  display: flex; align-items: center; padding: 76px 24px 24px 0;
}
#inspect[hidden], #notebook[hidden] { display: none; }
#notebook { width: min(560px, 100%); left: 50%; right: auto; transform: translateX(-50%); padding: 76px 16px 24px; }
#notebook::before { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: -1; }
.sheet-card {
  position: relative; width: 100%; background: var(--paper); color: var(--ink); border-radius: 3px; padding: 46px 34px 30px;
  max-height: 100%; overflow: auto; cursor: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.8), inset 0 0 60px rgba(150, 110, 50, .22);
  background-image: radial-gradient(circle at 50% 0%, rgba(255, 236, 190, .5), transparent 60%);
  user-select: text; -webkit-user-select: text;
  animation: lift .5s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes lift { from { transform: translateX(30px) rotate(1deg); opacity: 0; } }
.put-back { position: absolute; right: 14px; top: 12px; appearance: none; border: 1px solid rgba(36, 26, 18, .25); background: transparent; border-radius: 999px;
  font: 13px var(--f-type); color: var(--ink); padding: 6px 12px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; }
.put-back:hover, .put-back:focus-visible { background: var(--ink); color: var(--paper); outline: none; }
.put-back kbd { font: 11px var(--f-type); opacity: .6; }
.sheet-card h2 { font: 600 30px/1.12 var(--f-body); margin: 0 0 4px; letter-spacing: -.3px; }
.sheet-card .sub { font: 15px var(--f-type); color: #6a5a45; margin: 0 0 18px; }
.sheet-card p, .sheet-card li { font: 18px/1.6 var(--f-body); }
.sheet-card p { margin: 0 0 12px; }
.sheet-card ul { padding-left: 1.1em; margin: 0 0 14px; }
.sheet-card li { margin-bottom: 6px; }
.sheet-card li::marker { color: var(--string); }
.sheet-card a { color: #23458a; text-underline-offset: 3px; }
.sheet-card a:hover { color: var(--string); }
.sheet-card .tech { font: 14px/1.6 var(--f-type); color: #5a4a35; border-top: 1px dashed rgba(36, 26, 18, .3); padding-top: 12px; margin-top: 16px; }
.sheet-card .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn-ink { appearance: none; border: 0; background: var(--ink); color: var(--paper); font: 15px var(--f-type); padding: 10px 16px; border-radius: 4px; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.btn-ink:hover, .btn-ink:focus-visible { background: var(--string); color: #fff; outline: none; }
.btn-ink.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px rgba(36, 26, 18, .4); }
.btn-ink.ghost:hover { background: var(--ink); color: var(--paper); }
.sheet-card .facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 6px 0 16px; font: 16px/1.4 var(--f-body); }
.sheet-card .facts dt { font: 14px var(--f-type); color: #6a5a45; padding-top: 2px; }
.sheet-card .facts dd { margin: 0; overflow-wrap: anywhere; }
.sheet-card code { font: 14px var(--f-type); background: rgba(36, 26, 18, .08); padding: 2px 6px; border-radius: 3px; }
.sheet-card .portrait { float: right; width: 110px; height: 140px; object-fit: cover; object-position: 50% 15%; margin: 0 0 12px 18px; border-radius: 3px; box-shadow: 0 6px 16px rgba(0,0,0,.35); transform: rotate(2deg); }
.sheet-card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; padding: 0; list-style: none; }
.sheet-card .chips li { font: 14px var(--f-type); margin: 0; padding: 4px 10px; border-radius: 3px; background: rgba(36, 26, 18, .08); }
.sheet-card .chips li::marker { content: none; }
.sheet-card .cert-hero { margin: -6px 0 18px; padding: 16px; background: #f6f1e4; border: 1px solid #c8a24b; box-shadow: inset 0 0 0 5px #fbf8ef, inset 0 0 0 6px rgba(200, 162, 75, .5); text-align: center; }
.cert-hero .t1 { font: 600 14px var(--f-body); color: #232f3e; }
.cert-hero .t2 { font: 600 26px/1.1 var(--f-body); color: #232f3e; margin-top: 4px; }
.cert-hero .t3 { font: italic 18px var(--f-body); color: #8a6a26; }
.copy-btn { appearance: none; border: 0; background: none; color: #23458a; font: 13px var(--f-type); cursor: pointer; text-decoration: underline; padding: 0 0 0 6px; }

#nb-list { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 18px; }
#nb-list li { break-inside: avoid; margin: 0 0 4px; font: 15px/1.3 var(--f-type); }
#nb-list li::marker { content: none; }
#nb-list button { appearance: none; background: none; border: 0; padding: 4px 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left; display: flex; gap: 8px; align-items: baseline; }
#nb-list button:hover, #nb-list button:focus-visible { color: var(--string); outline: none; text-decoration: underline; }
#nb-list .tick { color: #8a6a26; }
#nb-list li.unfound { color: #a2947c; }
#nb-list li.unfound button { color: #a2947c; }

#fail { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; font: 18px var(--f-body); z-index: 50; background: #000; }
#fail[hidden] { display: none; }
#fail a { color: var(--torch); }

@media (max-width: 760px) {
  .hud { padding-left: 14px; padding-right: 14px; align-items: flex-start; }
  .hud-name { font-size: 15px; }
  .hud-btn { padding: 7px 11px; font-size: 13px; }
  .hud-btn.resume-link { display: none; }
  .hud-right { max-width: 62vw; }
  #inspect { left: 0; width: 100%; top: auto; height: 62%; padding: 0 10px 10px; align-items: flex-end; }
  .sheet-card { padding: 50px 22px 26px; }
  .sheet-card h2 { font-size: 25px; }
  .sheet-card p, .sheet-card li { font-size: 16.5px; }
  .sheet-card .portrait { width: 84px; height: 106px; }
  #nb-list { columns: 1; }
  @keyframes lift { from { transform: translateY(30px); opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
