:root {
  --bg: #15121f; --panel: #221d33; --panel2: #2d2742; --line: #4a4068; --ink: #efe9d9; --muted: #a79fbd;
  --gold: #ffd24a; --red: #ff6b6b; --green: #7dff8f; --blue: #7cc4ff; --warn: #ff9b3d; --accent: #ffb347;
  --r1: #ff6b57; --r2: #ffae42; --r3: #8fce6b; --r4: #6fa8dc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: 'DotGothic16', 'Yu Gothic', 'Hiragino Sans', sans-serif; font-size: 16px; line-height: 1.5; }
h1, h2, h3, p { margin: 0; font-weight: normal; }
h3 { font-size: 18px; color: var(--accent); margin-bottom: 6px; }
button { font: inherit; color: inherit; }
select { font: inherit; background: var(--bg); color: var(--ink); border: 2px solid var(--line); padding: 2px 4px; min-height: 30px; max-width: 100%; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
.muted { color: var(--muted); } .small { font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; } .wrap { flex-wrap: wrap; } .center { justify-content: center; }
.spacer { flex: 1; }
.btn { background: var(--panel2); border: 2px solid var(--line); padding: 6px 14px; cursor: pointer; min-height: 38px; box-shadow: 0 3px 0 #0a0812; }
.btn:hover { background: #3a3256; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0a0812; }
.btn:focus-visible, .cell:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }
.btn.primary { background: #c8502e; border-color: #ffb347; color: #fff5dc; }
.btn.primary:hover { background: #dd6239; }
.btn.big { font-size: 20px; padding: 10px 26px; }
.btn.on { background: var(--gold); color: #21180a; border-color: #fff0a8; }
.chip { background: var(--bg); border: 2px solid var(--line); padding: 2px 10px; white-space: nowrap; }
.chip.gold { color: var(--gold); } .chip.warn { color: var(--warn); }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.bar h2 { font-size: 20px; }
.panel { background: var(--panel); border: 2px solid var(--line); padding: 12px; }
.spr { display: inline-block; image-rendering: pixelated; background-repeat: no-repeat; vertical-align: middle; flex: none; }

/* タイトル */
#title.active { align-items: center; justify-content: center; padding: 24px 16px; }
.title-box { max-width: 640px; text-align: center; display: flex; flex-direction: column; gap: 16px; }
.kicker { color: var(--accent); letter-spacing: .3em; }
h1 { line-height: 1.15; color: var(--gold); text-shadow: 0 4px 0 #7a3b12; }
h1 span { display: block; white-space: nowrap; }
h1 .t1 { font-size: min(7.4vw, 46px); }
h1 .t2 { font-size: min(10vw, 62px); }
.lead { font-size: 18px; }
.title-scene { display: flex; justify-content: center; align-items: flex-end; gap: 10px; min-height: 76px; }

/* 導入 */
#intro.active { position: fixed; inset: 0; min-height: 0; background: #000; overflow: hidden; cursor: pointer; z-index: 5; }
#introCv { position: absolute; left: 0; top: 0; image-rendering: pixelated; }
[hidden] { display: none !important; }
.intro-skip { position: absolute; top: 10px; right: 10px; z-index: 3; opacity: .85; }
.intro-year { position: absolute; top: 10px; left: 10px; background: #0c0a18d9; border: 2px solid var(--gold); padding: 3px 12px; display: flex; flex-direction: column; font-size: clamp(14px, 2.4vw, 20px); line-height: 1.3; }
.intro-year b { font-weight: normal; color: var(--gold); font-size: 1.35em; }
.intro-cap { position: absolute; left: 50%; bottom: max(14px, 3vh); transform: translateX(-50%); width: min(92vw, 860px); background: #0c0a18ee; border: 3px solid var(--gold); padding: 10px 18px; font-size: clamp(17px, 2.8vw, 26px); line-height: 1.45; box-shadow: 0 4px 0 #000; text-align: center; }
.intro-cap .who { display: block; color: var(--gold); font-size: .8em; line-height: 1.2; }
.intro-big { position: absolute; left: 0; right: 0; top: 50%; text-align: center; font-size: clamp(30px, 7.4vw, 92px); line-height: 1.1; color: #fff; pointer-events: none; padding: 0 12px; transform: translateY(-50%); text-shadow: 3px 0 0 #1d0f1a, -3px 0 0 #1d0f1a, 0 3px 0 #1d0f1a, 0 -3px 0 #1d0f1a, 3px 3px 0 #1d0f1a, -3px -3px 0 #1d0f1a, 3px -3px 0 #1d0f1a, -3px 3px 0 #1d0f1a, 0 7px 0 #7a3b12; }
.intro-big.chant { color: var(--gold); animation: bigPunch .28s steps(4); top: 32%; }
.intro-big.name { color: var(--gold); top: 24%; font-size: clamp(44px, 11vw, 130px); letter-spacing: .3em; padding-left: .3em; animation: bigRise .6s steps(6); }
.intro-big.law { color: #fff; top: 62%; animation: bigPunch .25s steps(4); }
@keyframes bigPunch { from { transform: translateY(-50%) scale(2.2); opacity: .2; } to { transform: translateY(-50%) scale(1); opacity: 1; } }
@keyframes bigRise { from { transform: translateY(-20%); opacity: 0; } to { transform: translateY(-50%); opacity: 1; } }
.intro-edict { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; cursor: default; }
.intro-edict .paper { position: relative; background: #f3e3b8; color: #2a1a0c; border: 4px solid #7a3b12; outline: 4px solid #ffd24a; padding: 18px clamp(24px, 6vw, 64px) 22px; text-align: center; font-size: clamp(17px, 2.6vw, 24px); line-height: 1.7; animation: paperDown .4s steps(6); box-shadow: 0 8px 0 #000; }
.edict-title { font-size: 1.9em; line-height: 1.2; color: #8e1f2b; margin-bottom: 8px; }
.edict-law { margin-top: 8px; color: #8e1f2b; }
.seal { position: absolute; right: -30px; bottom: -30px; width: 84px; height: 84px; display: flex; align-items: center; justify-content: center; font-size: 58px; line-height: 1; color: #f3e3b8; background: #b3172a; border: 5px solid #7d0f1d; animation: sealHit .16s steps(3); transform: rotate(-8deg); }
@keyframes paperDown { from { transform: translateY(-60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sealHit { from { transform: rotate(-8deg) scale(3); opacity: .2; } to { transform: rotate(-8deg) scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .intro-big, .intro-big.chant, .intro-big.name, .intro-big.law, .intro-edict .paper, .seal { animation: none; } }

/* 準備 */
.setup-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; padding: 12px; align-items: start; }
.side-col { display: flex; flex-direction: column; gap: 12px; }
.panel-head { margin-bottom: 8px; }
.preset-row { margin-bottom: 10px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { font-weight: normal; }
.th-job { padding: 2px; font-size: 13px; line-height: 1.15; min-width: 44px; text-align: center; }
.th-job .spr { display: block; margin: 0 auto 2px; }
.hero-cell { text-align: left; padding: 6px 8px 6px 0; min-width: 190px; white-space: nowrap; }
.hero-line { display: flex; align-items: center; gap: 6px; }
.hero-name { font-size: 17px; }
.hero-meta { font-size: 13px; color: var(--muted); }
.mini { background: var(--panel2); border: 2px solid var(--line); min-width: 30px; min-height: 30px; cursor: pointer; padding: 0 5px; font-size: 13px; }
.mini:hover { background: #3a3256; }
.cell { width: 100%; height: 40px; min-width: 40px; border: 2px solid #171324; background: #171324; color: var(--muted); cursor: pointer; font-size: 19px; }
.cell[data-v="1"] { background: var(--r1); color: #2a0c07; }
.cell[data-v="2"] { background: var(--r2); color: #2e1b00; }
.cell[data-v="3"] { background: var(--r3); color: #12260a; }
.cell[data-v="4"] { background: var(--r4); color: #0b1a2c; }
.cell:hover { border-color: #fff; }
td { padding: 1px; }
.rules-row td { padding: 2px 0 14px; }
.rule-grid { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; color: var(--muted); }
.rule-grid label { display: flex; align-items: center; gap: 4px; }
.shop-line { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.shop-line .nm { flex: 1; }
.shop-line .pr { color: var(--gold); font-size: 14px; }
.shop-line b { font-weight: normal; min-width: 22px; text-align: center; }
.total { margin-top: 6px; text-align: right; }
.form-line { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }

/* ゲーム */
#game.active { height: 100vh; }
.hud { padding: 5px 10px; gap: 8px; }
.hud-bag { display: flex; gap: 8px; align-items: center; }
.hud-bag span.it { display: inline-flex; align-items: center; gap: 2px; }
.speed { display: flex; gap: 2px; }
.speed .btn { padding: 2px 8px; min-width: 40px; }
.game-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 310px; }
#stage { position: relative; background: #000; min-height: 0; min-width: 0; overflow: hidden; }
#cv { position: absolute; left: 0; top: 0; image-rendering: pixelated; }
#bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fffdf2; color: #1c1626; padding: 3px 9px; border: 2px solid #1c1626; font-size: 16px; line-height: 1.3; max-width: 240px; width: max-content; text-align: center; box-shadow: 0 2px 0 #0007; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -4px; border: 4px solid transparent; border-top-color: #1c1626; }
#banner { position: absolute; left: 12px; right: 12px; bottom: 12px; pointer-events: none; display: flex; justify-content: center; }
.case { background: #2a1408f2; border: 3px solid var(--warn); padding: 7px 14px; max-width: 760px; animation: pop .18s steps(3); }
.case.good { background: #0d2a14f2; border-color: var(--green); }
.case .no { color: var(--warn); font-size: 14px; }
.case.good .no { color: var(--green); }
.case .ttl { font-size: 21px; color: #fff; margin-left: 4px; }
.case .why { font-size: 15px; color: #ffe2b8; }
.case.good .why { color: #caffd6; }
@keyframes pop { from { transform: translateY(12px); } to { transform: none; } }
#pausedMark { display: none; position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: #000c; border: 2px solid var(--gold); color: var(--gold); padding: 3px 14px; }
#stage.paused #pausedMark { display: block; }
#sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 2px solid var(--line); }
#cards { display: flex; flex-direction: column; gap: 4px; padding: 6px; }
.card { background: var(--panel2); padding: 4px 6px; border-left: 5px solid var(--c, #fff); display: grid; grid-template-columns: 34px 1fr; gap: 0 6px; }
.card.down { background: #3d1f2a; }
.card.dead { opacity: .5; }
.card .line1 { overflow: hidden; display: flex; justify-content: space-between; gap: 6px; font-size: 15px; white-space: nowrap; }
.card .lv { color: var(--muted); font-size: 13px; }
.card .doing { font-size: 14px; color: #ffe9b0; display: flex; align-items: center; gap: 3px; min-height: 21px; }
.bars { display: grid; grid-template-columns: 1fr 44px; gap: 3px; margin: 2px 0; }
.meter { height: 7px; background: #120f1c; border: 1px solid #000; }
.meter i { display: block; height: 100%; background: var(--green); }
.meter.low i { background: var(--red); }
.meter.food i { background: #e8b65a; }
.log-head { padding: 2px 8px 0; }
.key-hint { padding: 0 8px 4px; font-size: 13px; color: var(--muted); }
.edict-note { color: var(--gold); margin-bottom: 2px; }
#log { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px; font-size: 14px; line-height: 1.4; }
#log div { padding: 2px 0; border-bottom: 1px solid #ffffff10; }
#log .bad { color: #ffb0a8; } #log .good { color: #b6f5c0; } #log .info { color: var(--muted); }
#log .floor { color: var(--gold); text-align: center; }
#log .caseline { color: #ffc27a; background: #ff9b3d1f; padding: 3px 5px; }
#log .caseline.goodcase { color: #b6f5c0; background: #7dff8f1f; }
#log small { display: block; font-size: 13px; opacity: .85; }

/* 結果 */
#result.active { align-items: center; padding: 18px 12px 90px; }
.result-box { width: min(860px, 100%); display: flex; flex-direction: column; gap: 12px; }
#resTitle { font-size: 38px; color: var(--gold); text-align: center; }
#resSub { text-align: center; }
.stat { background: var(--panel); border: 2px solid var(--line); padding: 4px 14px; text-align: center; min-width: 96px; }
.stat b { display: block; font-size: 24px; font-weight: normal; color: var(--gold); }
.fix-list { margin: 0; padding-left: 20px; }
.fix-list li { margin: 3px 0; }
.cases { display: flex; flex-direction: column; gap: 4px; max-height: 44vh; overflow-y: auto; }
.case-row { background: var(--panel2); padding: 5px 9px; border-left: 4px solid var(--warn); }
.case-row.good { border-left-color: var(--green); }
.case-row .new { background: var(--gold); color: #000; padding: 0 5px; font-size: 13px; margin-left: 5px; }
.case-row .hd { color: #fff; }
.case-row .w { font-size: 14px; color: var(--muted); }
.sticky-actions { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px; background: #15121ff0; border-top: 2px solid var(--line); }

/* モーダル */
.modal { display: none; position: fixed; inset: 0; background: #000b; z-index: 10; padding: 16px; overflow-y: auto; }
.modal.open { display: flex; align-items: flex-start; justify-content: center; }
.modal-box { background: var(--panel); border: 3px solid var(--line); width: min(1000px, 100%); padding-bottom: 12px; }
.modal-box .table-wrap { padding: 10px; }
.check { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
#bookTabs { padding: 8px 12px 0; }
.rumors { margin: 10px 12px 0; padding: 8px 12px; background: #2a2140; border: 2px solid var(--gold); }
.rumors h3 { margin-bottom: 2px; font-size: 16px; color: var(--gold); }
.rumors ul { margin: 0; padding-left: 20px; font-size: 14px; }
.rumors li { margin: 2px 0; }
.book-item.rumored { opacity: 1; border-left-color: var(--gold); }
.book-item .rumor { color: var(--gold); }
#bookTabs .btn { min-height: 32px; padding: 2px 10px; font-size: 14px; }
#bookList { padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 6px; }
.book-item { background: var(--panel2); padding: 6px 9px; border-left: 4px solid var(--warn); font-size: 14px; }
.book-item.good { border-left-color: var(--green); }
.book-item.unknown { opacity: .55; border-left-color: var(--line); }
.book-item .nm { font-size: 16px; color: #fff; }
.book-item .no { color: var(--muted); }
.book-item .fx { color: var(--muted); }
.book-item .say { color: #ffe9b0; }

@media (max-width: 1100px) {
  .setup-body { grid-template-columns: 1fr; }
  .side-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 860px) {
  #game.active { height: auto; min-height: 100vh; }
  .game-body { grid-template-columns: 1fr; grid-template-rows: 62vh auto; }
  #sidebar { border-left: 0; border-top: 2px solid var(--line); }
  #cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #log { max-height: 40vh; }
  .hud-bag .it b { font-size: 13px; }
  .bubble { font-size: 14px; max-width: 170px; }
  .case .ttl { font-size: 17px; }
  .hero-cell { min-width: 150px; }
}
@media (prefers-reduced-motion: reduce) { .case { animation: none; } }
