:root {
  --ink: #f2efe8; --muted: #b9b5ad; --panel: rgba(12,13,18,.86); --line: rgba(255,255,255,.14);
  --red: #e0242d; --safe: #6fb38a; --luck: #d7a84a; --danger: #e05a5a;
  --serif: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  --sans: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #0b0c10; color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }

/* ステージ */
#stage { position: absolute; inset: 0; overflow: hidden; background: #0b0c10; user-select: none; -webkit-user-select: none; }
.bg, .cg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s ease; }
.bg.on, .cg.on { opacity: 1; }
.cg { z-index: 2; }
.ch { position: absolute; z-index: 1; left: 50%; bottom: 0; height: min(78vh, 680px); transform: translateX(-50%) translateY(12px); opacity: 0; transition: opacity .5s, transform .5s; pointer-events: none; }
.ch.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#fx-dark, #fx-pulse, #fx-flash, #fx-patrol, #grain { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
#fx-pulse { background: radial-gradient(ellipse at center, transparent 45%, rgba(120,0,6,.55) 100%); opacity: 0; }
#fx-pulse.on { animation: pulse 1.6s ease-out 1; }
@keyframes pulse { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }
#fx-flash { background: #fff; opacity: 0; }
#fx-flash.on { animation: flash .5s ease-out 1; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
#fx-patrol { opacity: 0; background: linear-gradient(90deg, rgba(220,30,40,.22), transparent 40%, transparent 60%, rgba(40,90,220,.22)); }
#fx-patrol.on { animation: patrol 1.2s ease-in-out 3; }
@keyframes patrol { 0%,100% { opacity: 0; } 50% { opacity: 1; } }
#grain { opacity: .07; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>"); }
#stage.shake { animation: shake .45s linear 1; }
@keyframes shake { 0%,100% { transform: translate(0,0); } 20% { transform: translate(-8px,3px); } 40% { transform: translate(7px,-4px); } 60% { transform: translate(-5px,2px); } 80% { transform: translate(4px,-2px); } }
body.reduce #fx-pulse.on { animation: none; opacity: .45; transition: opacity 1s; }
body.reduce #fx-flash.on, body.reduce #fx-patrol.on { animation: none; }
body.reduce #stage.shake { animation: none; }
body.reduce .bg, body.reduce .cg, body.reduce .ch { transition-duration: .15s; }

/* テキストボックス */
#textbox { position: absolute; z-index: 5; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); width: min(940px, calc(100% - 24px)); min-height: 150px; padding: 26px 26px 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; backdrop-filter: blur(3px); }
#name { position: absolute; top: -15px; left: 18px; padding: 4px 14px; background: #1e2129; border: 1px solid var(--line); border-radius: 4px; font-size: 15px; letter-spacing: .08em; }
#name:empty { display: none; }
#name.memo { background: #2a3a33; color: #dff3e8; }
#text { font-size: clamp(17px, 2.1vw, 21px); line-height: 1.9; letter-spacing: .03em; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }
#next-ind { position: absolute; right: 18px; bottom: 10px; font-size: 13px; color: var(--muted); opacity: 0; }
#textbox.done #next-ind { opacity: 1; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
body.reduce #textbox.done #next-ind { animation: none; }

/* 選択肢 */
#choices { position: absolute; z-index: 6; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px 16px 190px; background: rgba(5,6,9,.45); }
#choices .prompt { font-family: var(--serif); font-size: clamp(18px, 2.4vw, 24px); margin-bottom: 6px; text-shadow: 0 2px 8px #000; }
#choices button { width: min(560px, 100%); padding: 16px 18px; background: rgba(16,17,23,.92); border: 1px solid rgba(255,255,255,.22); border-left: 4px solid var(--red); border-radius: 6px; font-size: clamp(16px, 2vw, 19px); text-align: left; transition: background .15s, transform .15s; }
#choices button:hover, #choices button:focus-visible { background: rgba(40,20,24,.95); outline: none; transform: translateX(3px); }

/* メニュー */
#menubar { position: absolute; z-index: 7; top: max(10px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; align-items: flex-start; }
#menuitems { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
#menubar button { padding: 6px 11px; background: rgba(12,13,18,.72); border: 1px solid var(--line); border-radius: 4px; font-size: 13px; }
#menubar button.active { background: #5a1d22; border-color: #b8434b; }
#menutoggle { display: none; }
#world-badge { position: absolute; z-index: 7; top: max(10px, env(safe-area-inset-top)); left: 10px; padding: 5px 10px; font-size: 12px; background: rgba(90,20,26,.75); border: 1px solid #b8434b; border-radius: 4px; }
@media (max-width: 720px) {
  #menutoggle { display: block; }
  #menuitems { display: none; position: absolute; top: 38px; right: 0; flex-direction: column; background: rgba(12,13,18,.95); padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
  #menubar.open #menuitems { display: flex; }
  #menuitems button { min-width: 130px; padding: 10px 12px; font-size: 15px; }
  #textbox { min-height: 132px; padding: 22px 18px 26px; }
  #choices { padding-bottom: 170px; }
}

/* 画面（タイトル） */
.screen { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; background: #0b0c10; overflow: hidden; }
.screen[hidden] { display: none; }
.screen-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 76% 50%; }
@media (max-aspect-ratio: 1/1) { .screen-bg { opacity: .75; } }
.title-inner { position: relative; padding: 24px clamp(20px, 7vw, 90px); max-width: 640px; }
.brand { font-size: 13px; letter-spacing: .15em; color: var(--muted); margin: 0 0 12px; }
h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(40px, 7.5vw, 76px); line-height: 1.15; margin: 0; letter-spacing: .04em; text-shadow: 0 4px 24px #000; }
.ep { font-family: var(--serif); font-size: clamp(17px, 2.4vw, 22px); margin: 14px 0 26px; color: #e6dfd2; }
.title-menu { display: flex; flex-direction: column; gap: 9px; width: min(330px, 100%); }
.title-menu button { padding: 12px 16px; background: rgba(14,15,20,.78); border: 1px solid var(--line); border-radius: 6px; text-align: left; font-size: 16px; }
.title-menu button:hover, .title-menu button:focus-visible { border-color: #b8434b; outline: none; }
.title-menu button.primary { border-left: 4px solid var(--red); }
#btn-worldb { border-left: 4px solid #8a2a31; background: rgba(40,10,14,.8); }
.small { font-size: 12px; color: var(--muted); margin-top: 18px; }
@media (max-height: 560px) { .title-inner { padding-top: 10px; } h1 { font-size: 36px; } .ep { margin: 6px 0 12px; } .title-menu { gap: 5px; } .title-menu button { padding: 8px 12px; } }

/* オーバーレイ */
#overlay { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(3,4,6,.72); }
#overlay[hidden] { display: none; }
#panel { width: min(640px, 100%); max-height: calc(100% - 20px); overflow-y: auto; padding: 24px 22px; background: #14161c; border: 1px solid var(--line); border-radius: 10px; line-height: 1.75; }
#panel h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 12px; }
#panel h3 { font-size: 16px; margin: 18px 0 6px; }
#panel p { margin: 8px 0; }
#panel .row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
#panel .row button, #panel .btn { padding: 10px 16px; background: #22252e; border: 1px solid var(--line); border-radius: 6px; }
#panel .row button.primary { background: #5a1d22; border-color: #b8434b; }
#panel label { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; }
#panel input[type=range] { width: 55%; }
#panel select { font: inherit; background: #22252e; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; }
#panel a { color: #9fc4e8; }
.slot { display: block; width: 100%; text-align: left; margin: 8px 0; padding: 12px 14px; background: #1d2028; border: 1px solid var(--line); border-radius: 6px; }
.slot small { display: block; color: var(--muted); font-size: 12px; }
.slot:disabled { opacity: .45; cursor: default; }
.notice { font-size: 13px; color: var(--muted); }

/* エンディングカード */
.ending .edid { font-size: 12px; letter-spacing: .2em; color: var(--muted); }
.ending h2 { font-size: 28px !important; margin: 4px 0 14px !important; }
.ending dl { display: grid; grid-template-columns: 5em 1fr; gap: 6px 10px; margin: 0; }
.ending dt { color: var(--muted); }
.ending dd { margin: 0; font-weight: 600; }
.tone-safe dd.judge { color: var(--safe); } .tone-luck dd.judge { color: var(--luck); } .tone-danger dd.judge { color: var(--danger); }
.ending .why { margin-top: 14px; padding: 12px 14px; background: #1c1f27; border-radius: 6px; font-size: 15px; }

/* クイズ */
.quiz .qnum { font-size: 12px; color: var(--muted); letter-spacing: .15em; }
.quiz .opts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.quiz .opts button { text-align: left; padding: 12px 14px; background: #1d2028; border: 1px solid var(--line); border-radius: 6px; }
.quiz .opts button.ok { border-color: var(--safe); background: #1b2c23; }
.quiz .opts button.ng { border-color: var(--danger); background: #2e1b1d; }
.quiz .ex { margin-top: 12px; padding: 12px 14px; background: #1c1f27; border-radius: 6px; font-size: 15px; }
.endlist li { margin: 6px 0; }
.endlist .lock { color: #6c6a66; }
