:root {
  --ink: #f4f1ea;
  --ink-dim: #b9b4a8;
  --accent: #ffcf5a;
  --em: #ff5b5b;
  --dream: #ff9ecf;
  --panel: rgba(8, 10, 20, 0.92);
  --line: rgba(255, 255, 255, 0.18);
  --blue: #3f7dff;
  --fs: clamp(16px, 1.1vw + 1.1vh, 26px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
body { font-family: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif; color: var(--ink); -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; }

#stage { position: fixed; inset: 0; overflow: hidden; user-select: none; }
#stage.shake { animation: shake .45s; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); } 15% { transform: translate(-14px, 6px); } 30% { transform: translate(12px, -8px); }
  45% { transform: translate(-9px, -4px); } 60% { transform: translate(8px, 6px); } 80% { transform: translate(-4px, 2px); }
}

#bg { position: absolute; inset: 0; background: #000 center/cover no-repeat; transition: background-image .6s; }
#bg.fade { animation: bgfade .7s; }
@keyframes bgfade { from { filter: brightness(0); } to { filter: brightness(1); } }
#snow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#charas { position: absolute; left: 0; right: 0; bottom: 0; height: 88%; display: flex; justify-content: center; align-items: flex-end; gap: 1vw; pointer-events: none; }
#charas .sil { height: 100%; flex: 0 1 auto; opacity: 0; transition: opacity .5s; filter: drop-shadow(0 0 12px rgba(80, 140, 255, .45)); }
#charas .sil.on { opacity: .92; }
#charas .sil svg { height: 100%; width: auto; display: block; }

#tint { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .8s, background .8s; mix-blend-mode: multiply; }
#tint.red { background: #d0101a; opacity: .75; }
#tint.blue { background: #2a5cff; opacity: .6; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash .5s; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }

/* テキスト：画面全体に重ねる（かまいたちの夜風） */
#textlayer { position: absolute; inset: 0; background: linear-gradient(rgba(0,0,0,.52), rgba(0,0,0,.62)); padding: max(6vh, 44px) max(6vw, 18px) 12vh; cursor: pointer; transition: background .3s; }
#textlayer.hidden { opacity: 0; pointer-events: none; }
#textlayer.dim0 { background: rgba(0, 0, 0, 0.1); }
#text { max-width: 980px; margin: 0 auto; font-size: var(--fs); line-height: 1.95; letter-spacing: .04em; }
#text p { margin: 0 0 .15em; text-shadow: 0 0 6px #000, 0 0 2px #000, 2px 2px 0 #000; white-space: pre-wrap; word-break: break-word; }
#text p.em { color: var(--em); font-weight: 900; font-size: 1.22em; letter-spacing: .08em; }
#text p.dream { color: var(--dream); font-style: italic; }
#text .typing::after { content: ''; }
#cursor { position: absolute; right: max(6vw, 18px); bottom: 5vh; font-size: calc(var(--fs) * .9); color: var(--accent); opacity: 0; animation: blink 1s infinite; }
#cursor.on { opacity: 1; }
@keyframes blink { 50% { opacity: .2; } }

#choices { max-width: 980px; margin: 1.2em auto 0; display: flex; flex-direction: column; gap: .5em; }
#choices button { text-align: left; background: rgba(10, 20, 50, .55); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--blue); padding: .55em .9em; font-size: calc(var(--fs) * .95); line-height: 1.5; cursor: pointer; text-shadow: 0 0 4px #000; transition: background .15s, transform .15s; }
#choices button:hover, #choices button:focus-visible { background: rgba(40, 80, 180, .6); transform: translateX(6px); outline: none; }
#choices button .num { color: var(--accent); margin-right: .6em; }
#choices button.seen { color: var(--ink-dim); }
#choices button.gold { border-left-color: var(--accent); color: var(--accent); box-shadow: 0 0 14px rgba(255, 207, 90, .25); }
#choices button.gold .num::before { content: '✦ '; }

#titlecard { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #000; font-family: 'Yuji Syuku', 'Noto Serif JP', serif; font-size: calc(var(--fs) * 1.9); font-weight: 400; letter-spacing: .3em; opacity: 0; pointer-events: none; transition: opacity .8s; text-align: center; padding: 0 16px; }
#titlecard.on { opacity: 1; }

#hud { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 5; }
#hud button { background: rgba(0, 0, 0, .45); color: var(--ink-dim); border: 1px solid var(--line); font-size: 13px; padding: 6px 10px; border-radius: 3px; cursor: pointer; }
#hud button:hover { color: var(--ink); }
#hud button.active { color: #000; background: var(--accent); border-color: var(--accent); }
#stage.intitle #bg { filter: brightness(.5) saturate(.55); }
#stage.intitle #hud, #stage.intitle #textlayer, #stage.intitle #charas { display: none; }

.screen { position: absolute; inset: 0; display: none; z-index: 10; }
.screen.on { display: flex; }

/* タイトル */
#title { align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 45%, rgba(4,8,24,.55), rgba(0,0,6,.92) 75%); }
.title-inner { text-align: center; padding: 16px; }
.title-sub { letter-spacing: .8em; color: #8a93a8; font-size: 12px; margin-top: .4em; }
#title h1 { font-family: 'Yuji Syuku', 'Noto Serif JP', serif; font-size: clamp(44px, 9vw, 110px); margin: 0; font-weight: 400; letter-spacing: .02em; color: #f2f2f2; text-shadow: 0 0 2px rgba(255,255,255,.6), 3px 4px 0 rgba(0,0,0,.85), 0 0 40px rgba(120,150,255,.25); line-height: 1.1; filter: blur(.25px); }
#title h1 span { font-size: 1.45em; margin-left: .04em; vertical-align: -0.06em; }
.title-catch { color: #9aa3b5; font-size: clamp(12px, 1.4vw, 15px); line-height: 1.9; margin: 1.6em 0 2.6em; }
#title-menu { display: flex; flex-direction: column; gap: 4px; align-items: center; }
#title-menu button { position: relative; background: none; color: #d8d8d8; border: 0; padding: 6px 1.6em; font-size: clamp(16px, 2vw, 20px); letter-spacing: .35em; cursor: pointer; text-shadow: 2px 2px 0 #000; }
#title-menu button::before { content: '▶'; position: absolute; left: 0; top: 50%; transform: translateY(-50%); font-size: .7em; color: #e03030; opacity: 0; }
#title-menu button:hover, #title-menu button:focus-visible { color: #fff; outline: none; }
#title-menu button:hover::before, #title-menu button:focus-visible::before { opacity: 1; }
#title-menu button.gold { color: var(--accent); }
#title-info { margin-top: 1.6em; color: var(--ink-dim); font-size: 13px; letter-spacing: .1em; }

/* パネル */
#panel { align-items: center; justify-content: center; background: rgba(0,0,0,.6); }
.panel-inner { background: var(--panel); border: 1px solid var(--line); width: min(760px, calc(100% - 32px)); max-height: calc(100% - 40px); display: flex; flex-direction: column; padding: 22px 24px; }
#panel-title { margin: 0 0 14px; font-size: 20px; letter-spacing: .2em; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
#panel-body { overflow-y: auto; flex: 1; font-size: 15px; line-height: 1.8; }
#panel-close { margin-top: 14px; align-self: center; background: none; border: 1px solid var(--line); color: var(--ink); padding: 8px 30px; cursor: pointer; letter-spacing: .2em; }
#panel-close:hover { border-color: var(--blue); }
.row { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px dashed rgba(255,255,255,.08); }
.row .no { color: var(--ink-dim); width: 3em; flex: none; }
.row .tt { flex: 1; }
.row .ty { font-size: 12px; padding: 1px 8px; border: 1px solid; border-radius: 10px; flex: none; }
.ty.BAD { color: #ff7070; } .ty.NORMAL { color: #9fc4ff; } .ty.GOOD { color: #8fe0a0; } .ty.TRUE { color: var(--accent); }
.row.locked .tt { color: #666; }
.slot { width: 100%; text-align: left; background: rgba(255,255,255,.04); color: var(--ink); border: 1px solid var(--line); padding: 10px 14px; margin-bottom: 8px; cursor: pointer; font-size: 15px; line-height: 1.6; }
.slot:hover { border-color: var(--blue); background: rgba(40,80,180,.3); }
.slot small { color: var(--ink-dim); display: block; }
.slot:disabled { opacity: .45; cursor: default; }
.log p { margin: 0 0 .5em; }
.log .choice { color: var(--accent); }
.log .em { color: var(--em); }
.log .dream { color: var(--dream); font-style: italic; }
.log hr { border: 0; border-top: 1px dashed rgba(255,255,255,.12); }
.setting { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.setting label { width: 8em; }
.setting input { flex: 1; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list button { background: rgba(255,255,255,.04); color: var(--ink); border: 1px solid var(--line); padding: 12px; font-size: 16px; letter-spacing: .2em; cursor: pointer; }
.menu-list button:hover { border-color: var(--blue); background: rgba(40,80,180,.3); }
.help p { margin: 0 0 .8em; }
kbd { border: 1px solid var(--line); padding: 0 6px; border-radius: 3px; font-family: inherit; font-size: 13px; }

/* エンディング */
#ending { align-items: center; justify-content: center; background: #000; cursor: pointer; }
.ending-inner { text-align: center; padding: 16px; animation: rise 1.6s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
#ending-no { color: var(--ink-dim); letter-spacing: .4em; font-size: 15px; }
#ending-title { font-family: 'Yuji Syuku', 'Noto Serif JP', serif; font-size: clamp(32px, 5.5vw, 62px); font-weight: 400; margin: .3em 0; letter-spacing: .1em; }
#ending-type { display: inline-block; font-size: 14px; padding: 2px 16px; border: 1px solid; border-radius: 14px; letter-spacing: .3em; }
#ending-count { margin-top: 1.4em; color: var(--ink-dim); font-size: 14px; }
#ending-extra { margin-top: 1.6em; color: var(--accent); font-size: 16px; line-height: 1.9; }
.ending-hint { margin-top: 2.4em; color: #666; font-size: 13px; letter-spacing: .2em; }

@media (max-width: 640px) {
  #hud button { font-size: 12px; padding: 5px 7px; }
  #textlayer { padding-top: 56px; }
}

#toast { position: absolute; left: 50%; bottom: 8%; transform: translate(-50%, 10px); background: rgba(0,0,0,.8); border: 1px solid var(--accent); color: var(--accent); padding: 8px 22px; font-size: 15px; letter-spacing: .1em; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; z-index: 20; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
