:root {
  --ink: #f4f1e8;
  --box: rgba(12, 16, 38, 0.92);
  --box-border: #c9b37a;
  --accent: #e8c24a;
  --testimony: #6fe07a;
  --danger: #e3463c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #07080f; color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif; }
body { display: flex; justify-content: center; align-items: flex-start; }
button { font: inherit; cursor: pointer; }

#game { position: relative; width: min(100vw, 960px); user-select: none; }

/* ---------- 舞台 ---------- */
#stage { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  transition: background 0.3s; }
#stage.shake { animation: shake 0.4s; }
@keyframes shake {
  0%,100% { transform: translate(0,0); } 20% { transform: translate(-10px,4px); }
  40% { transform: translate(10px,-4px); } 60% { transform: translate(-6px,2px); }
  80% { transform: translate(6px,-2px); }
}
.bg-black    { background: #000; }
.bg-kitchen  { background:
    linear-gradient(90deg, transparent 49.6%, #c9d6de 49.6%, #c9d6de 50.4%, transparent 50.4%) 0 0 / 80px 80px,
    linear-gradient(transparent 49.2%, #c9d6de 49.2%, #c9d6de 50.8%, transparent 50.8%) 0 0 / 80px 80px,
    linear-gradient(#eef4f7, #dce8ee 62%, #9aa9b3 62%, #c4ced4 64%, #7d8b94 100%); }
.bg-prep     { background:
    repeating-linear-gradient(90deg, #6d5b44 0 6px, transparent 6px 120px),
    linear-gradient(#8a7a64, #5c4e3c 60%, #3a3128 60%); }
.bg-hallway  { background:
    repeating-linear-gradient(90deg, transparent 0 180px, #b9ae93 180px 190px),
    linear-gradient(#f1e9d2, #d8ccac 58%, #9c8e6f 58%, #b5a888 100%); }
.bg-clubroom { background: linear-gradient(#ffd9a8, #f0b979 60%, #8a5a34 60%, #6b4426 100%); }
.bg-dusk     { background: linear-gradient(#f28a5b, #8e4a7a 55%, #2d2440 100%); }
.bg-memory   { background: radial-gradient(circle, #555, #111); filter: grayscale(1); }

#portrait { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 44%; height: 88%; display: flex; align-items: flex-end; justify-content: center;
  z-index: 1; transition: opacity 0.2s; }
#portrait.hidden { opacity: 0; }
#portrait-face { display: flex; align-items: flex-end; justify-content: center; height: 100%;
  font-size: clamp(80px, 22vw, 210px); line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,0.6)); }
#portrait-face svg { height: 100%; width: auto; max-width: 100%; display: block; }
#portrait.bounce #portrait-face { animation: bounce 0.25s; }
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.04); } }

#toolbar { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; z-index: 5; }
#toolbar button { background: var(--box); color: var(--ink); border: 2px solid var(--box-border);
  border-radius: 6px; padding: 6px 12px; font-size: 14px; }
#toolbar button:hover { background: #1f2a5a; }

#health { position: absolute; top: 12px; left: 12px; z-index: 5; display: flex; gap: 4px; align-items: center;
  background: var(--box); padding: 4px 8px; border-radius: 6px; }
#health .label { font-size: 12px; margin-right: 4px; }
#health .pip { width: 22px; height: 14px; border-radius: 3px; background: var(--testimony);
  border: 1px solid #0006; }
#health .pip.lost { background: #333; }
#health .pip.just-lost { animation: lose 0.6s; }
@keyframes lose { 0%,50% { background: var(--danger); } }

#banner { position: absolute; top: 18%; left: 0; right: 0; text-align: center; z-index: 6;
  font-size: clamp(22px, 4.5vw, 40px); font-weight: 900; color: var(--accent);
  text-shadow: 0 0 6px #000, 3px 3px 0 #000; letter-spacing: 0.1em; white-space: pre-line; }
#banner.place { top: 40%; font-size: clamp(20px, 4vw, 32px); color: #fff; }
#banner.episode { top: 34%; color: #fff; font-size: clamp(22px, 5vw, 44px); line-height: 1.6; }
#banner.verdict { top: 36%; font-size: clamp(48px, 12vw, 110px); }
#banner.verdict.win { color: #fff; }
#banner.verdict.lose { color: var(--danger); }

#shout { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 8; background: radial-gradient(circle, rgba(255,255,255,0.15), rgba(0,0,0,0.35)); }
#shout span { font-size: clamp(48px, 13vw, 130px); font-weight: 900; color: #fff;
  -webkit-text-stroke: 4px #1a3aa0; paint-order: stroke fill;
  text-shadow: 6px 6px 0 #0a1a60; transform: rotate(-6deg);
  animation: shoutIn 0.35s cubic-bezier(.2,1.6,.4,1); }
#shout.rival span { -webkit-text-stroke-color: #a01a1a; text-shadow: 6px 6px 0 #600a0a; }
@keyframes shoutIn { from { transform: rotate(-6deg) scale(2.4); opacity: 0; } }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 9; }
#flash.on { animation: flash 0.35s; }
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }

/* ---------- テキストボックス ---------- */
#textbox { position: relative; z-index: 3; min-height: 130px; margin-top: -2px; padding: 26px 22px 18px;
  background: var(--box); border: 3px solid var(--box-border); border-radius: 0 0 10px 10px;
  font-size: clamp(15px, 2.3vw, 20px); line-height: 1.7; cursor: pointer; }
#nameplate { position: absolute; top: -18px; left: 16px; padding: 2px 16px;
  background: #1f2a5a; border: 2px solid var(--box-border); border-radius: 6px;
  font-weight: bold; font-size: 0.9em; }
#text { white-space: pre-wrap; min-height: 3.4em; }
#text.testimony { color: var(--testimony); }
#text.thought { color: #8fc8ff; }
#text em { font-style: normal; color: #ff6b5e; font-weight: bold; }
#next-indicator { position: absolute; right: 16px; bottom: 8px; color: var(--accent);
  animation: blink 0.8s infinite; visibility: hidden; }
#textbox.ready #next-indicator { visibility: visible; }
@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- 現在地・選択肢 ---------- */
#location { position: absolute; bottom: 12px; left: 12px; z-index: 5; background: var(--box);
  border: 2px solid var(--box-border); border-radius: 6px; padding: 4px 12px; font-size: 14px; }
#choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; padding: 12px; }
#choices button { padding: 10px 14px; border-radius: 8px; border: 2px solid var(--box-border);
  background: #1f2a5a; color: var(--ink); font-size: 15px; text-align: left; }
#choices button:hover { filter: brightness(1.3); }
#choices button.done { opacity: 0.6; }
#choices button.done::after { content: " ✓"; color: var(--testimony); }
#choices button.back { background: #333; text-align: center; }

/* ---------- 尋問コントロール ---------- */
#cross-controls { display: flex; gap: 10px; justify-content: center; padding: 12px; }
#cross-controls button { padding: 10px 18px; border-radius: 8px; border: 2px solid var(--box-border);
  background: #1f2a5a; color: var(--ink); font-size: 16px; font-weight: bold; }
#cross-controls #btn-press { background: #2a6a3a; }
#cross-controls #btn-present { background: #8a2a22; }
#cross-controls button:hover { filter: brightness(1.25); }
#cross-controls button:disabled { opacity: 0.35; cursor: default; filter: none; }

/* ---------- 法廷記録 ---------- */
#record { position: absolute; inset: 0; background: rgba(0,0,0,0.6); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 16px; }
#record-panel { width: 100%; max-width: 640px; background: #231a10; border: 3px solid var(--box-border);
  border-radius: 10px; padding: 16px; }
#record-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#record-title { font-weight: bold; color: var(--accent); font-size: 18px; }
#record-close { background: none; border: none; color: var(--ink); font-size: 20px; }
#record-prompt { white-space: pre-wrap; background: #3a2a14; padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; font-size: 14px; }
#record-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
#record-list li svg, #record-detail-icon svg { width: 72%; height: 72%; }
#record-detail-icon { width: 64px; height: 64px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
#record-detail-icon svg { width: 100%; height: 100%; }
#record-list li { aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 34px; background: #3d2c18; border: 2px solid #6b5230; border-radius: 8px; cursor: pointer; }
#record-list li.selected { border-color: var(--accent); background: #5a4220; }
#record-detail { display: flex; gap: 12px; background: #120d07; border-radius: 8px; padding: 12px; min-height: 96px; }
#record-detail-icon { font-size: 48px; }
#record-detail-name { font-weight: bold; color: var(--accent); margin-bottom: 4px; }
#record-detail-desc { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
#record-present { margin-top: 12px; width: 100%; padding: 12px; font-size: 18px; font-weight: bold;
  background: #8a2a22; color: #fff; border: 2px solid var(--box-border); border-radius: 8px; }

/* ---------- 証拠入手ポップアップ ---------- */
#evidence-popup { position: absolute; top: 56px; left: 16px; z-index: 7;
  background: #231a10; border: 3px solid var(--box-border); border-radius: 10px; padding: 12px 20px;
  text-align: center; animation: popIn 0.3s ease-out; }
#evidence-popup-icon { width: clamp(64px, 14vw, 110px); height: clamp(64px, 14vw, 110px); margin: 0 auto 6px; }
#evidence-popup-icon svg { width: 100%; height: 100%; }
#evidence-popup-name { color: var(--accent); font-weight: bold; }
@keyframes popIn { from { transform: scale(0.6); opacity: 0; } }

/* ---------- タイトル ---------- */
#title-portrait { width: clamp(120px, 26vw, 220px); margin-bottom: -8px; }
#title-portrait svg { width: 100%; height: auto; display: block; }
#title-screen { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: radial-gradient(circle, #1f2a5a, #05060d); }
#title-screen h1 { font-size: clamp(36px, 8vw, 72px); margin: 0; color: var(--accent);
  text-shadow: 4px 4px 0 #000; letter-spacing: 0.08em; }
#title-screen .subtitle { margin: 8px 0 32px; opacity: 0.8; }
#title-screen button { padding: 14px 44px; font-size: 20px; font-weight: bold; border-radius: 10px;
  background: #8a2a22; color: #fff; border: 3px solid var(--box-border); }
#title-screen .hint { margin-top: 24px; font-size: 13px; opacity: 0.6; }

[hidden] { display: none !important; }
