/*
 * 藪の中 — ビジュアルノベル スタイルシート
 * ノワール/セピア調の基調。デスクトップ(16:9)とモバイル(縦長)の両方に対応する。
 */

:root {
  --sepia-dark: #1a1410;
  --sepia-mid: #3a2e22;
  --sepia-light: #d8c8a8;
  --paper: #efe6d0;
  --ink: #2a2118;
  --accent: #b03a2e;
  --window-ratio: 16 / 9;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "MS PMincho", serif;
  -webkit-user-select: none;
  user-select: none;
}

#game-root {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ステージ: JS がウィンドウ比率に合わせてリサイズする */
#stage {
  position: relative;
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,.8);
}

/* ---------- レイヤー ---------- */
#bg-layer, #char-layer, #fx-layer {
  position: absolute;
  inset: 0;
}

#bg-layer .bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity .8s ease;
}
#bg-layer .bg.visible { opacity: 1; }

/* 画像がない場合のプレースホルダ（グラデーション+ラベル） */
#bg-layer .bg.placeholder::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2vmin;
  color: rgba(216,200,168,.45);
  letter-spacing: .5em;
}

/* ---------- 立絵 ---------- */
#char-layer .char {
  position: absolute;
  bottom: 12%;
  height: 72%;
  transform: translateX(-50%);
  transition: opacity .4s ease, filter .4s ease;
  filter: drop-shadow(0 0 12px rgba(0,0,0,.6));
}
#char-layer .char img {
  height: 100%;
  display: block;
}
#char-layer .char.dim { filter: brightness(.55) drop-shadow(0 0 12px rgba(0,0,0,.6)); }
#char-layer .char.hidden-char { opacity: 0; pointer-events: none; }

/* 立絵の画像が無いときのシルエット */
#char-layer .char .silhouette {
  height: 100%;
  aspect-ratio: 3 / 7;
  background: linear-gradient(to top, rgba(0,0,0,.85), rgba(40,30,20,.7));
  clip-path: polygon(38% 0, 62% 0, 68% 10%, 62% 16%, 78% 30%, 82% 70%, 74% 100%, 26% 100%, 18% 70%, 22% 30%, 38% 16%, 32% 10%);
  border-radius: 8px 8px 0 0;
}

/* ---------- セリフウィンドウ ---------- */
#dialogue-box {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 3%;
  min-height: 22%;
  background: linear-gradient(to bottom, rgba(20,14,8,.92), rgba(30,22,14,.96));
  border: 1px solid rgba(216,200,168,.5);
  border-radius: 8px;
  padding: 2.4% 3%;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(0,0,0,.7);
  z-index: 30;
}

#dialogue-name {
  position: absolute;
  top: -1.4em;
  left: 2%;
  background: var(--sepia-mid);
  color: var(--paper);
  border: 1px solid rgba(216,200,168,.6);
  border-radius: 6px 6px 0 0;
  padding: .25em 1.2em;
  font-size: 2.6vmin;
  letter-spacing: .2em;
  display: none;
}
#dialogue-name.visible { display: block; }

#dialogue-text {
  color: var(--paper);
  font-size: 3.2vmin;
  line-height: 1.75;
  letter-spacing: .08em;
  text-shadow: 0 0 4px rgba(0,0,0,.9);
  white-space: pre-wrap;
}

#advance-mark {
  position: absolute;
  right: 2.5%;
  bottom: 3%;
  color: var(--accent);
  font-size: 2.6vmin;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 選択肢 ---------- */
#choice-layer {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vh;
  z-index: 40;
}

#choice-prompt {
  color: var(--paper);
  font-size: 3.4vmin;
  letter-spacing: .15em;
  text-shadow: 0 0 8px #000;
  padding: 0 6%;
  text-align: center;
}

#choice-options {
  display: flex;
  flex-direction: column;
  gap: 1.6vh;
  width: min(72%, 560px);
}

.choice-btn {
  font-family: inherit;
  font-size: 2.9vmin;
  color: var(--paper);
  background: linear-gradient(to right, rgba(58,46,34,.95), rgba(43,33,23,.95));
  border: 1px solid rgba(216,200,168,.6);
  border-radius: 6px;
  padding: 1.4vh 2em;
  letter-spacing: .1em;
  cursor: pointer;
  transition: background .25s ease, transform .15s ease;
  text-align: left;
}
.choice-btn:hover {
  background: linear-gradient(to right, rgba(176,58,46,.85), rgba(58,46,34,.95));
  transform: scale(1.02);
}

/* ---------- タイトル/ログ等の全面スクリーン ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

#title-screen {
  background-size: cover;
  background-position: center;
  background-color: var(--sepia-dark);
}

.title-inner {
  text-align: center;
  color: var(--paper);
  text-shadow: 0 0 10px #000, 0 2px 6px #000;
}
.title-author {
  font-size: 2.8vmin;
  letter-spacing: .6em;
  margin-bottom: 1.5vh;
}
.title-main {
  font-size: 9vmin;
  font-weight: normal;
  letter-spacing: .2em;
  line-height: 1.4;
  border-top: 1px solid rgba(216,200,168,.7);
  border-bottom: 1px solid rgba(216,200,168,.7);
  padding: 2vh 1em;
  margin-bottom: 2vh;
}
.title-sub { font-size: 2.4vmin; letter-spacing: .4em; opacity: .8; }

.title-menu {
  margin-top: 6vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.8vh;
}

.menu-btn {
  font-family: inherit;
  font-size: 3vmin;
  color: var(--paper);
  background: rgba(26,20,16,.75);
  border: 1px solid rgba(216,200,168,.7);
  border-radius: 4px;
  padding: 1.4vh 4em;
  letter-spacing: .4em;
  cursor: pointer;
  transition: background .25s ease;
}
.menu-btn:hover { background: rgba(176,58,46,.7); }

.credits-inner {
  max-width: 80%;
  max-height: 80%;
  overflow: auto;
  color: var(--paper);
  background: rgba(26,20,16,.95);
  border: 1px solid rgba(216,200,168,.6);
  border-radius: 8px;
  padding: 4vmin;
  font-size: 2.6vmin;
  line-height: 1.9;
}
.credits-inner h2 { margin-bottom: 2vh; letter-spacing: .3em; font-weight: normal; }
.credits-source { opacity: .7; font-size: .85em; margin-top: 2vh; }
.credits-inner .menu-btn { margin-top: 3vh; }

/* ---------- 下部UIバー ---------- */
#ui-bar {
  position: absolute;
  top: 1.5%;
  right: 1.5%;
  display: flex;
  gap: .5em;
  z-index: 35;
}
#ui-bar button {
  font-family: inherit;
  font-size: 1.9vmin;
  letter-spacing: .15em;
  color: var(--paper);
  background: rgba(26,20,16,.7);
  border: 1px solid rgba(216,200,168,.45);
  border-radius: 4px;
  padding: .45em 1.1em;
  cursor: pointer;
}
#ui-bar button:hover { background: rgba(58,46,34,.9); }
#ui-bar button.active { background: rgba(176,58,46,.75); border-color: var(--accent); }

/* ---------- バックログ ---------- */
.log-inner {
  width: 86%;
  height: 84%;
  display: flex;
  flex-direction: column;
  color: var(--paper);
  background: rgba(26,20,16,.96);
  border: 1px solid rgba(216,200,168,.6);
  border-radius: 8px;
  padding: 3vmin;
}
.log-inner h2 { font-weight: normal; letter-spacing: .3em; margin-bottom: 1.5vh; font-size: 3vmin; }
#log-body {
  flex: 1;
  overflow-y: auto;
  font-size: 2.7vmin;
  line-height: 1.8;
  padding-right: 1em;
}
#log-body .log-name { color: var(--accent); font-weight: bold; margin-top: 1.2em; }
#log-body .log-line { margin-bottom: .6em; }
.log-inner .menu-btn { margin-top: 1.5vh; align-self: center; }

/* ---------- トースト ---------- */
#toast {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,20,16,.92);
  color: var(--paper);
  border: 1px solid rgba(216,200,168,.7);
  border-radius: 6px;
  padding: 1vh 2.5em;
  font-size: 2.6vmin;
  letter-spacing: .15em;
  z-index: 60;
  transition: opacity .4s ease;
}

/* ---------- 画面フラッシュ等の演出 ---------- */
#fx-layer .flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
#fx-layer .flash.play { animation: flash .5s ease-out; }
@keyframes flash {
  0% { opacity: .9; }
  100% { opacity: 0; }
}

#stage.shake { animation: shake .45s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-.6%, .3%); }
  40% { transform: translate(.6%, -.3%); }
  60% { transform: translate(-.4%, .2%); }
  80% { transform: translate(.4%, -.2%); }
}

/* ---------- ユーティリティ ---------- */
.hidden { display: none !important; }

/* ---------- モバイル対応（縦長画面） ---------- */
@media (max-aspect-ratio: 4/5) {
  :root { --window-ratio: 3 / 4; }

  #dialogue-box { min-height: 26%; padding: 3% 4%; }
  #dialogue-text { font-size: 4.2vmin; line-height: 1.7; }
  #dialogue-name { font-size: 3.6vmin; }
  .choice-btn { font-size: 4vmin; }
  #choice-prompt { font-size: 4.4vmin; }
  .menu-btn { font-size: 4.2vmin; }
  .title-main { font-size: 12vmin; }
  .title-author, .title-sub { font-size: 4vmin; }
  #ui-bar button { font-size: 2.8vmin; padding: .5em 1.2em; }
  #log-body { font-size: 3.6vmin; }
  #char-layer .char { bottom: 24%; height: 58%; }
  #toast { font-size: 3.6vmin; }
  #bg-layer .bg.placeholder::after { font-size: 3.6vmin; }
}

/* 超狭幅（Foldable など）での安全策 */
@media (max-width: 360px) {
  #ui-bar { flex-wrap: wrap; max-width: 60%; justify-content: flex-end; }
}

/* ----------
 * 連想診断 (心理試験) パート
 * ---------- */
#quiz-layer {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3%;
  background: radial-gradient(ellipse at 50% 40%, rgba(30, 22, 12, .96), rgba(10, 7, 4, .99));
  animation: quiz-in .35s ease-out;
}
@keyframes quiz-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#quiz-counter {
  position: absolute;
  top: 3%;
  right: 4%;
  font-size: calc(min(3.4vw, 3.4vh) * .8);
  letter-spacing: .15em;
  color: #8a7a5e;
}
#quiz-prompt {
  font-size: min(3vw, 3vh);
  letter-spacing: .4em;
  text-indent: .4em;
  color: #9c8a66;
}
#quiz-word {
  font-family: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  font-weight: 700;
  font-size: min(13vw, 22vh);
  line-height: 1.1;
  color: #e8dcc0;
  text-shadow: 0 0 .25em rgba(232, 220, 192, .25), 0 2px 0 #000;
}
#quiz-sub {
  font-size: min(2.8vw, 2.8vh);
  color: #b3a382;
}
#quiz-result {
  min-height: 1.6em;
  font-size: min(3.4vw, 3.4vh);
  color: #d8c9a3;
  opacity: 0;
  transition: opacity .25s;
}
#quiz-result.shown { opacity: 1; }
#quiz-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: min(1.6vw, 1.6vh);
  max-width: 82%;
}
.quiz-btn {
  font-family: inherit;
  font-size: min(3.6vw, 3.6vh);
  padding: .5em 1.3em;
  color: #e2d5b4;
  background: rgba(58, 45, 26, .85);
  border: 1px solid #6d5c3c;
  border-radius: 3px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.quiz-btn:hover { background: rgba(96, 76, 42, .95); }
.quiz-btn:active { transform: scale(.97); }
.quiz-btn.picked {
  background: #6d5a33;
  border-color: #c9b586;
}

/* ----------
 * 不気味演出 (HorrorFX) — 本作専用
 * ---------- */
/* 持続モード: 脉動する暗いヴィネット */
#fx-vignette {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s;
  background: radial-gradient(ellipse at 50% 45%, transparent 40%, rgba(0, 0, 0, .78) 100%);
}
.mood-dread #fx-vignette {
  opacity: 1;
  animation: dread-pulse 4.2s ease-in-out infinite;
}
@keyframes dread-pulse {
  0%, 100% { opacity: .85; }
  50%      { opacity: 1; }
}

/* 裸電球の点滅 (背景層ごと) */
.fx-flicker { animation: bulb-flicker 1.3s steps(1) both; }
@keyframes bulb-flicker {
  0%   { filter: brightness(1); }
  8%   { filter: brightness(.35); }
  14%  { filter: brightness(1.15); }
  22%  { filter: brightness(.25); }
  30%  { filter: brightness(1); }
  52%  { filter: brightness(.45); }
  60%  { filter: brightness(1.1); }
  78%  { filter: brightness(.6); }
  100% { filter: brightness(1); }
}

/* グリッチ: RGBズレとスライスずれ */
.fx-glitch { animation: stage-glitch .45s steps(2) both; }
.fx-glitch #bg-layer  { animation: glitch-bg .45s steps(2) both; }
.fx-glitch #char-layer { animation: glitch-char .45s steps(2) both; }
@keyframes stage-glitch {
  0%   { filter: none; transform: none; }
  25%  { filter: hue-rotate(15deg) contrast(1.4); transform: translateX(3px); }
  50%  { filter: invert(.85) hue-rotate(180deg); transform: translateX(-4px) skewX(1.5deg); }
  75%  { filter: contrast(2) saturate(0); transform: translateX(2px); }
  100% { filter: none; transform: none; }
}
@keyframes glitch-bg {
  0%, 100% { clip-path: none; transform: none; }
  30% { clip-path: inset(12% 0 64% 0); transform: translateX(-6px); }
  60% { clip-path: inset(58% 0 8% 0);  transform: translateX(5px); }
}
@keyframes glitch-char {
  0%, 100% { transform: none; }
  40% { transform: translateX(8px) scaleY(1.03); }
  70% { transform: translateX(-5px); }
}

/* 耳元の囁き */
.fx-whisper {
  position: absolute;
  z-index: 45;
  max-width: 60%;
  font-family: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  font-size: min(3.2vw, 3.2vh);
  letter-spacing: .18em;
  color: rgba(214, 200, 168, 0);
  text-shadow: 0 0 8px rgba(0,0,0,.9);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.1s ease-in;
}
.fx-whisper.shown {
  opacity: 1;
  color: rgba(214, 200, 168, .82);
  text-shadow: 0 0 10px rgba(60, 20, 10, .95), 0 0 2px #000;
}

/* 背景の緩慢なズーム (圧迫) */
#bg-layer.fx-zoom { animation: bg-zoom 24s ease-out both; }
@keyframes bg-zoom {
  from { transform: scale(1); }
  to   { transform: scale(var(--zoom, 1.25)); }
}

/* ----------
 * 夜選択サブメニュー (夢十夜)
 * ---------- */
.night-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(2vh, 2vh);
  padding: min(6vh, 6vh) min(6vw, 6vw);
  max-height: 100%;
  overflow-y: auto;
  background: rgba(8, 6, 10, .88);
  border: 1px solid rgba(190, 180, 160, .35);
  border-radius: 4px;
}
.night-inner h2 {
  font-size: min(3.4vw, 3.4vh);
  letter-spacing: .3em;
  color: #d9d0bc;
  margin: 0 0 .4em;
}
#night-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(9em, 1fr));
  gap: min(1.6vh, 1.6vh);
}
