:root {
  --paper: #f2ece0;
  --ink: #14120f;
  --shu: #c8402a;
  --fg: #1d1a16;
  --fg-dim: rgba(29, 26, 22, .7);
  --panel: rgba(242, 236, 224, .72);
  --line: rgba(29, 26, 22, .22);
  --mincho: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --brush: "Yuji Syuku", "Shippori Mincho", "Yu Mincho", serif;
  --latin: "Cormorant Garamond", "Shippori Mincho", serif;
  --ease: cubic-bezier(.2, .7, .1, 1);
}
body[data-theme="night"] {
  --fg: #f2ece0;
  --fg-dim: rgba(242, 236, 224, .76);
  --panel: rgba(12, 14, 22, .5);
  --line: rgba(242, 236, 224, .25);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--fg); }
body { font-family: var(--mincho); -webkit-font-smoothing: antialiased; touch-action: none; user-select: none; -webkit-user-select: none; transition: color .4s; }
body.started { cursor: none; }
body.started.ended { cursor: auto; }
body.started button { cursor: pointer; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; font-family: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--shu); outline-offset: 3px; }

/* ---------- 起動画面 ---------- */
.boot { position: absolute; inset: 0; transition: opacity 1s var(--ease); }
.boot.gone { opacity: 0; pointer-events: none; }
.boot-list {
  position: absolute; top: 50%; right: max(6vw, 28px); transform: translateY(-50%);
  margin: 0; padding: 0; list-style: none; height: 11em;
  writing-mode: vertical-rl; font-size: clamp(13px, 1.25vw, 16px); letter-spacing: .3em; color: var(--fg-dim);
}
.boot-list li { display: block; margin-left: .9em; opacity: .28; transition: opacity .5s, color .5s; }
.boot-list li.done { opacity: 1; color: var(--fg); }
.boot-list li.done::after { content: "　了"; color: var(--shu); }
.boot-cta {
  position: absolute; left: 50%; bottom: max(9vh, 40px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; width: min(92vw, 420px);
}
.boot-status { margin: 0; font-size: 14px; letter-spacing: .25em; color: var(--fg-dim); }
.btn-start {
  pointer-events: auto; border: 0; background: var(--ink); color: var(--paper) !important;
  padding: 14px 40px 12px; border-radius: 2px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: var(--mincho); letter-spacing: .4em; transition: transform .3s var(--ease), opacity .4s, background .3s;
  box-shadow: 0 10px 30px -12px rgba(20, 18, 15, .6);
}
.btn-start:disabled { opacity: .25; }
.btn-start:not(:disabled):hover { transform: translateY(-2px); background: #2a2520; }
.btn-start-main { font-size: 20px; padding-left: .4em; }
.btn-start-sub { font-size: 11px; letter-spacing: .2em; opacity: .7; }
.btn-watch {
  border: 0; background: none; font-size: 14px; letter-spacing: .3em; padding: 8px 14px;
  border-bottom: 1px solid var(--line); transition: opacity .3s;
}
.btn-watch:disabled { opacity: .25; }
.boot-note { margin: 4px 0 0; font-size: 12px; letter-spacing: .1em; color: var(--fg-dim); line-height: 1.8; }

/* ---------- ヘッダ ---------- */
.top { isolation: isolate;
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) clamp(14px, 2.4vw, 32px) 0; gap: 12px;
  opacity: 0; transition: opacity 1.2s var(--ease);
}
body.started .top { opacity: 1; }
/* ヘッダの背後の薄い帯（主役がヘッダ下に来ても文字が読めるように） */
.top::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 92px; z-index: -1; pointer-events: none;
  background: linear-gradient(to bottom, rgba(242, 236, 224, .62), rgba(242, 236, 224, .3) 55%, rgba(242, 236, 224, 0));
  transition: background .4s;
}
body[data-theme="night"] .top::before { background: linear-gradient(to bottom, rgba(8, 10, 18, .55), rgba(8, 10, 18, .22) 55%, rgba(8, 10, 18, 0)); }
.mark { display: flex; align-items: baseline; gap: 10px; }
.mark-k { font-family: var(--brush); font-size: 30px; line-height: 1; }
.mark-r { font-family: var(--latin); font-size: 15px; letter-spacing: .45em; font-weight: 600; }
.rail { display: flex; gap: 2px; align-items: center; }
.rail-i {
  border: 0; background: none; padding: 6px 7px; font-size: 13px; letter-spacing: .05em; color: var(--fg-dim) !important;
  position: relative; transition: color .4s;
}
.rail-i::after { content: ""; position: absolute; left: 50%; bottom: 0; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; opacity: 0; transition: opacity .4s; }
.rail-i.past { color: var(--fg) !important; opacity: .75; }
.rail-i.on { color: var(--fg) !important; opacity: 1; }
.rail-i.on::after { opacity: 1; background: var(--shu); }
.rail-i:hover { color: var(--fg) !important; }
.top-btns { display: flex; gap: 8px; }
.top-btns button {
  border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 7px 12px 6px; font-size: 12px; letter-spacing: .15em; display: flex; align-items: center; gap: 7px; border-radius: 2px;
}
.btn-auto .ico { font-size: 9px; color: var(--shu); }
.btn-auto[aria-pressed="true"] { border-color: var(--shu); }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 10px; }
.bars i { width: 2px; background: currentColor; height: 100%; animation: bar 1.1s ease-in-out infinite; }
.bars i:nth-child(2) { animation-delay: -.3s; } .bars i:nth-child(3) { animation-delay: -.6s; } .bars i:nth-child(4) { animation-delay: -.9s; }
.btn-sound.off .bars i { animation: none; height: 2px; }
@keyframes bar { 0%, 100% { height: 30%; } 50% { height: 100%; } }

/* ---------- 章タイトル ---------- */
.card {
  position: absolute; top: 50%; right: clamp(24px, 9vw, 160px); transform: translateY(-50%);
  writing-mode: vertical-rl; display: flex; flex-direction: column; align-items: flex-start; gap: .6em;
  opacity: 0; transition: opacity 1.2s var(--ease), transform 1.4s var(--ease), top 1.4s var(--ease), right 1.4s var(--ease);
  text-shadow: 0 0 18px var(--panel);
}
.card.in { opacity: 1; }
.card p, .card h2 { margin: 0; }
.card-no { font-size: 14px; letter-spacing: .5em; color: var(--shu); }
.card-k { font-family: var(--brush); font-weight: 400; font-size: clamp(64px, 9vw, 132px); line-height: 1; letter-spacing: .05em; }
.card-r { font-family: var(--latin); font-size: 14px; letter-spacing: .6em; writing-mode: vertical-rl; color: var(--fg-dim); }
.card-s { font-size: 15px; letter-spacing: .35em; color: var(--fg-dim); }
.card.small { top: 76px; right: clamp(14px, 2.4vw, 32px); transform: translateY(0) scale(.42); transform-origin: top right; opacity: .8; }
.card.small .card-s, .card.small .card-r { opacity: 0; transition: opacity .6s; }

/* ---------- 操作の案内 ---------- */
.act {
  position: absolute; left: 50%; bottom: max(36px, calc(env(safe-area-inset-bottom) + 24px)); transform: translate(-50%, 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; opacity: 0; transition: opacity .8s var(--ease), transform .8s var(--ease);
  text-shadow: 0 0 14px var(--panel), 0 0 4px var(--panel);
}
.act.show { opacity: 1; transform: translate(-50%, 0); transition-delay: 1.6s; }
.act.done { opacity: 0; transition-delay: .5s; }
.act p { margin: 0; }
.act-text { font-size: clamp(16px, 1.6vw, 20px); letter-spacing: .32em; padding-left: .32em; white-space: nowrap; }
.act-prog { display: flex; gap: 10px; align-items: center; min-height: 10px; }
.act-prog i { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--fg); opacity: .6; transition: all .4s var(--ease); }
.act-prog i.on { background: var(--shu); border-color: var(--shu); opacity: 1; transform: scale(1.25); }
.act-prog b { display: block; width: min(220px, 50vw); height: 3px; background: var(--line); overflow: hidden; border-radius: 2px; }
.act-prog s { display: block; height: 100%; background: var(--shu); transform-origin: left; transform: scaleX(0); transition: transform .25s linear; }
.act-remain { font-size: 13px; letter-spacing: .25em; color: var(--fg-dim); min-height: 1.2em; }

/* ---------- 次へ・ヒント ---------- */
.btn-next {
  position: absolute; right: clamp(14px, 2.4vw, 32px); bottom: max(30px, calc(env(safe-area-inset-bottom) + 20px));
  border: 0; background: none; font-size: 13px; letter-spacing: .3em; display: flex; align-items: center; gap: 8px; padding: 10px 6px;
  opacity: 0; transition: opacity .8s; color: var(--fg) !important; min-height: 44px; font-size: 14px;
}
.btn-next.show { opacity: .82; }
.btn-next.show:hover { opacity: 1; }
/* 遷移中: 前の章の案内は隠し、レールは薄く */
body.trans .act { opacity: 0 !important; transition-delay: 0s !important; }
body.trans .rail { opacity: .3; }
.rail { transition: opacity .5s; }
.mark-ch { display: none; font-size: 12px; letter-spacing: .2em; color: var(--fg-dim); }
.kbd { }
.for-touch { display: none; }
@media (hover: none) { .kbd { display: none; } .for-pointer { display: none; } .for-touch { display: inline; } }
.btn-next:hover { color: var(--fg) !important; }
.btn-next .arr { font-size: 20px; line-height: 1; }
.btn-next[hidden] { display: none; }
.hint {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); margin: 0; font-size: 15px; letter-spacing: .25em;
  opacity: 0; transition: opacity .6s; white-space: nowrap; text-shadow: 0 0 14px var(--panel), 0 0 4px var(--panel);
}
.hint.show { opacity: 1; }

/* ---------- 筆先カーソル ---------- */
.cursor { position: absolute; left: 0; top: 0; width: 0; height: 0; opacity: 0; transition: opacity .3s; }
body.started .cursor { opacity: 1; }
.cursor.hide { opacity: 0 !important; }
.cursor i {
  position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--fg); transition: transform .18s var(--ease), background .2s;
}
.cursor.down i { transform: scale(.55); background: var(--fg); }
.cursor span { position: absolute; left: 14px; top: 10px; font-size: 10px; letter-spacing: .2em; white-space: nowrap; opacity: 0; color: var(--shu); }
.cursor.bot i { border-color: var(--shu); border-style: dashed; }
.cursor.bot.down i { background: var(--shu); }
.cursor.bot span { opacity: .9; }
@media (hover: none) { .cursor:not(.bot) { display: none; } }

.layers, .layer { position: absolute; inset: 0; }
.layer[hidden] { display: none; }

/* ---------- 狭い画面 ---------- */
@media (max-width: 720px) {
  .rail { display: none; }
  .mark-r { display: none; }
  .mark-ch { display: inline; }
  .top-btns button { padding: 7px 10px 6px; min-height: 44px; }
  .card { right: 18px; }
  .card.small { top: 64px; right: 14px; }
  .act-text { font-size: 15px; letter-spacing: .2em; }
  .boot-list { right: 18px; top: 40%; font-size: 12px; }
}
/* 縦長: 章題は上 1/4 の右寄りに小さく出す（主役に重ねない） */
@media (max-aspect-ratio: 1/1) {
  .card { top: 84px; right: 16px; transform: scale(.68); transform-origin: top right; }
  .card.small { top: 64px; right: 12px; transform: scale(.36); }
}
@media (prefers-reduced-motion: reduce) {
  .bars i { animation: none; }
}

/* 撮影モード（仮想時計）: CSS の遷移・アニメは実時間で進むので止める */
body.capture *, body.capture *::before, body.capture *::after { transition: none !important; animation: none !important; }
