/* ==========================================================================
   エンジンの土台：舞台・段階表示・寄り道・操作UI・全体表示・設定
   ========================================================================== */
html, body { overflow: hidden; background: var(--stage); }
body.mode-preview { background: var(--paper); }

.deck { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; overflow: hidden; }
.slide {
  position: absolute; inset: 0; overflow: hidden;
  visibility: hidden; opacity: 0;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
.slide.active { visibility: visible; opacity: 1; transition: opacity .35s ease; z-index: 1; }
.slide.instant, .slide.instant *, body.instant .slide, body.instant .slide * { transition: none !important; animation-delay: -60s !important; }
body.instant .slide *, .slide.instant * { animation-play-state: paused !important; }
body.instant .slide .keep-anim, .slide.instant .keep-anim { animation-play-state: running !important; animation-delay: 0s !important; }

/* 段階表示：既定はふわっと出る。種類はクラスで変える */
[data-in], [data-only] { opacity: 0; transition: opacity .4s ease, transform .5s cubic-bezier(.2, .9, .25, 1.15); }
[data-in].shown, [data-only].shown { opacity: 1; }
.pop[data-in], .pop[data-only] { transform: scale(.6) rotate(-6deg); }
.pop.shown { transform: none; }
.rise[data-in], .rise[data-only] { transform: translateY(40px); }
.rise.shown { transform: none; }
.slide-l[data-in] { transform: translateX(-80px); }
.slide-l.shown { transform: none; }

/* 欠けている素材の仮置き */
.media { position: relative; overflow: hidden; background: var(--stage); }
.media > img, .media > video { display: block; width: 100%; height: 100%; object-fit: cover; }
.media.contain > img, .media.contain > video { object-fit: contain; }
.media.missing > img, .media.missing > video { visibility: hidden; }
.media.missing {
  background:
    repeating-linear-gradient(-45deg, var(--tint) 0 22px, var(--paper) 22px 44px);
}
.media.missing::after {
  content: "素材待ち\A" attr(data-missing);
  white-space: pre; text-align: center;
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-2deg);
  font: 700 30px/1.5 var(--f-body); color: var(--ink);
  background: var(--white); border: 3px dashed var(--ink); padding: 14px 26px;
}

/* カメラ */
.cam { position: relative; overflow: hidden; background: var(--stage); }
.cam .cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 50% 50%; }
.cam[data-cam-error]::after {
  content: "カメラを開けません（" attr(data-cam-error) "）\A設定（S）でカメラを選んでください";
  white-space: pre; position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--paper); font: 700 26px/1.6 var(--f-body);
}
body.mode-preview .cam::before {
  content: "LIVE CAMERA"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--paper); font: 64px var(--f-latin); letter-spacing: .06em;
}
.demo-off .only-demo { display: none !important; }
.demo-on .only-nodemo { display: none !important; }

/* 黒画面 */
body.blackout .deck { visibility: hidden; }

/* 操作ボタン（マウスを動かしたときだけ出る） */
.ctrl {
  position: fixed; right: 18px; bottom: 18px; z-index: 50; display: flex; gap: 8px;
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s; pointer-events: none;
}
.ctrl .btn { font-size: 15px; min-width: 44px; }
body.pointer .ctrl { opacity: 1; transform: none; pointer-events: auto; }
body:not(.pointer) { cursor: none; }

/* レール型の進行バー */
.rail-progress { position: absolute; left: 60px; right: 60px; bottom: 22px; height: 14px; z-index: 5; pointer-events: none; }
.rail-progress i { position: absolute; left: 0; right: 0; top: 6px; height: 3px; background: var(--ink-25);
  background-image: repeating-linear-gradient(90deg, var(--ink-25) 0 2px, transparent 2px 26px); }
.rail-progress b {
  position: absolute; top: 0; width: 26px; height: 14px; border: 3px solid var(--ink); background: var(--orange); border-radius: 3px;
  left: calc(var(--p, 0) * (100% - 26px)); transition: left .6s cubic-bezier(.3, .8, .3, 1);
}
.rail-progress[hidden] { display: none; }

/* 全体表示 */
.overview {
  position: fixed; inset: 0; z-index: 60; overflow: auto; padding: 24px 32px 48px;
  background: var(--paper); display: none;
}
.overview.open { display: block; }
.ov-head { font-weight: 700; margin-bottom: 16px; color: var(--ink); }
.ov-head .latin { font-size: 28px; color: var(--orange); margin-right: 10px; }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 22px; }
.ov-card { all: unset; cursor: pointer; display: block; }
.ov-thumb { position: relative; aspect-ratio: 16 / 9; border: 3px solid var(--ink); background: var(--paper); overflow: hidden; box-shadow: 4px 4px 0 var(--ink); }
.ov-card:hover .ov-thumb { box-shadow: 4px 4px 0 var(--orange); }
.ov-card.current .ov-thumb { outline: 5px solid var(--orange); outline-offset: 3px; }
.ov-card.appendix .ov-thumb { border-style: dashed; }
.ov-inner { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; pointer-events: none; }
.ov-inner { transform: scale(var(--s, .16)); }
.ov-inner .slide { visibility: visible; opacity: 1; }
.ov-label { margin-top: 8px; font-weight: 700; font-size: 15px; color: var(--ink); }
.ov-label b { font-family: var(--f-latin); color: var(--orange); font-size: 18px; margin-right: 4px; }

/* 設定 */
dialog.settings {
  width: min(760px, 94vw); max-height: 92vh; overflow: auto; padding: 0;
  border: 3px solid var(--ink); box-shadow: var(--shadow); background: var(--paper); color: var(--ink);
}
dialog.settings::backdrop { background: rgba(4, 4, 15, .55); }
.set-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--ink); color: var(--paper); margin: 0; }
.set-head h2 { margin: 0; font: 26px var(--f-title); }
dialog.settings section { padding: 14px 20px; border-bottom: 2px dashed var(--ink-25); }
dialog.settings h3 { margin: 0 0 10px; font-size: 17px; }
dialog.settings .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
dialog.settings .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-top: 10px; align-items: center; }
dialog.settings select, dialog.settings input[type=number] { border: 2px solid var(--ink); padding: 6px 8px; background: var(--white); border-radius: 6px; }
dialog.settings input[type=range] { width: 100%; accent-color: var(--orange); }
dialog.settings .hint { color: var(--ink-60); font-size: 13px; margin: 8px 0 0; }
.cam-preview { width: 100%; aspect-ratio: 16 / 9; margin-top: 10px; border: 3px solid var(--ink); }
.cam-frame { position: absolute; inset: 0; border: 2px dashed var(--mustard); z-index: 1; pointer-events: none; }
.ser-state { font-weight: 800; padding: 2px 10px; border: 2px solid var(--ink); border-radius: 99px; background: var(--white); }
.off-state { font-weight: 700; }
.off-state.ok { color: var(--ink); }
.ser-state.ok { background: var(--orange); color: var(--white); }
.ser-test { margin-top: 10px; }
.ser-test .btn { font-size: 13px; padding: 4px 10px; }
.ser-log { height: 140px; overflow: auto; margin: 10px 0 0; padding: 8px 10px; background: var(--stage); color: #CFE3F7; font: 12px/1.5 ui-monospace, Consolas, monospace; border-radius: 6px; }

/* 3Dシーン（scene3d.js） */
.scene3d {
  position: absolute; inset: 0; opacity: 0; transition: opacity .6s ease;
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 2px, transparent 2px), linear-gradient(90deg, var(--grid) 2px, transparent 2px);
  background-size: 60px 60px;
}
.scene3d.on { opacity: 1; }
.scene3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
body.scene-edit .scene3d { z-index: 40; }
body.scene-edit .rail-progress { display: none; }
.scene-hud { position: fixed; left: 16px; top: 16px; z-index: 70; max-width: 640px; padding: 10px 14px; background: var(--ink); color: var(--paper); font: 14px/1.6 var(--f-body); border-radius: 6px; }
.scene-hud code { color: var(--mustard); font: 12px ui-monospace, Consolas, monospace; word-break: break-all; }
.scene-hud[hidden] { display: none; }
