/* 錆木蒼の探偵法廷 ― 見た目
   色: 夜の紺（#0b1020）・深い青・蝶の青（#3d7bff）・紙の白（#e9e4d8）。細い金の線
   字は明朝（外から読みこまない）。スマホの縦を一番に。パソコンはまん中に縦長の画面（最大幅 560px） */

:root {
  --night-0: #05070d;
  --night-1: #0b1020;
  --night-2: #111a33;
  --night-3: #1a2647;
  --deep: #1d3a8a;
  --bfly: #3d7bff;
  --bfly-hi: #9dbcff;
  --paper: #e9e4d8;
  --paper-dim: #b8b3a7;
  --paper-faint: #7d7a73;
  --gold: #c9a45c;
  --gold-hi: #e6c886;
  --gold-soft: rgba(201, 164, 92, 0.45);
  --gold-faint: rgba(201, 164, 92, 0.22);
  --danger: #d77a7a;
  --ok: #8fd0b4;
  --font: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", "BIZ UDPMincho", serif;
  --text-size: clamp(17px, 4.5vw, 19px);
  --btn-h: 52px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night-0);
  background-image: radial-gradient(ellipse 70% 50% at 50% 0%, rgba(29, 58, 138, 0.28), transparent 70%), linear-gradient(180deg, #070b16, #05070d);
  color: var(--paper);
  font-family: var(--font);
  font-weight: 500;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font-family: inherit; color: inherit; }
svg.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ───────── 画面のわく ───────── */
#app {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px; margin: 0 auto;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--night-1);
  box-shadow: 0 0 0 1px var(--gold-faint), 0 0 80px rgba(29, 58, 138, 0.25);
}

/* 上の帯 */
#topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 4px 6px 4px 12px;
  padding-top: max(4px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #0e152b, #0b1020);
  border-bottom: 1px solid var(--gold-faint);
  position: relative; z-index: 20;
}
#tb-title {
  flex: 1 1 auto; min-width: 0;
  font-size: 14px; line-height: 1.35; color: var(--paper);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  letter-spacing: .04em;
}
#tb-title .kind { color: var(--gold-hi); margin-right: 6px; letter-spacing: .12em; }
#lamps { flex: 0 0 auto; display: flex; gap: 1px; align-items: center; }
#lamps[hidden] { display: none; }

.ibtn {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 8px;
  border: 1px solid var(--gold-soft); background: rgba(17, 26, 51, 0.9); color: var(--paper);
  font-size: 20px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.ibtn:active { transform: translateY(1px); }

/* ───────── 蝶（命・飾り・演出で共通） ───────── */
.bf { position: relative; width: 40px; height: 32px; }
.bf .w { position: absolute; top: 0; width: 50%; height: 100%; display: block; }
.bf .w svg { width: 100%; height: 100%; display: block; overflow: visible; }
.bf .w.l { left: 0; transform-origin: 100% 50%; }
.bf .w.r { right: 0; transform-origin: 0% 50%; }
.bf .w.r svg { transform: scaleX(-1); }
.bf .wu { fill: url(#bfw); stroke: #0b1a44; stroke-width: 1.2; }
.bf .wd { fill: url(#bfw2); stroke: #0b1a44; stroke-width: 1.2; }
.bf .wv { stroke: rgba(8, 14, 34, 0.55); stroke-width: 1; fill: none; }
.bf .ws { fill: var(--paper); opacity: .85; }
.bf .bd { position: absolute; left: 50%; top: 22%; width: 3px; height: 60%; margin-left: -1.5px; border-radius: 2px; background: #dfe8ff; box-shadow: 0 0 0 1px rgba(8, 14, 34, 0.6); }
.bf .bd::before, .bf .bd::after { content: ""; position: absolute; top: -26%; width: 1px; height: 34%; background: #c9d6f5; }
.bf .bd::before { left: 0; transform: rotate(-24deg); transform-origin: 50% 100%; }
.bf .bd::after { right: 0; transform: rotate(24deg); transform-origin: 50% 100%; }

.life { width: 26px; height: 21px; display: inline-block; position: relative; }
.life .bf { width: 26px; height: 21px; opacity: .18; filter: grayscale(1); }
.life.on .bf { opacity: 1; filter: none; }
.life.on .bf .w { animation: flapIdle 3.6s ease-in-out infinite; }
.life:nth-child(2) .bf .w { animation-delay: -.7s; } .life:nth-child(3) .bf .w { animation-delay: -1.5s; }
.life:nth-child(4) .bf .w { animation-delay: -2.2s; } .life:nth-child(5) .bf .w { animation-delay: -2.9s; }
.life.flyaway .bf { animation: flyaway 1s ease-in forwards; }
.life.flyaway .bf .w { animation: flap .16s ease-in-out infinite; }

/* ───────── 舞台 ───────── */
#stage { position: relative; flex: 1 1 auto; min-height: 200px; overflow: hidden; background: var(--night-0); }
#stage.quake { animation: quake .45s linear 1; }
.bg-layer { position: absolute; inset: 0; opacity: 0; transition: opacity .45s ease; overflow: hidden; }
.bg-layer.show { opacity: 1; }
.bg-layer.img { background-size: cover; background-position: center; }
.snow { position: absolute; inset: 0; pointer-events: none; }
.snow i { position: absolute; top: -10px; border-radius: 50%; background: #e9eefc; animation: snowfall 9s linear infinite; }

/* 人物 */
#chars { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.chara {
  position: absolute; bottom: 4%;
  transform: translateX(-50%);
  transition: left .35s ease, width .35s ease, filter .25s ease, opacity .3s ease;
}
.chara.enter { opacity: 0; }
.chara.dim { filter: brightness(.6) saturate(.75); }
.chara.dim2 { filter: brightness(.8); }
.chara .frame {
  position: relative; width: 100%; aspect-ratio: 520 / 560; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--gold-soft);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55), 0 0 0 3px rgba(11, 16, 32, 0.85), 0 0 0 4px var(--gold-faint);
  background: var(--card, #141c34);
  background: radial-gradient(ellipse 72% 62% at 50% 42%, var(--card, #141c34) 0%, color-mix(in srgb, var(--card, #141c34) 55%, #1d3a8a) 62%, #0b1020 100%);
  transition: transform .2s ease;
}
.chara.talk { z-index: 2; }
.chara.talk .frame { transform: translateY(-6px) scale(1.04); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(11, 16, 32, 0.85), 0 0 0 4px var(--gold-soft), 0 0 22px rgba(61, 123, 255, 0.35); }
.chara .frame img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; -webkit-user-drag: none; object-fit: contain; object-position: 50% 100%; }
.chara.k-stand .frame { aspect-ratio: 480 / 1120; border: 0; border-radius: 0; background: transparent; box-shadow: none; overflow: visible; }
.chara.k-stand.talk .frame { transform: none; box-shadow: none; }
.chara.k-stand .frame img { object-fit: contain; object-position: 50% 100%; }
.chara .shake-box { width: 100%; }
.chara.shake .shake-box { animation: shake .5s linear 1; }
.chara.jump .shake-box { animation: jump .5s ease-out 1; }

/* 白い光（見破った時は青白い） */
#fx-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 30; }
#fx-flash.on { animation: flash .5s ease-out 1; }

/* 舞台の上の札 */
#toast {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%) translateY(-8px);
  padding: 8px 18px; border-radius: 6px; background: rgba(11, 16, 32, 0.94); border: 1px solid var(--gold);
  color: var(--gold-hi); font-size: 16px; letter-spacing: .08em; opacity: 0; transition: opacity .25s, transform .25s;
  pointer-events: none; z-index: 60; white-space: nowrap;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 推理の糸の板 */
#board {
  position: absolute; left: 10px; right: 10px; top: 10px; z-index: 5;
  padding: 10px 12px; border-radius: 8px; background: rgba(11, 16, 32, 0.94); border: 1px solid var(--gold-soft);
  font-size: 15px; line-height: 1.5;
}
#board[hidden] { display: none; }
#board h3 { margin: 0 0 4px; font-size: 13px; color: var(--gold-hi); letter-spacing: .2em; font-weight: 600; }
#board ol { margin: 0; padding-left: 1.4em; }
#board li { color: var(--paper-dim); }
#board li b { color: var(--bfly-hi); font-weight: 700; }

/* サビ（ヒントの猫）。舞台の左下からのぞく */
#sabi {
  position: absolute; left: 10px; bottom: 36px; width: 92px; height: 99px; z-index: 6;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--gold); background: #141c34;
  transform: translateY(140%); opacity: 0; transition: transform .35s cubic-bezier(.2, 1.2, .4, 1), opacity .25s;
  pointer-events: none;
}
#sabi.on { transform: none; opacity: 1; }
#sabi img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ───────── 現場（一枚絵と調べる所） ───────── */
#scene { position: absolute; inset: 0; z-index: 2; overflow: hidden; background: var(--night-0); touch-action: none; }
#scene[hidden] { display: none; }
#scene .pic { position: absolute; left: 0; top: 0; will-change: transform; }
#scene .pic.smooth { transition: transform .35s ease; }
#scene .pic-bg { position: absolute; inset: 0; background-size: cover; background-position: center; }
#scene .spots { position: absolute; inset: 0; }
.spot { position: absolute; padding: 0; margin: 0; border: 0; background: transparent; cursor: pointer; border-radius: 8px; transition: background .2s, box-shadow .2s; }
.spot .glint {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 232, 255, 0.95) 0%, rgba(61, 123, 255, 0.6) 40%, rgba(61, 123, 255, 0) 72%);
  animation: glint 2.6s ease-in-out infinite; pointer-events: none;
}
.spot:nth-child(2n) .glint { animation-delay: -1.1s; } .spot:nth-child(3n) .glint { animation-delay: -1.9s; }
.spot.seen .glint { display: none; }
.spot .mark {
  display: none; position: absolute; right: 3px; top: 3px; font-size: 11px; line-height: 1; padding: 3px 4px; border-radius: 4px;
  background: rgba(11, 16, 32, 0.8); color: var(--paper-dim); border: 1px solid var(--gold-soft); pointer-events: none;
}
.spot.seen .mark { display: block; }
.spot .tag {
  display: none; position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%); white-space: nowrap;
  font-size: 13px; padding: 3px 9px; border-radius: 5px; background: rgba(11, 16, 32, 0.92); border: 1px solid var(--gold); color: var(--paper); pointer-events: none;
}
.spot:hover .tag, .spot.kbsel .tag { display: block; }
.spot:hover, .spot.kbsel { background: rgba(61, 123, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(230, 200, 134, 0.9), 0 0 0 1px rgba(5, 8, 18, 0.6); }
.spot.hinted { animation: hintpulse 1.3s ease-in-out infinite; }
.spot.hinted .glint { width: 30px; height: 30px; margin: -15px 0 0 -15px; }
#scene.busy .spot { opacity: 0; pointer-events: none; }
#scene.busy .spot.hinted { opacity: 1; }
#scene.busy .spot.hinted .tag { display: block; }
#scene .pan {
  position: absolute; top: 10px; width: 44px; height: 44px; z-index: 3; cursor: pointer;
  border-radius: 8px; background: rgba(11, 16, 32, 0.66); border: 1px solid var(--gold-soft); color: var(--paper); font-size: 16px;
}
#scene .pan.l { left: 6px; } #scene .pan.r { right: 6px; }
#scene .pan[hidden], #scene.busy .pan { display: none; }

/* ───────── 文の窓（半透明の紺に、細い金の線） ───────── */
#textbox {
  position: relative; flex: 0 0 auto;
  height: 172px; margin: 0 8px; margin-top: -26px; z-index: 10;
  padding: 26px 18px 12px;
  border-radius: 6px;
  background: rgba(11, 16, 32, 0.86);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid rgba(201, 164, 92, 0.75);
  box-shadow: 0 -6px 26px rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(11, 16, 32, 0.6), inset 0 0 0 4px rgba(201, 164, 92, 0.2);
  cursor: pointer;
}
#nameplate {
  position: absolute; left: 12px; top: -15px; min-width: 96px; padding: 4px 16px;
  border-radius: 4px; background: linear-gradient(180deg, #17213f, #0b1020); border: 1px solid var(--gold);
  font-weight: 700; font-size: 16px; letter-spacing: .14em; color: var(--nc, var(--paper));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
#nameplate[hidden] { display: none; }
#text {
  height: 100%; overflow-y: auto; overscroll-behavior: contain;
  font-size: var(--text-size); line-height: 1.7; white-space: pre-wrap; word-break: break-word; letter-spacing: .03em;
  scrollbar-width: none;
}
#text::-webkit-scrollbar { display: none; }
#text.narr { color: #cdc8bc; }
#text.low { color: #b3c3ea; letter-spacing: .07em; }
#text.testi { color: var(--gold-hi); }
#text.sys { color: var(--bfly-hi); }
#text.question { color: var(--paper); }
#text .qno { display: block; font-size: 13px; color: var(--gold-hi); letter-spacing: .14em; margin-bottom: 2px; }
#next-mark { position: absolute; right: 14px; bottom: 8px; color: var(--gold); font-size: 13px; opacity: 0; }
#textbox.waiting #next-mark { opacity: 1; animation: bob 1s ease-in-out infinite; }
#textbox .testi-mark { position: absolute; right: 12px; top: 6px; font-size: 12px; color: var(--gold-hi); letter-spacing: .2em; }

/* ───────── ボタンの段 ───────── */
#controls {
  flex: 0 0 auto; padding: 10px 8px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; min-height: 64px;
}
.row { display: flex; gap: 8px; align-items: stretch; }
.row > .btn { flex: 1; }
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 540px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
.btn {
  min-height: var(--btn-h); padding: 6px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--gold-soft); background: linear-gradient(180deg, #19233f, #0f162b);
  font-size: 16px; font-weight: 600; letter-spacing: .1em; color: var(--paper);
  box-shadow: inset 0 1px 0 rgba(233, 228, 216, 0.07), 0 2px 8px rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; line-height: 1.3;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); filter: brightness(1.12); }
.btn[disabled] { opacity: .38; cursor: default; }
.btn.blue { background: linear-gradient(180deg, #4b87ff, #2a5ad8); border-color: var(--bfly-hi); color: #fff; text-shadow: 0 1px 0 rgba(5, 8, 18, 0.5); }
.btn.deep { background: linear-gradient(180deg, #27479a, #172c68); border-color: #7c9be0; }
.btn.ghost { background: rgba(11, 16, 32, 0.6); }
.btn.small { min-height: 44px; font-size: 15px; letter-spacing: .06em; }
.btn.wide { width: 100%; }
.btn.sel { outline: 2px solid var(--gold-hi); outline-offset: -2px; background: linear-gradient(180deg, #24346a, #182651); }
.btn.right-ans { background: linear-gradient(180deg, #3f78f0, #2450c0); border-color: var(--bfly-hi); }
.btn.right-ans[disabled], .btn.wrong-ans[disabled] { opacity: 1; }
.btn.wrong-ans { background: linear-gradient(180deg, #4a2230, #2e1520); border-color: var(--danger); }
.btn.ready { animation: readyglow 1.8s ease-in-out infinite; }
.btn em.new { font-style: normal; font-size: 10px; line-height: 1; padding: 3px 5px; border-radius: 3px; background: var(--bfly); color: #fff; letter-spacing: .05em; }
.btn.seenitem { color: var(--paper-dim); }
.btn.seenitem::after { content: "済"; font-size: 11px; padding: 2px 4px; border: 1px solid var(--gold-faint); border-radius: 3px; color: var(--paper-faint); }
.btn.kbsel, .kbsel.btn { outline: 2px solid var(--gold-hi); outline-offset: 2px; box-shadow: 0 0 14px rgba(230, 200, 134, 0.45); }
.nav { display: flex; gap: 8px; align-items: center; }
.nav .btn { flex: 0 0 auto; width: 60px; }
.nav .count { flex: 1 1 auto; text-align: center; font-size: 15px; color: var(--paper-dim); }
.nav .count b { color: var(--gold-hi); font-size: 18px; }
.nav .count .done { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--bfly); color: var(--bfly-hi); font-size: 12px; }
.nav .hintbtn { font-size: 18px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.invlist { max-height: 36vh; overflow-y: auto; }
.invlist .btn { justify-content: space-between; padding: 6px 14px; flex: 0 0 auto; }
.talkrow .btn { padding: 4px 4px; }

/* ───────── 重ねる画面 ───────── */
.layer {
  position: absolute; inset: 0; z-index: 80;
  display: flex; flex-direction: column;
  background: rgba(8, 12, 24, 0.95);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fadein .15s ease 1;
}
.layer.solid { background: linear-gradient(180deg, #0e152b, #070b16); -webkit-backdrop-filter: none; backdrop-filter: none; }
.layer header { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 16px; border-bottom: 1px solid var(--gold-faint); }
.layer header h2 { flex: 1; margin: 0; font-size: 18px; letter-spacing: .2em; color: var(--gold-hi); font-weight: 600; }
.layer .body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; overscroll-behavior: contain; }
.layer footer { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: flex; gap: 8px; border-top: 1px solid var(--gold-faint); }
.layer footer .btn { flex: 1; }

/* タイトル（書斎の絵の上に、縦書きの題字） */
.title-screen { background: var(--night-0); -webkit-backdrop-filter: none; backdrop-filter: none; justify-content: flex-end; }
.title-screen .bgwrap { position: absolute; inset: 0; z-index: -1; }
.title-screen .shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5, 7, 13, 0.25) 0%, rgba(5, 7, 13, 0) 22%, rgba(5, 7, 13, 0.1) 45%, rgba(5, 7, 13, 0.8) 70%, rgba(5, 7, 13, 0.96) 100%); }
.logo {
  position: absolute; right: 4%; top: 5%;
  writing-mode: vertical-rl;
  padding: 16px 12px 22px; border-radius: 4px;
  background: linear-gradient(90deg, rgba(5, 7, 13, 0), rgba(5, 7, 13, 0.5) 25%, rgba(5, 7, 13, 0.5) 75%, rgba(5, 7, 13, 0));
}
.logo .kicker {
  font-size: clamp(16px, 4.6vw, 20px); letter-spacing: .36em; color: var(--paper); text-shadow: 0 0 10px rgba(5, 7, 13, 0.95);
  padding-left: 8px; margin-left: 6px; border-left: 1px solid var(--gold-soft);
}
.logo h1 {
  margin: 0; font-weight: 700; font-size: clamp(42px, 12vw, 58px); letter-spacing: .2em; line-height: 1.05;
  color: var(--paper); text-shadow: 0 0 20px rgba(61, 123, 255, 0.75), 0 0 3px #050810, 0 2px 0 #050810;
}
.orn { display: flex; align-items: center; justify-content: center; gap: 10px; }
.orn > i { display: block; width: 70px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold)); }
.orn > i:last-child { background: linear-gradient(90deg, var(--gold), transparent); }
.bf.mark { width: 34px; height: 27px; }
.bf.mark .w { animation: flapIdle 4s ease-in-out infinite; }
.title-menu { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 0 30px; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.title-menu .btn { min-height: 52px; font-size: 18px; letter-spacing: .24em; }
.credit-line { margin: 6px 0 0; text-align: center; font-size: 12px; letter-spacing: .14em; color: var(--paper-dim); text-shadow: 0 1px 4px #000; }
.credit-line a { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.credit-line a:focus-visible { outline: 2px solid var(--blue, #3d7bff); outline-offset: 2px; }
.tap-start { position: relative; text-align: center; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.tap-start .btn { margin: 0 auto; width: min(320px, 86%); min-height: 58px; font-size: 17px; letter-spacing: .14em; animation: glow 2.4s ease-in-out infinite; }
.tap-start p { color: var(--paper-dim); font-size: 13px; margin: 12px 0 0; }

/* 事件の記録・章をえらぶ */
.files { display: flex; flex-direction: column; gap: 12px; }
.chap-ep { margin: 0 0 4px; text-align: center; color: var(--gold-hi); letter-spacing: .3em; font-size: 15px; }
.filecard {
  position: relative; display: block; width: 100%; text-align: left; padding: 14px 16px; border-radius: 8px;
  border: 1px solid var(--gold-soft); background: linear-gradient(135deg, #141d39, #0d1428); cursor: pointer; color: var(--paper);
  min-height: 76px;
}
.filecard .no { font-size: 13px; color: var(--gold-hi); letter-spacing: .24em; }
.filecard .ttl { font-size: 20px; font-weight: 700; margin-top: 4px; letter-spacing: .1em; }
.filecard .sub { font-size: 14px; color: var(--paper-dim); margin-top: 4px; }
.filecard .stamp { position: absolute; right: 12px; top: 12px; font-size: 13px; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--bfly); color: var(--bfly-hi); }
.filecard.soon, .filecard.secret { cursor: default; opacity: .55; background: repeating-linear-gradient(135deg, #0f162b 0 12px, #0c1224 12px 24px); }

/* 設定 */
.setting { margin-bottom: 22px; }
.setting label { display: block; font-size: 15px; color: var(--paper-dim); margin-bottom: 8px; }
.setting input[type=range] { width: 100%; height: 36px; accent-color: var(--bfly); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg .btn { min-height: 44px; font-size: 15px; padding: 4px; }

/* ログ */
.log-item { padding: 8px 0; border-bottom: 1px solid var(--gold-faint); font-size: 16px; line-height: 1.65; white-space: pre-wrap; }
.log-item .who { display: block; font-size: 13px; font-weight: 700; color: var(--nc, var(--gold-hi)); border-left: 3px solid var(--nc, var(--gold)); padding-left: 6px; letter-spacing: .1em; }
.log-item.narr { color: var(--paper-dim); }

/* 手帳 */
.tabs { display: flex; gap: 6px; padding: 8px 12px 0; }
.tabs .btn { flex: 1; min-height: 44px; border-radius: 8px 8px 0 0; }
.tabs .btn.on { background: linear-gradient(180deg, #2a4da8, #1d3a8a); border-color: var(--bfly-hi); }
.detail { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 8px; background: rgba(17, 26, 51, 0.7); border: 1px solid var(--gold-faint); margin-bottom: 12px; min-height: 110px; }
.detail .big { flex: 0 0 auto; width: 76px; height: 76px; border-radius: 8px; display: grid; place-items: center; font-size: 44px; background: radial-gradient(circle at 50% 40%, #1f2d58, #0b1020); border: 1px solid var(--gold-soft); overflow: hidden; }
.detail .big img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; }
.detail .info { flex: 1; min-width: 0; }
.detail .info h3 { margin: 0 0 4px; font-size: 18px; color: var(--gold-hi); letter-spacing: .06em; }
.detail .info p { margin: 0; font-size: 15px; line-height: 1.7; color: var(--paper); white-space: pre-wrap; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.item {
  min-height: 92px; padding: 8px 4px; border-radius: 8px; cursor: pointer; border: 1px solid var(--gold-faint); color: var(--paper);
  background: linear-gradient(180deg, #151f3c, #0d1428); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.item .ic { font-size: 30px; line-height: 1; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; overflow: hidden; }
.item .ic img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; }
.item .nm { font-size: 13px; line-height: 1.35; text-align: center; }
.item.on { border-color: var(--bfly-hi); box-shadow: 0 0 0 2px rgba(61, 123, 255, 0.5); background: linear-gradient(180deg, #23397a, #172a5c); }
.empty { color: var(--paper-faint); font-size: 15px; text-align: center; padding: 24px 0; }

/* 重ねる（証言の一覧から2行） */
.clash-hint { font-size: 14px; color: var(--paper-dim); margin: 0 0 10px; letter-spacing: .06em; }
.clash-list { display: flex; flex-direction: column; gap: 8px; }
.clash-list .btn { justify-content: flex-start; text-align: left; font-weight: 500; font-size: 16px; min-height: 56px; padding: 8px 12px; letter-spacing: .03em; }
.clash-list .btn .n { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--gold-soft); font-size: 13px; color: var(--gold-hi); }

/* メニュー・確かめ */
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.dialog { margin: auto 20px; padding: 20px; border-radius: 10px; background: #0e152b; border: 1px solid var(--gold); }
.dialog p { margin: 0 0 16px; font-size: 16px; line-height: 1.7; white-space: pre-wrap; }
.dialog .row .btn { flex: 1; }

/* 結果 */
.result { text-align: center; }
.result .orn { margin-top: 8px; }
.result h2 { font-size: 30px; color: var(--paper); letter-spacing: .4em; margin: 10px 0 4px; font-weight: 700; text-shadow: 0 0 16px rgba(61, 123, 255, 0.6); }
.result .ep { color: var(--paper-dim); font-size: 15px; margin-bottom: 18px; letter-spacing: .1em; }
.result .stat { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--gold-faint); font-size: 16px; }
.result .stat .v { color: var(--gold-hi); font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.lampsrow { display: inline-flex; gap: 2px; vertical-align: middle; }
.result .credit { margin-top: 20px; padding: 14px; border-radius: 8px; border: 1px solid var(--gold-faint); background: rgba(17, 26, 51, 0.6); text-align: left; }
.result .credit h3 { margin: 0 0 8px; font-size: 14px; color: var(--gold-hi); letter-spacing: .3em; }
.result .credit p { margin: 0 0 8px; font-size: 15px; line-height: 1.6; }
.result .credit .btn { width: 100%; margin-bottom: 10px; }

/* 記録が途切れた */
.lose { justify-content: center; text-align: center; background: rgba(3, 5, 12, 0.97); }
.lose h2 { font-size: clamp(22px, 6.4vw, 28px); letter-spacing: .16em; color: var(--paper); margin: 0 0 12px; font-weight: 600; }
.lose p { color: var(--paper-dim); margin: 0 0 28px; font-size: 15px; letter-spacing: .08em; }
.lose .lampsrow { display: flex; gap: 4px; justify-content: center; margin-bottom: 20px; }
.lose .btns { display: flex; flex-direction: column; gap: 10px; padding: 0 28px; }

/* ───────── カットイン（錆木だけ） ───────── */
#cutin { position: absolute; inset: 0; z-index: 90; pointer-events: none; overflow: hidden; }
#cutin[hidden] { display: none; }
#cutin .dark { position: absolute; inset: 0; background: rgba(3, 5, 12, 0.58); animation: fadein .12s ease 1; }
#cutin .band {
  position: absolute; left: -8%; right: -8%; top: 48%; height: 150px; margin-top: -75px;
  transform: rotate(-4deg);
  background: linear-gradient(90deg, rgba(8, 12, 24, 0.97) 0%, rgba(29, 58, 138, 0.96) 45%, rgba(17, 26, 51, 0.97) 100%);
  overflow: hidden;
}
#cutin .gl { position: absolute; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--gold) 15%, var(--gold-hi) 50%, var(--gold) 85%, transparent); }
#cutin .gl.t { top: 6px; } #cutin .gl.b { bottom: 6px; }
#cutin .face {
  position: absolute; left: 11%; top: 50%; width: 124px; height: 124px; margin-top: -62px; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #e9e4d8 0%, #b9c4de 55%, #31447a 100%); border: 1px solid var(--gold); transform: rotate(4deg);
}
#cutin .face img { position: absolute; left: -18%; top: -14%; width: 136%; height: auto; }
#cutin .words {
  position: absolute; left: 40%; right: 4%; top: 50%; transform: translateY(-50%) rotate(4deg);
  font-weight: 700; font-size: clamp(26px, 7.4vw, 40px); letter-spacing: .12em; white-space: pre; line-height: 1.3;
  color: var(--paper); text-shadow: 0 0 14px rgba(61, 123, 255, 0.75), 0 2px 0 #050810;
}
#cutin.go .band { animation: bandin 1.05s cubic-bezier(.2, .9, .2, 1) 1 both; }
#cutin.go .words { animation: wordsin 1.05s ease 1 both; }
#cutin.tou .band { height: 120px; margin-top: -60px; background: linear-gradient(90deg, rgba(8, 12, 24, 0.97), rgba(20, 31, 64, 0.97) 60%, rgba(8, 12, 24, 0.97)); }
#cutin.tou .words { font-size: clamp(22px, 6.2vw, 34px); color: #d8def0; }
#cutin.tou .face { width: 100px; height: 100px; margin-top: -50px; }

/* 青い蝶が横切る ／ 最後の決め手（蝶が止まる） */
#bfly { position: absolute; inset: 0; z-index: 88; pointer-events: none; overflow: hidden; }
#bfly[hidden] { display: none; }
#bfly .lane { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#bfly.cross.go .lane { animation: laneX 1.5s cubic-bezier(.35, .1, .25, 1) both; }
#bfly .bob { position: absolute; left: 50%; top: 50%; }
#bfly.cross.go .bob { animation: bobY .5s ease-in-out infinite alternate; }
#bfly .bf.big { position: absolute; width: 156px; height: 125px; left: -78px; top: -62px; transform: rotate(-16deg); }
#bfly .bf.big .w { animation: flap .22s ease-in-out infinite; }
#bfly .glow { position: absolute; left: -130px; top: -130px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(circle, rgba(61, 123, 255, 0.42) 0%, rgba(61, 123, 255, 0.12) 45%, rgba(61, 123, 255, 0) 70%); }
#bfly .dot { position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle, #dfe9ff 0%, rgba(61, 123, 255, 0.65) 45%, rgba(61, 123, 255, 0) 75%); }
#bfly .sweep { position: absolute; inset: -20%; background: linear-gradient(110deg, transparent 38%, rgba(61, 123, 255, 0.16) 50%, transparent 62%); }
#bfly.cross.go .sweep { animation: sweep 1.5s ease both; }

#bfly.final .dim { position: absolute; inset: 0; background: rgba(3, 5, 12, 0); }
#bfly.final.go .dim { animation: dimIn 1.6s ease forwards; }
#bfly .fcard {
  position: absolute; left: 50%; top: 40%; width: min(300px, 78%); padding: 20px 16px 16px; transform: translate(-50%, -50%);
  border-radius: 10px; text-align: center; background: linear-gradient(180deg, rgba(20, 28, 52, 0.97), rgba(11, 16, 32, 0.97)); border: 1px solid var(--gold);
  opacity: 0;
}
#bfly.final.go .fcard { animation: fadeUp .8s ease .15s forwards; }
#bfly .fic { font-size: 56px; line-height: 1.2; }
#bfly .fic img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; }
#bfly .fname { margin-top: 6px; color: var(--paper); font-size: 18px; letter-spacing: .1em; }
#bfly .flines p { margin: 0 0 6px; font-size: 15px; line-height: 1.55; color: var(--gold-hi); text-align: left; }
#bfly .perch { position: absolute; right: 22px; top: 4px; width: 0; height: 0; }
#bfly.final.go .perch .lane { animation: land 1.4s cubic-bezier(.2, .7, .2, 1) .35s both; width: 0; height: 0; }
#bfly .perch .glow { left: -60px; top: -60px; width: 120px; height: 120px; }
#bfly .bf.perched { position: absolute; width: 64px; height: 52px; left: -32px; top: -40px; transform: rotate(-10deg); }
#bfly .bf.perched .w { animation: flap .16s ease-in-out 9, flapSlow 2.6s ease-in-out 1.75s infinite; }
#bfly .fwords {
  position: absolute; left: 0; right: 0; top: 64%; text-align: center; white-space: pre;
  font-weight: 700; font-size: clamp(26px, 7.4vw, 40px); letter-spacing: .16em; line-height: 1.35; color: var(--paper);
  text-shadow: 0 0 18px rgba(61, 123, 255, 0.6), 0 2px 0 #050810; opacity: 0;
}
#bfly.final.go .fwords { animation: fadein 1.1s ease 1.4s forwards; }
#bfly.final.out { animation: fadeout .6s ease forwards; }

/* 大きな帯（探偵法廷 開廷／閉廷／証言） */
#banner { position: absolute; inset: 0; z-index: 85; display: grid; place-items: center; pointer-events: none; }
#banner[hidden] { display: none; }
#banner .b {
  width: 100%; padding: 18px 10px; text-align: center;
  background: linear-gradient(90deg, transparent, rgba(11, 16, 32, 0.95) 15%, rgba(11, 16, 32, 0.95) 85%, transparent);
  animation: bannerin 1.4s ease 1 both;
}
#banner .bl { display: block; height: 1px; margin: 0 auto; width: 70%; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
#banner .b .big { font-size: clamp(30px, 9vw, 42px); font-weight: 700; letter-spacing: .4em; color: var(--paper); text-shadow: 0 0 16px rgba(61, 123, 255, 0.6); margin: 12px 0 4px; padding-left: .4em; }
#banner .b .small { margin-bottom: 12px; font-size: 15px; color: var(--gold-hi); letter-spacing: .12em; padding: 0 10px; }

/* 題の札（章のはじまり） */
.titlecard { background: radial-gradient(ellipse 80% 60% at 50% 45%, #111a33, #05070d); justify-content: center; align-items: center; text-align: center; cursor: pointer; }
.titlecard .no { font-size: 15px; letter-spacing: .6em; color: var(--gold-hi); padding-left: .6em; margin-bottom: 14px; }
.titlecard .ttl { margin: 16px 0; font-size: clamp(28px, 8.4vw, 38px); color: var(--paper); letter-spacing: .2em; text-shadow: 0 0 18px rgba(61, 123, 255, 0.55); padding: 0 16px; font-weight: 700; }
.titlecard .sub { font-size: 14px; color: var(--paper-dim); letter-spacing: .3em; margin-top: 14px; }
.titlecard .line { width: 60%; height: 1px; margin: 0 auto; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.titlecard .orn { margin-top: 22px; }
.bf.small { width: 30px; height: 24px; }
.bf.small .w { animation: flapIdle 3s ease-in-out infinite; }

/* 証拠を手に入れた（手帳に書きとめた） */
.gain { justify-content: center; align-items: center; background: rgba(3, 5, 12, 0.6); cursor: pointer; }
.gain .card {
  width: min(340px, 88%); padding: 18px 18px 16px; border-radius: 10px; text-align: center;
  background: linear-gradient(180deg, #141d39, #0b1020); border: 1px solid var(--gold);
  box-shadow: 0 0 30px rgba(61, 123, 255, 0.3); animation: pop .35s cubic-bezier(.2, 1.3, .4, 1) 1;
}
.gain .card .head { font-size: 14px; color: var(--gold-hi); letter-spacing: .3em; }
.gain .card .ic { font-size: 60px; line-height: 1.2; margin: 10px 0 4px; }
.gain .card .ic img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; }
.gain .card h3 { margin: 0 0 8px; font-size: 20px; color: var(--paper); letter-spacing: .08em; }
.gain .card p { margin: 0; font-size: 15px; line-height: 1.7; color: var(--paper-dim); text-align: left; white-space: pre-wrap; }
.gain .card .tapnote { margin-top: 12px; font-size: 12px; color: var(--paper-faint); }

/* ───────── 動き ───────── */
@keyframes snowfall { 0% { transform: translate(0, -10px); } 50% { transform: translate(14px, 50vh); } 100% { transform: translate(-6px, 102vh); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 15% { transform: translateX(-9px); } 30% { transform: translateX(8px); } 45% { transform: translateX(-6px); } 60% { transform: translateX(5px); } 75% { transform: translateX(-3px); } 90% { transform: translateX(2px); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 35% { transform: translateY(-18px); } 60% { transform: translateY(0); } 78% { transform: translateY(-6px); } }
@keyframes quake { 0%, 100% { transform: translate(0, 0); } 12% { transform: translate(-7px, 3px); } 25% { transform: translate(6px, -4px); } 38% { transform: translate(-5px, -2px); } 52% { transform: translate(5px, 3px); } 66% { transform: translate(-3px, 2px); } 82% { transform: translate(2px, -1px); } }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { from { opacity: 1; } to { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, -44%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 rgba(61, 123, 255, 0); } 50% { box-shadow: 0 0 22px rgba(61, 123, 255, 0.6); } }
@keyframes readyglow { 0%, 100% { box-shadow: 0 0 0 rgba(61, 123, 255, 0); } 50% { box-shadow: 0 0 18px rgba(61, 123, 255, 0.85); } }
@keyframes bandin { 0% { transform: rotate(-4deg) translateX(-110%); } 22% { transform: rotate(-4deg) translateX(0); } 82% { transform: rotate(-4deg) translateX(0); opacity: 1; } 100% { transform: rotate(-4deg) translateX(30%); opacity: 0; } }
@keyframes wordsin { 0% { opacity: 0; letter-spacing: .5em; } 30% { opacity: 1; letter-spacing: .12em; } 82% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bannerin { 0% { opacity: 0; transform: scaleY(.2); } 15% { opacity: 1; transform: scaleY(1); } 82% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flap { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(.22); } }
@keyframes flapSlow { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(.55); } }
@keyframes flapIdle { 0%, 80%, 100% { transform: scaleX(1); } 86% { transform: scaleX(.35); } 92% { transform: scaleX(1); } 96% { transform: scaleX(.5); } }
@keyframes flyaway { 0% { transform: none; opacity: 1; } 100% { transform: translate(26px, -44px) rotate(28deg) scale(.6); opacity: 0; } }
@keyframes laneX { 0% { transform: translate(-64%, 28%); } 100% { transform: translate(64%, -30%); } }
@keyframes bobY { from { transform: translateY(-12px); } to { transform: translateY(12px); } }
@keyframes sweep { from { transform: translateX(-60%); } to { transform: translateX(60%); } }
@keyframes dimIn { to { background: rgba(3, 5, 12, 0.86); } }
@keyframes land { 0% { transform: translate(-240px, -200px) rotate(-30deg); opacity: 0; } 12% { opacity: 1; } 100% { transform: translate(0, 0) rotate(0deg); opacity: 1; } }
@keyframes glint { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }
@keyframes hintpulse { 0%, 100% { box-shadow: inset 0 0 0 1px rgba(157, 188, 255, 0.5), 0 0 0 0 rgba(61, 123, 255, 0); } 50% { box-shadow: inset 0 0 0 2px rgba(157, 188, 255, 0.95), 0 0 18px 2px rgba(61, 123, 255, 0.55); } }

@media (prefers-reduced-motion: reduce) {
  .snow i, .life .bf .w, .spot .glint, .bf.mark .w, .bf.small .w { animation: none !important; }
}

/* パソコン（広い画面） */
@media (min-width: 561px) {
  #textbox { height: 180px; }
}
/* 背の低い画面 */
@media (max-height: 700px) {
  #textbox { height: 150px; }
  :root { --btn-h: 46px; }
}

/* ───────── コントローラー（パッドがつながっている時だけ出す） ───────── */
.only-pad { display: none; }
html[data-pad="1"] .only-pad { display: inline; }
html[data-pad="1"] p.only-pad, html[data-pad="1"] div.only-pad { display: block; }
html[data-pad="1"] .no-pad { display: none; }
.btn, .ibtn { position: relative; }
html[data-pad="1"] [data-padkey]::before, html[data-pad="1"] [data-esc]::before {
  content: attr(data-padkey); position: absolute; top: -8px; left: -6px; z-index: 3;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; box-sizing: border-box;
  display: grid; place-items: center;
  font: 700 11px/1 sans-serif; letter-spacing: 0; color: #0b1020;
  background: var(--gold-hi); border: 1px solid var(--gold); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
html[data-pad="1"] [data-esc]:not([data-padkey])::before { content: 'B'; }
html[data-pad="1"] .ibtn[data-padkey="START"]::before { top: auto; bottom: -7px; left: 50%; transform: translateX(-50%); font-size: 9px; }
html[data-pad="1"] .padfocus {
  outline: 3px solid var(--gold-hi); outline-offset: 2px;
  box-shadow: 0 0 0 1px #050810, 0 0 16px rgba(230, 200, 134, 0.6) !important;
}
html[data-pad="1"] input[type=range].padfocus { outline-offset: 4px; border-radius: 8px; }
html[data-pad="1"] #textbox.waiting #next-mark::before { content: 'Ⓐ 進む  '; font-size: 13px; }
html[data-pad="1"] .tap-start .btn::after { content: '（Ⓐ）'; font-size: 14px; }
