:root {
  --paper: #efe6d2;
  --ink: #1b1815;
  --shu: #c8401e;
  --lead: #6a6d73;
  --lead-hi: #c9ccd1;
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1d1a17; overflow: hidden; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#stage {
  position: fixed; inset: 0; background: var(--paper); color: var(--ink);
  font-family: var(--mincho); user-select: none; -webkit-user-select: none; overflow: hidden;
  cursor: default;
}
/* 紙の繊維と周辺の焼け */
#stage::before {
  content: ""; position: absolute; inset: 0; z-index: 60; pointer-events: none; mix-blend-mode: multiply; opacity: .5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .40  0 0 0 0 .32  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
#stage::after {
  content: ""; position: absolute; inset: 0; z-index: 61; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(84, 62, 30, .22) 100%);
}

/* ── 挿絵：紙に乗算で刷る ── */
.illust {
  position: absolute; left: 0; top: 0; bottom: 0; width: 68%;
  background-size: cover; background-position: center; mix-blend-mode: multiply;
  opacity: 0; filter: blur(16px) brightness(1.3) contrast(.5);
  transition: opacity 2.4s ease, filter 3s ease;
  -webkit-mask-image: linear-gradient(90deg, #000 52%, transparent 97%);
  mask-image: linear-gradient(90deg, #000 52%, transparent 97%);
}
.illust.on { opacity: .95; filter: blur(0) brightness(1.07) contrast(1.06); }

/* ── 本文 ── */
#page {
  position: absolute; z-index: 10; top: 12vh; right: 7vw; height: 68vh; max-width: 62vw;
  writing-mode: vertical-rl; font-size: clamp(16px, 2.55vh, 24px); line-height: 2.15; letter-spacing: .09em;
  font-weight: 600; transition: opacity .4s ease, transform .5s ease;
  text-shadow: 0 0 5px var(--paper), 0 0 10px var(--paper), 0 0 18px var(--paper), 0 0 26px var(--paper);
}
#page.out { opacity: 0; transform: translateX(-24px); }
.line { margin: 0; text-indent: 1em; }
.line.sp { text-indent: 0; }
.line.wait { visibility: hidden; position: absolute; }
.c { opacity: 0; }
.c.on { opacity: var(--o, 1); animation: stamp .16s ease-out; }
@keyframes stamp { from { opacity: 0; color: var(--shu); } }

/* ── 行間 ── */
.gap { position: relative; block-size: 10px; inline-size: 100%; }
.gap.wait { display: none; }
.gap.live { cursor: col-resize; touch-action: none; }
.gap.live::after { content: ""; position: absolute; inset: 0 -16px; }
.gap.live::before {
  content: ""; position: absolute; top: 3%; bottom: 3%; left: calc(50% - 1px); width: 2px; border-radius: 2px;
  background: linear-gradient(180deg, transparent, var(--lead) 20%, var(--lead-hi) 50%, var(--lead) 80%, transparent);
  opacity: .25; animation: shimmer 2.6s ease-in-out infinite;
}
.gap.live:hover::before, .gap.prying::before { opacity: 1; width: 4px; left: calc(50% - 2px); animation: none; }
.gap.no { animation: shake .3s; }
@keyframes shimmer { 50% { opacity: .75; } }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.gap.open { block-size: auto; cursor: default; padding-block: 3px; animation: settle .35s ease-out; }
.gap.open::before, .gap.open::after { display: none; }
@keyframes settle { from { transform: scaleX(1.15); } }
.bar {
  block-size: 5px; inline-size: 100%; border-radius: 1px;
  background: linear-gradient(90deg, #4c4f55, #d5d8dc 40%, #8d9096 60%, #3f4247);
  box-shadow: 0 0 0 .5px rgba(0, 0, 0, .35), 2px 2px 5px rgba(0, 0, 0, .25);
}
.hid {
  margin: 0 .25em; font-size: .8em; line-height: 1.85; color: #474a52; font-weight: 400; text-indent: 0;
  letter-spacing: .06em;
}
.hid::before { content: "〈"; } .hid::after { content: "〉"; }

#hint {
  position: absolute; z-index: 20; left: 50%; bottom: 13vh; transform: translateX(-50%);
  font-size: 14px; letter-spacing: .2em; color: var(--shu); opacity: 0; transition: opacity .8s; pointer-events: none;
  white-space: nowrap; padding: .4em 1.2em; background: rgba(239, 230, 210, .88); border-block: 1px solid var(--shu);
}
#hint.on { opacity: 1; }

/* ── ボタン ── */
.btn {
  font-family: var(--mincho); font-weight: 600; background: transparent; border: 1px solid var(--ink);
  padding: .55em 1.6em; letter-spacing: .3em; cursor: pointer; transition: background .2s, color .2s; font-size: 15px;
}
.btn:hover { background: var(--ink); color: var(--paper); }
#next { position: absolute; z-index: 20; right: 7vw; bottom: 5.5vh; background: rgba(239, 230, 210, .85); }
#next:hover { background: var(--ink); }

/* ── HUD ── */
#hud { position: absolute; z-index: 20; left: 3vw; bottom: 4vh; display: flex; flex-direction: column; gap: 10px; }
.hudrow { display: flex; align-items: center; gap: 12px; background: rgba(239, 230, 210, .8); padding: 4px 10px 4px 6px; width: fit-content; }
.hudlabel { font-size: 11px; letter-spacing: .25em; opacity: .65; width: 5.4em; }
#leads { display: flex; gap: 5px; min-height: 8px; }
#leads i {
  display: block; width: 46px; height: 7px; border-radius: 1px;
  background: linear-gradient(180deg, #d5d8dc, #8d9096 45%, #4c4f55); box-shadow: 1px 1px 3px rgba(0, 0, 0, .3);
  animation: drop .4s ease-out;
}
#leads em { font-style: normal; font-size: 11px; opacity: .45; letter-spacing: .1em; }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }
#tray { display: flex; flex-wrap: wrap; gap: 5px; max-width: 46vw; }
.type {
  font-size: 12px; font-weight: 600; letter-spacing: .08em; padding: 3px 8px 4px; color: #ecebe6; border-radius: 1px;
  background: linear-gradient(180deg, #7b7e84, #4b4e54); box-shadow: inset 0 1px 0 #b9bcc2, 1px 1px 3px rgba(0, 0, 0, .35);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .5);
}
.type.new { animation: drop .6s ease-out; }
.type[data-slot="A"] { border-bottom: 2px solid #c8401e; }
.type[data-slot="B"] { border-bottom: 2px solid #d9a441; }
.type[data-slot="C"] { border-bottom: 2px solid #4d7f8c; }

#tools { position: absolute; z-index: 70; right: 2vw; top: 2.4vh; display: flex; gap: 8px; }
.tool { font-family: var(--mincho); font-size: 11px; letter-spacing: .2em; background: none; border: none; opacity: .45; cursor: pointer; padding: 6px; }
.tool:hover, .tool.on { opacity: 1; color: var(--shu); }

#toast {
  position: absolute; z-index: 80; left: 50%; top: 7vh; transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  transition: opacity .5s, transform .5s; font-size: 14px; letter-spacing: .22em; white-space: nowrap;
  padding: .7em 1.6em; background: var(--ink); color: var(--paper);
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast b { color: #f0a58c; font-weight: 600; }

/* ── オーバーレイ共通 ── */
#overlay {
  position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: var(--paper); opacity: 0; transition: opacity .7s ease;
}
#overlay.on { opacity: 1; }
#overlay.veil { background: rgba(239, 230, 210, .9); }
#overlay.dark { background: radial-gradient(ellipse at 50% 40%, #2c2723, #151210); color: #d8d2c4; }

/* 章扉 */
.card { height: 62vh; display: flex; flex-direction: row-reverse; gap: 3.2vw; align-items: flex-start; }
.card > * { writing-mode: vertical-rl; white-space: nowrap; }
.card .no { font-size: 15px; letter-spacing: .6em; color: var(--shu); padding-top: 1em; }
.card .ttl { font-size: clamp(56px, 11vh, 110px); font-weight: 800; letter-spacing: .18em; line-height: 1; }
.card .term { font-size: 17px; letter-spacing: .2em; font-weight: 600; border-inline-start: 0; padding-top: 30vh; }
.card .def { font-size: 14px; letter-spacing: .16em; line-height: 2.1; padding-top: 30vh; max-height: 62vh; white-space: normal; }
.card > * { opacity: 0; animation: rise 1.1s ease forwards; }
.card > :nth-child(2) { animation-delay: .35s; } .card > :nth-child(3) { animation-delay: 1s; } .card > :nth-child(4) { animation-delay: 1.4s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(4px); } to { opacity: 1; } }

/* 題字 */
.tcard { text-align: center; }
.tcard h2, #title h1 { writing-mode: vertical-rl; margin: 0 auto; font-weight: 800; letter-spacing: .12em; line-height: 1.05; }
.tcard h2 { font-size: clamp(54px, 12.5vh, 130px); white-space: nowrap; }
.tcard h2 span, #title h1 span { display: inline-block; opacity: 0; animation: stampBig .5s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.tcard h2 span:nth-child(1), #title h1 span:nth-child(1) { animation-delay: .3s; }
.tcard h2 span:nth-child(2), #title h1 span:nth-child(2) { animation-delay: 1.0s; margin-top: .42em; }
.tcard h2 span:nth-child(3), #title h1 span:nth-child(3) { animation-delay: 1.7s; font-size: .5em; margin: .35em 0; }
.tcard h2 span:nth-child(4), #title h1 span:nth-child(4) { animation-delay: 2.4s; }
.lead-ch {
  background: linear-gradient(160deg, #3d4046 10%, #b9bcc2 42%, #5a5d63 58%, #2b2d31 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
@keyframes stampBig { from { opacity: 0; transform: scale(1.5); filter: blur(6px); } to { opacity: 1; } }

/* ── 抜き（言いすぎた言葉を消す） ── */
.strike { display: flex; flex-direction: row-reverse; align-items: center; gap: 5vw; }
.strike .note { writing-mode: vertical-rl; font-size: 13px; letter-spacing: .3em; color: var(--shu); height: 50vh; }
.draft { writing-mode: vertical-rl; height: 80vh; font-size: clamp(20px, 3.5vh, 42px); font-weight: 800; letter-spacing: .1em; line-height: 1.5; white-space: nowrap; }
.seg { transition: color .3s, opacity .3s; position: relative; }
.seg.cut { cursor: pointer; background: linear-gradient(90deg, transparent 46%, rgba(200, 64, 30, .16) 46%, rgba(200, 64, 30, .16) 54%, transparent 54%); }
.seg.cut:hover { color: var(--shu); }
.seg.x { color: rgba(27, 24, 21, .22); text-decoration: line-through; text-decoration-color: var(--shu); text-decoration-thickness: 3px; background: none; }
.strike .side { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.strike .said { writing-mode: vertical-rl; height: 44vh; font-size: 15px; letter-spacing: .15em; opacity: .7; line-height: 1.9; }

/* ── 組版と印刷 ── */
.printer { display: flex; align-items: center; gap: 4vw; font-family: var(--mincho); }
.bed {
  position: relative; padding: 22px; background: linear-gradient(145deg, #4a443e, #2a2623);
  box-shadow: 0 0 0 9px #1b1815, 0 0 0 11px #5a534b, 0 30px 80px rgba(0, 0, 0, .7), inset 0 0 30px rgba(0, 0, 0, .6);
  transition: transform .5s ease;
}
.forme {
  writing-mode: vertical-rl; transform: scaleX(-1); height: 62vh; min-width: 180px;
  font-size: clamp(17px, 3.1vh, 30px); font-weight: 800; letter-spacing: .14em; line-height: 1;
}
.fl {
  display: block; padding: .32em .22em; color: #cfcabb; white-space: nowrap;
  background: linear-gradient(270deg, #57514a, #3b3632 60%, #2c2825);
  text-shadow: 0 0 1px #000, -1px -1px 0 rgba(0, 0, 0, .7), 1px 1px 0 rgba(255, 255, 255, .13);
}
.fbar { display: block; block-size: 6px; background: linear-gradient(90deg, #4c4f55, #aeb1b6 40%, #6f7278 60%, #33363a); }
.slot { color: #f08a66; cursor: pointer; padding-block: .15em; border-inline: 1px dashed rgba(240, 138, 102, .7); transition: background .2s; }
.slot:hover, .slot.sel { background: rgba(240, 138, 102, .25); }
.slot.empty { letter-spacing: .05em; color: #0d0b0a; text-shadow: 0 0 6px rgba(240, 138, 102, .9); }
.pside { width: min(30vw, 330px); display: flex; flex-direction: column; gap: 14px; align-items: flex-start; min-height: 54vh; justify-content: center; }
.pside .note { font-size: 13px; letter-spacing: .22em; line-height: 2; opacity: .8; }
.cands { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.cand {
  font-family: var(--mincho); font-weight: 600; text-align: left; cursor: pointer; padding: .6em .9em; letter-spacing: .12em; font-size: 15px;
  color: #ecebe6; border: none; border-radius: 1px; background: linear-gradient(180deg, #7b7e84, #4b4e54);
  box-shadow: inset 0 1px 0 #b9bcc2, 2px 2px 6px rgba(0, 0, 0, .5); text-shadow: 0 -1px 0 rgba(0, 0, 0, .5);
}
.cand:hover { filter: brightness(1.2); }
.cand.keep { background: #191614; color: #8f897c; box-shadow: inset 0 0 0 1px #4a443e; }
.cand small { display: block; font-size: 10px; opacity: .6; letter-spacing: .2em; margin-top: 2px; font-weight: 400; }
.pull {
  position: relative; width: 132px; height: 132px; border-radius: 50%; border: none; cursor: pointer; touch-action: none;
  background: radial-gradient(circle, #2a2623 38%, transparent 39%), conic-gradient(var(--shu) calc(var(--p, 0) * 360deg), #4a443e 0);
  color: #d8d2c4; font-family: var(--mincho); font-weight: 600; letter-spacing: .2em; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .6);
}
.pull::before {
  content: ""; position: absolute; inset: 9px; border-radius: 50%; pointer-events: none;
  background: repeating-conic-gradient(from calc(var(--p, 0) * 900deg), rgba(216, 210, 196, .32) 0 4deg, transparent 4deg 60deg);
  -webkit-mask: radial-gradient(circle, transparent 54%, #000 55%); mask: radial-gradient(circle, transparent 54%, #000 55%);
}
.pull small { display: block; font-size: 10px; opacity: .6; margin-top: 4px; letter-spacing: .15em; }
.bed.pressed { transform: scale(.965); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 90; }
.flash.go { animation: flash .9s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
.sheet {
  writing-mode: vertical-rl; height: 78vh; padding: 8vh 5vw; background: #f6efdf; color: var(--ink);
  font-size: clamp(17px, 3.1vh, 30px); font-weight: 800; letter-spacing: .14em; line-height: 2.3;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .75); transform: rotate(-.6deg); animation: lift 1.1s cubic-bezier(.2, .9, .3, 1);
}
.sheet p { margin: 0; white-space: nowrap; }
.sheet .c.on { text-shadow: 0 0 .6px var(--ink); }
@keyframes lift { from { transform: translateY(40px) rotate(2deg) scale(.94); opacity: 0; } }

/* ── 結び ── */
.endcard { height: 66vh; display: flex; flex-direction: row-reverse; gap: 3.4vw; align-items: flex-start; }
.endcard > * { writing-mode: vertical-rl; white-space: nowrap; }
.endcard .big { font-size: clamp(50px, 10vh, 100px); font-weight: 800; letter-spacing: .14em; line-height: 1; }
.endcard .k { font-size: 13px; letter-spacing: .5em; color: var(--shu); padding-top: 1em; }
.endcard .v { font-size: 16px; letter-spacing: .22em; line-height: 2.2; padding-top: 22vh; }
.endcard .v b { font-size: 1.5em; }
.endcard .btn { writing-mode: horizontal-tb; align-self: flex-end; margin-right: 3vw; }
.endcard > * { opacity: 0; animation: rise 1.2s ease forwards; }
.endcard > :nth-child(2) { animation-delay: .8s; } .endcard > :nth-child(3) { animation-delay: 1.6s; }
.endcard > :nth-child(4) { animation-delay: 2.2s; } .endcard > :nth-child(5) { animation-delay: 3s; }

/* ── タイトル ── */
#title { position: absolute; inset: 0; z-index: 65; background: var(--paper); transition: opacity 1.2s ease; }
#title.gone { opacity: 0; pointer-events: none; }
.titleart {
  position: absolute; left: 0; top: 0; bottom: 0; width: 70%; background: url(img/title.png) 12% center/cover; mix-blend-mode: multiply;
  filter: brightness(1.07) contrast(1.06); opacity: .95;
  -webkit-mask-image: linear-gradient(90deg, #000 50%, transparent 96%); mask-image: linear-gradient(90deg, #000 50%, transparent 96%);
  animation: soak 4s ease;
}
@keyframes soak { from { opacity: 0; filter: blur(18px) brightness(1.4) contrast(.4); } }
.titlebox { position: absolute; right: 9vw; top: 9vh; height: 76vh; display: flex; flex-direction: row-reverse; gap: 2.6vw; }
#title h1 { font-size: clamp(56px, 13.5vh, 140px); height: 76vh; white-space: nowrap; }
#title .sub { writing-mode: vertical-rl; margin: 0; font-size: 11px; letter-spacing: .55em; color: var(--shu); padding-top: .8em; font-family: Georgia, serif; }
#title .lede { writing-mode: vertical-rl; margin: 0; font-size: 15px; letter-spacing: .22em; line-height: 2.2; padding-top: 28vh; white-space: nowrap; font-weight: 600; opacity: 0; animation: rise 1.6s ease 3.2s forwards; }
.titlemenu { position: absolute; left: 6vw; bottom: 9vh; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; opacity: 0; animation: rise 1.2s ease 3.6s forwards; }
.titlemenu .btn { background: rgba(239, 230, 210, .85); }
.titlemenu .btn:hover { background: var(--ink); }
#record { margin: 0 0 0 8px; font-size: 12px; letter-spacing: .2em; background: rgba(239, 230, 210, .8); padding: 2px 8px; }
#record:empty { display: none; }
.copy { position: absolute; right: 3vw; bottom: 2.4vh; margin: 0; font-size: 10px; letter-spacing: .2em; opacity: .55; font-family: Georgia, serif; }

/* ── 縦長の画面 ── */
@media (max-aspect-ratio: 1/1) {
  .illust, .titleart { width: 100%; bottom: auto; height: 46%; -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent 98%); mask-image: linear-gradient(180deg, #000 55%, transparent 98%); }
  #page { top: 34vh; height: 48vh; right: 5vw; max-width: 90vw; font-size: clamp(15px, 2vh, 20px); }
  .titlebox { top: 30vh; height: 50vh; } #title h1 { height: 50vh; font-size: 9vh; } #title .lede { padding-top: 18vh; }
  #hud { bottom: 2vh; } #next { bottom: 11vh; } #hint { bottom: 18vh; white-space: normal; width: 86vw; text-align: center; }
  .printer, .strike { flex-direction: column; gap: 3vh; } .forme, .sheet { height: 38vh; } .pside { width: 84vw; min-height: 0; }
  .draft { height: 46vh; } .strike .said, .strike .note { height: auto; writing-mode: horizontal-tb; }
}
