/* ゲーム画面の見た目。色はここの変数だけで変えられるようにしてある。 */
:root {
  --bg: #1a1420;
  --panel: rgba(26, 20, 32, 0.86);
  --panel-solid: #241b2c;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f6eef3;
  --muted: #bfaebb;
  --accent: #e89ab5;
  --accent-strong: #f2b8cc;
  --radius: 14px;
  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #0e0b12;
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
}

.screen { position: absolute; inset: 0; }

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #2a1420; font-weight: 700; }
.btn.primary:hover { background: var(--accent-strong); }

/* ---- タイトル ---- */
.title-screen {
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
  background: #140f19;
}
/* アジトの背景を暗くして敷く */
.title-bg {
  position: absolute;
  inset: 0;
  background: url("/assets/bg/azito_night.webp") center / cover no-repeat;
  filter: brightness(0.55) saturate(1.1);
}
/* 常連の立ち絵を、背景の上に横一列で並べる */
.title-cast { position: absolute; inset: auto 0 0 0; height: 78%; pointer-events: none; }
.title-chara {
  position: absolute;
  bottom: 0;
  height: 100%;
  transform: translateX(-50%);
  filter: brightness(0.7);
}
/* 横長の画面では、メニューを左に置き、キャラを右半分に並べる（KOTAYAが隠れないように） */
.title-screen { justify-items: start; padding-left: 5%; }
.title-chara[data-i="0"] { left: 44%; height: 84%; }
.title-chara[data-i="1"] { left: 58%; height: 84%; }
.title-chara[data-i="2"] { left: 73%; filter: none; z-index: 1; }
.title-chara[data-i="3"] { left: 90%; height: 92%; }
.title-cast::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg, transparent 40%, rgba(12, 8, 18, 0.9) 100%);
}
.title-inner {
  position: relative;
  z-index: 3;
  width: min(380px, 100%);
  text-align: center;
  padding: 24px 20px;
  border-radius: var(--radius);
  background: rgba(14, 10, 20, 0.62);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
}
.title-menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.small { min-height: 34px; padding: 0 14px; font-size: 13px; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #2a1420; }

/* ---- 章の題 ---- */
.chapter-card {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  background: rgba(10, 6, 16, 0.78);
  cursor: pointer;
  animation: card-in 0.5s ease both;
}
.chapter-card.out { animation: card-out 0.35s ease both; }
.chapter-no { margin: 0; font-size: 14px; letter-spacing: 0.4em; color: var(--accent-strong); }
.chapter-title {
  margin: 0;
  padding: 10px 28px;
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
  border-top: 1px solid rgba(232, 72, 138, 0.6);
  border-bottom: 1px solid rgba(86, 199, 224, 0.6);
}
@keyframes card-in { from { opacity: 0; letter-spacing: 0.3em; } to { opacity: 1; } }
@keyframes card-out { to { opacity: 0; } }

/* ---- スタッフロール ---- */
.credits-screen {
  position: absolute;
  inset: 0;
  z-index: 13;
  overflow: hidden;
  background: #0b0810 center / cover no-repeat;
  cursor: pointer;
}
.credits-roll { position: absolute; left: 0; right: 0; top: 0; text-align: center; padding: 0 16px; }
.credits-title { margin: 0 0 80px; font-size: clamp(26px, 6vw, 36px); font-weight: 700; }
.credits-section { margin-bottom: 56px; }
.credits-heading { margin: 0 0 12px; font-size: 13px; letter-spacing: 0.3em; color: var(--accent-strong); }
.credits-name { margin: 0 0 8px; font-size: 18px; }
.credits-closing { margin: 120px 0 0; font-size: 16px; color: var(--muted); }
.credits-skip { position: absolute; right: 16px; bottom: 12px; margin: 0; font-size: 11px; color: var(--muted); }

/* ---- エンディング ---- */
.ending-screen {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px 16px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(232, 72, 138, 0.28), transparent 65%), #0e0a14;
}
/* 画面ごとフェードすると下のゲーム画面が透けるので、フェードは中身だけ */
.ending-screen:not(.has-still) .ending-info { animation: card-in 1.2s ease both; }
.ending-info { display: grid; gap: 14px; }
/* エンディングの一枚絵: 先に絵だけを見せて、あとから文字が下に出る */
.ending-still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; animation: still-in 2s ease both; }
.ending-screen.has-still { place-content: end stretch; padding: 0; }
.ending-screen.has-still .ending-info {
  position: relative;
  z-index: 1;
  padding: 72px 16px max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, rgba(14, 10, 20, 0.82) 38%, rgba(14, 10, 20, 0.94));
  animation: card-in 1.2s ease 2.2s both;
}
.ending-screen.has-still .ending-info { gap: 8px; padding-top: 56px; }
.ending-screen.has-still .ending-title { font-size: clamp(22px, 5vw, 32px); }
.ending-screen.has-still .ending-actions { display: flex; flex-wrap: wrap; justify-content: center; width: min(760px, 100%); }
.ending-screen.has-still .ending-actions .btn { flex: 1 1 180px; }
.ending-hint { margin: 0; font-size: 11px; color: var(--muted); }
.ending-screen:not(.has-still) .ending-hint { display: none; }
/* 絵のところをタップすると文字をしまって絵だけ見せる */
.ending-screen.art-only .ending-info { opacity: 0; pointer-events: none; animation: none; transition: opacity 0.4s; }
.ending-screen.has-still .ending-info { transition: opacity 0.4s; animation: none; }
.ending-tap { position: absolute; right: 16px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 1; margin: 0; font-size: 12px; color: rgba(255, 255, 255, 0.75); text-shadow: 0 1px 4px #000; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
.ending-screen.art-only .ending-tap { opacity: 1; transition-delay: 2s; }
@keyframes still-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }
.ending-kind { margin: 0; font-size: 15px; letter-spacing: 0.5em; color: var(--muted); }
.ending-screen[data-kind="true"] .ending-kind { color: #f3cf6a; }
.ending-screen[data-kind="friend"] .ending-kind { color: #cfd6e4; }
.ending-screen[data-kind="normal"] .ending-kind { color: #d49a6a; }
.ending-title { margin: 0; font-size: clamp(26px, 7vw, 40px); line-height: 1.4; }
.ending-count { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.ending-actions { display: grid; gap: 10px; width: min(320px, 100%); margin: 0 auto; }

/* ---- 図鑑 ---- */
.zukan-screen { overflow-y: auto; background: linear-gradient(170deg, #1d1528, #0e0a14); padding: 16px; }
.zukan-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.zukan-head h2 { margin: 0; font-size: 22px; }
.zukan-count { margin: 0; flex: 1; font-size: 13px; color: var(--muted); }
.zukan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.zukan-card {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 0 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  text-align: center;
  cursor: pointer;
}
.zukan-card:hover:not(:disabled) { border-color: var(--accent); }
.zukan-thumb { display: block; height: 180px; overflow: hidden; background: rgba(20, 27, 58, 0.6); }
.zukan-thumb img { width: 100%; height: auto; margin-top: -4%; object-fit: cover; }
.zukan-card.locked { cursor: default; }
/* まだ出会っていないキャラは、グレーのシルエット */
.zukan-card.locked .zukan-thumb img { filter: brightness(0) invert(0.35); opacity: 0.6; }
.zukan-name { font-weight: 700; font-size: 15px; }
.zukan-role { font-size: 11px; color: var(--muted); padding: 0 6px; }
.zukan-mark {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #1a1420;
}
.zukan-card > .zukan-mark { position: absolute; top: 8px; right: 8px; }
.zukan-mark.true { background: #f3cf6a; }
.zukan-mark.friend { background: #cfd6e4; }
.zukan-mark.normal { background: #d49a6a; }
.zukan-mark.off { background: transparent; color: var(--muted); border: 1px dashed var(--line); }
.zukan-detail { position: absolute; inset: 0; z-index: 2; overflow-y: auto; padding: 16px; background: #120d1a; }
.zukan-detail-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; max-width: 900px; margin: 0 auto; }
.zukan-big-wrap { border-radius: var(--radius); background: radial-gradient(ellipse at 50% 30%, rgba(232, 72, 138, 0.25), rgba(20, 27, 58, 0.6)); overflow: hidden; }
.zukan-big { width: 100%; display: block; }
.zukan-info { display: grid; gap: 12px; align-content: start; }
.zukan-info .zukan-role { font-size: 13px; padding: 0; margin: 0; }
.zukan-detail-name { margin: 0; font-size: 28px; }
.zukan-marks { display: flex; gap: 6px; flex-wrap: wrap; }
.zukan-profile { margin: 0; line-height: 1.9; }
.zukan-credit { margin: 0; font-size: 13px; color: var(--accent-strong); }
.zukan-soon { margin: 0; font-size: 12px; color: var(--muted); }
.zukan-sub { margin: 4px 0 -4px; font-size: 12px; color: var(--muted); }
.zukan-costumes { display: flex; gap: 6px; flex-wrap: wrap; }
.title-sub { margin: 0 0 8px; color: var(--muted); font-size: 13px; letter-spacing: 0.08em; }
.title-text { margin: 0 0 16px; font-size: clamp(26px, 7vw, 40px); line-height: 1.35; }
.access-badge {
  display: inline-block;
  margin: 0 0 28px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.access-badge[data-access="member"], .access-badge[data-access="cast"] { border-color: var(--accent); color: var(--accent-strong); }
.title-menu { display: grid; gap: 12px; }
.title-note { margin-top: 28px; font-size: 12px; color: var(--muted); }

/* ---- ゲーム ---- */
.game-screen { cursor: pointer; user-select: none; }
.bg {
  position: absolute;
  inset: 0;
  background-color: #231a2b;
  background-size: cover;
  background-position: center;
  transition: background-image 0.4s;
}
/* 背景の絵がまだ無いとき、どこの場面かを左上に出す */
.bg[data-label]:not([data-label=""])::after {
  content: attr(data-label);
  position: absolute;
  top: 12px;
  left: 16px;
  padding: 2px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12px;
  color: var(--muted);
}

.stage {
  position: absolute;
  inset: 0 0 18% 0;
  overflow: hidden;
  /* 立ち絵どうしの前後（話している人を手前に）を、この中だけで決める。文字窓より前に出さない */
  z-index: 0;
  pointer-events: none;
}
/* 立ち位置と大きさは main.ts の layoutStage() が人数に合わせて決める（left / height を直接入れる） */
.chara { position: absolute; bottom: 0; transform: translateX(-50%); transition: filter 0.2s; }
/* 誰かが話しているとき、話していない人。暗い背景でも差が分かるように、色も少し落とす。
   地の文のときは誰も暗くしない（その人と話している場面なので） */
.chara.dim { filter: brightness(0.45) saturate(0.7); }
/* 立ち絵が出るとき・服が変わるとき（main.ts の renderVisual） */
.chara.appear { animation: chara-in 0.3s ease both; }
.chara.leave { animation: chara-out 0.25s ease both; }
@keyframes chara-in { from { opacity: 0; translate: 0 12px; } to { opacity: 1; translate: 0 0; } }
@keyframes chara-out { to { opacity: 0; } }
.chara.placeholder {
  border-radius: 48% 48% 10px 10px / 30% 30% 10px 10px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--chara-color) 70%, transparent), color-mix(in srgb, var(--chara-color) 25%, transparent));
  border: 2px dashed color-mix(in srgb, var(--chara-color) 80%, white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.ph-name { font-size: 18px; font-weight: 700; }
.ph-face { font-size: 13px; opacity: 0.85; }

.textbox {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  min-height: 30%;
  padding: 26px 20px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(6px);
}
.namebox {
  position: absolute;
  top: -16px;
  left: 16px;
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--panel-solid);
  border: 2px solid var(--name-color, var(--accent));
  font-weight: 700;
  font-size: 15px;
}
.text { margin: 0; font-size: 17px; line-height: 1.85; white-space: pre-wrap; word-break: break-word; }
/* 文字送りで、まだ出ていない部分。場所は取ったまま見えなくする（改行位置を最初から決めるため） */
.text-rest { visibility: hidden; }
/* 地の文は、台詞と窓の色を変える。台詞＝紫がかった黒にピンクの縁、地の文＝夜の紺にシアンの縁 */
.textbox { transition: background-color 0.2s, border-color 0.2s; }
.textbox[data-narration="false"] { border-color: rgba(232, 72, 138, 0.45); }
.textbox[data-narration="true"] { background: rgba(14, 22, 52, 0.84); border-color: rgba(86, 199, 224, 0.4); }
.textbox[data-narration="true"] .text { color: #d3dcf0; }
.textbox[data-narration="true"] .next-mark { color: #56c7e0; }
.next-mark { position: absolute; right: 18px; bottom: 10px; color: var(--accent); font-size: 12px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

.quick {
  position: absolute;
  top: -40px;
  right: 4px;
  display: flex;
  gap: 6px;
}
.quick button {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 15, 25, 0.75);
  font-size: 12px;
  cursor: pointer;
}
.quick button.on { background: var(--accent); color: #2a1420; border-color: var(--accent); }

.choices {
  position: absolute;
  inset: 0 0 30% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(10, 6, 14, 0.35);
  cursor: default;
}
.choice {
  width: min(520px, 100%);
  min-height: 52px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--panel);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.choice:hover { background: rgba(232, 154, 181, 0.25); }
.choice:active { transform: scale(0.98); }

.debug {
  position: absolute;
  top: 8px;
  right: 8px;
  max-width: 60%;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.7);
  font: 11px/1.5 ui-monospace, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* ---- モーダル ---- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 5, 12, 0.6);
}
.modal-panel {
  width: min(480px, 100%);
  max-height: 88dvh;
  overflow: auto;
  padding: 24px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  cursor: default;
}
.modal-title { margin: 0 0 16px; font-size: 20px; text-align: center; }
.modal[data-variant="ending"] .modal-title { font-size: 30px; letter-spacing: 0.2em; color: var(--accent-strong); }
.modal-text { margin: 0 0 16px; line-height: 1.8; text-align: center; }
.modal-text.small { font-size: 13px; color: var(--muted); }
.modal-body > .btn, #modal-body > .btn { display: flex; width: 100%; margin-top: 8px; }
.modal-actions { display: grid; gap: 10px; }
.menu-list { display: grid; gap: 10px; }

.slot-list { display: grid; gap: 8px; margin-bottom: 8px; }
.slot {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
  cursor: pointer;
}
.slot:disabled { opacity: 0.45; cursor: default; }
.slot:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.slot-no { flex: 0 0 52px; font-weight: 700; color: var(--accent-strong); }
.slot-info { display: grid; gap: 2px; min-width: 0; }
.slot-meta { font-size: 12px; color: var(--muted); }
.slot-excerpt { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-list { max-height: 55dvh; overflow: auto; display: grid; gap: 12px; margin-bottom: 8px; }
.log-entry { display: grid; gap: 2px; }
.log-name { font-size: 12px; color: var(--accent-strong); }
.log-text { line-height: 1.7; }

.setting { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 18px; }
.setting-label { font-size: 14px; }
.setting-value { font-size: 12px; color: var(--muted); text-align: right; }
.setting input[type="range"] { width: 100%; accent-color: var(--accent); }
.setting.check { grid-template-columns: auto 1fr; align-items: center; font-size: 14px; }
.setting.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.ending-list { margin: 0 0 16px; padding-left: 1.2em; line-height: 2; }

.toast {
  position: absolute;
  left: 50%;
  top: 16px;
  z-index: 20;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel-solid);
  border: 1px solid var(--accent);
  font-size: 14px;
  line-height: 1.6;
}

@media (max-width: 600px) {
  .text { font-size: 16px; }
  .textbox { min-height: 32%; padding: 24px 16px 18px; }
  .stage { inset: 0 0 26% 0; }
  /* スマホ縦: キャラを上に並べ、メニューを下に */
  .title-screen { justify-items: center; align-items: end; padding: 16px; }
  .title-cast { inset: 0 0 auto 0; height: 58%; }
  .title-chara[data-i="0"] { left: 12%; }
  .title-chara[data-i="1"] { left: 34%; }
  .title-chara[data-i="2"] { left: 60%; }
  .title-chara[data-i="3"] { left: 88%; }
  .zukan-detail-inner { grid-template-columns: 1fr; }
  .zukan-grid { grid-template-columns: repeat(2, 1fr); }
  .zukan-thumb { height: 150px; }
}
