* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Hiragino Kaku Gothic Pro', 'Meiryo', 'Yu Gothic', sans-serif;
}

#game {
  position: relative;
  width: min(100vw, calc(100vh * 4 / 3));
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #111;
  cursor: pointer;
  user-select: none;
}

/* PC：80%サイズで中央表示 */
@media (min-width: 768px) {
  #game {
    width: min(80vw, calc(80vh * 4 / 3));
  }
}


.hidden { display: none !important; }

/* ===== タイトル画面 ===== */
#title-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(160deg, #0a0f2e 0%, #1a1040 100%);
  padding: 3% 5% 4%;
}
#title-text-block {
  text-align: center;
  flex-shrink: 0;
}
#title-main {
  color: #fff;
  font-size: clamp(16px, 3vw, 38px);
  text-shadow: 2px 2px 8px rgba(0,0,0,0.9), 0 0 24px rgba(100,180,255,0.5);
  letter-spacing: 0.06em;
  margin-bottom: 0.25em;
}
#title-sub {
  color: #aad4ff;
  font-size: clamp(11px, 1.8vw, 22px);
  text-shadow: 1px 1px 6px rgba(0,0,0,0.8);
}
#title-img {
  flex: 1;
  min-height: 0;
  max-width: 90%;
  object-fit: contain;
  border-radius: 8px;
  margin: 2% 0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#start-btn {
  flex-shrink: 0;
  padding: 0.6em 3em;
  background: linear-gradient(135deg, #2a4a9a, #3a6acc);
  color: #fff;
  border: 1px solid rgba(120,180,255,0.6);
  border-radius: 30px;
  font-size: clamp(13px, 1.8vw, 22px);
  letter-spacing: 0.2em;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(60,100,220,0.4);
  transition: background 0.2s, transform 0.1s;
}
#start-btn:hover {
  background: linear-gradient(135deg, #3a5aaa, #4a7add);
  transform: translateY(-2px);
}
#start-btn:active { transform: translateY(0); }
#bgm-notice {
  color: rgba(180, 210, 255, 0.7);
  font-size: clamp(9px, 1.1vw, 13px);
  margin-top: 0.6em;
  letter-spacing: 0.05em;
}
#bgm-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
#bgm-toggle {
  background: rgba(5, 10, 30, 0.75);
  border: 1px solid rgba(100, 150, 255, 0.4);
  border-radius: 8px;
  color: #fff;
  font-size: clamp(12px, 1.6vw, 18px);
  padding: 4px 8px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  line-height: 1;
}
#bgm-toggle:hover { background: rgba(30, 50, 120, 0.85); }
#bgm-toggle.muted { opacity: 0.45; }
#bgm-volume {
  width: clamp(44px, 5.5vw, 70px);
  accent-color: #5599ff;
  cursor: pointer;
  opacity: 0.75;
}
#bgm-volume:hover { opacity: 1; }

@keyframes blink {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.2; }
}

/* ===== ゲーム画面 ===== */
#game-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* 画像エリア */
#image-area {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* 背景 */
#bg-layer { position: absolute; inset: 0; }
#bg-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0a0d1a;
  transition: opacity 0.4s;
}

/* キャラクター */
#chara-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}
#chara-img {
  height: 85%;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(3px 3px 12px rgba(0,0,0,0.6));
  transition: opacity 0.3s;
}

/* ===== ステータスバー ===== */
#status-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(5, 10, 25, 0.75);
  border: 1px solid rgba(100, 150, 255, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  backdrop-filter: blur(4px);
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-label {
  color: #aac8ff;
  font-size: clamp(9px, 1.1vw, 13px);
  width: 3.5em;
  text-align: right;
}
.bar-track {
  width: clamp(60px, 8vw, 100px);
  height: 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}
.bar-trust { background: linear-gradient(to right, #4a9eff, #7ecfff); }
.bar-fund  { background: linear-gradient(to right, #f5a623, #ffd700); }
.bar-fame  { background: linear-gradient(to right, #a855f7, #ec4899); }
.stat-num {
  color: #fff;
  font-size: clamp(9px, 1.1vw, 13px);
  width: 2em;
  text-align: right;
}

/* ===== 章タイトルカード ===== */
#chapter-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 5, 20, 0.82);
  animation: fadeIn 0.5s ease;
}
#chapter-num {
  color: #7ab4ff;
  font-size: clamp(14px, 2vw, 26px);
  letter-spacing: 0.3em;
  margin-bottom: 0.6em;
}
#chapter-title {
  color: #fff;
  font-size: clamp(18px, 3vw, 40px);
  font-weight: bold;
  letter-spacing: 0.1em;
  text-shadow: 0 0 20px rgba(100,180,255,0.6);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }


/* ===== セリフボックス ===== */
#textbox {
  position: relative;
  flex-shrink: 0;
  height: 25%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #050a1e;
  border-top: 1px solid rgba(100,160,255,0.35);
}
#text-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 24px 44px;
}
#speaker-name {
  display: inline-block;
  color: #9dc8ff;
  font-size: clamp(11px, 1.4vw, 17px);
  font-weight: bold;
  background: rgba(30,60,130,0.7);
  border-left: 4px solid #5599ff;
  padding: 3px 14px 3px 10px;
  margin-bottom: 8px;
  min-width: 2em;
}
#text-content {
  color: #eef4ff;
  font-size: clamp(12px, 1.6vw, 19px);
  line-height: 1.75;
  min-height: 2.5em;
}
#next-btn {
  position: absolute;
  bottom: 12px;
  right: 24px;
  padding: 4px 14px;
  background: rgba(30, 60, 130, 0.7);
  color: #7ab4ff;
  border: 1px solid rgba(80, 130, 220, 0.5);
  border-radius: 14px;
  font-size: clamp(10px, 1.2vw, 14px);
  cursor: pointer;
  transition: background 0.15s;
}
#next-btn:hover { background: rgba(50, 90, 180, 0.8); color: #fff; }

#back-btn {
  position: absolute;
  bottom: 12px;
  left: 24px;
  padding: 4px 14px;
  background: rgba(20, 30, 60, 0.7);
  color: #aac8ff;
  border: 1px solid rgba(80, 130, 220, 0.4);
  border-radius: 14px;
  font-size: clamp(10px, 1.2vw, 14px);
  cursor: pointer;
  transition: background 0.15s;
}
#back-btn:hover { background: rgba(40, 60, 120, 0.85); color: #fff; }

/* ===== 選択肢 ===== */
#choice-box {
  flex-shrink: 0;
  height: 25%;
  overflow-y: auto;
  background: #050a1e;
  border-top: 1px solid rgba(100,160,255,0.35);
  padding: 14px 20px 16px;
}
#choice-prompt {
  color: #aac8ff;
  font-size: clamp(11px, 1.3vw, 16px);
  margin-bottom: 10px;
  font-weight: bold;
}
#choice-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(20,40,90,0.7);
  border: 1px solid rgba(80,130,220,0.5);
  border-radius: 6px;
  padding: 9px 14px;
  color: #ddeeff;
  font-size: clamp(11px, 1.4vw, 17px);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.5;
}
.choice-btn:hover {
  background: rgba(40,80,160,0.8);
  border-color: rgba(120,180,255,0.8);
  color: #fff;
}
.choice-label {
  font-weight: bold;
  color: #7ab4ff;
  min-width: 1.5em;
  flex-shrink: 0;
}
.choice-effect {
  font-size: 0.8em;
  color: #88aacc;
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
  padding-left: 8px;
  align-self: center;
}

/* ===== エンディング画面 ===== */
#ending-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ending-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,5,15,0.5);
  background-size: cover;
  background-position: center;
}
#ending-chara-l, #ending-chara-r {
  position: absolute;
  bottom: 0;
  height: 75%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
  filter: drop-shadow(2px 4px 12px rgba(0,0,0,0.7));
}
#ending-chara-l { left: 0; }
#ending-chara-r { right: 0; transform: scaleX(-1); }

#ending-panel {
  position: relative;
  z-index: 2;
  width: 85%;
  max-width: 600px;
  max-height: 90%;
  overflow-y: auto;
  background: rgba(5,15,40,0.72);
  border: 1px solid rgba(100,160,255,0.4);
  border-radius: 16px;
  padding: 5% 6%;
  text-align: center;
  animation: fadeIn 0.6s ease;
}
#ending-badge {
  font-size: clamp(28px, 5vw, 60px);
  margin-bottom: 0.3em;
}
#ending-title {
  color: #7ad4ff;
  font-size: clamp(16px, 2.5vw, 32px);
  font-weight: bold;
  white-space: pre-line;
  margin-bottom: 0.8em;
}
#ending-text {
  color: #cce0ff;
  font-size: clamp(11px, 1.4vw, 17px);
  line-height: 1.8;
  white-space: pre-wrap;
  margin-bottom: 1.2em;
  text-align: left;
}
#ending-score {
  color: #aac8ff;
  font-size: clamp(11px, 1.3vw, 16px);
  margin-bottom: 1.5em;
  background: rgba(20,40,90,0.5);
  border-radius: 8px;
  padding: 0.6em 1em;
}
#btn-retry {
  padding: 0.6em 2.5em;
  background: #2a4a8a;
  color: #fff;
  border: 1px solid #5588cc;
  border-radius: 20px;
  font-size: clamp(12px, 1.4vw, 17px);
  cursor: pointer;
  transition: background 0.2s;
}
#btn-retry:hover { background: #3a5faa; }

/* ===== モバイル（縦長画面） ===== */
/* ゲーム全体を縦に伸ばし、画像サイズはそのまま、テキストを3倍に */
@media (max-width: 767px) {
  #game {
    aspect-ratio: unset;
    height: calc(100vw * 1.3125); /* 75vw(画像4:3) + 56.25vw(テキスト3倍) */
  }
  #image-area {
    height: 75vw; /* 明示的に指定してキャラ画像のheight:85%を正しく計算させる */
  }
  #textbox {
    height: 56.25vw; /* 元の25%の3倍 */
  }
  #choice-box {
    height: 56.25vw;
  }
}
