/* VN runtime 固定スタイル。レイアウト数値はゲーム仕様書§3の確定値。
   デザイン(色・装飾・壁紙)はdesign.cssのカスタムプロパティ上書きで注入する。 */
@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;
}
#bglayer { z-index: 1; }
#cglayer { z-index: 2; opacity: 0; }
#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は旧ネーム行(プレート高さ+下間隔)込み: プレート独立化後も本文の行位置は不変 */
body[data-layout="pc"]   #textarea { left: 152px; top: 799px; width: 1617px; height: 274px; padding: 94px 44px 16px; }
body[data-layout="sp-v"] #textarea { left: 8px;   top: 369px; width: 374px;  height: 332px; padding: 67px 14px 6px; }
body[data-layout="sp-h"] #textarea { left: 12px;  top: 216px; width: 820px;  height: 166px; padding: 50px 16px 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; }
body[data-layout="pc"]   #namezone { height: 48px; font-size: 24px;
  left: 196px; top: 803px; max-width: 420px; }
body[data-layout="sp-v"] #namezone { height: 28px; font-size: 15px;
  left: 22px; top: 372px; max-width: 160px; }
body[data-layout="sp-h"] #namezone { height: 26px; font-size: 15px;
  left: 28px; top: 219px; 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-episodes { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
#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.5em; font-weight: bold; }
#end-credits { margin-top: 14px; font-size: 0.8em; opacity: 0.85; line-height: 1.8; white-space: pre-line; }
#end-actions { margin-top: 16px; display: flex; gap: 12px; 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; }

/* ===== フェード ===== */
/* 全画面フェーダーは面遷移(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; } }
#cgarea.fx-shake-small { animation: fx-shake-s 0.4s ease; }
#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 { 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; }
