/* ==========================================================
   Dolce andante  style.css
   - 水彩・淡い色調・2005年ノスタルジー
   - スマホ縦・横、PCの両対応
   ========================================================== */

:root {
  --bg-cream: #f6f1e4;
  --bg-paper: #ece4d0;
  --ink: #3a2f28;
  --ink-soft: #6b5c4e;
  --accent: #8a6a8c;      /* くすんだ藤色 */
  --accent-2: #c9a55a;    /* 銀杏色 */
  --shadow: rgba(58, 47, 40, 0.15);
  --radius: 14px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 縦画面検知：スマホが縦のときにローテーション促し画面を表示 */
#rotate-prompt {
  display: none;
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #1a1510, #2a2215);
  color: #f6f1e4;
  z-index: 10000;
  align-items: center; justify-content: center;
  font-family: "Hiragino Mincho ProN","游明朝","Yu Mincho",serif;
}
#rotate-prompt .rotate-inner {
  text-align: center;
  padding: 20px 30px;
  max-width: 80vw;
}
#rotate-prompt .rotate-icon {
  font-size: 4rem;
  display: inline-block;
  transform: rotate(-90deg);
  animation: rotate-wiggle 2s ease-in-out infinite;
  margin-bottom: 20px;
}
#rotate-prompt p {
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
#rotate-prompt .rotate-sub {
  font-size: 0.85rem;
  color: #c9a55a;
  line-height: 1.8;
}
@keyframes rotate-wiggle {
  0%, 100% { transform: rotate(-90deg); }
  50%      { transform: rotate(0deg); }
}
/* 縦画面かつモバイルサイズのときだけローテーション画面を表示 */
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-prompt { display: flex; }
  #app           { display: none; }
}

body {
  font-family: "Hiragino Mincho ProN", "游明朝", "Yu Mincho", serif;
  color: var(--ink);
  background: #1a1510;
  line-height: 1.7;
  letter-spacing: 0.02em;
}

#app {
  position: fixed; inset: 0;
  display: flex; justify-content: center; align-items: center;
}

/* ========== 共通：画面切替 ========== */
.screen {
  position: absolute; inset: 0;
  display: none;
}
.screen.active { display: block; }

/* ========== タイトル画面 ========== */
#title-screen { overflow: hidden; }

.title-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 70% 80%, rgba(201, 165, 90, 0.35), transparent 60%),
    radial-gradient(ellipse at 30% 20%, rgba(138, 106, 140, 0.25), transparent 60%),
    linear-gradient(180deg, #f7ead0 0%, #dfd0b0 100%);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* 水彩テクスチャを擬似的に */
  filter: blur(0.3px);
}
.title-bg::after {
  content: "";
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence baseFrequency='0.7' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.12'/></svg>");
  opacity: 0.5; pointer-events: none;
}

.title-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 6vh 8vw;
}

.game-title {
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  font-weight: 300;
  color: var(--ink);
  letter-spacing: 0.18em;
  text-shadow: 0 2px 8px rgba(255,255,255,0.5);
  margin-bottom: 0.6em;
  font-family: "Didot","Bodoni 72","Hiragino Mincho ProN", serif;
}
.title-sub {
  font-size: clamp(0.9rem, 2.2vw, 1.2rem);
  color: var(--ink-soft);
  margin-bottom: 2.5em;
  letter-spacing: 0.15em;
}

/* タイトル画像が読み込まれたら、テキストのロゴ・サブタイトルを非表示にして
   メニューだけを下部に押し下げる */
#title-screen.has-image .game-title,
#title-screen.has-image .title-sub {
  display: none;
}
#title-screen.has-image .title-inner {
  justify-content: flex-end;
  padding-bottom: 8vh;
}
.title-menu {
  display: flex; flex-direction: column; gap: 14px;
  width: min(320px, 80vw);
}
.title-btn {
  padding: 14px 28px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 252, 240, 0.7);
  border: 1px solid rgba(58, 47, 40, 0.2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(2px);
  letter-spacing: 0.1em;
}
.title-btn:hover, .title-btn:active {
  background: rgba(255, 252, 240, 0.95);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}
.title-foot {
  position: absolute; bottom: 14px;
  font-size: 0.75rem;
  color: var(--ink-soft);
  letter-spacing: 0.2em;
}

/* ========== ゲーム画面 ========== */
#game-screen { background: #1a1510; }

.bg-layer, .cg-layer {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity 0.6s ease;
}
.cg-layer { pointer-events: none; opacity: 0; }
.cg-layer.show { opacity: 1; }

.bg-layer {
  background-color: #f6f1e4;  /* プレースホルダー */
  background-image:
    linear-gradient(180deg, rgba(247,234,208,0.9), rgba(223,208,176,0.9)),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence baseFrequency='0.015' numOctaves='2'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/></svg>");
}

/* キャラクター立ち絵 */
.chara-layer {
  position: absolute; inset: 0;
  pointer-events: none;
}
.chara-slot {
  position: absolute;
  bottom: 70px;
  height: 85vh;
  width: 40vw;
  background-repeat: no-repeat;
  background-position: bottom center;
  background-size: contain;
  transition: opacity 0.4s ease, transform 0.4s ease;
  opacity: 0;
}
.chara-slot[data-pos="left"]   { left: 2vw; }
.chara-slot[data-pos="center"] { left: 30vw; }
.chara-slot[data-pos="right"]  { right: 2vw; }
.chara-slot.show { opacity: 1; }
.chara-slot.dim  { opacity: 0.75; filter: brightness(0.85) saturate(0.85); }

/* 日付バナー */
.date-banner {
  position: absolute; top: 16px; left: 16px;
  padding: 6px 14px;
  background: rgba(255, 252, 240, 0.75);
  border-left: 3px solid var(--accent-2);
  font-size: 0.9rem;
  color: var(--ink);
  letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 0.4s ease;
  backdrop-filter: blur(2px);
}
.date-banner.show { opacity: 1; }

/* テキストボックス
   合計の高さを固定。話者ありなら最大2行、話者なしなら最大3行のテキストが収まる。
   話者がない時は text が上から始まるように flex で詰める。 */
.textbox {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 3%;
  height: 144px;             /* 固定。3行テキスト + パディング相当 */
  padding: 18px 24px 22px;
  background: rgba(255, 252, 240, 0.92);
  border: 1px solid rgba(58,47,40,0.15);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px var(--shadow);
  backdrop-filter: blur(6px);
  cursor: pointer;
  z-index: 5;
  display: flex;
  flex-direction: column;
}
.speaker {
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 6px;
  letter-spacing: 0.08em;
  line-height: 1.4em;
  flex: 0 0 auto;
}
.speaker:empty { display: none; }   /* 話者なしなら詰める */
.text {
  font-size: clamp(0.95rem, 2.3vw, 1.1rem);
  color: var(--ink);
  line-height: 1.85;
  white-space: pre-wrap;
  flex: 1 1 auto;
  overflow: hidden;
}
.next-indicator {
  position: absolute;
  right: 16px; bottom: 8px;
  color: var(--accent);
  font-size: 0.9rem;
  animation: blink 1.2s infinite;
  opacity: 0;
}
.next-indicator.show { opacity: 1; }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* 選択肢 */
.choices {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 20px;
  background: rgba(26, 21, 16, 0.35);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.choices.show { display: flex; }
.choice-btn {
  width: min(620px, 92vw);
  padding: 16px 20px;
  font-size: clamp(0.95rem, 2.2vw, 1.05rem);
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 252, 240, 0.95);
  border: 1px solid rgba(58,47,40,0.25);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  line-height: 1.6;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px var(--shadow);
}
.choice-btn:hover {
  transform: translateY(-2px);
  background: #fffcf0;
  box-shadow: 0 8px 22px var(--shadow);
  border-color: var(--accent);
}

/* ツールバー */
.toolbar {
  position: absolute;
  right: 10px; top: 10px;
  display: flex; gap: 6px;
  z-index: 6;
}
.tool-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 252, 240, 0.8);
  border: 1px solid rgba(58,47,40,0.2);
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.08em;
  min-width: 44px;
  min-height: 32px;
}
.tool-btn.active {
  background: var(--accent);
  color: #fff;
}

/* 巻き戻しインジケーター */
.review-indicator {
  position: absolute;
  top: 60px; right: 12px;
  padding: 6px 12px;
  background: rgba(138, 106, 140, 0.92);
  color: #fff;
  font-size: 0.8rem;
  border-radius: 8px;
  letter-spacing: 0.1em;
  display: flex; gap: 10px; align-items: center;
  z-index: 7;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.review-indicator.hidden { display: none; }
.review-indicator .review-hint {
  font-size: 0.7rem;
  opacity: 0.8;
  border-left: 1px solid rgba(255,255,255,0.4);
  padding-left: 10px;
}

/* オーバーレイ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(26, 21, 16, 0.7);
  display: flex; justify-content: center; align-items: center;
  z-index: 100;
  padding: 20px;
}
.overlay.hidden { display: none; }

.menu-inner, .log-inner, .gallery-inner {
  background: var(--bg-cream);
  border-radius: var(--radius);
  padding: 28px;
  width: min(600px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.menu-inner h2, .log-inner h2, .gallery-inner h2 {
  font-size: 1.4rem;
  color: var(--ink);
  margin-bottom: 16px;
  letter-spacing: 0.1em;
  border-bottom: 1px solid rgba(58,47,40,0.2);
  padding-bottom: 8px;
}
.menu-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid rgba(58,47,40,0.2);
  border-radius: 10px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
}
.menu-btn:hover { background: #fffcf0; transform: translateY(-1px); }
.menu-note { color: var(--ink-soft); font-size: 0.85rem; margin-top: 10px; }

/* ログ */
#log-content {
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px;
  background: #fff;
  border: 1px solid rgba(58,47,40,0.15);
  border-radius: 8px;
  margin-bottom: 14px;
}
.log-entry {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dotted rgba(58,47,40,0.2);
}
.log-entry:last-child { border-bottom: none; }
.log-speaker { font-size: 0.85rem; color: var(--accent); margin-bottom: 4px; }
.log-text { font-size: 0.95rem; color: var(--ink); }

/* ギャラリー */
#gallery-content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  min-height: 200px;
}
.gallery-item {
  aspect-ratio: 16 / 9;
  background: #ddd;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
}
.gallery-hint { color: var(--ink-soft); grid-column: 1 / -1; text-align: center; padding: 40px 0; }

/* エンディング画面 */
#ending-screen { background: #0b0808; color: #f6f1e4; cursor: pointer; }
.ending-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 40px 20px;
  text-align: center;
  overflow-y: auto;
}
/* 縦方向の余白で中央寄せしつつ、オーバーフロー時はスクロール可 */
.ending-inner > :first-child { margin-top: auto; }
.ending-inner > :last-child  { margin-bottom: auto; }
#ending-title {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  color: #c9a55a;
  letter-spacing: 0.2em;
  margin-bottom: 24px;
  font-weight: 300;
}
#ending-text {
  font-size: clamp(0.95rem, 2.3vw, 1.1rem);
  line-height: 2;
  color: #e4dccb;
  max-width: 640px;
  margin-bottom: 40px;
  white-space: pre-wrap;
}

/* ========== モバイル調整 ========== */
@media (max-width: 640px) {
  .chara-slot {
    bottom: 60px;
    height: 70vh;
    width: 60vw;
  }
  .chara-slot[data-pos="left"]   { left: 0; }
  .chara-slot[data-pos="center"] { left: 20vw; }
  .chara-slot[data-pos="right"]  { right: 0; }

  .textbox {
    height: 132px;
    padding: 14px 16px 18px;
  }
  .toolbar { top: 6px; right: 6px; }
  .tool-btn { padding: 5px 8px; font-size: 0.75rem; min-width: 40px; }
  .date-banner { top: 8px; left: 8px; font-size: 0.8rem; padding: 4px 10px; }
}

@media (orientation: portrait) and (max-width: 768px) {
  .textbox { height: 144px; }
}

/* ========== 横長スマホ向け微調整（短い縦幅） ========== */
@media (orientation: landscape) and (max-height: 540px) {
  /* タイトル画面: タイトル/サブは上部に、ボタンは下部に寄せる */
  .title-inner {
    padding: 3vh 8vw 4vh;
  }
  .title-menu {
    margin-top: auto;
    gap: 10px;
  }
  .title-btn {
    padding: 10px 24px;
    font-size: 0.95rem;
  }
  #title-screen.has-image .title-inner {
    padding-bottom: 4vh;
  }

  /* メッセージウィンドウを低めにして立ち絵を大きく見せる。
     行間と話者の余白を詰めることで、3行テキストも収まるようにする。 */
  .textbox {
    height: 120px;
    padding: 10px 20px 14px;
  }
  .textbox .speaker {
    line-height: 1.25;
    margin-bottom: 3px;
  }
  .textbox .text {
    line-height: 1.55;
  }

  /* エンディング画面: 狭い縦幅でも内容が収まるように詰める */
  .ending-inner { padding: 20px 20px; }
  #ending-title { margin-bottom: 14px; }
  #ending-text {
    line-height: 1.7;
    margin-bottom: 20px;
  }
}
