/* ============================================================
   終端記録館 — styles.css
   外部フォント・外部素材なし。静かで不穏な記録保管庫の空気。
   ============================================================ */

:root {
  --bg: #0b0e13;
  --panel: #141a23;
  --panel-2: #1a212c;
  --line: #2c3540;
  --ink: #d8d3c4;
  --ink-dim: #8d8a7e;
  --accent: #c9a96a;
  --accent-dim: #8a784f;
  --cold: #7fc2c9;
  --danger: #b56a5e;
  --ok: #8fc9a0;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "MS PMincho", serif;
}

* { box-sizing: border-box; }

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

body.act3 {
  --accent: #7fc2c9;
  --accent-dim: #4f7e8a;
}

#app { max-width: 1080px; margin: 0 auto; padding: 0 12px 48px; }

button { font-family: var(--serif); cursor: pointer; }

p { margin: 0 0 0.4em; }
p.blank-line { min-height: 0.9em; margin: 0; }

/* 「説明へ戻る」: 浮かせず文書フローに置く(HUD・トースト・モーダルと重ならない)。
   file:// で開いた場合は main.js が #site-bar ごと非表示にする。 */
.site-bar {
  max-width: 1080px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
}
.site-back {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-dim);
  padding: 6px 16px;
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.08em;
}
.site-back:hover, .site-back:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.site-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- 共通ボタン ---------------- */
.btn {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 18px;
  font-size: 15px;
  letter-spacing: 0.08em;
  transition: border-color 0.2s, background 0.2s;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); background: #202836; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { border-color: var(--accent-dim); color: var(--accent); }
.btn.danger { border-color: #6e4039; color: var(--danger); }
.btn.subtle { font-size: 13px; color: var(--ink-dim); }
.btn.big { padding: 12px 36px; font-size: 17px; min-width: 240px; }
.btn.tool { font-size: 13px; padding: 6px 12px; }

/* ---------------- タイトル画面 ---------------- */
.title-screen, .ending-screen {
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}
.title-kicker {
  color: var(--accent-dim);
  letter-spacing: 0.5em;
  font-size: 13px;
  margin: 0;
}
.title-main {
  font-size: clamp(40px, 9vw, 76px);
  font-weight: 600;
  letter-spacing: 0.22em;
  margin: 0 0 4px;
  color: var(--ink);
  text-shadow: 0 0 40px rgba(201, 169, 106, 0.18);
  animation: titleIn 2.4s ease-out both;
}
@keyframes titleIn { from { opacity: 0; letter-spacing: 0.5em; } to { opacity: 1; letter-spacing: 0.22em; } }
.title-tag { color: var(--ink-dim); font-size: 15px; margin-bottom: 14px; }
.title-tag.lit { color: var(--accent); }
.title-menu { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; align-items: center; }
.title-foot { color: var(--ink-dim); font-size: 12px; margin-top: 36px; letter-spacing: 0.12em; }

.title-lamp {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--accent-dim);
  margin-bottom: 18px;
  background: transparent;
}
.title-lamp.lit {
  background: var(--accent);
  box-shadow: 0 0 18px 4px rgba(201, 169, 106, 0.45);
  animation: lampPulse 3.5s ease-in-out infinite;
}
.title-lamp.off { opacity: 0.35; }
@keyframes lampPulse { 0%, 100% { box-shadow: 0 0 14px 3px rgba(201,169,106,0.35); } 50% { box-shadow: 0 0 26px 7px rgba(201,169,106,0.55); } }

/* ---------------- HUD ---------------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 4px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.hud-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.hud-name { font-size: 20px; letter-spacing: 0.18em; }
.hud-no {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  padding: 1px 8px;
  border-radius: 2px;
}
.hud-no.lit { color: var(--cold); border-color: var(--cold); }
.hud-room { color: var(--accent); font-size: 14px; letter-spacing: 0.12em; }
.hud-tools { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- 部屋ビュー ---------------- */
.room-stage { width: 100%; }
.room-view {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: #07090d;
}
.room-view svg { display: block; width: 100%; height: 100%; }

body.act3 .room-view svg { filter: hue-rotate(165deg) saturate(0.75) brightness(0.92); }

.hotspot {
  position: absolute;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 4px;
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}
.hotspot:hover, .hotspot:focus-visible {
  border-color: rgba(201, 169, 106, 0.7);
  background: rgba(201, 169, 106, 0.06);
  outline: none;
}
body.act3 .hotspot:hover, body.act3 .hotspot:focus-visible {
  border-color: rgba(127, 194, 201, 0.7);
  background: rgba(127, 194, 201, 0.06);
}
.hs-dot {
  width: 7px; height: 7px;
  margin: 6px;
  border-radius: 50%;
  background: rgba(201, 169, 106, 0.55);
  animation: dotPulse 2.6s ease-in-out infinite;
}
@keyframes dotPulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.9; } }

.room-desc {
  color: var(--ink-dim);
  font-size: 14.5px;
  margin: 12px 4px 10px;
  letter-spacing: 0.04em;
}

/* ---------------- チップ(調べる・移動) ---------------- */
.hotspot-list, .nav-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
}
.list-label { color: var(--ink-dim); font-size: 13px; margin-right: 4px; }
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 14px;
  font-size: 13px;
  padding: 4px 14px;
  transition: border-color 0.2s;
}
.chip:hover, .chip:focus-visible { border-color: var(--accent); outline: none; }
.nav-chip { border-color: var(--accent-dim); color: var(--accent); }
.nav-chip.locked { border-color: var(--line); color: var(--ink-dim); }

/* ---------------- モーダル ---------------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
  animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  max-width: 560px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px 30px 20px;
  box-shadow: 0 10px 60px rgba(0, 0, 0, 0.6);
}
.modal-panel.wide { max-width: 720px; }
.modal-kicker { color: var(--accent-dim); font-size: 12px; letter-spacing: 0.3em; margin: 0 0 2px; }
.modal-title {
  font-size: 22px;
  letter-spacing: 0.12em;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.modal-body { font-size: 15.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-close { font-size: 13px; }

/* ---------------- 謎UI ---------------- */
.puzzle-host { margin-top: 14px; }
.puzzle-input-row { display: flex; gap: 8px; margin: 12px 0 6px; flex-wrap: wrap; }
.puzzle-input {
  background: #0e131b;
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.3em;
  padding: 9px 14px;
  border-radius: 4px;
  flex: 1;
  min-width: 160px;
}
.puzzle-input:focus { outline: none; border-color: var(--accent); }
.puzzle-feedback { min-height: 1.6em; color: var(--danger); font-size: 14.5px; margin-top: 8px; }
.puzzle-feedback.ok { color: var(--ok); }
.puzzle-tools { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }

.seq-row { display: flex; gap: 10px; margin: 16px 0 10px; flex-wrap: wrap; }
.seq-btn {
  width: 64px; height: 84px;
  font-size: 30px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.seq-btn:hover, .seq-btn:focus-visible { border-color: var(--accent); outline: none; }
.seq-trail { color: var(--accent); font-size: 17px; letter-spacing: 0.1em; min-height: 1.6em; }

/* ---------------- ヒント・パネル類 ---------------- */
.hint-note { color: var(--ink-dim); font-size: 13.5px; }
.hint-item {
  border-left: 2px solid var(--accent-dim);
  padding: 6px 0 6px 14px;
  margin: 12px 0;
}
.hint-tag { color: var(--accent); font-size: 12.5px; letter-spacing: 0.2em; display: block; }

.panel-h {
  color: var(--accent-dim);
  font-size: 13px;
  letter-spacing: 0.25em;
  margin: 18px 0 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  font-weight: 600;
}
.list-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px dotted var(--line);
  color: var(--ink);
  font-size: 15px;
  padding: 7px 6px;
}
.list-btn:hover, .list-btn:focus-visible { color: var(--accent); background: rgba(201,169,106,0.05); outline: none; }

.puzzle-row {
  border-bottom: 1px dotted var(--line);
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.puzzle-row-main { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.puzzle-status { color: var(--ink-dim); width: 1.2em; }
.puzzle-row.solved .puzzle-status { color: var(--ok); }
.puzzle-row-title { font-size: 16px; }
.puzzle-row-loc { color: var(--ink-dim); font-size: 12.5px; }
.puzzle-row-ans { color: var(--accent-dim); font-size: 13.5px; padding-left: 1.7em; }
.puzzle-row .btn { align-self: flex-start; margin-left: 1.7em; }

.frag-grid { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.frag-slot {
  width: 56px; height: 72px;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #0e131b;
}
.frag-slot.owned { border-color: var(--accent-dim); box-shadow: 0 0 12px rgba(201,169,106,0.12) inset; }
.frag-idx { font-size: 11px; color: var(--ink-dim); }
.frag-kana { font-size: 26px; color: var(--accent); }
.frag-slot:not(.owned) .frag-kana { color: var(--line); }

.item-row { display: flex; gap: 14px; padding: 12px 4px; border-bottom: 1px dotted var(--line); }
.item-icon { font-size: 26px; line-height: 1.4; }
.item-desc { color: var(--ink-dim); font-size: 14px; }

.memo-area {
  width: 100%;
  background: #0e131b;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.9;
  padding: 12px 14px;
  resize: vertical;
}
.memo-area:focus { outline: none; border-color: var(--accent); }

/* ---------------- トースト ---------------- */
#toasts {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  max-width: min(360px, 86vw);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-dim);
  color: var(--ink);
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 3px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.4s ease-out;
}
.toast-doc { border-left-color: var(--cold); }
.toast-item { border-left-color: var(--accent); }
.toast-fragment { border-left-color: #c98aa0; }
.toast.out { opacity: 0; transition: opacity 0.5s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------------- カットシーン ---------------- */
.cutscene {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 7, 0.96);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: pointer;
  animation: fadeIn 0.4s ease-out;
}
.cutscene.cut-out { opacity: 0; transition: opacity 0.35s; }
.cut-text {
  max-width: 620px;
  font-size: clamp(17px, 2.6vw, 21px);
  line-height: 2.3;
  letter-spacing: 0.1em;
  text-align: center;
  white-space: pre-line;
  animation: fadeIn 0.6s ease-out;
}
.cut-hint {
  position: absolute;
  bottom: 26px;
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.2em;
  animation: dotPulse 2.4s ease-in-out infinite;
}
.cutscene.cut-true { background: radial-gradient(ellipse at center, #1c2520 0%, #030407 75%); }
.cutscene.cut-true .cut-text { color: #e8e3d0; text-shadow: 0 0 24px rgba(201, 169, 106, 0.3); }
.cutscene.cut-normal { background: radial-gradient(ellipse at center, #14161c 0%, #030407 75%); }

/* ---------------- エンディング ---------------- */
.ending-title {
  font-size: clamp(34px, 7vw, 58px);
  letter-spacing: 0.3em;
  margin: 6px 0 18px;
  font-weight: 600;
}
.ending-screen.true-end .ending-title { color: var(--accent); text-shadow: 0 0 36px rgba(201, 169, 106, 0.3); }
.ending-after {
  max-width: 540px;
  color: var(--ink-dim);
  font-size: 15px;
  margin-bottom: 10px;
}
.ending-stats { color: var(--ink-dim); font-size: 13px; letter-spacing: 0.1em; }

/* ---------------- 質感(紙・記録媒体の空気。すべて静的でreduce-motion安全) ---------------- */
.room-view::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(232, 227, 208, 0.016) 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at 50% 0%, rgba(232, 217, 176, 0.05), transparent 60%);
}
.modal-panel { background-image: linear-gradient(180deg, rgba(232, 227, 208, 0.03), transparent 140px); }
.title-screen { background: radial-gradient(ellipse at 50% 36%, rgba(201, 169, 106, 0.05), transparent 55%); }

/* ---------------- Act 3: 同じ部屋が、違って見える ---------------- */
body.act3 { background: #090d14; }
body.act3 .room-view { border-color: #2a3d46; }
body.act3 .room-view::after {
  background:
    repeating-linear-gradient(0deg, rgba(127, 194, 201, 0.03) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 110%, rgba(127, 194, 201, 0.07), transparent 55%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(2, 6, 10, 0.45) 100%);
}
body.act3 .hud-no.lit { animation: noPulse 4s ease-in-out infinite; }
@keyframes noPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(127, 194, 201, 0); }
  50% { box-shadow: 0 0 14px rgba(127, 194, 201, 0.45); }
}
.cutscene.cut-act3 { background: radial-gradient(ellipse at center, #0c1a20 0%, #020407 75%); }
.cutscene.cut-act3 .cut-text { color: #cfe7ea; }

/* ---------------- p8 正解時の白いフラッシュ(アニメ無効時は不可視のまま) ---------------- */
.screen-flash {
  position: fixed;
  inset: 0;
  background: #fffdf4;
  opacity: 0;
  z-index: 120;
  pointer-events: none;
  animation: flashFade 0.9s ease-out;
}
@keyframes flashFade { 0% { opacity: 0.9; } 100% { opacity: 0; } }

/* ---------------- 誤答シェイク ---------------- */
@keyframes denyShake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-5px); }
  55% { transform: translateX(4px); }
  80% { transform: translateX(-2px); }
}
.puzzle-input-row.shake { animation: denyShake 0.3s ease-out; }

/* ---------------- 手帳: 未読・重要マーク・参照メモ ---------------- */
.doc-row { display: flex; align-items: stretch; gap: 2px; }
.doc-row .list-btn { flex: 1; }
.mark-btn {
  background: transparent;
  border: none;
  border-bottom: 1px dotted var(--line);
  color: var(--ink-dim);
  font-size: 16px;
  padding: 0 9px;
}
.mark-btn.on { color: var(--accent); }
.mark-btn:hover, .mark-btn:focus-visible { color: var(--accent); outline: none; }
.doc-tag {
  font-size: 11px;
  letter-spacing: 0.1em;
  border: 1px solid;
  border-radius: 3px;
  padding: 0 6px;
  margin-left: 8px;
}
.doc-tag.new { color: var(--cold); border-color: rgba(127, 194, 201, 0.6); }
.doc-tag.heika { color: #c98aa0; border-color: rgba(201, 138, 160, 0.55); }
.tool-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cold);
  margin-left: 6px;
  vertical-align: 2px;
  box-shadow: 0 0 6px rgba(127, 194, 201, 0.8);
}
.puzzle-ref {
  color: var(--accent-dim);
  font-size: 13.5px;
  border: 1px dashed var(--accent-dim);
  border-radius: 3px;
  padding: 8px 12px;
  margin-top: 10px;
}
.puzzle-hintcount { color: var(--ink-dim); font-size: 12px; }

/* ---------------- タイトル・エンディングの小さな変化 ---------------- */
.title-clock { color: var(--accent-dim); font-size: 13px; letter-spacing: 0.3em; margin: 0; }
.about-link { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.about-link:hover, .about-link:focus-visible { color: var(--ink); outline: none; }
.ending-stats.lit { color: var(--accent); }

/* ---------------- 設定: 文字サイズ大 ---------------- */
body.text-large { font-size: 17px; }
body.text-large .modal-body { font-size: 17px; }
body.text-large .room-desc { font-size: 16px; }
body.text-large .cut-text { font-size: clamp(19px, 3vw, 23px); }
body.text-large .chip { font-size: 14px; }

/* ---------------- 設定: 演出控えめ(reduce-motionと同等) ---------------- */
body.calm *, body.calm *::before, body.calm *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ---------------- アクセシビリティ ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------- レスポンシブ ---------------- */
@media (max-width: 720px) {
  .hud { flex-direction: column; align-items: flex-start; }
  .btn.big { min-width: 200px; padding: 10px 24px; }
  .modal-panel { padding: 20px 18px 16px; }
  .hs-dot { width: 9px; height: 9px; }
  .room-desc { font-size: 13.5px; }
}

/* スマホ縦(420px級)での操作感 */
@media (max-width: 460px) {
  #app { padding: 0 8px 40px; }
  .hud-name { font-size: 17px; letter-spacing: 0.12em; }
  .btn { padding: 8px 14px; font-size: 14px; }
  .btn.tool { font-size: 12px; padding: 7px 9px; }
  .seq-btn { width: 54px; height: 72px; font-size: 26px; }
  .seq-row { gap: 7px; }
  .modal-panel { padding: 18px 14px 14px; }
  .modal-title { font-size: 19px; }
  .modal-body { font-size: 15px; }
  .puzzle-input { font-size: 17px; letter-spacing: 0.2em; min-width: 130px; }
  .chip { padding: 6px 12px; }
  .frag-slot { width: 48px; height: 62px; }
  .frag-kana { font-size: 22px; }
  .title-main { letter-spacing: 0.14em; }
  .site-back { font-size: 12px; padding: 6px 12px; }
  .mark-btn { min-width: 42px; font-size: 18px; }
}
