:root {
  --ink: #edf7f5;
  --muted: #8ea7a6;
  --panel: rgba(7, 16, 20, .89);
  --panel-solid: #0a1519;
  --line: rgba(202, 237, 231, .18);
  --cyan: #50e4d2;
  --cyan-soft: rgba(80, 228, 210, .14);
  --amber: #f4bd62;
  --coral: #f47669;
  --blue: #73a9ff;
  --body-size: 18px;
  color-scheme: dark;
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-height: 100%; margin: 0; background: #071014; }

body {
  min-height: 100dvh;
  color: var(--ink);
  font-size: var(--body-size);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(80, 228, 210, .05), transparent 38%),
    radial-gradient(circle at 80% 10%, rgba(244, 189, 98, .07), transparent 28%),
    #071014;
}

button, select, input { font: inherit; }
button { color: inherit; }

button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.app-shell {
  width: 100%;
  /* min-height だと中身が伸びたぶん body（overflow:hidden）の外へ出てしまい、
     どこにもスクロールバーが立たない。画面の高さで固定し、
     はみ出しは .screen 側で受ける */
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px clamp(12px, 3vw, 28px);
  background: rgba(4, 11, 14, .92);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand-button, .icon-button, .modal-close {
  border: 0;
  background: none;
  cursor: pointer;
}

.brand-button { display: flex; align-items: center; gap: 10px; padding: 2px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #071014;
  background: var(--cyan);
  font: 900 14px/1 monospace;
  letter-spacing: -1px;
  clip-path: polygon(0 0, 87% 0, 100% 26%, 100% 100%, 13% 100%, 0 74%);
}
.brand-mark span { opacity: .55; }
.brand-copy { font: 800 13px/1.1 monospace; letter-spacing: .08em; }

.topbar-actions { display: flex; gap: 6px; }
.icon-button {
  min-width: 50px;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 13px;
  letter-spacing: .08em;
}
.icon-button:hover { color: var(--ink); border-color: var(--line); }

.screen {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-color: var(--cyan) transparent;
}

.title-screen {
  min-height: 100%;
  display: grid;
  align-items: end;
  position: relative;
  isolation: isolate;
  padding: clamp(24px, 6vw, 76px);
  overflow: hidden;
}

.title-screen::before,
.title-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
}
.title-screen::before {
  background:
    linear-gradient(90deg, rgba(7,16,20,.96) 0%, rgba(7,16,20,.72) 52%, rgba(7,16,20,.18)),
    var(--title-art, linear-gradient(120deg, #0a171b, #173438));
  background-size: cover;
  background-position: center;
}
.title-screen::after {
  z-index: -1;
  opacity: .28;
  background-image:
    linear-gradient(rgba(80, 228, 210, .16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 228, 210, .16) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to right, black, transparent 70%);
}

.title-copy { width: min(680px, 100%); }
.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font: 800 12px/1.2 monospace;
  letter-spacing: .22em;
  text-transform: uppercase;
}
.title-screen h1 {
  margin: 0;
  font: 900 clamp(42px, 9vw, 104px)/.85 "Arial Narrow", "Yu Gothic UI", sans-serif;
  letter-spacing: -.07em;
  text-transform: uppercase;
}
.title-screen h1 span { display: block; color: transparent; -webkit-text-stroke: 1px var(--cyan); }
.title-subtitle {
  margin: 20px 0 4px;
  color: var(--amber);
  font-weight: 800;
  letter-spacing: .06em;
}
.title-progress { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.title-menu { display: grid; gap: 10px; width: min(360px, 100%); }

.primary-button, .secondary-button, .choice-button, .command-button, .resolve-button, .danger-button {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 16px;
  background: rgba(7, 16, 20, .82);
  cursor: pointer;
  text-align: left;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.primary-button {
  color: #061013;
  background: var(--cyan);
  border-color: var(--cyan);
  font-weight: 900;
}
.primary-button:hover, .secondary-button:hover, .choice-button:hover, .command-button:hover, .resolve-button:hover {
  transform: translateX(4px);
  border-color: var(--cyan);
}
.secondary-button[disabled] { opacity: .35; cursor: default; transform: none; }

.adv-screen {
  min-height: 100%;
  display: grid;
  grid-template-rows: minmax(250px, 1fr) auto;
  position: relative;
  background: #081216;
}

.scene-stage {
  position: relative;
  min-height: 290px;
  overflow: hidden;
  background:
    linear-gradient(to top, rgba(4, 10, 12, .96), transparent 55%),
    var(--scene-art, linear-gradient(135deg, #11272b, #081216 65%));
  background-position: center;
  background-size: cover;
}
.scene-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(5, 12, 15, .16), transparent 45%, rgba(5, 12, 15, .16));
}

.scene-meta {
  position: absolute;
  top: 18px;
  left: clamp(14px, 3vw, 30px);
  z-index: 3;
  padding: 7px 10px;
  color: var(--cyan);
  background: rgba(5, 12, 15, .78);
  border-left: 3px solid var(--cyan);
  font: 700 12px/1.2 monospace;
  letter-spacing: .08em;
}

.portrait {
  position: absolute;
  bottom: -2%;
  height: min(68vh, 610px);
  max-width: 44vw;
  object-fit: contain;
  filter: drop-shadow(0 24px 20px rgba(0,0,0,.45));
  pointer-events: none;
  transform-origin: bottom;
  animation: portrait-in .28s ease-out both;
}
/* 画面外へはみ出させず、少し内側に寄せて顔が切れないようにする */
.portrait.left { left: clamp(0px, 2vw, 36px); }
.portrait.right { right: clamp(0px, 2vw, 36px); transform: scaleX(-1); }
.portrait.dim { opacity: .38; filter: saturate(.55) drop-shadow(0 24px 20px rgba(0,0,0,.45)); }

.portrait-fallback {
  position: absolute;
  bottom: 0;
  width: min(34vw, 320px);
  height: 78%;
  background: linear-gradient(to top, rgba(80,228,210,.2), rgba(80,228,210,.04));
  border: 1px solid rgba(80,228,210,.22);
  clip-path: polygon(20% 0, 80% 0, 100% 28%, 88% 100%, 12% 100%, 0 28%);
}
.portrait-fallback.left { left: 4vw; }
.portrait-fallback.right { right: 4vw; }

.dialogue-panel {
  position: relative;
  z-index: 4;
  margin: -42px auto 18px;
  width: min(980px, calc(100% - 28px));
  min-height: 190px;
  padding: 22px clamp(18px, 4vw, 36px) 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--cyan);
  box-shadow: 0 24px 50px rgba(0,0,0,.45);
  backdrop-filter: blur(13px);
}
.speaker {
  display: inline-block;
  min-width: 120px;
  margin: 0 0 13px;
  color: var(--cyan);
  font: 900 14px/1 monospace;
  letter-spacing: .15em;
}
.dialogue-text {
  min-height: 3.6em;
  margin: 0;
  font-size: var(--body-size);
  line-height: 1.8;
  letter-spacing: .02em;
}
.advance-hint {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}
.advance-hint::after { content: "›"; color: var(--amber); font-size: 22px; }
.dialogue-panel.clickable { cursor: pointer; }

.choice-list { display: grid; gap: 9px; margin-top: 14px; }
.choice-button {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  color: var(--ink);
  background: rgba(16, 32, 36, .95);
}
.choice-code { color: var(--amber); font: 800 12px/1.8 monospace; }

.battle-screen {
  position: relative; /* 被弾フラッシュの重ね先 */
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(420px, 1.1fr);
  background: #071014;
}
.battle-visual {
  min-height: 320px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(to top, #071014 0%, transparent 58%),
    var(--battle-art, linear-gradient(145deg, #132c31, #071014));
  background-size: cover;
  background-position: center;
}
.battle-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 4px, rgba(80,228,210,.025) 5px);
  pointer-events: none;
}
.target-image {
  position: absolute;
  left: 50%;
  bottom: 8%;
  width: min(72%, 520px);
  height: 68%;
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(0 16px 28px rgba(0,0,0,.6));
}
/* 手応えを画で返す。translateX(-50%) を保ったまま揺らす */
@keyframes target-hit {
  0%   { transform: translateX(-50%) translate(0, 0); }
  15%  { transform: translateX(-50%) translate(-9px, 3px); }
  30%  { transform: translateX(-50%) translate(7px, -2px); }
  45%  { transform: translateX(-50%) translate(-5px, 2px); }
  60%  { transform: translateX(-50%) translate(4px, -1px); }
  80%  { transform: translateX(-50%) translate(-2px, 1px); }
  100% { transform: translateX(-50%) translate(0, 0); }
}
@keyframes target-hit-big {
  0%   { transform: translateX(-50%) scale(1); filter: drop-shadow(0 16px 28px rgba(0,0,0,.6)); }
  10%  { transform: translateX(-50%) translate(-16px, 5px) scale(1.04); filter: drop-shadow(0 0 26px rgba(244,189,98,.95)) brightness(1.9); }
  25%  { transform: translateX(-50%) translate(14px, -4px) scale(1.02); filter: drop-shadow(0 0 18px rgba(244,189,98,.7)) brightness(1.4); }
  45%  { transform: translateX(-50%) translate(-9px, 3px); }
  65%  { transform: translateX(-50%) translate(6px, -2px); }
  85%  { transform: translateX(-50%) translate(-3px, 1px); }
  100% { transform: translateX(-50%) translate(0, 0) scale(1); filter: drop-shadow(0 16px 28px rgba(0,0,0,.6)); }
}
@keyframes target-guard {
  0%, 100% { transform: translateX(-50%) translate(0, 0); }
  50% { transform: translateX(-50%) translate(0, -2px); filter: drop-shadow(0 16px 28px rgba(0,0,0,.6)) brightness(1.15) saturate(.7); }
}
.target-image.hit { animation: target-hit .38s ease-out; }
.target-image.hit-big { animation: target-hit-big .62s ease-out; }
.target-image.guarded { animation: target-guard .3s ease-in-out; }
/* 画面全体で殴った感を返す */
@keyframes visual-shock { 0%,100% { transform: translate(0,0); } 25% { transform: translate(4px,-3px); } 60% { transform: translate(-3px,2px); } }
.battle-visual.shock { animation: visual-shock .3s ease-out; }
.target-fallback {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(58vw, 340px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 70px rgba(80,228,210,.22), inset 0 0 50px rgba(80,228,210,.12);
}
.target-fallback::after {
  content: "";
  position: absolute;
  inset: 20%;
  border: 1px solid var(--amber);
}
.battle-target-label {
  position: absolute;
  inset: auto 18px 18px;
  z-index: 2;
  padding: 11px 13px;
  background: rgba(5,12,15,.85);
  border-left: 3px solid var(--coral);
}
.battle-target-label strong { display: block; }
.battle-target-label span { color: var(--muted); font-size: 12px; }

.battle-console {
  min-height: 0;
  overflow: auto;
  padding: clamp(16px, 3vw, 30px);
  border-left: 1px solid var(--line);
}
.battle-heading { display: flex; justify-content: space-between; gap: 12px; align-items: end; }
.battle-heading h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); }
.turn-counter { color: var(--amber); font: 800 13px/1 monospace; }

.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0; }
.gauge-card { padding: 10px 12px; background: rgba(255,255,255,.025); border: 1px solid var(--line); }
.gauge-label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.gauge-track { position: relative; height: 9px; overflow: hidden; background: rgba(255,255,255,.08); }
.gauge-fill { height: 100%; width: 0; background: var(--cyan); transition: width .38s cubic-bezier(.2,.8,.2,1); }
/* 減った幅・増えた幅を残像で見せる */
.gauge-ghost {
  position: absolute; top: 0; height: 100%;
  background: #ff7d6a;
  animation: ghost-fade .75s ease-out forwards;
}
.gauge-ghost.up { background: var(--amber); }
@keyframes ghost-fade { 0% { opacity: .95; } 70% { opacity: .6; } 100% { opacity: 0; } }
/* 動いた数値の増減バッジ */
.gauge-diff {
  margin-left: 7px; padding: 1px 6px;
  font: 800 11px/1.5 monospace; vertical-align: middle;
  animation: diff-in .5s ease-out both;
}
.gauge-diff.down { color: #0b1a1e; background: #ff7d6a; }
.gauge-diff.up { color: #0b1a1e; background: var(--amber); }
@keyframes diff-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
.gauge-card.changed .gauge-label strong { color: #fff; }

/* 対象の上に飛ぶ数値 */
.pop-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.damage-pop {
  position: absolute; left: 50%; top: 30%;
  display: grid; justify-items: center; gap: 2px;
  transform: translateX(-50%);
  font: 900 34px/1 monospace;
  text-shadow: 0 3px 12px rgba(0,0,0,.85), 0 0 22px rgba(0,0,0,.6);
  animation: pop-rise 1.05s cubic-bezier(.2,.9,.25,1) both;
  animation-delay: var(--pop-delay, 0ms);
  white-space: nowrap;
}
.damage-pop small { font: 700 12px/1.2 var(--font-ui, inherit); letter-spacing: .04em; }
.damage-pop.hit { color: #fff; }
.damage-pop.weak { color: rgba(255,255,255,.5); font-size: 22px; }
.damage-pop.crit { color: var(--amber); font-size: 54px; text-shadow: 0 0 26px rgba(244,189,98,.95), 0 4px 14px rgba(0,0,0,.9); }
.damage-pop.grasp { color: var(--cyan); font-size: 26px; }
.damage-pop.crit-grasp { color: var(--cyan); font-size: 42px; text-shadow: 0 0 26px rgba(80,228,210,.95), 0 4px 14px rgba(0,0,0,.9); }
.damage-pop.counter { color: var(--amber); font-size: 26px; top: 46%; }
.damage-pop.morale { color: #ff7d6a; font-size: 24px; top: 60%; }
.damage-pop.heal { color: var(--cyan); font-size: 24px; top: 60%; }
@keyframes pop-rise {
  0%   { opacity: 0; transform: translateX(-50%) translateY(14px) scale(.6); }
  18%  { opacity: 1; transform: translateX(-50%) translateY(-6px) scale(1.18); }
  32%  { transform: translateX(-50%) translateY(0) scale(1); }
  75%  { opacity: 1; transform: translateX(-50%) translateY(-26px) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-46px) scale(.95); }
}

/* こちらが撃たれたら画面が鳴る */
.battle-screen.damaged::after {
  content: ""; position: absolute; inset: 0; z-index: 7; pointer-events: none;
  background: radial-gradient(circle at 50% 55%, rgba(255,80,60,.05), rgba(255,60,40,.3) 100%);
  animation: hurt-flash .5s ease-out forwards;
}
@keyframes hurt-flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.gauge-fill.morale { background: var(--amber); }
.gauge-fill.integrity { background: var(--coral); }
.gauge-fill.progress { background: var(--blue); }

.phase-strip {
  margin: 0 0 15px;
  padding: 10px 12px;
  color: var(--cyan);
  background: var(--cyan-soft);
  border-left: 2px solid var(--cyan);
  font-size: 13px;
}
.link-button {
  min-height: 0;
  padding: 2px 6px;
  color: var(--amber);
  background: transparent;
  border: 1px solid var(--amber);
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.link-button:hover { color: var(--ink); background: var(--cyan-soft); }
.command-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.command-button { min-height: 66px; padding: 10px 12px; background: #0b1a1e; }
.command-button strong { display: block; margin-bottom: 4px; font-size: 14px; }
.command-button small { color: var(--muted); font-size: 11px; }
.command-button[disabled], .resolve-button[disabled] { opacity: .34; cursor: not-allowed; transform: none; }

.turn-warning {
  margin: 12px 0 0;
  padding: 9px 12px;
  color: var(--amber);
  background: rgba(244,189,98,.08);
  border-left: 3px solid var(--amber);
  font-size: 13px;
}
/* 誰が動くか → その人の手、の2段階選択 */
.command-step {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 16px 0 10px;
  color: var(--muted); font: 700 13px/1.4 var(--font-ui, inherit); letter-spacing: .04em;
}
.command-actor { color: var(--cyan); font-size: 15px; font-weight: 800; }
.actor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 9px; }
.actor-button {
  display: grid; gap: 4px; padding: 15px 12px;
  text-align: left; color: var(--ink);
  background: rgba(80, 228, 210, .07);
  border: 1px solid rgba(80, 228, 210, .3);
  border-left: 3px solid var(--cyan);
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.actor-button:hover { background: rgba(80, 228, 210, .14); }
.actor-button:active { transform: translateY(1px); }
.actor-button strong { font-size: 17px; }
.actor-button small { color: var(--muted); font-size: 11px; }

.locked-skills { margin-top: 10px; color: var(--muted); font-size: 12px; }
.locked-skills summary { cursor: pointer; padding: 6px 0; }
.locked-skills ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.locked-skills li span { color: rgba(255,255,255,.35); }

/* 相手の周期表示。読めた拍だけが開き、隙が光る */
.pattern-strip {
  margin: 14px 0;
  padding: 12px 14px;
  background: rgba(0,0,0,.3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
}
.pattern-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; color: var(--muted); font-size: 12px; }
.pattern-head strong.gap-open { color: #0b1a1e; background: var(--amber); padding: 2px 8px; font-size: 12px; animation: gap-pulse .9s ease-in-out infinite; }
.pattern-beats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.beat {
  padding: 6px 10px;
  font: 700 12px/1.2 monospace;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.beat-unknown { color: rgba(255,255,255,.28); }
.beat-next { color: var(--ink); border-color: var(--cyan); background: rgba(80,228,210,.1); }
.beat-sync { color: var(--amber); border-color: rgba(244,189,98,.6); background: rgba(244,189,98,.1); }
.beat-guard { color: #9fb6bd; border-color: rgba(160,190,200,.45); background: rgba(160,190,200,.08); }
@keyframes gap-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.pattern-advice { margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 12px; line-height: 1.6; }
.pattern-advice strong { color: var(--cyan); }
.pattern-advice.sync strong { color: var(--amber); }
.pattern-advice.guard strong { color: #9fb6bd; }
.pattern-head strong.gap-shut { color: #0b1a1e; background: #9fb6bd; padding: 2px 8px; font-size: 12px; }

.battle-log {
  max-height: 176px;
  overflow: auto;
  margin: 15px 0;
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(0,0,0,.28);
  border-left: 1px solid var(--line);
  font: 12px/1.65 monospace;
}
.battle-log p { margin: 0; }

/* 戦況の流れを目で追えるように、行の種別ごとに見た目を変える */
.battle-log { font: 13px/1.7 var(--font-ui, inherit); }
.battle-log p { padding: 1px 0 1px 10px; border-left: 2px solid transparent; }

/* 手番の区切り。左右の線で挟んで、どちらの手番かを色で示す */
.battle-log p.log-sep {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 6px; padding: 0;
  border-left: 0;
  font: 700 11px/1 monospace; letter-spacing: .1em;
}
.battle-log p.log-sep::before, .battle-log p.log-sep::after {
  content: ""; flex: 1; height: 1px; background: currentColor; opacity: .35;
}
.battle-log p.log-sep:first-child { margin-top: 0; }
.battle-log p.log-turn-own { color: var(--cyan); }
.battle-log p.log-turn-foe, .battle-log p.log-turn { color: var(--coral, #f4bd62); }

/* RAML側の行動 */
.battle-log p.log-act {
  margin-top: 6px;
  color: var(--ink); font-weight: 700; font-size: 14px;
  border-left-color: var(--cyan);
  background: linear-gradient(90deg, rgba(80,228,210,.09), transparent 70%);
}
/* 相手の一手 */
.battle-log p.log-enemy {
  margin-top: 6px;
  color: #ffd9a0; font-weight: 700; font-size: 14px;
  border-left-color: var(--amber);
  background: linear-gradient(90deg, rgba(244,189,98,.1), transparent 70%);
}
/* 数値の動き */
.battle-log p.log-num { color: var(--cyan); font-family: monospace; font-size: 13px; }
/* 読み勝ち・隙を突いた */
.battle-log p.log-good {
  color: #0b1a1e; font-weight: 800;
  background: var(--amber); border-left-color: var(--amber);
  padding: 4px 10px; margin: 4px 0;
}
/* 構えた */
.battle-log p.log-ready { color: var(--cyan); border-left-color: rgba(80,228,210,.5); }
/* 被弾・被害 */
.battle-log p.log-bad { color: #ff9a8a; border-left-color: rgba(255,120,100,.55); }
/* 効果が通った（封鎖・開示・解析など） */
.battle-log p.log-effect { color: #cfe9e4; border-left-color: rgba(80,228,210,.28); }
/* 受け止められた・通らなかった */
.battle-log p.log-guard { color: rgba(255,255,255,.45); }
/* 対象の反応 */
.battle-log p.log-react { color: rgba(255,255,255,.62); font-style: italic; }
/* 台詞と演出 */
.battle-log p.log-line { color: var(--ink); }
.battle-log p.log-stage { color: var(--muted); }
.battle-log p.log-info { color: var(--muted); }
.resolution-bar { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.resolve-button { text-align: center; font-weight: 800; background: rgba(244,189,98,.07); }
.resolve-button:not([disabled]) { border-color: rgba(244,189,98,.55); }

.result-screen, .ending-screen, .records-screen {
  min-height: 100%;
  padding: clamp(24px, 7vw, 78px);
  background:
    linear-gradient(135deg, rgba(80,228,210,.06), transparent 40%),
    #071014;
}
.result-card, .ending-card {
  width: min(780px, 100%);
  margin: 0 auto;
  padding: clamp(22px, 5vw, 48px);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-top: 3px solid var(--cyan);
}
.result-card h1, .ending-card h1 { margin: 4px 0 20px; font-size: clamp(30px, 6vw, 58px); line-height: 1; }
.dialogue-text.stage-text { color: var(--muted); font-size: 0.95em; line-height: 1.9; }
.scene-cutin {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* 端末の縦横比で人物が欠けないよう、切り抜かずに収める */
  object-fit: contain;
  object-position: center;
  opacity: .92;
  pointer-events: none;
}
/* 収めたぶん空く左右（または上下）は、同じ絵をぼかして敷いて埋める */
.scene-cutin-bed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(26px) saturate(.55) brightness(.42);
  transform: scale(1.15);
  pointer-events: none;
}
.battle-aftermath {
  margin: 0 0 24px;
  padding: 20px clamp(16px, 3vw, 26px);
  background: rgba(255,255,255,.035);
  border-left: 2px solid var(--cyan);
}
.aftermath-line { margin: 0 0 12px; line-height: 1.9; }
.aftermath-line:last-child { margin-bottom: 0; }
.aftermath-stage { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.8; }
.aftermath-stage:last-child { margin-bottom: 0; }
/* 決着後の対象。結果画面の頭に一枚だけ置く */
.result-visual { position: relative; margin: 0 0 18px; text-align: center; }
.result-visual img {
  max-width: min(100%, 320px); max-height: 34dvh; object-fit: contain;
  filter: saturate(.55) brightness(.85);
}
.result-visual-label {
  display: block; margin-top: 6px; color: var(--muted);
  font-size: 12px; letter-spacing: .1em;
}
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 24px 0; }
.result-cell { padding: 14px; background: rgba(255,255,255,.035); }
.result-cell span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.ending-body { line-height: 1.9; white-space: pre-line; }

/* 幕引きは1行ずつ送る。背景を薄く敷いて、読ませる画面にする */
.ending-screen { position: relative; }
/* 端末の縦横比で絵が切れないよう、::before に全体を収め（contain）、
   余白は ::after の引き伸ばし＋ぼかしで埋める。顔や人物が欠けない */
.ending-screen::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--scene-art, none) center / cover no-repeat;
  filter: blur(28px) saturate(.6) brightness(.35);
  transform: scale(1.12);
  opacity: .5;
}
.ending-screen::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--scene-art, none) center / contain no-repeat;
  opacity: .16;
  filter: saturate(.7);
}
.ending-screen > .ending-card { position: relative; z-index: 1; }
.ending-screen.cinematic::before {
  opacity: .82;
  filter: saturate(.9) brightness(.72);
}
.ending-screen.cinematic > .ending-card {
  background: rgba(7, 16, 20, .86);
  backdrop-filter: blur(5px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .48);
}
.ending-screen.reading { cursor: pointer; }
.ending-screen.reading .ending-card { min-height: 46dvh; display: grid; align-content: center; }
.ending-screen.reading .ending-body {
  font-size: clamp(17px, 2.4vw, 21px);
  animation: ending-in .45s ease-out both;
}
@keyframes ending-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }
.ending-line { color: var(--ink); }
.ending-stage { color: var(--muted); }
.ending-progress {
  margin-top: 26px; color: rgba(255,255,255,.35);
  font: 600 12px/1 monospace; letter-spacing: .08em;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
/* 読み終えたあとの通し表示 */
.ending-recap { display: grid; gap: 11px; margin: 22px 0 26px; }
.ending-recap p { margin: 0; line-height: 1.85; }
.ending-recap .ending-stage { font-size: .95em; }
.release-note { margin: 24px 0; padding: 20px; border: 1px solid var(--amber); background: rgba(244,189,98,.06); font-family: monospace; }
.release-note strong { color: var(--amber); }
.noise-line { margin: 28px 0; color: var(--cyan); font-family: monospace; line-height: 1.8; }

.records-heading { width: min(1080px, 100%); margin: 0 auto 26px; }
.records-heading h1 { margin: 0; font-size: clamp(36px, 7vw, 72px); }
.records-grid { width: min(1080px, 100%); margin: auto; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.archive-panel { padding: 20px; background: var(--panel-solid); border: 1px solid var(--line); }
.archive-panel.wide { grid-column: 1 / -1; }
.archive-panel h2 { margin: 0 0 14px; color: var(--cyan); font-size: 16px; }
.archive-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.archive-item { padding: 10px 12px; background: rgba(255,255,255,.03); color: var(--muted); font-size: 14px; }
.archive-item.unlocked { color: var(--ink); border-left: 2px solid var(--amber); }
.archive-item summary { cursor: pointer; }
.archive-item summary::marker { color: var(--amber); }
.recall-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.recall-line, .recall-stage { margin: 0 0 8px; line-height: 1.7; }
.recall-line:last-child, .recall-stage:last-child { margin-bottom: 0; }
.recall-stage { color: var(--muted); font-size: 13px; }
.recall-speaker { display: block; color: var(--cyan); font-size: 12px; letter-spacing: .08em; }

.modal {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}
.modal::backdrop { background: rgba(1, 5, 7, .82); backdrop-filter: blur(5px); }
.modal-card { margin: 0; padding: 22px; background: #0a1519; border: 1px solid var(--line); border-top: 3px solid var(--cyan); }
.modal-heading { display: grid; grid-template-columns: 1fr auto; align-items: start; margin-bottom: 20px; }
.modal-heading .eyebrow { grid-column: 1; }
.modal-heading h2 { grid-column: 1; margin: 0; }
.modal-close { grid-column: 2; grid-row: 1 / 3; min-width: 44px; min-height: 44px; color: var(--muted); font-size: 27px; }
.setting-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); }
.setting-row select { min-height: 40px; padding: 5px 10px; background: #071014; color: var(--ink); border: 1px solid var(--line); }
.toggle-row input { width: 24px; height: 24px; accent-color: var(--cyan); }
.danger-button { width: 100%; margin-top: 20px; color: var(--coral); border-color: rgba(244,118,105,.45); text-align: center; }
.info-card { max-height: calc(100dvh - 28px); overflow: auto; }
.info-content { color: var(--muted); line-height: 1.75; }
.info-content h3 { color: var(--ink); margin-top: 22px; }
.info-content .insight { padding: 12px; margin: 8px 0; border-left: 2px solid var(--cyan); background: var(--cyan-soft); }

.toast-layer { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 80; display: grid; gap: 8px; pointer-events: none; }
.toast { padding: 11px 14px; color: var(--ink); background: #0c1d21; border-left: 3px solid var(--amber); box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: toast-in .22s ease-out both; font-size: 14px; }

.text-large { --body-size: 21px; }
.motion-reduced *, .motion-reduced *::before, .motion-reduced *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }

@keyframes portrait-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 760px) {
  .brand-copy { display: none; }
  .topbar { min-height: 52px; }
  .icon-button { min-width: 44px; padding: 6px; }
  .title-screen { padding: 22px 18px 32px; }
  .title-screen h1 { font-size: clamp(42px, 17vw, 68px); }
  /* 絵の高さを 40dvh で固定する。1fr にすると台詞が短い場面で絵が肥大し、
     選択肢のある場面と台詞欄の開始位置が揃わなくなる */
  .adv-screen { grid-template-rows: minmax(230px, 40dvh) auto; }
  .portrait { height: min(38dvh, 340px); max-width: 58vw; }
  .portrait.left { left: clamp(0px, 1vw, 14px); }
  .portrait.right { right: clamp(0px, 1vw, 14px); }
  .dialogue-panel { margin-top: -28px; padding: 18px; min-height: 132px; }
  .dialogue-text { font-size: var(--body-size); line-height: 1.72; }
  .choice-button { grid-template-columns: 34px 1fr; min-height: 58px; }
  .battle-screen { grid-template-columns: 1fr; grid-template-rows: 30dvh auto; }
  .battle-visual { min-height: 220px; }
  /* 横並びのPCではコンソール内スクロールで足りるが、縦積みのスマートフォンでは
     ここが内部スクロールになると手順ボタンや決着ボタンへ到達できない。
     高さ制約を外してページごとスクロールさせる */
  .battle-console { border-left: 0; border-top: 1px solid var(--line); padding: 15px; overflow: visible; min-height: auto; }
  .battle-screen { min-height: auto; }
  .battle-heading h1 { font-size: 24px; }
  .gauges { gap: 7px; margin: 14px 0; }
  .gauge-card { padding: 8px; }
  .command-grid { grid-template-columns: 1fr 1fr; }
  .command-button { min-height: 62px; padding: 8px; }
  .result-grid, .records-grid { grid-template-columns: 1fr; }
  .archive-panel.wide { grid-column: auto; }
  .result-screen, .ending-screen, .records-screen { padding: 22px 14px; }
}

/* 縦長の画面では、幕引きCGを重ねずに上へ置いて全体を見せ、本文はその下に流す。
   横長のままだと 16:9 の絵が本文カードで隠れてしまうため */
@media (max-aspect-ratio: 3 / 4) {
  .ending-screen.cinematic {
    display: grid;
    grid-template-rows: auto 1fr;
    align-content: start;
    gap: clamp(10px, 2dvh, 18px);
  }
  .ending-screen.cinematic::before {
    position: relative;
    inset: auto;
    width: 100%;
    aspect-ratio: 16 / 9;
    opacity: 1;
    filter: none;
    border-radius: 10px;
    border: 1px solid var(--line);
  }
  .ending-screen.cinematic > .ending-card { margin: 0; }
  .ending-screen.cinematic.reading .ending-card { min-height: auto; }
}

@media (max-width: 380px) {
  :root { --body-size: 17px; }
  .topbar-actions { gap: 0; }
  .scene-meta { top: 10px; }
  .dialogue-panel { width: calc(100% - 16px); }
  .command-grid, .resolution-bar { grid-template-columns: 1fr; }
  .battle-screen { grid-template-rows: 25dvh auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
