/* 落ち着いた暗めの色 */
:root {
  --bg: #0b0d12;
  --window: #000000;
  --line: #ffffff;
  --text: #ffffff;
  --muted: #a0aec0;
  --accent: #f6e05e;
  --face: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: relative;
  width: 100%;
  max-width: 760px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 背景・一枚絵 ---------- */
#bg, #cg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transition: background-color 0.6s;
}
/* 中の2枚：.pic がくっきりした絵、.fill がぼかした下敷き（スマホ縦で絵のまわりを埋める） */
#bg .pic, #cg .pic, #bg .fill, #cg .fill {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat; /* 絵を小さく置くときの余白に、絵をくり返さない */
  background-size: cover;
  background-position: center;
}
#bg .fill, #cg .fill {
  display: none;
  inset: -40px; /* ぼかしの端が薄くならないように、少し大きめに広げる */
  filter: blur(24px) brightness(0.45);
}
#bg.framed .fill, #cg.framed .fill { display: block; }
/* 絵が無いあいだの仮の場所名（左上） */
#bg-label, #cg-caption {
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.2em;
}
#bg-label, #cg-caption { position: relative; z-index: 1; }
#bg-label {
  position: absolute;
  top: 12px;
  left: 16px;
  font-size: 0.85rem;
}
#cg {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s;
  z-index: 2;
}
#cg.show { opacity: 1; }
#cg-caption {
  margin-top: 30%;
  color: rgba(255, 255, 255, 0.55);
  font-size: 1.3rem;
}

/* ---------- 初登場の紹介カット ---------- */
#intro {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
}
#intro.show { opacity: 1; }
.intro-wrap {
  position: relative;
  height: 80%;              /* パソコン：画面の縦の8割 */
  display: flex;
  justify-content: center;
}
#intro.portrait .intro-wrap {
  height: 60%;              /* スマホ縦：画面の縦の6割 */
  margin-bottom: 12%;       /* 少し上寄り */
}
.intro-wrap img {
  height: 100%;
  width: auto;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.6));
}
.intro-name {
  /* 名前は全身の右横に縦書きで、頭の高さから（足元だと見逃しやすいので） */
  position: absolute;
  top: 6%;
  left: 100%;
  margin-left: 4px;
  writing-mode: vertical-rl;
  text-orientation: upright;
  inline-size: max-content;  /* 縦に文字数ぶん伸ばす（切れないように） */
  padding: 16px 8px;
  white-space: nowrap;
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 0.3em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--accent);
  border-radius: 999px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  /* 全身より少し遅れて、上からすっと出る（目が行くように） */
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.4s 0.25s, transform 0.4s 0.25s;
}
#intro.show .intro-name { opacity: 1; transform: none; }

/* ---------- 背景の上の画面 ---------- */
#stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 16px 16px; /* 上は「スレを遡る」ボタンのぶん空ける */
  overflow-y: auto;
}
#stage:empty { pointer-events: none; }

button {
  font: inherit;
  color: var(--text);
  background: var(--window);
  border: 3px double var(--line);
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #1a1f2b; }
button:disabled { color: #555; border-color: #555; cursor: default; }

/* タイトル */
.title-screen {
  margin: auto;
  text-align: center;
}
.title-screen h1 {
  font-size: 3.4rem;
  letter-spacing: 0.4em;
  margin: 0 0 0 0.4em;
}
.title-screen .sub { color: var(--muted); margin: 0.2em 0 3em; }
.title-screen .menu { display: flex; flex-direction: column; gap: 12px; width: 220px; margin: 0 auto; }

/* 地図 */
.map-screen {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: auto 0;
}
.map-screen h2 { margin: 0; letter-spacing: 0.3em; text-align: center; }
.compass { margin: 0 0 8px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.places { display: flex; flex-direction: column; gap: 12px; }
.place {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
}
.place-name { font-size: 1.15rem; }
.place-desc { font-size: 0.85rem; color: var(--muted); }
.place.base { margin-top: 12px; border-style: dashed; border-width: 2px; }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 7px;
  background: var(--accent);
  color: #000;
  border-radius: 10px;
  font-size: 0.85rem;
  animation: pulse 1s infinite alternate;
}
.small { align-self: center; font-size: 0.85rem; padding: 6px 14px; border-width: 1px; border-style: solid; color: var(--muted); }

/* 看板 */
/* 看板は会話ウィンドウのすぐ上（#bottom の中）に出す。視火の顔にかからないように */
#sign {
  align-self: center;
  max-width: 100%;
}
.signboard {
  padding: 12px 18px;
  border: 2px solid #f687b3;
  border-radius: 8px;
  color: #fbb6ce;
  text-shadow: 0 0 8px #f687b3, 0 0 16px #d53f8c;
  box-shadow: 0 0 12px rgba(246, 135, 179, 0.5);
  background: rgba(0, 0, 0, 0.4);
  text-align: center;
}

/* 空挺 */
.ship {
  margin-top: 4%;
  width: 100%;
  max-width: 460px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid #4a5568;
  border-radius: 8px;
}
.ship-title { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
.parts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.part { border: 1px solid #4a5568; border-radius: 6px; padding: 6px; }
.part-name { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.slots { display: flex; gap: 6px; }
.slot {
  flex: 1;
  height: 34px;
  border: 1px dashed #4a5568;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.slot.filled {
  border: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 35%, transparent);
  box-shadow: 0 0 10px var(--c);
}

/* ---------- 下のウィンドウ ---------- */
#bottom {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: none;
}
#bottom > * { pointer-events: auto; }

.window {
  background: var(--window);
  border: 4px double var(--line);
  border-radius: 8px;
}
.hidden { display: none !important; }

/* 会話ウィンドウ（ドラクエ風） */
#msg {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  min-height: 8.5em;
  cursor: pointer;
}
#face {
  flex: none;
  width: var(--face);
  height: var(--face);
  border: 2px solid var(--line);
  border-radius: 4px;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}
#face[hidden] { display: none; } /* 地の文のときは顔を出さない */
/* 顔画像があるとき：縦長の画像を上寄せで枠に収める。背景は切り抜きの縁が目立たない明るい色で統一 */
#face.has-image, .log-face.has-image {
  background-color: #e8e4ef;
  background-size: cover;
  background-position: center top;
}
#msg-body { flex: 1; min-width: 0; }
#speaker { color: var(--accent); font-size: 0.95rem; margin-bottom: 4px; min-height: 1.2em; }
#text { font-size: 1.1rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
#msg.narration #text { color: #e2e8f0; }
#next-mark {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 0.8rem;
  visibility: hidden;
}
#msg.waiting #next-mark { visibility: visible; animation: blink 0.8s steps(1) infinite; }

/* 選択肢 */
#choices {
  align-self: flex-end;
  width: min(100%, 420px);
  max-height: 55vh;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  gap: 4px;
}
.choice {
  border: none;
  text-align: left;
  padding: 10px 12px 10px 28px;
  position: relative;
  border-radius: 4px;
}
.choice::before {
  content: "▶";
  position: absolute;
  left: 8px;
  font-size: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
}
.choice:hover::before, .choice:focus-visible::before { opacity: 1; }
.choice.done { color: var(--muted); }
.choice.locked { color: #666; }
.choice.shake { animation: shake 0.3s; }

/* 文字入力 */
#input-box {
  display: flex;
  gap: 8px;
  padding: 10px;
}
#input-field {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* スマホで勝手に拡大されないように */
  color: var(--text);
  background: #111;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
}

/* ---------- ログ（スレを遡る） ---------- */
/* 右上のボタン（音のオン・オフ、スレを遡る） */
#top-btns {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  z-index: 4;
  display: flex;
  gap: 8px;
}
#log-btn, #sound-btn, #ff-btn {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.9rem;
  border-width: 2px;
  border-style: solid;
  background: rgba(0, 0, 0, 0.75);
}
#sound-btn { min-width: 44px; }
#ff-btn.on { color: #000; background: var(--accent); border-color: var(--accent); }
#sound-btn.off { color: var(--muted); border-color: #555; }
#log {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  background: #07090d;
}
.log-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  border-bottom: 1px solid #4a5568;
  color: var(--accent);
  letter-spacing: 0.1em;
}
.log-head button { min-height: 44px; min-width: 88px; }
#log-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  user-select: text;
  -webkit-user-select: text;
}
.log-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #1f2430; }
.log-face {
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}
.log-body { flex: 1; min-width: 0; }
.log-name { color: var(--accent); font-size: 0.85rem; }
.log-text { line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.log-narration .log-text { color: var(--muted); padding-left: 50px; }
.log-choice { color: #90cdf4; font-size: 0.9rem; padding-left: 50px; }
.log-empty { color: var(--muted); text-align: center; }

/* ---------- 演出 ---------- */
#flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
#flash.go { animation: flash 0.7s ease-out; }

#toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
#toast.show { animation: toast 2.6s ease-out; }

@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
@keyframes toast { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { from { opacity: 0.6; } to { opacity: 1; } }
.jolt { animation: jolt 0.45s ease-out; }
@keyframes jolt {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  15% { transform: translate(-6px, 3px) rotate(-1deg); }
  35% { transform: translate(5px, -2px) rotate(0.8deg); }
  55% { transform: translate(-3px, 1px) rotate(-0.4deg); }
  75% { transform: translate(2px, 0) rotate(0.2deg); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* スマホ縦 */
@media (max-width: 480px) {
  :root { --face: 56px; }
  #msg { min-height: 9.5em; padding: 10px; gap: 10px; }
  #text { font-size: 1rem; }
  .title-screen h1 { font-size: 2.6rem; }
}

/* テスト用のワープ（?test のときだけタイトルに出る） */
.title-screen .warp { border-style: dashed; border-width: 2px; color: var(--muted); font-size: 0.9rem; }
