* { box-sizing: border-box; }

/* メッセージボックスの最大の横幅（立ち絵もこの幅の中に立つ） */
:root { --box-width: 1240px; }

html, body {
  margin: 0;
  height: 100%;
  background: #111;
  color: #eee;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  position: fixed;
  inset: 0;
}
.screen[hidden] { display: none !important; }

/* ---------- タイトル画面 ---------- */
#title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  text-align: center;
  overflow-y: auto; /* 開発用の場面ジャンプを開いたとき、低い画面でもはみ出さないように */
  justify-content: safe center;
}
.title-logo { margin: 0; font-size: clamp(24px, 6vw, 44px); }
.title-sub { margin: 0; color: #aaa; }
.title-menu {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 16px;
  min-width: min(280px, 100%);
}
.title-button {
  padding: 12px 40px;
  font-size: 18px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 6px;
  cursor: pointer;
}
.title-button:hover { background: #3a4150; }
.title-button[hidden] { display: none; }
.title-button-info { display: block; margin-top: 2px; font-size: 12px; color: #9aa3b0; }
.title-button.small { padding: 8px 24px; font-size: 15px; }
.chapter-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chapter-list[hidden] { display: none; }

/* 開発用の場面ジャンプ（URLの最後に ?dev を付けたときだけ出る） */
.dev-badge { margin: 0; font-size: 12px; color: #f0c060; }
.dev-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 45vh;
  overflow-y: auto;
  padding: 8px;
  min-width: min(360px, 100%);
  text-align: left;
  border: 1px dashed #f0c060;
  border-radius: 6px;
}
.dev-list[hidden] { display: none; }
.dev-part { margin: 6px 0 2px; font-size: 14px; color: #f0c060; }
.dev-jump {
  padding: 5px 10px;
  font-size: 13px;
  text-align: left;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #556;
  border-radius: 4px;
  cursor: pointer;
}
.dev-jump:hover { background: #3a4150; }
.dev-jump.sub { margin-left: 16px; }
.dev-jump.arrange { margin-left: 16px; border-color: #f0c060; }

/* ---------- ゲーム画面 ---------- */
/* 横長：背景＋立ち絵が全面、下にメッセージボックスを重ねる */

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  background: #333;
  transition: background-color 0.4s;
}
#bg-label {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

#place-label {
  position: absolute;
  top: 12px;
  left: 16px;
  padding: 4px 12px;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}
#place-label:empty { display: none; }

/* 立ち絵はメッセージボックスの上に立つ */
/* 横幅はメッセージボックスと同じにして、人がボックスからはみ出さないようにする */
#chara-layer {
  position: absolute;
  left: 50%;
  translate: -50% 0;
  width: min(calc(100% - 32px), var(--box-width));
  top: 48px;
  bottom: 172px;
  pointer-events: none;
}

/* 仮の立ち絵（色の四角） */
.chara {
  position: absolute;
  bottom: 0;
  width: min(30vw, 260px);
  height: 100%;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 16px;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  animation: chara-in 0.2s ease-out;
  transition: filter 0.2s;
}
/* 立ち位置：左右の2枠。中央は1人だけのとき */
.chara.pos-left   { left: 8%; }
.chara.pos-right  { right: 8%; }
.chara.pos-center { left: 50%; margin-left: calc(min(30vw, 260px) / -2); }
/* 聞いている人は少し暗く */
.chara.listening { filter: brightness(0.55); }
.chara .face { font-size: 13px; font-weight: normal; opacity: 0.85; margin-top: 4px; }
/* 本番の立ち絵：メッセージボックスの上に立たせる（腰から下は絵にない） */
/* --chara-size：立ち絵の大きさ（立てる場所の高さに対する割合）。小さくするほど引きになる */
#chara-layer { --chara-size: 75%; }
.chara.has-img {
  width: auto;
  max-width: 38%;
  height: var(--chara-size);
  padding: 0;
  border-radius: 0;
}
.chara.has-img img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom center; /* 幅が足りないときは縮めて、足元をそろえる */
}
/* 中央を向くように左右反転 */
.chara.flip img { transform: scaleX(-1); }
.chara.has-img.pos-left   { left: 6%; }
.chara.has-img.pos-right  { right: 6%; }
.chara.has-img.pos-center { left: 50%; margin-left: 0; translate: -50% 0; }

/* 人影：まだ顔の分からない若い男。話している人の横（画面の中央寄り）に、1行のあいだだけ並ぶ */
.shadow-figure {
  position: absolute;
  bottom: 0;
  height: var(--chara-size); /* 絵は佐野の立ち絵と同じ大きさ・位置で作ってある */
  animation: chara-in 0.2s ease-out;
}
.shadow-figure img { display: block; height: 100%; width: auto; }
.shadow-figure.beside-left   { left: 30%; }
.shadow-figure.beside-right  { right: 30%; }
.shadow-figure.beside-center { left: 50%; translate: -50% 0; }
.shadow-name {
  position: absolute;
  top: 8%;
  left: 50%;
  translate: -50% 0;
  padding: 2px 12px;
  font-size: 14px;
  font-weight: bold;
  color: #eee;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  white-space: nowrap;
}

@keyframes chara-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

#message-box {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), var(--box-width));
  min-height: 140px;
  padding: 28px 24px 20px;
  background: rgba(10, 12, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  outline: none;
}

#speaker-name {
  position: absolute;
  top: -16px;
  left: 16px;
  padding: 4px 16px;
  font-size: 15px;
  font-weight: bold;
  background: #2a2f3a;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}
#speaker-name:empty { display: none; }

#message-text {
  margin: 0;
  font-size: 18px;
  line-height: 1.8;
  white-space: pre-wrap;
}

/* 地の文：話者名なし・少し控えめな色 */
#message-box.narration #message-text { color: #cfd6e0; }

/* 小声 */
#message-box.aside #message-text { font-size: 15px; color: #b8c0cc; }
#message-box.aside #speaker-name::after {
  content: "（小声）";
  font-weight: normal;
  font-size: 12px;
  margin-left: 4px;
}

#next-mark {
  position: absolute;
  right: 16px;
  bottom: 10px;
  font-size: 12px;
  opacity: 0;
}
#message-box.ready #next-mark {
  opacity: 1;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

/* 縦持ち：上半分に背景と立ち絵、下半分に大きめのメッセージボックス */
@media (orientation: portrait) {
  #stage { bottom: 50%; }
  #chara-layer { bottom: 8px; }
  .chara { width: 42vw; }
  .chara.pos-left   { left: 4%; }
  .chara.pos-right  { right: 4%; }
  .chara.pos-center { margin-left: -21vw; }
  .chara.has-img { max-width: 46%; }
  #chara-layer { --chara-size: 85%; }
  .chara.has-img.pos-left   { left: 0; }
  .chara.has-img.pos-right  { right: 0; }
  .chara.has-img.pos-center { margin-left: 0; }
  #message-box {
    top: calc(50% + 24px);
    bottom: 16px;
    min-height: 0;
  }
  #message-text { font-size: 17px; }
}

/* ---------- メニューのボタン（右上） ---------- */
#menu-bar {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 7; /* 事件の整理の画面より上（整理の途中でもメモを見られるように） */
  display: flex;
  gap: 8px;
}
.menu-button {
  padding: 6px 14px;
  font-size: 14px;
  color: #eee;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  cursor: pointer;
}
.menu-button:hover { background: rgba(40, 46, 60, 0.85); }
.menu-button { position: relative; }
/* 新しいものがある印 */
.menu-button.has-new::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f0b040;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.6);
}
/* 押してほしいボタン（操作説明の練習中） */
.menu-button.pulse {
  border-color: #f0b040;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(240, 176, 64, 0.45); background: rgba(90, 70, 20, 0.85); }
}
/* 仮背景の名前はボタンの下へ */
#bg-label { top: 52px; }

/* ---------- 会話ログなどの窓 ---------- */
.panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
}
.panel[hidden] { display: none; }
.panel-inner {
  display: flex;
  flex-direction: column;
  width: min(100%, 860px);
  max-height: 100%;
  background: #161a24;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}
.panel-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-note { font-size: 12px; color: #9aa3b0; }
.panel-close {
  margin-left: auto;
  padding: 6px 16px;
  font-size: 14px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 4px;
  cursor: pointer;
}
.panel-close:hover { background: #3a4150; }

.panel-body {
  margin: 0;
  padding: 8px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.panel-empty { padding: 24px 0; text-align: center; color: #9aa3b0; line-height: 1.7; }
.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}
.foot-button {
  padding: 8px 20px;
  font-size: 15px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 4px;
  cursor: pointer;
}
.foot-button:hover:not(:disabled) { background: #3a4150; }
.foot-button.primary { background: #2d4a7a; border-color: #5b7fbf; }
.foot-button.primary:hover:not(:disabled) { background: #3a5d96; }
.foot-button:disabled { opacity: 0.45; cursor: default; }
.foot-button[hidden] { display: none; }

#log-list { list-style: none; }
.log-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.log-main { flex: 1; min-width: 0; }
/* 操作説明の練習で、メモしてほしい行 */
.log-entry.target {
  margin: 0 -8px;
  padding: 10px 8px;
  background: rgba(240, 176, 64, 0.12);
  border-radius: 6px;
  outline: 1px solid rgba(240, 176, 64, 0.6);
}
.memo-toggle {
  flex: none;
  padding: 5px 10px;
  font-size: 13px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.memo-toggle:hover { background: #3a4150; }
.memo-toggle.done { color: #f0d090; border-color: #a08040; background: #3a3220; }
.log-entry.target .memo-toggle:not(.done) { border-color: #f0b040; animation: pulse 1.2s ease-in-out infinite; }
.log-name { font-size: 14px; font-weight: bold; margin-bottom: 2px; }
.log-text { font-size: 16px; line-height: 1.7; white-space: pre-wrap; }
.log-entry.narration .log-text { color: #cfd6e0; }
.log-entry.aside .log-text { font-size: 14px; color: #b8c0cc; }
.log-empty { padding: 24px 0; text-align: center; color: #9aa3b0; }

/* ---------- 台本にない案内（操作説明の練習など） ---------- */
#message-box.system #message-text { color: #f0d090; }

/* ---------- 捜査メモ ---------- */
.memo-group { padding: 8px 0 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.memo-group:last-child { border-bottom: none; }
.memo-speaker { margin: 4px 0 6px; font-size: 16px; }
.memo-part {
  display: inline-block;
  margin: 4px 0;
  padding: 1px 10px;
  font-size: 12px;
  color: #cfd6e0;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
.memo-items { list-style: none; margin: 0 0 6px; padding: 0; }
.memo-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 8px 0 8px 12px;
  border-left: 2px solid rgba(255, 255, 255, 0.15);
}
.memo-text { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.memo-item.aside .memo-text { color: #b8c0cc; }
.memo-place { grid-column: 1; font-size: 12px; color: #9aa3b0; }
.memo-remove {
  grid-column: 2;
  grid-row: 1 / span 2;
  padding: 4px 10px;
  font-size: 12px;
  color: #ccc;
  background: transparent;
  border: 1px solid #556;
  border-radius: 4px;
  cursor: pointer;
}
.memo-remove:hover { background: #3a2a2a; color: #fff; }

/* ---------- 人物ファイル ---------- */
#profile-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  padding-top: 12px;
}
.profile-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}
.profile-face {
  flex: none;
  width: 72px;
  height: 72px;
  overflow: hidden;
  border-radius: 50%;
  background: #333;
}
.profile-face img {
  display: block;
  width: 100%;
  height: auto;
  background: #2a2f3a;
  transform: scale(1.9);
  transform-origin: 50% 10%;
}
/* 人影は黒一色なので、明るめの地にして寄りを弱め、頭の形が見えるようにする */
.profile-face.shadow img { background: #6a7282; transform: scale(1.15); transform-origin: 42% 0; }
.profile-face.unknown {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #9aa3b0;
  background: #262b36;
}
.profile-body { min-width: 0; }
.profile-body h3 { margin: 2px 0 6px; font-size: 16px; }
.profile-body ul { margin: 0; padding-left: 1.2em; font-size: 14px; line-height: 1.7; }

/* ---------- 資料 ---------- */
.doc-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0 12px; }
.doc-tab {
  padding: 6px 14px;
  font-size: 14px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 16px;
  cursor: pointer;
}
.doc-tab.selected { background: #4a3f2a; border-color: #c0a060; }
.doc-paper {
  max-width: 560px;
  margin: 0 auto 8px;
  padding: 20px 24px 28px;
  color: #2a2620;
  background: #f4efe2;
  border-radius: 2px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.doc-title { font-size: 12px; color: #7a7060; margin-bottom: 16px; }
.doc-text { font-size: 20px; line-height: 1.9; text-align: center; white-space: pre-wrap; }

/* ---------- 事件の整理 ---------- */
/* 右上のメニューは見えるようにしておく（整理の途中でも捜査メモを見られるように） */
.arrange-panel { z-index: 5; padding-top: 52px; }
.arrange-text { margin: 8px 0 16px; font-size: 17px; line-height: 2; }
.arrange-text .blank {
  display: inline-block;
  margin: 0 2px;
  padding: 0 8px;
  line-height: 1.6;
  color: #ffe2a0;
  border-bottom: 2px solid #f0b040;
}
.arrange-text .blank.empty { color: #9aa3b0; border-bottom-style: dashed; }
.arrange-text .blank.ok { color: #9be0a8; border-bottom-color: #5cbf70; }
.blank-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.blank-label { flex: none; width: 1.6em; font-size: 18px; color: #f0b040; text-align: center; }
.blank-options { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.blank-option {
  padding: 7px 14px;
  font-size: 15px;
  color: #eee;
  background: #2a2f3a;
  border: 1px solid #667;
  border-radius: 4px;
  cursor: pointer;
}
.blank-option:hover:not(:disabled) { background: #3a4150; }
.blank-option.selected { background: #4a3f2a; border-color: #f0b040; color: #ffe2a0; }
.blank-option:disabled { cursor: default; opacity: 0.5; }
.blank-option.selected:disabled { opacity: 1; }
.blank-row.locked .blank-option.selected { background: #213a28; border-color: #5cbf70; color: #9be0a8; }
.blank-ok { font-size: 13px; color: #9be0a8; }
.arrange-result { min-height: 1.5em; margin: 12px 0 0; font-size: 15px; line-height: 1.6; }
.arrange-result.ok { color: #9be0a8; font-weight: bold; }
.arrange-result.ng { color: #f0a8a0; }
.arrange-hint {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(31, 47, 92, 0.5);
  border: 1px solid rgba(143, 176, 255, 0.4);
  border-radius: 6px;
}
.arrange-hint[hidden] { display: none; }
.arrange-hint-name { font-size: 13px; font-weight: bold; margin-bottom: 2px; }
.arrange-hint-text { font-size: 15px; line-height: 1.7; }

/* ---------- 操作説明・部の終わり ---------- */
.tutorial-panel { z-index: 12; }
.tutorial-inner { width: min(100%, 560px); }
/* 部の終わりは、右上のメニュー（人物ファイルなど）を開けるようにしておく */
.end-panel { z-index: 6; padding-top: 52px; }
.end-panel .panel-inner { width: min(100%, 560px); }
#tutorial-body p, #end-body p { margin: 10px 0; font-size: 16px; line-height: 1.8; }

/* ---------- お知らせ ---------- */
.toast {
  position: absolute;
  top: 56px;
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  font-size: 14px;
  color: #fff;
  background: rgba(40, 34, 20, 0.95);
  border: 1px solid #c0a060;
  border-radius: 6px;
  translate: -50% 0;
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.show { animation: toast-in 0.25s ease-out; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- スマホの横持ち（高さが低い画面） ---------- */
/* メッセージボックスを小さくして、そのぶん立ち絵を大きく出す */
@media (orientation: landscape) and (max-height: 500px) {
  #place-label { top: 8px; left: 12px; font-size: 12px; padding: 3px 10px; }
  #menu-bar { top: 6px; right: 10px; }
  .menu-button { padding: 4px 10px; font-size: 12px; }
  #bg-label { top: 40px; font-size: 10px; }
  #chara-layer { top: 8px; bottom: 112px; --chara-size: 100%; }
  #message-box {
    bottom: 8px;
    min-height: 92px;
    padding: 18px 18px 12px;
  }
  #speaker-name { top: -13px; font-size: 13px; padding: 2px 12px; }
  #message-text { font-size: 15px; line-height: 1.65; }
  #message-box.aside #message-text { font-size: 13px; }
  .log-text { font-size: 14px; }
  .panel { padding: 8px; }
  .panel-head { padding: 8px 12px; }
  .panel-foot { padding: 6px 12px; }
  .arrange-panel, .end-panel { padding-top: 40px; }
  .arrange-text { font-size: 15px; line-height: 1.8; margin: 4px 0 8px; }
  .blank-row { padding: 4px 0; }
  .blank-option { padding: 5px 10px; font-size: 13px; }
  .toast { top: 40px; font-size: 13px; }
  #tutorial-body p, #end-body p { font-size: 14px; margin: 6px 0; }
}

/* ---------- スマホを縦に持っているとき ---------- */
/* スマホは横持ちで遊ぶ。縦のときは横向きにするようお願いを出す（PCの縦長の窓には出さない） */
#rotate-notice { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    background: #111;
    text-align: center;
    font-size: 17px;
  }
  #rotate-notice p { margin: 0; }
  #rotate-notice .rotate-sub { font-size: 13px; color: #9aa3b0; line-height: 1.7; max-width: 20em; }
  .rotate-icon {
    font-size: 56px;
    animation: rotate-hint 2s ease-in-out infinite;
  }
}
@keyframes rotate-hint {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
