:root {
  --paper: #e9e2cf;
  --ink: #1d1a16;
  --panel: rgba(12, 10, 10, 0.92);
  --accent: #c8283a;
  --text: #ddd6c8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px;
  background: rgba(255,255,255,0.55); border-radius: 50%; }
/* HUD text sits on a dark box with an outline so it stays readable over white walls / bright light */
#prompt { position: absolute; left: 50%; top: 56%; transform: translateX(-50%); font-size: 15px; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 0 6px #000; white-space: nowrap; background: rgba(0,0,0,0.55); padding: 3px 12px; border-radius: 4px; }
#prompt:empty { display: none; }
#objective { position: absolute; left: 12px; top: 10px; font-size: 13px; color: #eee; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 0 6px #000;
  background: rgba(0,0,0,0.5); padding: 3px 10px; border-radius: 4px; }
#objective:empty { display: none; }
#toast { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); font-size: 16px; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 0 6px #000; background: rgba(0,0,0,0.6); padding: 8px 18px; border-radius: 4px; max-width: 90vw; opacity: 0; transition: opacity 0.4s; text-align: center; white-space: pre-line; }
#toast.show { opacity: 1; }
#subtitle { position: absolute; left: 50%; bottom: 9%; transform: translateX(-50%); width: min(820px, 90vw);
  text-align: center; font-size: 18px; line-height: 1.6; color: #fff; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 0 6px #000; white-space: pre-line; }
#subtitle span { background: rgba(0,0,0,0.6); padding: 2px 10px; border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
#hold { position: absolute; left: 50%; top: 62%; width: 220px; height: 6px; margin-left: -110px;
  background: rgba(255,255,255,0.15); display: none; }
#hold.show { display: block; }
#hold-bar { height: 100%; width: 0; background: #d9c38a; }
#debug { position: absolute; right: 8px; bottom: 6px; font: 11px monospace; opacity: 0.6; white-space: pre; }

/* overlays */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#doc { background: rgba(0,0,0,0.25); }
.paper { position: relative; z-index: 2; width: min(560px, 92vw); max-height: 84vh; overflow-y: auto; padding: 34px 38px 22px;
  background: var(--paper); color: var(--ink); box-shadow: 0 0 60px #000; font-size: 16px; line-height: 1.9;
  background-image: repeating-linear-gradient(0deg, rgba(0,0,0,0.03) 0 1px, transparent 1px 29px); }
#doc-title { font-weight: bold; font-size: 17px; margin-bottom: 14px; border-bottom: 1px solid #8a8070; padding-bottom: 6px; }
#doc-body { white-space: pre-wrap; }
#doc-body .alt { display: block; margin-top: 12px; font-family: "Klee One", cursive; color: #5a1010; font-style: italic; }
.hint { font-size: 13px; opacity: 0.85; margin-top: 14px; }
#fingers { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
#fingers img { position: absolute; width: 180px; height: 180px; opacity: 0; transition: opacity 1.5s, transform 4s linear; }

.panel { background: var(--panel); border: 1px solid #554; padding: 22px 26px; min-width: 300px; text-align: center; }
.panel.wide { width: min(760px, 94vw); }
.panel-title { font-size: 16px; letter-spacing: 0.1em; margin-bottom: 12px; }
#keypad-display { font: 34px monospace; letter-spacing: 0.4em; margin: 6px 0 14px; color: #f3d9a0; }
#keypad-keys { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; justify-content: center; }
#keypad-keys button, #reels-list button, #start-btn {
  font: inherit; font-size: 18px; padding: 10px; background: #1d1918; color: var(--text); border: 1px solid #665; cursor: pointer; }
#keypad-keys button:hover, #reels-list button:hover, #start-btn:hover { background: #3a2a26; }
#reels-slots { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
#reels-slots div { width: 150px; height: 40px; border: 1px dashed #776; display: flex; align-items: center; justify-content: center; font-size: 13px; }
#reels-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
#reels-list button { font-size: 13px; padding: 6px; }
#reels-list canvas { width: 100%; display: block; margin-bottom: 4px; }
#reels-list button.used { opacity: 0.3; }

.inv-box { background: var(--panel); border: 1px solid #554; width: min(760px, 94vw); height: min(440px, 80vh); display: grid;
  grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; }
.inv-head { grid-column: 1 / 3; padding: 10px 16px; border-bottom: 1px solid #443; }
#inv-list { overflow-y: auto; border-right: 1px solid #443; }
#inv-list div { padding: 9px 14px; cursor: pointer; border-bottom: 1px solid #2a2622; }
#inv-list div:hover, #inv-list div.sel { background: #2e2420; }
#inv-detail { padding: 14px; overflow-y: auto; }
#inv-canvas { width: 100%; max-width: 360px; background: #111; display: block; margin: 0 auto 10px; }
#inv-desc { white-space: pre-wrap; line-height: 1.7; font-size: 14px; }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.6s; }
#death { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center;
  font-size: 22px; letter-spacing: 0.3em; color: #c9c2b4; }
#ending { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#ending-inner { text-align: center; white-space: pre-line; font-size: 18px; line-height: 2; text-shadow: 0 0 8px #000; }
#ending-inner .phone { display: inline-block; text-align: left; width: 300px; background: #f4f4f4; color: #111; border-radius: 18px;
  padding: 18px; font-family: sans-serif; font-size: 14px; line-height: 1.5; border: 8px solid #222; white-space: pre; }
#ending-inner .big { font-size: 28px; letter-spacing: 0.2em; }
#ending-inner .small { font-size: 13px; opacity: 0.7; }

#pause { background: rgba(0,0,0,0.6); }
.small { font-size: 12px; opacity: 0.75; }

/* title */
#title { position: fixed; inset: 0; background: radial-gradient(#1a1212, #000 70%); display: flex; align-items: center; justify-content: center; }
.title-inner { text-align: center; padding: 16px; }
.tweet { display: inline-block; text-align: left; background: #0d0d0f; border: 1px solid #333; border-radius: 12px; padding: 12px 18px;
  font-family: sans-serif; margin-bottom: 20px; }
.tweet-head { font-size: 13px; color: #aaa; }
.tweet-head span { color: #666; }
.tweet pre { font-family: sans-serif; font-size: 14px; margin: 8px 0 0; line-height: 1.35; }
h1 { font-size: 46px; letter-spacing: 0.15em; margin: 6px 0; color: #e8dcc6; text-shadow: 2px 0 #a00, -2px 0 #0aa; }
.sub { opacity: 0.7; margin-bottom: 22px; }
#start-btn { padding: 12px 42px; letter-spacing: 0.3em; }
#start-btn:disabled { opacity: 0.4; cursor: default; }
#loading { font-size: 12px; opacity: 0.6; margin-top: 8px; }
.controls { margin-top: 22px; font-size: 13px; opacity: 0.75; line-height: 1.9; }
.warn { color: #d88; }

/* stacking order */
#fade { z-index: 4; }
#hud { z-index: 5; }
#death { z-index: 6; }
#ending { z-index: 7; }
.overlay { z-index: 8; }
#pause { z-index: 9; }
#title { z-index: 10; }
.tweet-body { font-family: sans-serif; font-size: 14px; margin: 8px 0 0; line-height: 1.5; white-space: pre-line; }
.tweet-body .mill { margin: 6px 0 6px 28px; white-space: normal; }
#ending-inner .phone .mill-wrap { white-space: normal; }

/* pause / relock / controls */
.pause-buttons { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; }
.pause-buttons button { font: inherit; font-size: 16px; padding: 10px 18px; background: #1d1918; color: var(--text); border: 1px solid #665; cursor: pointer; }
.pause-buttons button:hover { background: #3a2a26; }
#relock { position: fixed; left: 50%; top: 64%; transform: translateX(-50%); z-index: 9; padding: 8px 16px; font-size: 14px;
  background: rgba(0,0,0,0.6); border: 1px solid #554; cursor: pointer; }
.controls-panel { width: min(620px, 94vw); text-align: left; cursor: pointer; }
.controls-panel .panel-title { text-align: center; font-size: 20px; }
.keys { display: grid; grid-template-columns: 170px 1fr; gap: 10px 16px; align-items: center; margin: 10px 0 16px; }
.kc { display: inline-block; min-width: 30px; padding: 3px 7px; margin-right: 4px; text-align: center; border: 1px solid #998; border-bottom-width: 3px;
  border-radius: 4px; background: #24201e; font-family: sans-serif; font-size: 14px; }
.kc.wide { min-width: 64px; }
.rule { border-top: 1px solid #443; padding-top: 12px; line-height: 1.8; font-size: 14px; }
.rule b { color: #e8c0b0; }
.go { text-align: center; margin-top: 16px; letter-spacing: 0.2em; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .go { animation: none; } }

/* aged paper documents */
#doc .paper { background-color: #d9cba6; background-size: cover; color: var(--ink, #222); box-shadow: none;
  filter: drop-shadow(0 12px 30px rgba(0,0,0,0.9)); padding: 40px 46px 26px 64px; }
#doc .paper #doc-title { font-family: var(--ink-font); font-size: calc(var(--ink-size) * 0.85); opacity: 0.75; border-bottom: 1px dashed rgba(60,40,20,0.4); }
#doc .paper #doc-body { font-family: var(--ink-font); font-size: var(--ink-size); line-height: 2.0; color: var(--ink); position: relative; }
#doc .paper #doc-body span { text-shadow: 0 0 0.6px currentColor; }
#doc .paper .hint { font-family: sans-serif; color: #3a3020; }
#doc .paper-typed #doc-body { letter-spacing: 0.04em; line-height: 1.9; }
#doc .paper-typed #doc-body span { text-shadow: 0.4px 0 0 rgba(0,0,0,0.5); }
#doc .paper-scrawl #doc-body { font-weight: bold; }
#doc .paper-poster #doc-body { text-align: center; }
#doc .stamp { position: absolute; right: 6px; top: -18px; transform: rotate(-14deg); border: 4px double rgba(170,20,20,0.7);
  color: rgba(170,20,20,0.7); font-family: "Zen Old Mincho", serif; font-weight: 700; font-size: 26px; padding: 2px 10px; letter-spacing: 0.3em; mix-blend-mode: multiply; }
#doc .alt { margin-top: 18px; font-family: "Zen Kurenaido", "Yomogi", cursive; color: #6a0e0a; font-size: calc(var(--ink-size) * 1.15); }

/* ---- touch controls ---- */
body.touch { touch-action: none; -webkit-user-select: none; user-select: none; }
body.touch .desk-only, body:not(.touch) .touch-only { display: none !important; }
#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#t-look { position: absolute; top: 0; right: 0; width: 60%; height: 100%; pointer-events: auto; }
#t-stick { position: absolute; left: calc(18px + env(safe-area-inset-left, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 140px; height: 140px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.06); pointer-events: auto; }
#t-knob { position: absolute; left: 45px; top: 45px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.3); }
#t-buttons { position: absolute; right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid; grid-template-columns: repeat(2, 76px); gap: 10px; pointer-events: auto; }
#t-buttons button, #t-pause { font: inherit; font-size: 14px; height: 52px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.3);
  background: rgba(20,16,14,0.55); color: var(--text); }
#t-buttons button.big { grid-column: 1 / 3; height: 60px; font-size: 17px; background: rgba(90,40,30,0.6); }
#t-buttons button.on { background: rgba(200,160,90,0.5); }
#t-pause { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); width: 48px; height: 44px; pointer-events: auto; }
#t-rotate { position: absolute; top: 40%; left: 0; right: 0; text-align: center; font-size: 15px; display: none; text-shadow: 0 0 6px #000; }
@media (orientation: portrait) { body.touch #t-rotate { display: block; animation: blink 2s 3 forwards; opacity: 0.8; } }
@media (max-width: 700px) {
  .controls-panel { padding: 14px; font-size: 13px; }
  .keys { grid-template-columns: 110px 1fr; gap: 6px 10px; }
  .tweet { transform: scale(0.85); }
  h1 { font-size: 32px; }
  #doc .paper { padding: 26px 22px 18px 34px; }
  .inv-box { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: 86vh; }
  #inv-list { max-height: 30vh; border-right: 0; border-bottom: 1px solid #443; }
  #reels-list { grid-template-columns: repeat(2, 1fr); }
}
.controls-panel { max-height: 92vh; overflow-y: auto; }

/* short screens (phones in landscape): fit the controls card on one screen */
@media (max-height: 520px) {
  #controls { align-items: center; padding: max(6px, env(safe-area-inset-top, 0px)) 8px max(6px, env(safe-area-inset-bottom, 0px)); }
  .controls-panel { padding: 10px 16px; max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); width: min(780px, 96vw); }
  .controls-panel .panel-title { font-size: 15px; margin-bottom: 6px; }
  .controls-panel .keys { grid-template-columns: auto 1fr auto 1fr; gap: 5px 10px; margin: 4px 0 8px; font-size: 12px; }
  .controls-panel .kc { font-size: 11px; padding: 1px 5px; min-width: 22px; }
  .controls-panel .kc.wide { min-width: 52px; }
  .controls-panel .small { font-size: 10px; }
  .controls-panel .rule { font-size: 12px; line-height: 1.55; padding-top: 6px; }
  .controls-panel .go { margin-top: 6px; font-size: 13px; }
  #title { overflow-y: auto; }
  #title .title-inner { display: grid; grid-template-columns: auto minmax(0, 380px); align-items: center; column-gap: 28px; padding: 8px; }
  #title .tweet { grid-column: 1; grid-row: 1 / span 6; margin: 0; transform: none; }
  #title .tweet-body { font-size: 12px; }
  #title .tweet-body .mill { margin: 2px 0 2px 24px; }
  #title h1, #title .sub, #title #start-btn, #title #loading, #title .controls { grid-column: 2; }
  #title h1 { font-size: 30px; margin: 0; }
  #title .sub { margin-bottom: 10px; }
  #title #start-btn { justify-self: center; }
  #title .controls { font-size: 11px; margin-top: 10px; line-height: 1.6; }
}
.close-btn { font: inherit; font-size: 14px; padding: 6px 14px; margin-top: 10px; background: #2a2220; color: var(--text); border: 1px solid #776; cursor: pointer; }
.inv-head { display: flex; align-items: center; gap: 12px; }
.inv-head .close-btn { margin: 0 0 0 auto; }
#doc .paper canvas.ink { display: block; mix-blend-mode: multiply; }
#doc .paper #doc-title:empty { display: none; }

.close-how { font-size: 14px; color: #e8dcc0; margin: 14px 0 4px; }
#pause { cursor: pointer; }
#pause .panel { cursor: default; }

/* photographs shown with a document */
.doc-photo { position: relative; margin: 0 auto 14px; width: fit-content; transform: rotate(-1.5deg); box-shadow: 2px 3px 10px rgba(0,0,0,0.45); }
.doc-photo img { display: block; max-width: 100%; height: auto; }
.doc-photo.photo-staff img { width: min(380px, 70vw); }
.doc-photo.photo-id { transform: rotate(1deg); }
.doc-photo.photo-id img { width: min(120px, 30vw); }
.doc-photo.photo-news { transform: none; box-shadow: none; }
.doc-photo.photo-news img { width: min(300px, 60vw); }
.doc-photo::before { content: ''; position: absolute; left: 50%; top: -8px; width: 60px; height: 18px; margin-left: -30px;
  background: rgba(230,220,180,0.75); transform: rotate(3deg); }
.doc-photo.photo-news::before { display: none; }

/* headphones recommendation, shown big before the game starts */
.headphones { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 16px auto 18px; padding: 12px 22px;
  width: fit-content; max-width: 92vw; border: 2px solid #d9c38a; border-radius: 10px; background: rgba(40,30,10,0.75); color: #f3e6c0; text-align: left; }
.headphones .hp-icon { width: 46px; height: 46px; flex: none; color: #d9c38a; }
.headphones b { display: block; font-size: 24px; letter-spacing: 2px; }
.headphones span { display: block; font-size: 13px; opacity: 0.85; margin-top: 2px; }
.headphones.small-hp { margin: 4px auto 14px; padding: 8px 16px; }
.headphones.small-hp b { font-size: 18px; }
.headphones.small-hp .hp-icon { width: 32px; height: 32px; }
@media (max-height: 520px) {
  .headphones { margin: 6px auto 8px; padding: 6px 12px; }
  .headphones b { font-size: 17px; }
  .headphones .hp-icon { width: 30px; height: 30px; }
}

.credit { font-size: 11px; opacity: 0.55; }

/* the protagonist's thoughts while reading: a speech bubble under the paper */
.paper.with-think { max-height: calc(100vh - 150px); margin-bottom: 104px; }
.think { position: absolute; left: 50%; bottom: 3vh; transform: translateX(-50%); z-index: 3; width: min(620px, 92vw);
  background: rgba(10,10,12,0.88); color: #f2eee6; border: 1px solid #8a8070; border-radius: 16px; padding: 12px 20px;
  font-size: 16px; line-height: 1.6; box-shadow: 0 4px 24px #000; pointer-events: none; }
.think::after { content: ''; position: absolute; left: 34px; top: -12px; border: 12px solid transparent; border-top: 0;
  border-bottom-color: #8a8070; }
.think p { margin: 2px 0; animation: think-in 0.5s ease-out; }
.think p.old { opacity: 0.55; }
.think:empty { visibility: hidden; }
@keyframes think-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-height: 520px) { .paper.with-think { max-height: calc(100vh - 120px); margin-bottom: 92px; } .think { font-size: 14px; padding: 8px 14px; } }
.doc-photo.photo-missing img { width: min(440px, 76vw); max-height: 46vh; object-fit: contain; }
.doc-photo.photo-missing::before, .doc-photo.photo-crayonDoc::before { display: none; }
.doc-photo.photo-crayonDoc img { width: min(400px, 74vw); }

/* hiding in a locker: you look out through the door's slits */
#hide-vents { position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background:
    linear-gradient(#000, #000) top / 100% 34% no-repeat,
    linear-gradient(#000, #000) bottom / 100% 34% no-repeat,
    linear-gradient(90deg, #000 0 22%, transparent 22% 78%, #000 78%),
    repeating-linear-gradient(to bottom, rgba(0,0,0,0.96) 0 26px, rgba(0,0,0,0.25) 26px 38px); }
