:root {
  --bg: #1d1a16;
  --panel: #2b251e;
  --panel-2: #3a3128;
  --line: #5a4a38;
  --ink: #f3ead8;
  --ink-dim: #b9ab92;
  --accent: #e0a84a;
  --danger: #c4553f;
  --ground-y: 250px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
/* スマホのダブルタップ拡大で、タップが取りこぼされないようにする */
html { touch-action: manipulation; }
body {
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

#app {
  position: relative;
  max-width: 480px; margin: 0 auto;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }

/* ---------- 共通部品 ---------- */
.btn {
  border: 2px solid var(--accent); background: var(--accent); color: #2a1d10;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: bold; cursor: pointer;
  white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--accent); }
a.btn { display: inline-block; text-decoration: none; }
.btn.share { background: #000; color: #fff; border-color: #fff; }
.btn.big { font-size: 18px; padding: 12px 36px; }
.btn:active { transform: translateY(1px); }

.topbar {
  display: flex; gap: 6px; align-items: center;
  padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex: none;
}
.topbar .label { flex: 1; font-weight: bold; font-size: 14px; }

.art { pointer-events: none; }
.art svg, .art img { width: 100%; height: 100%; display: block; object-fit: contain; }
.obj { position: absolute; cursor: pointer; }
.obj > .art { width: 100%; height: 100%; }

.dialog {
  position: relative; flex: none;
  margin: 8px 10px 0; padding: 10px 14px 12px; min-height: 76px;
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px;
  cursor: pointer;
}
.dialog .who {
  display: inline-block; font-size: 12px; font-weight: bold; color: #2a1d10;
  background: var(--accent); border-radius: 6px; padding: 1px 8px; margin-bottom: 4px;
}
.dialog .who:empty { display: none; }
.dialog .text { margin: 0; font-size: 15px; line-height: 1.6; }
.dialog .more { position: absolute; right: 10px; bottom: 4px; font-size: 11px; color: var(--accent); animation: blink 1s infinite; }
.dialog .more[hidden] { display: none; }
@keyframes blink { 50% { opacity: 0; } }

.toast {
  position: absolute; left: 50%; top: 58px; transform: translate(-50%, -10px);
  max-width: 90%; padding: 8px 14px; border-radius: 10px;
  background: rgba(20, 16, 12, .92); border: 1px solid var(--accent);
  font-size: 14px; line-height: 1.5; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- タイトル ---------- */
.title-wrap {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 35%, #3b2f22, var(--bg) 70%);
}
.title-art { width: 200px; height: 150px; }
.title-wrap h1 { margin: 0; font-size: 40px; line-height: 1.2; letter-spacing: .08em; color: var(--accent); }
.title-sub { margin: 0 0 18px; color: var(--ink-dim); font-size: 14px; }

/* ---------- 研究所 ---------- */
.lab-scene {
  flex: none; padding: 12px 10px 0;
  background: linear-gradient(#4a3d30, #3a3027 70%, #2e271f);
}
.showcase {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 10px; border-radius: 10px;
  background: linear-gradient(#5b4c3c, #4b3e31); border: 3px solid #6e5b45;
  box-shadow: inset 0 0 20px rgba(0,0,0,.35);
}
.slot {
  position: relative; aspect-ratio: 4 / 3.6; border-radius: 8px; padding: 6px 4px 18px;
  background: linear-gradient(rgba(255,255,255,.12), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.18); cursor: pointer;
}
.slot .art { width: 100%; height: 100%; }
.slot .art img { object-fit: cover; border-radius: 6px; }
.slot .name { position: absolute; left: 0; right: 0; bottom: 3px; font-size: 10px; text-align: center; color: var(--ink-dim); }
/* 未入手：石板を消して、骨の形だけを薄いシルエットで見せる（人型の5枠目がラストのヒント） */
.slot.locked .art { filter: brightness(0) invert(1); opacity: .22; }
.slot.locked .art svg > rect, .slot.locked .art svg > circle, .slot.locked .art svg > text { display: none; }
.slot.new { animation: glow 1.4s ease-in-out 3; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); } }
.lab-floor { position: relative; height: 200px; }
/* 時間渡航装置は画面の中央。その下に「白亜紀へ」 */
.device-wrap {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.device-wrap .device { position: static; width: 110px; height: 148px; cursor: pointer; }
.lab-scroll { flex: 1; min-height: 0; overflow-y: auto; background: #2e271f; }
.showcase { grid-template-columns: repeat(2, 1fr); }
.showcase .slot { aspect-ratio: 4 / 3.2; }
.showcase .slot.plate { grid-column: 1 / -1; aspect-ratio: auto; padding: 6px; }
/* アマネの立っていた場所に置かれる、アマネの化石（台の上のガラスケース） */
.lab-fossil {
  right: 6px; bottom: 18px; width: 112px; height: 88px; padding: 4px;
  background: rgba(255,255,255,.08); border: 2px solid #6e5b45; border-radius: 6px;
  box-shadow: 0 14px 0 -4px #4a3d30, 0 0 18px rgba(0,0,0,.5);
}
.lab-fossil[hidden] { display: none; }
.lab-fossil .art img { object-fit: cover; border-radius: 3px; }
.lab-fossil.new { animation: glow 1.4s ease-in-out 3; }
.device > .art { width: 100%; height: 100%; }
.lab-guide { right: 24px; bottom: 4px; width: 66px; height: 132px; }
.lab-guide[hidden] { display: none; }

/* ---------- 過去ステージ ---------- */
.viewport {
  position: relative; flex: none; height: 360px;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.scene {
  position: relative; height: 360px;
  background: linear-gradient(#9fd2e3 0%, #f2dfae 68%, #f2dfae 69%);
  overflow: hidden; isolation: isolate;
}
.scene::after {
  content: ""; position: absolute; left: 0; right: 0; top: var(--ground-y); bottom: 0;
  background: linear-gradient(#6f9a45 0, #6f9a45 10px, #8a6a45 10px, #6e5236);
  z-index: -1;
}
.scene .bg { pointer-events: none; z-index: -1; }
.scene.shake { animation: shake .4s; }
@keyframes shake {
  20% { transform: translate(-4px, 2px); } 40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, -1px); }
}

.scroll-hint { text-align: center; font-size: 12px; color: var(--ink-dim); padding: 4px 0 0; }
.sel-hint { text-align: center; font-size: 12px; color: var(--ink-dim); padding: 6px 0 2px; }
.inventory {
  display: flex; gap: 8px; padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
  flex: none; min-height: 90px; align-items: flex-start;
}
.item {
  width: 72px; height: 76px; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel-2); border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
  font-size: 11px;
}
.item .art { width: 40px; height: 40px; }
.item.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,168,74,.35); background: #4a3d2d; }

/* 穴まわり */
.patch {
  position: absolute; top: calc(var(--ground-y) - 6px); height: 20px;
  border: 2px dashed rgba(255, 240, 200, .7); border-radius: 50%;
  background: rgba(110, 82, 54, .55); cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { border-color: rgba(255, 220, 140, 1); } }
.hole {
  position: absolute; top: calc(var(--ground-y) - 4px);
  background: radial-gradient(ellipse at 50% 0%, #1a110a 30%, #3a2818 100%);
  border-radius: 10px 10px 45% 45%;
  box-shadow: inset 0 6px 8px rgba(0,0,0,.6);
  cursor: pointer;
}
.mound {
  position: absolute; top: calc(var(--ground-y) - 16px); height: 24px;
  background: radial-gradient(ellipse at 50% 100%, #7b5a3a 55%, #5e4329 100%);
  border-radius: 50% 50% 8px 8px; cursor: pointer;
}
.result-btn {
  position: absolute; top: calc(var(--ground-y) - 62px); transform: translateX(-50%);
  padding: 10px 16px; font-size: 14px; z-index: 5; min-height: 44px;
  animation: callout 1.2s ease-in-out infinite;
}
@keyframes callout { 50% { box-shadow: 0 0 0 4px rgba(224,168,74,.45); } }
.done-mark {
  position: absolute; top: calc(var(--ground-y) - 30px); width: 34px; height: 34px;
  font-size: 11px; color: #2a1d10; text-align: center; line-height: 1.2;
  pointer-events: none;
}
.done-mark span { display: inline-block; background: #e8dcc0; border: 1px solid #7a5a3a; padding: 1px 3px; border-radius: 3px; }
.in-hole { position: absolute; cursor: pointer; z-index: 3; }

.trex { transition: none; }
.trex .art { animation: walk .5s ease-in-out infinite; }
@keyframes walk { 50% { transform: translateY(-3px); } }
.ptera { pointer-events: auto; z-index: 4; }
.rope-line {
  position: absolute; top: 0; width: 4px; margin-left: -2px; z-index: 4;
  background: repeating-linear-gradient(#c8a165 0 6px, #a07c45 6px 10px);
  animation: ropeFade .7s forwards; pointer-events: none;
}
@keyframes ropeFade { 0% { transform: scaleY(0); transform-origin: top; } 30% { transform: scaleY(1); } 100% { opacity: 0; } }
.ultra.nibble { animation: nibble 1.4s ease-in-out; transform-origin: 70% 85%; }
@keyframes nibble { 40%, 60% { transform: rotate(-18deg); } }
.ultra.plunge { animation: plunge 1.6s ease-in forwards; transform-origin: 70% 85%; }
@keyframes plunge {
  40% { transform: rotate(-22deg); }
  100% { transform: translate(-90px, 60px) rotate(-150deg); opacity: 0; }
}
.float-text {
  position: absolute; font-weight: bold; font-size: 18px; color: #fff; text-shadow: 0 2px 0 #000;
  pointer-events: none; animation: floatUp 1.6s forwards; z-index: 6;
}
@keyframes floatUp { to { transform: translateY(-40px); opacity: 0; } }

/* ---------- 演出 ---------- */
.cutscene {
  position: absolute; inset: 0; z-index: 40; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  cursor: pointer;
}
.cutscene[hidden] { display: none; }
.cut-frame { width: 100%; aspect-ratio: 3 / 2; transition: opacity .5s; }
.cut-frame.fade { opacity: 0; }
/* 写真はそのまま見せる（揺れ・明滅なし）。周辺をほんのり暗くするだけ */
.cut-frame { position: relative; }
.cut-frame::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,.6) 100%);
}
/* 自然な写真（v3）は作り物っぽくならないよう、ほぼ素のまま。少しだけ色を抜く */
/* 明るすぎる画像だけ heavy で強めに暗くする */
.cut-frame > img { filter: saturate(.85); }
.cut-frame.heavy > img { filter: saturate(.35) contrast(1.3) brightness(.58) sepia(.25) hue-rotate(45deg); }
/* フィルムの粒子 */
.cut-frame::before {
  content: ""; position: absolute; inset: -50%; pointer-events: none; z-index: 1; opacity: .12; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain .5s steps(4) infinite;
}
@keyframes grain { 0% { transform: translate(0, 0); } 25% { transform: translate(-7%, 4%); } 50% { transform: translate(5%, -6%); } 75% { transform: translate(-3%, -2%); } }
.cut-frame { overflow: hidden; }
.cut-frame > svg, .cut-frame > img { width: 100%; height: 100%; display: block; object-fit: cover; }
.slot.plate { cursor: default; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.18); }
.plate-text { font-size: 11px; text-align: center; color: var(--ink-dim); line-height: 1.6; }
.plate-text b { font-size: 18px; color: var(--accent); }
.cut-tap { position: absolute; bottom: 18px; font-size: 11px; color: #777; }

.fx {
  position: absolute; inset: 0; z-index: 45; background: #0b0907;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .6s;
}
.fx.on { opacity: 1; pointer-events: auto; }
.fx p { font-size: 20px; letter-spacing: .2em; color: var(--accent); }

.ending {
  position: absolute; inset: 0; z-index: 48; padding: 32px 24px;
  background: rgba(10, 8, 6, .96);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center;
}
.ending[hidden] { display: none; }
.ending { justify-content: flex-start; overflow-y: auto; padding-top: 0; }
/* ここだけリアル調の写真。ゆっくり浮かび上がらせてから文字を出す */
.ending-photo {
  width: calc(100% + 48px); margin: 0 -24px 6px; aspect-ratio: 4 / 5; max-height: 42vh; flex: none;
  animation: photoIn 3s ease-out both;
}
.ending-photo svg, .ending-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ending:not([hidden]) > :not(.ending-photo) { animation: textIn 1.5s 2.4s ease-out both; }
@keyframes photoIn { from { opacity: 0; filter: brightness(.3); } to { opacity: 1; filter: none; } }
@keyframes textIn { from { opacity: 0; } to { opacity: 1; } }
.ending-small { margin: 0; letter-spacing: .3em; font-size: 12px; color: var(--ink-dim); }
.ending h2 { margin: 0; font-size: 30px; color: var(--accent); }
.ending-body { margin: 4px 0 10px; font-size: 15px; line-height: 1.9; white-space: pre-line; }
