/* VN runtime 固定スタイル。レイアウト数値はゲーム仕様書§3の確定値。
   デザイン(色・装飾・壁紙)はdesign.cssのカスタムプロパティ上書きで注入する。 */
/* モバイルブラウザの自動テキスト拡大を禁止する(iOS Safariは横持ち回転で、
   Android Chromeは横長ブロックで、一部の文字だけ勝手に拡大する——本文が
   テキスト枠を越える実害。組版はレイアウト実測が正であり拡大は常に破壊的) */
html, body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@font-face {
  font-family: "Noto Sans JP VN";
  src: url("fonts/NotoSansJP.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}
:root {
  --wall-bg: #101014;
  --frame-bg: rgba(10, 12, 18, 0.92);
  --frame-border: transparent;
  --text-color: #f0f0ea;
  --name-color: #ffd479;
  --accent: #8fa3c8;
  --ui-color: #aab;
  --cutin-card-bg: linear-gradient(165deg, #333, #222);
  --cutin-border: rgba(255, 255, 255, 0.55);
  --top-overlay: rgba(8, 8, 12, 0.55);
  --body-font: "Noto Sans JP VN", "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { user-select: none; -webkit-user-select: none; }
img { -webkit-user-drag: none; pointer-events: none; }
input, button { pointer-events: auto; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
body { font-family: var(--body-font); }

/* ===== ビューポートと壁紙 ===== */
#viewport { position: fixed; inset: 0; overflow: hidden; }
#wallpaper {
  position: absolute; inset: 0; background: var(--wall-bg);
  background-size: cover; background-position: center; z-index: 0;
}
/* ===== キャンバス(等比contain配置。scaleはJSが設定) ===== */
#canvas {
  position: absolute; top: 50%; left: 50%; transform-origin: center center;
  z-index: 1;
}
body[data-layout="pc"]   #canvas { width: 1920px; height: 1080px; }
body[data-layout="sp-v"] #canvas { width: 390px;  height: 844px;  }
body[data-layout="sp-h"] #canvas { width: 844px;  height: 390px;  }

/* ===== CGエリア ===== */
#scene-look-target { position: absolute; inset: 0; }
#cgarea { position: absolute; overflow: hidden; background: #000; }
body[data-layout="pc"]   #cgarea { left: 294px; top: 40px;  width: 1332px; height: 749px; }
body[data-layout="sp-v"] #cgarea { left: 8px;   top: 100px; width: 374px;  height: 210px; }
body[data-layout="sp-h"] #cgarea { left: 244px; top: 8px;   width: 356px;  height: 200px; }
.cglayer {
  position: absolute; inset: 0;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  transition: opacity 0.5s ease;
}
/* 下地レイヤー(仕様§10): look(色調)・camera・衝撃の作用対象。カットイン層は外側の
   兄弟なので、cg区分の色調・変形はカットインカードに掛からない(scope表の構造保証) */
#stage-look { position: absolute; inset: 0; }
#bglayer { z-index: 1; }
#cglayer { z-index: 2; opacity: 0; }
/* 額縁レイヤー(仕様§10): CGエリア内容の最前面。デザイン正本がCGエリアの縁(額縁)を
   ここへ描く——絵・効果・フラッシュは額縁の奥で動き、縁を隠せない(ベゼルが液晶の
   縁に被さる構造。サブピクセル境界のちかちか防止) */
#cg-frame { position: absolute; inset: 0; z-index: 9; pointer-events: none; }
#cglayer.visible { opacity: 1; }

/* ===== カットイン(四隅スロット・作品内統一サイズ。サイズはJSが設定) =====
   出入りはフレーム外からのスライドが標準(右スロット=右から、左スロット=左から。
   方向はJSが--slide-xで与える)。速度既定0.4s・cueパラメータspeed=slowで--cut-dur切替。
   透過分離素材(仕様§9)用にJSがdata-char属性と--cutin-accent変数を与える——
   カードの地のキャラ別着色はdesign.cssが--cutin-accentを使って行う */
.cutin {
  position: absolute; z-index: 4; overflow: hidden; border-radius: 6px;
  background: var(--cutin-card-bg); border: 2px solid var(--cutin-border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  transform: translateX(var(--slide-x, 112%));
  transition: transform var(--cut-dur, 0.4s) ease, opacity var(--cut-dur, 0.4s) ease;
}
.cutin.visible { transform: translateX(0); }
/* 同キャラの表情差し替えはその場クロスフェード(スライドしない)。それ以外にフェードは使わない */
.cutin.xfade { transform: none; opacity: 0; }
.cutin.xfade.visible { opacity: 1; }
.cutin img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cutin[data-slot="左上"] { left: 0; top: 0; }
.cutin[data-slot="右上"] { right: 0; top: 0; }
.cutin[data-slot="左下"] { left: 0; bottom: 0; }
.cutin[data-slot="右下"] { right: 0; bottom: 0; }

/* ===== ステージフェーダー(話境界などで舞台=CGエリアのみを暗転。額縁は常設) ===== */
#stage-fader {
  position: absolute; inset: 0; z-index: 8; background: #000; opacity: 0;
  pointer-events: none; transition: opacity 0.5s ease;
}
#stage-fader.black { opacity: 1; }

/* ===== テキストエリア ===== */
#textarea {
  position: absolute; z-index: 5; background: var(--frame-bg);
  border: 1px solid var(--frame-border);
}
/* padding-topは旧ネーム行(プレート高さ+下間隔)込み。
   上下パディングは作品依存(フレーム装飾・プレート意匠の厚みで最適位置が変わる)のため、
   デザイントークン --text-pad-top-〜 と --text-pad-bottom-〜 でdesign.cssから調整できる(仕様§3)。
   既定値=ツール標準。許容範囲はビルドが機械検証する(上+下の合計≦枠高−最大行数×行送り:
   pc≦110 / spv≦60 / sph≦60。下限=プレートのドック領域)。左右は折返し幅=組版計測に直結するため固定 */
body[data-layout="pc"]   #textarea { left: 152px; top: 799px; width: 1617px; height: 274px;
  padding: var(--text-pad-top-pc, 94px) 44px var(--text-pad-bottom-pc, 16px); }
body[data-layout="sp-v"] #textarea { left: 8px;   top: 369px; width: 374px;  height: 332px;
  padding: var(--text-pad-top-spv, 52px) 14px var(--text-pad-bottom-spv, 6px); }
body[data-layout="sp-h"] #textarea { left: 12px;  top: 216px; width: 820px;  height: 166px;
  padding: var(--text-pad-top-sph, 46px) 16px var(--text-pad-bottom-sph, 5px); }
/* ネームプレート: 本文枠上辺のドック位置に収まる独立要素(上辺に接する。枠外・CGエリアへ
   突出しない)。#textareaの子にしないことで、design.cssが本文枠へ形状加工(clip-path等)を
   してもプレートが切られない。幅は作品内最長名で固定(runtimeが算出)。空のときは不可視 */
#namezone { position: absolute; z-index: 6; font-weight: bold; color: var(--name-color);
  display: flex; align-items: center; justify-content: center;
  width: max-content; padding: 0 18px; }
#namezone:empty { visibility: hidden; }
/* プレート位置はデザイン変数で作品ごとに微調整できる(仕様§3 v1.38:
   --plate-offset-x/--plate-offset-y。design.cssがbody[data-layout]へ設定・既定0) */
body[data-layout="pc"]   #namezone { height: 48px; font-size: 24px;
  left: calc(196px + var(--plate-offset-x, 0px));
  top: calc(803px + var(--plate-offset-y, 0px)); max-width: 420px; }
body[data-layout="sp-v"] #namezone { height: 28px; font-size: 15px;
  left: calc(22px + var(--plate-offset-x, 0px));
  top: calc(372px + var(--plate-offset-y, 0px)); max-width: 160px; }
body[data-layout="sp-h"] #namezone { height: 26px; font-size: 15px;
  left: calc(28px + var(--plate-offset-x, 0px));
  top: calc(219px + var(--plate-offset-y, 0px)); max-width: 160px; }
#bodyzone { color: var(--text-color); }
body[data-layout="pc"]   #bodyzone { font-size: 24px; line-height: 1.7; }
body[data-layout="sp-v"] #bodyzone { font-size: 16px; line-height: 1.7; }
body[data-layout="sp-h"] #bodyzone { font-size: 16px; line-height: 1.65; }
#bodyzone .line { white-space: pre; min-height: 1.65em; }
#bodyzone .pending { visibility: hidden; }
#bodyzone ruby rt { font-size: 0.45em; }

/* ===== クリック待ちマーカー ===== */
@keyframes cw-blink { 0%, 100% { opacity: 0.15; } 50% { opacity: 0.95; } }
#click-wait {
  position: absolute; color: var(--name-color); display: none;
  animation: cw-blink 1.1s ease-in-out infinite; pointer-events: none;
}
/* マーカーの意匠は作品デザイン(design.css)で差し替える。以下は標準仮デザイン */
#click-wait::after { content: "▼"; }
#click-wait.on { display: block; }
body[data-layout="pc"]   #click-wait { right: 44px; bottom: 14px; font-size: 22px; }
body[data-layout="sp-v"] #click-wait { right: 14px; bottom: 8px;  font-size: 14px; }
body[data-layout="sp-h"] #click-wait { right: 16px; bottom: 6px;  font-size: 14px; }

/* ===== 話数インジケータ ===== */
#ep-indicator { position: absolute; z-index: 6; color: var(--ui-color); display: flex; gap: 8px; }
body[data-layout="pc"] #ep-indicator {
  left: 44px; top: 90px; flex-direction: column; font-size: 15px; letter-spacing: 0.1em;
}
body[data-layout="sp-v"] #ep-indicator { left: 10px; top: 8px; font-size: 11px; }
body[data-layout="sp-h"] #ep-indicator { left: 12px; top: 6px; font-size: 11px; }
#ep-indicator .ep { opacity: 0.45; }
#ep-indicator .ep.current { opacity: 1; color: var(--name-color); }

/* ===== ゲーム中UI ===== */
#game-ui { position: absolute; z-index: 6; display: flex; gap: 10px; }
body[data-layout="pc"]   #game-ui { right: 44px; top: 84px; flex-direction: column; }
body[data-layout="sp-v"] #game-ui { right: 8px; top: 4px; }
/* スマホ横はCGエリア(x244〜600)に重ねない: 右余白に縦積み */
body[data-layout="sp-h"] #game-ui { right: 10px; top: 8px; flex-direction: column; }
.uibtn {
  min-width: 44px; min-height: 44px; padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06); color: var(--ui-color);
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 6px;
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.uibtn:hover { background: rgba(255, 255, 255, 0.14); }
.uibtn.active { color: var(--name-color); border-color: var(--name-color); }
body[data-layout="sp-v"] .uibtn, body[data-layout="sp-h"] .uibtn { font-size: 11px; padding: 2px 6px; }

/* ===== 画面(TOP/ED)共通 ===== */
.surface { position: absolute; inset: 0; display: none; }
.surface.active { display: block; }
#surface-game { z-index: 1; }
#surface-top, #surface-end { z-index: 10; }

/* TOP(標準仮デザイン。実デザインはdesign.cssが上書き) */
#top-kv { position: absolute; inset: 0; background-size: cover; background-position: center; }
/* スマホはKVを切り抜かない: ゲーム画面と同じ考え方でKV全体を見せる(仕様§5)
   縦=上部に全幅16:9帯+その下にパネル。横=高さフィットで中央配置(左右は壁紙) */
body[data-layout="sp-v"] #top-kv, body[data-layout="sp-v"] #end-kv {
  inset: 0 0 auto 0; height: 219px; }
body[data-layout="sp-h"] #top-kv, body[data-layout="sp-h"] #end-kv {
  background-size: contain; }
#top-panel {
  position: absolute; z-index: 2; padding: 24px 32px; background: var(--top-overlay);
  border-radius: 10px; color: #fff; max-width: 80%;
}
body[data-layout="pc"]   #top-panel { left: 8%; bottom: 12%; }
body[data-layout="sp-v"] #top-panel { left: 5%; right: 5%; top: 239px; bottom: auto; max-width: none; }
/* スマホ横は下段の横長帯(キャラの顔を隠さない。仕様§5) */
body[data-layout="sp-h"] #top-panel { left: 12px; right: 12px; bottom: 8px; max-width: none; }
#top-title { font-weight: bold; line-height: 1.35; }
body[data-layout="pc"] #top-title { font-size: 44px; }
body[data-layout="sp-v"] #top-title { font-size: 22px; }
body[data-layout="sp-h"] #top-title { font-size: 20px; }
#top-catch { margin-top: 8px; opacity: 0.85; font-size: 0.9em; }
#top-author { margin-top: 6px; font-size: 0.75em; opacity: 0.7; }
/* 話リストは話数が多い原作でもTOPが構造的に収まるよう、標準で高さ上限+スクロールを持つ
   (11話級で縦積みがキャンバスを突き破る実害への恒久対応。作品デザインはdesign.cssで
   この上限・並びを自由に再設計してよい) */
#top-episodes { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px;
  max-height: 380px; overflow-y: auto; }
body[data-layout="sp-v"] #top-episodes { max-height: 240px; }
body[data-layout="sp-h"] #top-episodes { max-height: 110px; }
/* 話ボタンの中身は3スパン(番号・タイトル・所要時間)。どれを見せるかは
   design.cssが取捨選択する(仕様§5。数字だけのチップも可)。
   標準はタイトル+所要時間=従来表示と同じ見た目 */
.ep-btn .ep-no { display: none; }
.ep-btn .ep-min::before { content: "("; }
.ep-btn .ep-min::after { content: ")"; }
/* リンク文言の長短スパン(原文方針/方針・原作を読む/原作)。切替はdesign.css。
   文言はDOM正本——CSS contentへの日本語注入は禁止(ビルド検査) */
.lbl-short { display: none; }
/* パネル自体の最終安全弁: 長いタイトル・多要素でもキャンバスを突き破らない
   (上限に達した場合のみパネル内スクロール。通常は発動しない) */
body[data-layout="pc"]   #top-panel { max-height: 880px; overflow-y: auto; }
body[data-layout="sp-v"] #top-panel { max-height: 597px; overflow-y: auto; }
body[data-layout="sp-h"] #top-panel { max-height: 300px; overflow-y: auto; }
#top-links { margin-top: 12px; display: flex; gap: 14px; font-size: 12px; }
#top-links a, #top-links button {
  color: var(--ui-color); background: none; border: none; cursor: pointer;
  text-decoration: underline; font-size: 12px; font-family: inherit;
  min-height: 44px; display: inline-flex; align-items: center;
}

/* ED */
#end-kv { position: absolute; inset: 0; background-size: cover; background-position: center; }
#end-panel {
  position: absolute; z-index: 2; left: 50%; top: 50%; transform: translate(-50%, -50%);
  text-align: center; color: #fff; background: var(--top-overlay);
  padding: 28px 36px; border-radius: 10px; max-width: 86%;
  opacity: 0; transition: opacity 1.2s ease;
}
#end-panel.visible { opacity: 1; }
/* KV帯(高さ219)の下の残り領域の中央に置く */
body[data-layout="sp-v"] #end-panel { top: 531px; }
body[data-layout="sp-h"] #end-panel { left: 12px; right: 12px; bottom: 8px; top: auto;
  transform: none; max-width: none; }
#end-message { font-size: 1.1em; opacity: 0.9; }
/* ED大型タイトル(runtimeがデータから表示。意匠はdesign.cssが自由に上書き) */
#end-title { margin-top: 10px; font-size: 2em; font-weight: bold; line-height: 1.35; }
#end-credits { margin-top: 14px; font-size: 0.8em; opacity: 0.85; line-height: 1.8; white-space: pre-line; }
/* 操作列はa/buttonのボックス差を消して同一の中央揃えにする(整列検査の上流保証) */
#end-actions { margin-top: 16px; display: flex; gap: 12px; justify-content: center; align-items: center; }
#end-actions .uibtn { display: inline-flex; align-items: center; justify-content: center; }

/* ===== オーバーレイ(設定・履歴) ===== */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: none;
  background: rgba(0, 0, 0, 0.72); color: #eee;
}
.overlay.active { display: flex; align-items: center; justify-content: center; }
.panel {
  background: #16161c; border: 1px solid #444; border-radius: 10px;
  padding: 22px 26px; max-width: 86%; max-height: 82%; overflow: auto; min-width: 40%;
}
.panel h2 { font-size: 16px; margin-bottom: 14px; color: var(--name-color); }
.setting-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.setting-row label { min-width: 9em; }
#history-list { font-size: 14px; line-height: 1.8; }
#history-list .h-name { color: var(--name-color); font-weight: bold; }
#history-list .h-page { margin-bottom: 10px; white-space: pre-wrap; }

/* ===== デバッグ位置番号(?debug=1のときのみ表示。公開用では出ない) ===== */
#debug-counter {
  position: fixed; left: 10px; bottom: 8px; z-index: 2147483000; display: none;
  font: bold 48px/1.1 Consolas, monospace; color: #8f9;
  background: rgba(0, 0, 0, 0.6); padding: 2px 14px; border-radius: 8px;
  text-shadow: 0 0 4px #000; pointer-events: none;
}
body[data-debug="1"] #debug-counter { display: block; }
/* デバッグ: 表示中イベントCGの番号+名称(右上。CG非表示中は消える) */
#debug-cg {
  position: fixed; right: 10px; top: 8px; z-index: 2147483000; display: none;
  font: bold 20px/1.2 Consolas, monospace; color: #9cf;
  background: rgba(0, 0, 0, 0.6); padding: 4px 12px; border-radius: 8px;
  text-shadow: 0 0 4px #000; pointer-events: none; max-width: 60vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
body[data-debug="1"] #debug-cg:not(:empty) { display: block; }

/* ===== フェード ===== */
/* 全画面フェーダーは面遷移(TOP→本編・本編→ED)専用。ゲーム内の転換はステージフェーダー/転換演出を使う */
#fader {
  position: absolute; inset: 0; z-index: 30; background: #000; opacity: 0;
  pointer-events: auto; transition: opacity 0.6s ease;
}
#fader { pointer-events: none; }
#fader.black { opacity: 1; pointer-events: auto; }

/* ===== エフェクト(組み込み分。カタログ結線は効果アダプタ経由) ===== */
@keyframes fx-shake-s { 0%,100% { transform: translate(0,0); } 25% { transform: translate(4px,2px); } 50% { transform: translate(-4px,-2px); } 75% { transform: translate(3px,-1px); } }
@keyframes fx-shake-l { 0%,100% { transform: translate(0,0); } 20% { transform: translate(10px,6px); } 40% { transform: translate(-10px,-6px); } 60% { transform: translate(8px,-4px); } 80% { transform: translate(-8px,4px); } }
@keyframes fx-flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
#stage-look.fx-shake-small, #scene-look-target.fx-shake-small, #cgarea.fx-shake-small { animation: fx-shake-s 0.4s ease; }
#stage-look.fx-shake-large, #scene-look-target.fx-shake-large, #cgarea.fx-shake-large { animation: fx-shake-l 0.6s ease; }
#fxflash {
  position: absolute; inset: 0; z-index: 8; background: #fff; opacity: 0; pointer-events: none;
}
#fxflash.run { animation: fx-flash 0.5s ease-out; }
body[data-effects="static"] #cgarea.fx-shake-small,
body[data-effects="static"] #cgarea.fx-shake-large,
body[data-effects="static"] #scene-look-target.fx-shake-small,
body[data-effects="static"] #scene-look-target.fx-shake-large,
body[data-effects="static"] #stage-look.fx-shake-small,
body[data-effects="static"] #stage-look.fx-shake-large { animation: none; }
body[data-effects="static"] #fxflash.run { animation: none; opacity: 0.35; transition: opacity 0.4s; }
body[data-effects="static"] .cutin { transition: opacity 0.01s; transform: none; }
