:root {
  --bg: #0a0f1a;
  --surface: #121a2b;
  --surface-2: #1a2438;
  --line: #2b3858;
  --text: #ece8df;
  --muted: #a3adc2;
  --accent: #f2c14e;
  --accent-ink: #1d1404;
  --danger: #e36b64;
  --ok: #86d6a6;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --sans: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.8;
  -webkit-text-size-adjust: 100%;
}

body { overflow-x: hidden; }

button, select { font: inherit; }

#app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 13px;
}
#hud[hidden] { display: none; }
.chapter { flex: 1 1 auto; min-width: 0; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trust-wrap { display: flex; align-items: center; gap: 6px; }
.trust-label { color: var(--muted); font-size: 12px; }
.trust { display: flex; gap: 4px; }
.trust span { width: 10px; height: 14px; border-radius: 5px 5px 2px 2px; background: #2c3650; transition: background .3s, box-shadow .3s; }
.trust span.on { background: var(--accent); box-shadow: 0 0 6px rgba(242, 193, 78, .7); }
.hud-buttons { display: flex; gap: 6px; }

/* ---------- ステージ ---------- */
#stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
}
#bg, #layer, #fx { position: absolute; inset: 0; }
#bg svg { width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; }
#layer.busy .hotspot { pointer-events: none; opacity: .25; }

.beam {
  transform-box: view-box;
  transform-origin: 112px 24.5px;
  animation: sweep 6s linear infinite;
}
.beam.stop { animation-play-state: paused; opacity: 0; transition: opacity .6s; }
.glow { transition: opacity .6s; }
.glow.off { opacity: 0; }
@keyframes sweep {
  0% { transform: scaleX(1); opacity: 1; }
  25% { transform: scaleX(0); opacity: .2; }
  50% { transform: scaleX(-1); opacity: 1; }
  75% { transform: scaleX(0); opacity: .2; }
  100% { transform: scaleX(1); opacity: 1; }
}
.rain { animation: rain .5s linear infinite; }
@keyframes rain { from { transform: translate(0, 0); } to { transform: translate(-2px, 6px); } }
.flicker { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 1.2s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scaleY(1); } to { transform: scaleY(.85); } }

#stage.shake { animation: shake .4s; }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
#stage.flashing::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff6d8;
  pointer-events: none;
  animation: flash .5s ease-out forwards;
}
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }

/* 調査ポイント */
.hotspot {
  position: absolute;
  padding: 0;
  border: 1.5px dashed rgba(242, 193, 78, .75);
  border-radius: 6px;
  background: rgba(242, 193, 78, .08);
  cursor: pointer;
  animation: pulse 2.4s ease-in-out infinite;
}
.hotspot:hover, .hotspot:focus-visible { background: rgba(242, 193, 78, .22); outline: none; }
.hotspot.seen { border-color: rgba(163, 173, 194, .45); background: rgba(163, 173, 194, .05); animation: none; }
.hotspot span {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 4px);
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(10, 15, 26, .88);
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
  z-index: 1;
}
.hotspot:hover span, .hotspot:focus-visible span { opacity: 1; }
@keyframes pulse { 50% { border-color: rgba(242, 193, 78, .3); } }

/* 章タイトル・演出 */
.chapter-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(5, 8, 14, .78);
  animation: fadein .8s ease-out;
}
.chapter-card span { color: var(--accent); letter-spacing: .3em; font-size: clamp(13px, 2.4vw, 18px); }
.chapter-card strong { font-size: clamp(24px, 5.5vw, 44px); letter-spacing: .12em; font-weight: 600; }
.chapter-card.fin { background: rgba(5, 8, 14, .45); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.present-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-6deg);
  padding: 8px 20px;
  background: var(--danger);
  color: #fff;
  font-size: clamp(22px, 6vw, 44px);
  font-weight: 800;
  letter-spacing: .1em;
  border: 3px solid #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  animation: burst 1.1s ease-out forwards;
}
@keyframes burst {
  0% { transform: translate(-50%, -50%) rotate(-6deg) scale(1.8); opacity: 0; }
  15% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.toast {
  position: absolute;
  right: 10px;
  top: 10px;
  max-width: calc(100% - 20px);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(18, 26, 43, .92);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 12px;
  animation: toast 2.4s ease forwards;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* タイトル */
.title-logo {
  position: absolute;
  left: 7%;
  top: 14%;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .8);
}
.title-logo span { color: var(--accent); font-size: clamp(11px, 2vw, 15px); letter-spacing: .3em; }
.title-logo h1 { margin: 4px 0 0; font-size: clamp(24px, 5.8vw, 50px); line-height: 1.3; letter-spacing: .08em; font-weight: 600; }

/* ---------- パネル ---------- */
#panel {
  flex: 1;
  padding: 16px 16px 32px;
  background: linear-gradient(var(--surface), var(--bg));
  border-top: 1px solid var(--line);
}

.textbox {
  position: relative;
  min-height: 150px;
  padding: 14px 18px 26px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  outline: none;
}
.textbox:focus-visible { border-color: var(--accent); }
.textbox .name { font-weight: 700; font-size: 15px; margin-bottom: 2px; letter-spacing: .06em; }
.textbox .text { margin: 0; font-size: clamp(15px, 2.2vw, 17px); white-space: pre-wrap; }
.textbox.narration .text { color: #d9d4c6; }
.textbox.thought .text { color: #b9d6ea; }
.textbox.system { border-color: rgba(242, 193, 78, .6); }
.textbox.system .name { color: var(--accent); }
.textbox.system .text { color: var(--accent); font-family: var(--sans); font-size: 14px; }
.next-hint { position: absolute; right: 14px; bottom: 6px; color: var(--accent); font-size: 12px; animation: bob 1s ease-in-out infinite; }
.next-hint[hidden] { display: none; }
@keyframes bob { 50% { transform: translateY(3px); } }

.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.tag {
  flex: none;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
}
.lead { margin: 0 0 12px; color: var(--muted); }
.help { margin: 8px 0 0; color: var(--muted); font-size: 13px; font-family: var(--sans); }
.msg { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: rgba(242, 193, 78, .08); }
.question { font-size: 18px; margin: 4px 0 14px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.controls { justify-content: flex-end; margin-top: 8px; }

/* ボタン */
.btn {
  min-height: 42px;
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #f7cf6d; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 3px 12px; font-size: 13px; }
.btn.wide { display: block; width: 100%; margin-top: 10px; }
.btn.nav { min-width: 48px; }

/* 探索 */
.spot-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px;
  padding: 4px 14px;
  border: 1px solid rgba(242, 193, 78, .6);
  border-radius: 999px;
  background: rgba(242, 193, 78, .08);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  cursor: pointer;
}
.chip:hover { background: rgba(242, 193, 78, .2); }
.chip.seen { border-color: var(--line); background: transparent; color: var(--muted); }

/* 証言 */
.statement {
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--c, var(--accent));
  border-radius: 10px;
  background: var(--surface-2);
}
.statement .name { font-family: var(--sans); font-size: 13px; font-weight: 700; }
.statement p { margin: 4px 0 8px; font-size: clamp(16px, 2.4vw, 18px); }
.dots { display: flex; gap: 6px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--c, var(--accent)); }

/* 閃きボード */
.goals { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.goals li { padding: 4px 12px; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted); }
.goals li.done { border-style: solid; border-color: var(--ok); color: var(--ok); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 64px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
}
.card small { color: var(--muted); font-size: 11px; }
.card.deduction { border-color: rgba(134, 214, 166, .5); }
.card.deduction small { color: var(--ok); }
.card.selected { border-color: var(--accent); background: rgba(242, 193, 78, .16); box-shadow: 0 0 0 1px var(--accent) inset; }
.card-info { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: rgba(255, 255, 255, .04); font-size: 14px; }

/* タイムライン */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.timeline li { display: flex; align-items: center; gap: 10px; }
.timeline .time { flex: none; width: 52px; color: var(--accent); font-family: var(--sans); font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline select {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

/* 最終推理 */
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }

/* エンディング */
.rank { display: flex; align-items: center; gap: 16px; margin: 12px 0; }
.rank-letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 40px;
  font-weight: 700;
}
.rank p { margin: 2px 0 0; color: var(--muted); }
.stats { margin: 0; padding-left: 20px; color: var(--muted); font-family: var(--sans); font-size: 14px; }

/* タイトルメニュー */
.title-menu { max-width: 420px; margin: 0 auto; }
.cleared { text-align: center; color: var(--accent); font-family: var(--sans); font-size: 13px; }

/* ---------- モーダル ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 5, 10, .72);
}
#modal[hidden] { display: none; }
.dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .6);
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.5; }
.dialog-body { padding: 12px 16px 18px; overflow-y: auto; }
.dialog-body h3 { margin: 12px 0 0; font-size: 14px; color: var(--muted); font-family: var(--sans); }
.dialog-body h3:first-child { margin-top: 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
}
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.items li { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.item-text { flex: 1; min-width: 0; }
.item-text strong { font-size: 15px; }
.item-text p { margin: 2px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.empty { color: var(--muted); }

.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log strong { font-size: 13px; font-family: var(--sans); }
.log p { margin: 0; font-size: 15px; }

.howto dt { margin-top: 10px; color: var(--accent); font-weight: 700; }
.howto dd { margin: 2px 0 0; color: var(--text); font-size: 14px; }

.noscript { padding: 16px; text-align: center; }

/* タッチ端末では調査ポイント名を常時表示 */
@media (hover: none) {
  .hotspot span { opacity: .9; }
}

@media (max-width: 520px) {
  #hud { padding: 6px 12px; }
  .chapter { flex-basis: 100%; }
  .hud-buttons { margin-left: auto; }
  .textbox { min-height: 160px; padding: 12px 14px 26px; }
  .hotspot span { font-size: 10px; }
}

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