/* 白い部屋: 青みのある無機質な白 / 試験官と診断書は明朝 / 時刻は等幅 / アクセントは監視の赤だけ */
:root {
  color-scheme: light;
  --wall: #e9edec;
  --wall-lo: #dfe4e3;
  --floor: #d3d9d8;
  --line: #b4bcba;
  --ink: #1e2324;
  --muted: #66706f;
  --paper: #fbfcfc;
  --red: #c8102e;
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --gothic: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  height: 100vh; height: 100dvh;
  overflow: hidden; overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--wall); color: var(--ink);
  font-family: var(--gothic);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
#app { position: relative; width: 100%; height: 100%; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }
.center { align-items: center; justify-content: center; gap: 1.25rem; padding: 1.5rem; text-align: center; overflow-y: auto; }
.muted { color: var(--muted); font-size: .9rem; }
.tiny { color: var(--muted); font-size: .8rem; letter-spacing: .08em; font-family: var(--mono); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.btn {
  min-height: 48px; min-width: 180px; padding: .75rem 1.75rem; border: 1px solid var(--ink); border-radius: 2px;
  font: inherit; font-size: 1rem; font-weight: 600; letter-spacing: .1em; color: var(--paper); background: var(--ink);
  cursor: pointer; touch-action: manipulation; transition: background .15s, color .15s;
}
.btn:hover { background: #3a4243; }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.secondary:hover { background: var(--wall-lo); }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 2px; background: transparent; color: var(--ink);
  font-size: 1.3rem; cursor: pointer; touch-action: manipulation;
}

/* ---- タイトル（偽装）: ありふれた脱出ゲームのふり ---- */
.title-screen { background: radial-gradient(ellipse at 50% 40%, #fff 0%, var(--wall) 70%); }
.eyebrow { font-family: var(--mono); font-size: .75rem; letter-spacing: .4em; color: var(--muted); }
.disguise { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 300; letter-spacing: .25em; }
.lead { color: var(--muted); letter-spacing: .1em; }

/* ---- 同意書 ---- */
.consent-sheet {
  width: min(100%, 560px); max-height: 100%; display: flex; flex-direction: column; gap: 1rem;
  background: var(--paper); border: 1px solid var(--line); padding: 1.5rem; text-align: left;
}
.consent-sheet h2 { font-family: var(--mincho); font-weight: 600; font-size: 1.15rem; letter-spacing: .1em; }
.consent-body {
  height: min(40vh, 280px); overflow-y: auto; font-size: .85rem; line-height: 1.9; color: #3c4445;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: .75rem .25rem;
  -webkit-user-select: text; user-select: text;
}
.consent-body p { margin-bottom: .6rem; }
.consent-body b { font-weight: 600; margin-right: .5em; }
.consent-sheet .btn { align-self: center; }

/* ---- 部屋 ---- */
.room-screen { background: var(--wall); }
.hud { flex: none; display: flex; align-items: center; gap: .5rem; padding: .25rem .5rem; height: 52px; }
.hud-hint { flex: 1; font-size: .8rem; color: var(--muted); text-align: center; visibility: hidden; }
@media (orientation: portrait) and (max-width: 700px) { .hud-hint { visibility: visible; } }
.inventory { display: flex; gap: .4rem; margin-left: auto; min-height: 44px; align-items: center; }
.inv-item {
  min-width: 44px; height: 44px; padding: 0 .75rem; border: 1px solid var(--line); background: var(--paper);
  font: inherit; font-size: .85rem; cursor: pointer; touch-action: manipulation; color: var(--ink);
}
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: manipulation; }
.room {
  position: absolute; left: 0; top: 0; width: 1600px; height: 900px; transform-origin: 0 0;
  background:
    linear-gradient(180deg, transparent 0 690px, var(--floor) 690px),
    linear-gradient(180deg, #f2f5f4 0%, var(--wall) 60%, var(--wall-lo) 690px);
  box-shadow: inset 0 0 120px rgba(0, 0, 0, .06);
}
.room::after { /* 床と壁の境目 */
  content: ""; position: absolute; left: 0; right: 0; top: 688px; height: 3px; background: var(--line); pointer-events: none;
}

.obj {
  position: absolute; border: 0; background: transparent; cursor: pointer; padding: 0; color: var(--ink);
  font: inherit; touch-action: manipulation;
}
.obj::before { /* ホバー時の輪郭 */
  content: ""; position: absolute; inset: -10px; border: 2px solid transparent; transition: border-color .15s; pointer-events: none;
}
.obj:hover::before, .obj:focus-visible::before { border-color: rgba(30, 35, 36, .35); }
.obj:focus-visible { outline: none; }
.obj .tag {
  position: absolute; left: 50%; bottom: calc(100% + 16px); transform: translateX(-50%); white-space: nowrap;
  font-size: 22px; padding: 4px 12px; background: var(--ink); color: var(--paper); opacity: 0; pointer-events: none; transition: opacity .15s;
}
.obj:hover .tag, .obj:focus-visible .tag { opacity: 1; }
.obj[hidden], .paper[hidden], .mirror-back[hidden] { display: none; }
/* タッチ端末では押せる物に小さな印 */
@media (hover: none) {
  .obj::after { content: ""; position: absolute; right: -8px; top: -8px; width: 18px; height: 18px; border-radius: 50%; background: rgba(30, 35, 36, .25); }
}

/* 扉 */
.door { background: linear-gradient(90deg, #f7f9f8, #eef1f0); border: 3px solid var(--line); }
.door .plate {
  position: absolute; left: 50%; top: -64px; transform: translateX(-50%); white-space: nowrap;
  font-family: var(--mincho); font-size: 30px; letter-spacing: .2em; padding: 4px 18px; border: 2px solid var(--ink); background: var(--paper);
}
.door .knob { position: absolute; right: 26px; top: 240px; width: 26px; height: 26px; border-radius: 50%; background: #aeb6b4; }
.door .pad { position: absolute; right: 18px; top: 160px; width: 44px; height: 60px; background: #c9d0ce; border: 2px solid #a3acaa;
  background-image: radial-gradient(circle, #8a9492 2px, transparent 3px); background-size: 13px 13px; background-position: 3px 3px; }
.door .hole { position: absolute; right: 34px; top: 280px; width: 10px; height: 22px; border-radius: 5px 5px 2px 2px; background: #4d5655; }

/* 時計（偽のタイマー） */
.timer-face {
  position: absolute; left: 10px; right: 10px; top: 20px; bottom: 20px; display: grid; place-items: center; background: #20282a; color: #e9edec;
  font-family: var(--mono); font-size: 52px; letter-spacing: .08em; border: 4px solid #39444a;
}
.timer-face.over { color: #ff8f9f; }

/* 鏡 */
.mirror-face { position: absolute; inset: 0; background: linear-gradient(135deg, #f8fbfc, #c7d1d4 55%, #e9eff1); border: 6px solid #a8b2b0; overflow: hidden; }
.mirror-face svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.mirror-back { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 40px; color: #5b6463; border: 2px dashed var(--line); }

/* 電話 */
.phone-stand { position: absolute; left: 60px; top: 110px; width: 30px; height: 90px; background: #cfd6d4; }
.phone-top { position: absolute; left: 30px; top: 60px; width: 90px; height: 52px; border-radius: 12px; background: #f9fbfa; border: 3px solid var(--line); }
.phone-recv { position: absolute; left: 10px; top: 32px; width: 130px; height: 30px; border-radius: 15px; background: #fdfefe; border: 3px solid var(--line); }
.ring-mark { position: absolute; left: 100%; top: 0; font-size: 24px; color: var(--ink); opacity: 0; white-space: nowrap; }
.phone.ringing .phone-recv { animation: shake .18s infinite; }
.phone.ringing .ring-mark { opacity: 1; animation: blink .6s steps(2) infinite; }
@keyframes shake { 0%, 100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-3px) rotate(-2deg); } 75% { transform: translateX(3px) rotate(2deg); } }

/* 通気口 */
.vent-face { position: absolute; left: 10px; right: 10px; bottom: 10px; height: 70px; background: repeating-linear-gradient(180deg, #8e9997 0 6px, #c3cbc9 6px 14px); border: 4px solid #a3acaa; }
.sob { position: absolute; left: 0; top: -12px; font-family: var(--mincho); font-size: 22px; color: var(--muted); white-space: nowrap; animation: fade 3s ease-in-out infinite; }
.vent.quiet .sob { display: none; }
@keyframes fade { 0%, 100% { opacity: .15; } 50% { opacity: .9; } }

/* 財布 */
.wallet-face { position: absolute; left: 30px; top: 40px; width: 90px; height: 50px; background: #5a4636; border-radius: 6px; box-shadow: 0 6px 0 rgba(0, 0, 0, .12); }
.wallet-face::after { content: ""; position: absolute; left: 10%; right: 10%; top: 45%; height: 3px; background: #6f5847; }

/* 押すなボタン */
.btn-sign { position: absolute; left: 5px; right: 5px; top: 20px; text-align: center; font-family: var(--mincho); font-size: 26px; font-weight: 600; border: 2px solid var(--ink); background: var(--paper); }
.btn-dome { position: absolute; left: 37px; top: 82px; width: 56px; height: 34px; border-radius: 28px 28px 4px 4px; background: var(--red); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .2); transition: transform .06s; }
.btn-base { position: absolute; left: 27px; top: 114px; width: 76px; height: 86px; background: #cfd6d4; }
.button.pressed .btn-dome { transform: translateY(8px) scaleY(.7); }
.paper {
  position: absolute; left: 1400px; top: 770px; width: 120px; height: 70px; background: var(--paper); border: 1px solid var(--line);
  transform: rotate(-8deg); display: grid; place-items: center; font-family: var(--mono); font-size: 26px; pointer-events: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .06);
}

/* カメラ */
.cam-body { position: absolute; right: 14px; top: 22px; width: 56px; height: 40px; background: #39434a; border-radius: 6px; }
.cam-led { position: absolute; right: 24px; top: 30px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: blink 2s steps(2) infinite; }
@keyframes blink { 50% { opacity: .15; } }

/* 字幕 */
.subtitles {
  flex: none; height: 8.8rem; /* 高さ固定: 行数で部屋の絵が縮まないように */ padding: .5rem 1rem .75rem; display: flex; flex-direction: column; justify-content: flex-end; gap: .2rem;
  background: linear-gradient(180deg, rgba(233, 237, 236, 0), var(--wall) 30%); overflow: hidden;
}
.sub { font-size: .95rem; line-height: 1.6; color: var(--muted); }
.sub:last-child { color: var(--ink); font-size: 1.05rem; }
.sub .who { font-family: var(--mono); font-size: .7rem; letter-spacing: .15em; margin-right: .75em; padding: 1px 6px; border: 1px solid currentColor; vertical-align: 2px; }
.sub.examiner .text { font-family: var(--mincho); font-weight: 600; }
.sub.examiner .who { color: var(--red); }
.sub.voice .text { font-family: var(--mincho); }
.sub.narration .text { color: inherit; }
.sub.phone .text { font-family: var(--mincho); }

/* 調べる画面（PC: 右側 / スマホ: 下から） */
.panel {
  position: absolute; right: 1rem; top: 60px; width: min(380px, calc(100% - 2rem)); max-height: calc(100% - 80px); overflow-y: auto;
  background: var(--paper); border: 1px solid var(--ink); padding: 1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: .9rem;
  box-shadow: 0 10px 40px rgba(30, 35, 36, .15); z-index: 5;
}
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { font-family: var(--mincho); font-size: 1.15rem; letter-spacing: .1em; }
.panel-desc { white-space: pre-line; line-height: 1.8; font-size: .95rem; }
.panel-actions { display: flex; flex-direction: column; gap: .5rem; }
.panel.left { right: auto; left: 1rem; }
.panel-tip { font-size: .75rem; color: var(--muted); }
.panel-actions .btn { width: 100%; min-width: 0; text-align: left; letter-spacing: .05em; font-weight: 500; }
@media (max-width: 700px), (max-height: 500px) {
  .panel, .panel.left { right: .5rem; left: .5rem; width: auto; top: auto; bottom: .5rem; max-height: 62%; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .panel, .panel.left { left: auto; right: .5rem; width: min(360px, 55%); top: .5rem; bottom: auto; max-height: calc(100% - 1rem); }
  .panel.left { left: .5rem; right: auto; }
}

.keypad { display: flex; flex-direction: column; gap: .6rem; align-items: center; }
.keypad[hidden] { display: none; }
.keypad-display { font-family: var(--mono); font-size: 2rem; letter-spacing: .5em; padding: .25rem .5rem .25rem 1rem; border: 1px solid var(--line); background: #fff; }
.keys { display: grid; grid-template-columns: repeat(3, 56px); gap: .4rem; }
.keys button { height: 48px; font: inherit; font-family: var(--mono); font-size: 1.2rem; border: 1px solid var(--line); background: #fff; cursor: pointer; touch-action: manipulation; color: var(--ink); }
.keys button:hover { background: var(--wall); }
.keys .enter { background: var(--ink); color: var(--paper); }
.keypad.wrong .keypad-display { animation: shake .12s 3; border-color: var(--red); }

/* ---- 脱出演出 ---- */
.escape-screen { background: #fff; }
.escape-line { font-family: var(--mincho); font-size: clamp(1rem, 2.4vw, 1.4rem); letter-spacing: .1em; min-height: 1.6em; }
.true-title { font-family: var(--mincho); font-weight: 600; font-size: clamp(2rem, 6.5vw, 4.2rem); line-height: 1.35; letter-spacing: .12em; animation: appear 2.4s ease-out both; }
.true-title[hidden] { display: none; }
@keyframes appear { from { opacity: 0; letter-spacing: .6em; filter: blur(6px); } to { opacity: 1; letter-spacing: .12em; filter: blur(0); } }
.btn.ink { animation: appear 1s ease-out both; }

/* ---- 診断書（公文書） ---- */
.report-screen { overflow-y: auto; background: #dfe4e3; padding: 1.5rem 1rem 3rem; display: block; -webkit-user-select: text; user-select: text; }
.retry { position: fixed; top: calc(env(safe-area-inset-top) + .75rem); right: calc(env(safe-area-inset-right) + .75rem); z-index: 3; min-width: 0; }
.report {
  position: relative; width: min(100%, 820px); margin: 2.5rem auto 0; background: var(--paper); padding: clamp(1.25rem, 4vw, 3rem);
  box-shadow: 0 1px 0 var(--line), 0 20px 60px rgba(30, 35, 36, .12);
  background-image: linear-gradient(var(--paper), var(--paper)), repeating-linear-gradient(0deg, transparent 0 31px, #edf1f0 31px 32px);
}
.doc-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; border-bottom: 3px double var(--ink); padding-bottom: .75rem; flex-wrap: wrap; }
.doc-head h2 { font-family: var(--mincho); font-size: clamp(1.5rem, 4vw, 2.2rem); letter-spacing: .5em; font-weight: 600; }
.doc-meta { font-family: var(--mono); font-size: .8rem; color: var(--muted); text-align: right; line-height: 1.7; }
.doc-sec { margin-top: 2rem; }
.doc-sec h3 { font-size: .8rem; letter-spacing: .3em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding-bottom: .3rem; margin-bottom: 1rem; }
.verdict { position: relative; padding: 1rem 0 .5rem; }
.verdict .label { font-family: var(--mincho); font-weight: 600; font-size: clamp(1.3rem, 3.6vw, 2rem); line-height: 1.5; padding-right: 110px; }
.verdict .sub-label { color: var(--muted); font-size: .85rem; margin-top: .5rem; }
.stamp {
  position: absolute; right: 0; top: 0; width: 96px; height: 96px; border: 4px solid var(--red); border-radius: 50%; color: var(--red);
  display: grid; place-items: center; font-family: var(--mincho); font-weight: 700; font-size: 1.4rem; letter-spacing: .1em;
  transform: rotate(-14deg); opacity: .85; animation: stamp .35s cubic-bezier(.2, 1.6, .4, 1) both .4s;
}
@keyframes stamp { from { transform: rotate(-14deg) scale(2.4); opacity: 0; } to { transform: rotate(-14deg) scale(1); opacity: .85; } }
.axes { display: grid; grid-template-columns: auto 1fr 3em; gap: .55rem .9rem; align-items: center; font-size: .9rem; }
.axes .bar { height: 10px; background: #e3e8e7; position: relative; }
.axes .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ink); }
.axes .bar::after { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1px; background: var(--muted); }
.axes .num { font-family: var(--mono); text-align: right; }
.evidence { list-style: none; display: flex; flex-direction: column; gap: .7rem; }
.evidence li { display: grid; grid-template-columns: 4.2em 1fr; gap: .8rem; line-height: 1.7; }
.evidence time { font-family: var(--mono); color: var(--red); font-size: .9rem; padding-top: .1em; }
.remark { margin-top: 1.1rem; font-family: var(--mincho); font-weight: 600; font-size: 1.1rem; }
.note { font-family: var(--mincho); line-height: 1.9; }
.trail-wrap canvas { width: 100%; display: block; border: 1px solid var(--line); }
.trail-wrap .btn { margin-top: .6rem; min-width: 0; }
.secrets { display: flex; flex-wrap: wrap; gap: .4rem; }
.secrets span { font-size: .8rem; padding: .2rem .6rem; border: 1px solid var(--line); color: var(--muted); }
.secrets span.got { color: var(--ink); border-color: var(--ink); }
.secrets span.new { color: var(--paper); background: var(--red); border-color: var(--red); }
.msg-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.msg-row input { flex: 1; min-width: 200px; min-height: 48px; font: inherit; font-size: 16px; padding: .5rem .75rem; border: 1px solid var(--ink); background: #fff; -webkit-user-select: text; user-select: text; }
.msg-row .btn { min-width: 0; }
.doc-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 2.5rem; }
.fine-stamp { position: absolute; right: 1rem; bottom: .75rem; font-size: .7rem; color: var(--red); border: 1px solid var(--red); padding: .15rem .4rem; transform: rotate(-3deg); }
.appeal .q { font-family: var(--mincho); font-size: 1.15rem; margin-bottom: .9rem; }
.appeal .choices { display: flex; flex-direction: column; gap: .5rem; }
.appeal .choices .btn { text-align: left; min-width: 0; font-weight: 500; letter-spacing: .03em; }

/* ---- 観察室（暗い） ---- */
.observe-screen { background: #0b0e10; color: #cfe3e8; overflow-y: auto; display: flex; }
.observe { width: min(100%, 1280px); margin: auto; padding: 1.5rem; display: grid; grid-template-columns: 1.7fr 1fr; gap: 2rem; align-items: center; }
@media (max-width: 760px) { .observe { grid-template-columns: 1fr; } }
.monitor { border: 2px solid #2b3a40; background: #0d1114; padding: .5rem; }
.monitor .cap { font-family: var(--mono); font-size: .75rem; letter-spacing: .2em; color: #7fe6ff; display: flex; justify-content: space-between; padding: .2rem .25rem .5rem; }
.monitor canvas { width: 100%; display: block; }
.obs-log { font-family: var(--mono); font-size: .85rem; line-height: 1.8; list-style: none; margin-top: .75rem; color: #9fb7bd; }
.obs-side { display: flex; flex-direction: column; gap: 1rem; }
.obs-side .speech { font-family: var(--mincho); font-size: 1.1rem; line-height: 1.8; }
.obs-q { font-family: var(--mincho); font-size: 1.25rem; }
.obs-btns { display: flex; gap: .75rem; }
.obs-btns .btn { flex: 1; min-width: 0; background: transparent; color: #cfe3e8; border-color: #cfe3e8; }
.obs-btns .btn:hover { background: #1c262a; }
.obs-reveal { font-family: var(--mincho); font-size: clamp(1.4rem, 3.5vw, 2rem); color: #fff; line-height: 1.6; }
.observe-screen .btn.light { background: #cfe3e8; color: #0b0e10; border-color: #cfe3e8; }

/* ---- モーダル ---- */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: rgba(30, 35, 36, .45); backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.dialog { width: min(100%, 360px); max-height: 100%; overflow-y: auto; padding: 1.5rem; background: var(--paper); border: 1px solid var(--ink); text-align: center; display: flex; flex-direction: column; gap: 1rem; }
.dialog .actions { display: flex; flex-direction: column; gap: .75rem; }
.dialog .btn { width: 100%; }
#rotate { display: none; }

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

/* 低い横画面（スマホ横向き）: HUD と字幕を詰め、字幕は直近2行だけ */
@media (max-height: 500px) {
  .hud { height: 40px; }
  .subtitles { height: 64px; padding: .15rem .75rem .3rem; }
  .sub { font-size: .8rem; line-height: 1.45; }
  .sub:last-child { font-size: .9rem; }
  .sub:nth-last-child(n+3) { display: none; }
}
