:root {
  --ink: #f2f2f0;       /* 文字 */
  --paper: #000000;     /* 背景 */
  --card: #141414;
  --soft: rgba(255, 255, 255, .12);
  --mute: #7c7c7c;
  --theme: #e6ff00;     /* テーマカラー（蛍光イエロー） */
  --on-theme: #000000;  /* テーマカラーの上に載せる文字 */
  --heart: var(--theme);
  --hd: 52px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  background: var(--paper); color: var(--ink);
  overflow: hidden; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
.sp-only { display: none; }

/* ---------- ヘッダー ---------- */
.hd {
  height: var(--hd); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--paper);
  position: relative; z-index: 30;
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--ink); text-decoration: none; font-size: 17px; }
.hd-btns { display: flex; gap: 8px; }
.btn {
  border: 0; background: var(--soft); border-radius: 999px;
  padding: 7px 15px; font-size: 13px; font-weight: 700; line-height: 1.2;
  transition: background .3s, color .3s;
}
.btn:hover { background: var(--theme); color: var(--on-theme); }
.btn:focus-visible, .toc button:focus-visible, .heart:focus-visible, .linkbtn:focus-visible, .play:focus-visible {
  outline: 3px solid var(--theme); outline-offset: 2px;
}

/* ---------- 3分割 ---------- */
.app {
  height: calc(100dvh - var(--hd));
  display: grid;
  --mid: min(calc((100dvh - var(--hd) - 40px) * 9 / 16 + 40px), 46vw);
  grid-template-columns: minmax(0, 1fr) var(--mid) minmax(0, 1.35fr);
  grid-template-rows: minmax(0, 1fr);
  position: relative;
}

/* 目次 */
.toc { grid-column: 1; grid-row: 1; padding: 28px 12px 28px 20px; overflow: auto; }
.toc ol { list-style: none; margin: 0 0 0 auto; padding: 0; max-width: 240px; counter-reset: n; }
.toc li { counter-increment: n; }
.toc button {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 10px; border-radius: 10px;
  font-size: 15px; font-weight: 600; color: var(--mute);
  transition: color .4s, background .4s, padding .4s;
}
.toc button::before { content: counter(n, decimal-leading-zero); font-size: 11px; font-variant-numeric: tabular-nums; opacity: .7; }
.toc button:hover { color: var(--ink); }
.toc button[aria-current="true"] { color: var(--on-theme); background: var(--theme); padding-left: 16px; }

/* ショート */
.stage { grid-column: 2; grid-row: 1; position: relative; min-width: 0;  }
.feed {
  height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; overscroll-behavior: contain;
  scrollbar-width: none; outline: none;
}
.feed::-webkit-scrollbar { display: none; }
.item { height: 100%; scroll-snap-align: start; scroll-snap-stop: always; display: grid; place-items: center; container-type: size; }
.endcap { height: 34%; scroll-snap-align: end; display: grid; place-items: center; color: var(--mute); font-weight: 700; font-size: 14px; letter-spacing: .2em; }
.scene {
  width: min(100cqw - 40px, (100cqh - 40px) * 9 / 16); aspect-ratio: 9 / 16;
  position: relative; overflow: hidden; border-radius: 20px; background: #111;
  opacity: .25; transition: opacity .7s;
}
.item.on .scene { opacity: 1; }
.scene video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

/* ハート */
.heart {
  position: absolute; right: 32px; bottom: 40px; z-index: 6;
  width: 58px; padding: 9px 0 6px; border-radius: 30px;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; justify-items: center; gap: 1px; font-size: 12px; font-weight: 800;
  font-variant-numeric: tabular-nums; transition: transform .12s;
}
.heart svg { width: 28px; height: 28px; fill: none; stroke: var(--ink); stroke-width: 1.6; transition: fill .15s, stroke .15s, transform .15s; }
.heart.liked svg { fill: var(--heart); stroke: var(--heart); }
.heart:hover { transform: scale(1.08); }
.heart:active svg { transform: scale(.8); }
.heart.pop svg { animation: heartpop .35s; }
@keyframes heartpop { 40% { transform: scale(1.45) rotate(-8deg); } }
.fly {
  position: absolute; z-index: 7; pointer-events: none; color: var(--heart); font-size: 22px;
  animation: fly 1s ease-out forwards;
}
@keyframes fly { to { transform: translate(var(--dx), -150px) scale(1.6) rotate(var(--rot)); opacity: 0; } }

/* 原稿 */
.script { grid-column: 3; grid-row: 1; min-width: 0; overflow: hidden; position: relative; }
.script-body {
  height: 100%; overflow-y: auto; padding: 32px clamp(18px, 3vw, 44px) 300px;
  max-width: 620px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, #000 44px, #000 calc(100% - 200px), transparent);
  mask-image: linear-gradient(transparent, #000 44px, #000 calc(100% - 200px), transparent);
}
.script-body::-webkit-scrollbar { display: none; }
.fadein { animation: fadein .7s ease both; }
@keyframes fadein { from { opacity: 0; } }
.script h1 { font-size: clamp(22px, 2.2vw, 30px); margin: 0 0 20px; line-height: 1.3; }
.script h1 { transition: color .6s; }
.script h1.now { color: var(--theme); }
.credit { margin: 22px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--mute); }
.toc-credit { max-width: 240px; margin: 28px 0 0 auto; padding: 0 10px; font-size: 10.5px; line-height: 1.8; color: var(--mute); opacity: .8; }
.script h1 small { display: block; font-size: 11px; letter-spacing: .14em; color: var(--mute); font-weight: 700; margin-bottom: 6px; }
.ln { margin: 0 0 .7em; font-size: clamp(15px, 1.25vw, 18px); line-height: 1.85; color: var(--ink); opacity: .16; transition: opacity .8s ease; }
.ln.gap { margin-top: 1.5em; }
.ln.done { opacity: .45; }
.ln.now { opacity: 1; color: var(--theme); }
body.is-loading .ln.done { opacity: 1; }
.links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.linkbtn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  border: 0; border-radius: 999px; padding: 10px 18px;
  background: var(--theme); color: var(--on-theme); font-weight: 800; font-size: 14px;
  opacity: .55; transition: background .3s, opacity .6s, transform .2s;
  white-space: nowrap; flex: none; /* せまい列でも折り返して縦長にならないように */
}
.linkbtn::after { content: "↗"; font-weight: 400; }
.linkbtn:hover { background: #fff; opacity: 1; }
.linkbtn:active { transform: scale(.94); }
.links.ready .linkbtn, body.is-loading .linkbtn { opacity: 1; }
.script .links { max-width: calc(100% - min(230px, 20vw)); }


/* ---------- siki ---------- */
.siki {
  grid-column: 3; grid-row: 1; align-self: end; justify-self: end; z-index: 8;
  width: min(330px, 30vw); position: relative; pointer-events: none; margin-right: -10px;
}
.siki-fig { position: relative; aspect-ratio: 764 / 640; pointer-events: auto; transform-origin: 50% 100%; cursor: grab; }
/* 透明な余白にはマウスが当たらないよう、体のあたりだけ反応させる */
.siki-fig { clip-path: polygon(0 45%, 30% 45%, 38% 5%, 78% 3%, 100% 60%, 100% 100%, 0 100%); }
.siki-fig img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0s .03s; user-select: none; -webkit-user-drag: none; }
/* 絵の入れ替え：新しい絵はすぐ出し、前の絵はほんの少し遅れて消す（両方が半透明になる瞬間を作らない） */
.siki-fig img.on { opacity: 1; transition: none; }
.siki.react .siki-fig { animation: hop .5s ease-out; }
/* 表情を入れ替えるときのグリッチ：絵が横にずれて、赤と水色の色ずれが出て、帯状に欠ける（0.22秒） */
.siki-fig.glitch img.on { animation: glitch .22s steps(1) both; }
@keyframes glitch {
  0%   { transform: translate(-7px, 0) skewX(-6deg); filter: drop-shadow(5px 0 0 rgba(255, 0, 90, .8)) drop-shadow(-5px 0 0 rgba(0, 220, 255, .8)); clip-path: inset(0 0 62% 0); }
  20%  { transform: translate(6px, 2px); filter: drop-shadow(-6px 0 0 rgba(255, 0, 90, .8)) drop-shadow(6px 0 0 rgba(0, 220, 255, .8)); clip-path: inset(30% 0 28% 0); }
  40%  { transform: translate(-4px, -1px) skewX(4deg); filter: drop-shadow(4px 0 0 rgba(255, 0, 90, .7)) drop-shadow(-4px 0 0 rgba(0, 220, 255, .7)); clip-path: inset(58% 0 6% 0); }
  60%  { transform: translate(3px, 0); filter: drop-shadow(-3px 0 0 rgba(255, 0, 90, .6)) drop-shadow(3px 0 0 rgba(0, 220, 255, .6)); clip-path: inset(12% 0 40% 0); }
  80%  { transform: translate(-2px, 0); filter: drop-shadow(2px 0 0 rgba(255, 0, 90, .5)) drop-shadow(-2px 0 0 rgba(0, 220, 255, .5)); clip-path: none; }
  100% { transform: none; filter: none; clip-path: none; }
}
@keyframes hop { 30% { transform: translateY(-16px) rotate(2deg); } 60% { transform: translateY(0); } 80% { transform: translateY(-5px); } }
/* はいロボ・知性：siki の左上の空いたところにとまる。それぞれ自分の回だけ出る */
.hibot {
  position: absolute; left: 2%; top: 4%; width: 31%; padding: 0; border: 0; background: none;
  opacity: 0; transform: translateY(24px) scale(.9); transition: opacity .6s, transform .6s; pointer-events: none;
}
.hibot img { width: 100%; display: block; transform-origin: 50% 100%; }
.app[data-sec="hibot"] #hibot, .app[data-sec="chisei"] #chisei { opacity: 1; transform: none; pointer-events: auto; }
.hibot.pu img { animation: hop .45s ease-out; }
.hibot-pu {
  position: absolute; left: -8%; top: -26%; background: #fff; color: #000; font-weight: 900; font-size: 15px;
  padding: 3px 11px; border-radius: 12px 12px 12px 3px; opacity: 0;
}
.hibot.pu .hibot-pu { animation: pu .9s ease-out; }
@keyframes pu { 0% { opacity: 0; transform: translateY(6px) scale(.7); } 20% { opacity: 1; transform: none; } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }
.siki-bubble {
  position: absolute; right: 30%; bottom: 92%; max-width: 230px; width: max-content;
  background: var(--theme); color: var(--on-theme); font-weight: 800; font-size: 16px; line-height: 1.4;
  padding: 10px 14px; border-radius: 16px 16px 4px 16px;
  opacity: 0; transform: translateY(8px) scale(.9); transform-origin: 100% 100%;
  transition: opacity .35s, transform .35s ease;
}
.siki-bubble.on { opacity: 1; transform: none; }

/* スマホ用の字幕（PCでは出さない） */
.cap { display: none; }

/* ---------- ロード画面 ---------- */
.loader {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: var(--paper); color: #fff; transition: opacity .5s, visibility .5s;
}
body:not(.is-loading) .loader { opacity: 0; visibility: hidden; }
.loader-in { display: grid; justify-items: center; gap: 22px; text-align: center; }
.loader-brand { margin: 0; font-weight: 800; letter-spacing: .04em; font-size: 15px; opacity: .7; }
.play {
  width: 112px; height: 112px; border-radius: 50%; border: 0; background: var(--theme); color: var(--on-theme);
  display: grid; place-items: center; animation: pulse 1.8s ease-in-out infinite;
}
.play svg { width: 54px; height: 54px; fill: currentColor; margin-left: 6px; }
.play:hover { background: #fff; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(230, 255, 0, .4); } 50% { box-shadow: 0 0 0 22px rgba(230, 255, 0, 0); } }
.loader-note { margin: 0; font-weight: 700; line-height: 1.7; }
.loader-note small { opacity: .65; font-weight: 500; }

/* ---------- テキスト版 ---------- */
.textdlg {
  width: min(720px, 94vw); max-height: 86dvh; padding: 0; border: 0; box-shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 20px 60px rgba(0, 0, 0, .6);
  border-radius: 16px; background: var(--card); color: var(--ink);
}
.textdlg[open] { display: flex; flex-direction: column; animation: fadein .35s ease both; }
.textdlg::backdrop { background: rgba(0, 0, 0, .7); }
.textdlg-hd { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.textdlg-btns { display: flex; gap: 8px; }
.textdlg pre {
  margin: 0; padding: 18px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font: 14px/1.8 ui-monospace, "SF Mono", Menlo, monospace; user-select: all;
}

.print { display: none; }

/* ---------- スマホ ---------- */
@media (max-width: 700px) {
  .sp-only { display: inline-block; }
  .hd { padding: 0 10px; }
  .brand { font-size: 15px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .stage { grid-column: 1; background: #000; }
  .script { display: none; }
  .scene { width: 100cqw; height: 100cqh; aspect-ratio: auto; border-radius: 0; }
  .endcap { color: #999; }

  .toc {
    grid-column: 1; z-index: 20; background: var(--paper); padding: 18px;
    transform: translateY(-102%); transition: transform .25s; visibility: hidden;
  }
  .toc.open { transform: none; visibility: visible; }
  .toc ol { max-width: none; margin: 0; }
  .toc button { font-size: 18px; padding: 13px 12px; }

  .siki { grid-column: 1; width: 46vw; max-width: 210px; margin-right: -8px; }
  .siki-bubble { right: 18%; font-size: 14px; max-width: 60vw; }
  .heart { right: 12px; bottom: calc(min(46vw, 210px) * .84 + 14px); width: 52px; }

  .cap {
    display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
    padding: 60px min(40vw, 190px) calc(14px + env(safe-area-inset-bottom)) 14px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .72) 45%); color: #fff; pointer-events: none;
  }
  .cap-title { font-size: 12px; font-weight: 800; opacity: .8; margin: 0 0 4px; transition: color .6s, opacity .6s; }
  .cap-title.now { color: var(--theme); opacity: 1; }
  .cap .credit { margin-top: 8px; font-size: 10.5px; color: rgba(255, 255, 255, .7); }
  .toc-credit { max-width: none; margin: 24px 0 0; padding: 0 12px; font-size: 12px; }
  .hibot-pu { font-size: 12px; padding: 2px 8px; }
  .cap-line { font-size: 15px; font-weight: 700; line-height: 1.55; margin: 0; min-height: 4.65em; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
  .cap .links { margin-top: 8px; gap: 6px; pointer-events: auto; }
  .cap .linkbtn { padding: 7px 12px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .play, .siki.talk .siki-fig, .siki-fig.glitch img.on { animation: none; }
}

/* ---------- 印刷 ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { height: auto; overflow: visible; background: #fff; }
  .hd, .app, .loader, .textdlg { display: none !important; }
  .print { display: block; color: #000; font-size: 10pt; line-height: 1.6; }
  .print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pr-hd { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 3mm; margin-bottom: 2mm; }
  .pr-hd h1 { margin: 0; font-size: 18pt; }
  .pr-hd p { margin: 0; font-size: 9pt; }
  .pr-table { width: 100%; border-collapse: collapse; }
  .pr-table tr { break-inside: avoid; }
  .pr-table td { vertical-align: top; padding: 4mm 0; }
  .pr-table td.pr-thumb { width: 38mm; padding-right: 5mm; }
  .pr-table .pr-thumb img { width: 33mm; height: 58.67mm; object-fit: cover; border-radius: 2mm; display: block; }
  .pr-table h2 { margin: 0 0 1.5mm; font-size: 13pt; }
  .pr-table p { margin: 0 0 .6mm; }
  .pr-table p.gap { margin-top: 2.5mm; }
  .pr-links { margin-top: 2.5mm; font-size: 8.5pt; }
  .pr-links span { display: block; }
  .pr-links b { margin-right: .5em; }
  .pr-bio { margin-top: 3mm; padding: 2.5mm 3mm; background: #eee; border-radius: 1.5mm; }
  .pr-bio p { margin: 0; }
  .pr-credit { margin-top: 2mm !important; font-size: 8.5pt; color: #555; }
  .pr-foot { margin: 5mm 0 0; font-size: 8pt; color: #555; }
}
