/* ==========================================================================
   終わらない街からの脱出（仮）- スタイルシート
   ========================================================================== */

:root {
  --bg-color: #0d0e12;
  --text-main: #d8d9de;
  --text-muted: #8b8f9e;
  --accent-red: #9e1b1b;
  --accent-blue: #182b45;
  --fusuma-bg: #ece7db;
  --fusuma-ink: #1a1714;
  --box-bg: rgba(14, 16, 22, 0.88);
  --border-color: rgba(90, 95, 115, 0.35);
  --choice-bg: rgba(26, 30, 42, 0.9);
  --choice-hover: rgba(45, 54, 77, 0.95);
  --choice-border: rgba(110, 120, 145, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: 'Shippori Mincho', 'Yu Mincho', 'Hiragino Mincho ProN', serif;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  user-select: none;
}

/* ゲームコンテナ */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 600px; /* スマートフォン最適化、PC中央配置 */
  margin: 0 auto;
  background-color: #08090c;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
}

/* ==========================================================================
   レイヤー構造
   ========================================================================== */
.layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* 1. 背景レイヤー */
#layer-background {
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1b202d 0%, #08090c 100%);
  transition: background 0.8s ease;
}

.bg-placeholder {
  text-align: center;
  opacity: 0.15;
  pointer-events: none;
}

#bg-location-display {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: 0.5rem;
}

#bg-time-display {
  font-size: 1.5rem;
  margin-top: 0.5rem;
  letter-spacing: 0.2rem;
}

/* 2. 演出・エフェクトレイヤー */
#layer-effect {
  z-index: 20;
  pointer-events: none;
}

#vignette-effect {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.75) 90%, #000 100%);
  transition: opacity 0.5s ease;
}

/* 狂気度が高いときの青黒い影 */
.insanity-heavy #vignette-effect {
  background: radial-gradient(circle at center, transparent 20%, rgba(10, 20, 45, 0.85) 75%, #050814 100%);
}

/* 3. キャラクターレイヤー */
#layer-character {
  z-index: 30;
  pointer-events: none;
}

/* 4. UIレイヤー */
#layer-ui {
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  pointer-events: auto;
}

/* ==========================================================================
   ヘッダーとステータス
   ========================================================================== */
#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  background: rgba(158, 27, 27, 0.25);
  border: 1px solid rgba(158, 27, 27, 0.6);
  color: #ff9e9e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.location-badge {
  background: rgba(24, 43, 69, 0.4);
  border: 1px solid rgba(70, 110, 170, 0.5);
  color: #a4ccff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.time-badge {
  font-size: 0.85rem;
  color: #d1b87a;
  background: rgba(80, 65, 30, 0.3);
  border: 1px solid rgba(160, 130, 60, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
}

.header-right {
  display: flex;
  gap: 8px;
}

.ui-btn {
  background: rgba(30, 35, 48, 0.8);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ui-btn:hover {
  background: rgba(50, 60, 85, 0.9);
  border-color: #7b88aa;
}

/* 精神状態インジケーター */
#sanity-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-label {
  letter-spacing: 0.05rem;
}

#sanity-status-text {
  color: #8ed6a5;
  transition: color 0.4s ease;
}

.insanity-mild #sanity-status-text {
  color: #d6b88e;
}

.insanity-heavy #sanity-status-text {
  color: #e06c6c;
}

/* ==========================================================================
   メインエリア（テキストボックス & 選択肢）
   ========================================================================== */
#game-main {
  flex: 1;
  min-height: 0; /* flexbox内スクロールに必須 */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  overflow: hidden;
}

/* テキストボックス */
.novel-box {
  background: var(--box-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 14px;
  min-height: 70px;
  max-height: 28vh;
  flex-shrink: 0;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.typewriter-text {
  font-size: 0.92rem;
  line-height: 1.65;
  letter-spacing: 0.04rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.feedback-text {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #f7a6a6;
  font-style: italic;
  min-height: 1.2rem;
}

/* 選択肢 */
.choice-container {
  flex: 1 1 auto;
  min-height: 0; /* 重要：中身に応じてスクロール */
  max-height: 52vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
  padding-bottom: 12px; /* 最後の選択肢が切れずに見えるための下部余白 */
}

/* カスタムスクロールバー */
.novel-box::-webkit-scrollbar,
.choice-container::-webkit-scrollbar,
.fusuma-body::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(90, 95, 115, 0.4);
  border-radius: 2px;
}

.choice-btn {
  flex-shrink: 0; /* ボタンが潰れないように固定 */
  background: var(--choice-bg);
  color: var(--text-main);
  border: 1px solid var(--choice-border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.86rem;
  font-family: inherit;
  text-align: left;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.choice-btn:hover {
  background: var(--choice-hover);
  border-color: #8da2d4;
  transform: translateY(-1px);
}

.choice-btn:active {
  transform: translateY(0);
}

.choice-btn.primary {
  border-color: rgba(180, 50, 50, 0.6);
}

.choice-btn.primary:hover {
  background: rgba(60, 20, 25, 0.9);
}

/* ==========================================================================
   モーダル
   ========================================================================== */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: #141720;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  max-height: 80%;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.9);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.modal-header h3 {
  font-size: 1.1rem;
  letter-spacing: 0.05rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

/* アイテムグリッド */
.inventory-grid {
  margin-top: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  background: rgba(25, 30, 42, 0.7);
  border: 1px solid rgba(80, 90, 115, 0.3);
  padding: 10px 12px;
  border-radius: 6px;
}

.item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #f2c078;
}

.item-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 24px 0;
}

/* ==========================================================================
   ふすまの因果図モーダル
   ========================================================================== */
.fusuma-paper {
  background: var(--fusuma-bg);
  color: var(--fusuma-ink);
  border: 2px solid #8f7f68;
}

.fusuma-paper .modal-header {
  border-color: rgba(80, 60, 40, 0.3);
}

.fusuma-paper .modal-header h3 {
  color: #3b2818;
  font-family: 'Yuji Boku', serif;
  font-size: 1.3rem;
}

.fusuma-paper .modal-close {
  color: #6b5843;
}

.fusuma-body {
  overflow-y: auto;
  margin-top: 12px;
  font-size: 0.85rem;
  line-height: 1.6;
}

.fusuma-lead {
  font-size: 0.8rem;
  color: #6b5c49;
  margin-bottom: 12px;
  border-bottom: 1px dashed rgba(80, 60, 40, 0.3);
  padding-bottom: 6px;
}

.fusuma-records {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-stamp {
  background: rgba(255, 255, 255, 0.6);
  border-left: 4px solid var(--accent-red);
  padding: 8px 10px;
  border-radius: 0 4px 4px 0;
  position: relative;
}

.stamp-title {
  font-weight: 600;
  color: var(--accent-red);
  font-size: 0.88rem;
}

.stamp-desc {
  font-size: 0.78rem;
  color: #40362c;
  margin-top: 2px;
}

/* ==========================================================================
   死亡画面
   ========================================================================== */
.death-theme {
  background: rgba(12, 4, 6, 0.95);
  animation: deathFadeIn 1s ease;
}

@keyframes deathFadeIn {
  from { opacity: 0; background: #000; }
  to { opacity: 1; background: rgba(12, 4, 6, 0.95); }
}

.death-content {
  text-align: center;
  max-width: 440px;
  padding: 24px 16px;
}

.death-title {
  font-family: 'Yuji Boku', serif;
  font-size: 2.2rem;
  color: var(--accent-red);
  margin-bottom: 16px;
  letter-spacing: 0.2rem;
  text-shadow: 0 0 15px rgba(230, 30, 30, 0.5);
}

.death-reason {
  font-size: 1rem;
  line-height: 1.7;
  color: #e3d2d2;
  margin-bottom: 20px;
  padding: 12px;
  background: rgba(255, 0, 0, 0.05);
  border: 1px solid rgba(160, 40, 40, 0.3);
  border-radius: 6px;
}

.death-knowledge {
  font-size: 0.85rem;
  color: #c99393;
  margin-bottom: 28px;
  font-style: italic;
}

.restart-btn {
  background: #871414;
  color: #fff;
  border: 1px solid #c22929;
  border-radius: 6px;
  padding: 12px 28px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(135, 20, 20, 0.4);
  transition: all 0.2s ease;
}

.restart-btn:hover {
  background: #a81c1c;
  transform: scale(1.03);
}
