/* クリスマスエンブレム style.css — 構造とクラス名は docs/design.md を参照 */

:root {
  --c-ink: #3b2f2f;
  --c-ink-sub: #7a6a5e;
  --c-paper: #fffdf7;
  --c-bg: #fff8ea;
  --c-line: #eadcc0;

  --c-red: #e8413b;
  --c-red-deep: #b8302c;
  --c-green: #3fa66a;
  --c-green-deep: #2b7a4b;
  --c-gold: #ffc83d;
  --c-gold-deep: #d99a00;
  --c-night: #1b2960;
  --c-night-deep: #0b1438;
  --c-sky: #4fb3ee;
  --c-snow: #ffffff;
  --c-snow-shade: #d3e5f5;
  --c-wood: #dba468;
  --c-wood-deep: #a86e38;

  --font-base: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic",
    "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-num: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "SF Pro Rounded",
    ui-rounded, system-ui, sans-serif;

  --radius-s: 10px;
  --radius-m: 18px;
  --radius-l: 28px;
  --shadow-card: 0 4px 0 rgba(59, 47, 47, 0.12), 0 10px 24px rgba(59, 47, 47, 0.08);
  --btn-depth: 6px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);


  --dur-fast: 0.15s;
  --dur-mid: 0.35s;
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-base);
  color: var(--c-ink);
  background-color: var(--c-night-deep);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
}

.num {
  font-family: var(--font-num);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--c-bg);
}

/* ---------- 画面切替 ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity var(--dur-mid) ease, transform var(--dur-mid) ease, visibility 0s linear var(--dur-mid);
  overflow-y: auto;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: opacity var(--dur-mid) ease, transform var(--dur-mid) ease, visibility 0s;
}

.screen__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

:where(.screen > :not(.screen__bg)) {
  position: relative;
  z-index: 1;
}

/* ---------- ボタン ---------- */

.btn {
  --btn-bg: var(--c-red);
  --btn-edge: var(--c-red-deep);
  --btn-fg: #fff;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 12px 28px;
  border: 3px solid var(--c-ink);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 var(--btn-depth) 0 var(--btn-edge), 0 var(--btn-depth) 0 3px var(--c-ink);
  transform: translateY(0);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter var(--dur-fast);
}

.btn::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 18%;
  right: 18%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.btn:hover { filter: brightness(1.05); }

.btn:active,
.btn.is-pressed {
  transform: translateY(var(--btn-depth));
  box-shadow: 0 0 0 var(--btn-edge), 0 0 0 3px var(--c-ink);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.stage-card:focus-visible,
.choice:focus-visible {
  outline: 4px solid var(--c-gold);
  outline-offset: 4px;
}

.btn:disabled {
  filter: grayscale(0.8) opacity(0.6);
  cursor: not-allowed;
  transform: translateY(var(--btn-depth));
  box-shadow: 0 0 0 var(--btn-edge), 0 0 0 3px var(--c-ink);
}

.btn--block { display: flex; width: 100%; }
.btn--green { --btn-bg: var(--c-green); --btn-edge: var(--c-green-deep); }
.btn--gold { --btn-bg: var(--c-gold); --btn-edge: var(--c-gold-deep); --btn-fg: var(--c-ink); }
.btn--ghost { --btn-bg: var(--c-paper); --btn-edge: var(--c-line); --btn-fg: var(--c-ink); }
.btn--small { min-height: 40px; padding: 6px 16px; font-size: 15px; --btn-depth: 4px; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 3px solid var(--c-ink);
  border-radius: 50%;
  background: var(--c-paper);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--c-ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background var(--dur-fast);
}

.icon-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--c-ink); }
.icon-btn.is-on { background: var(--c-gold); }

.icon-btn svg { width: 22px; height: 22px; fill: var(--c-ink); }

/* ---------- 共通カード ---------- */

.card {
  background: var(--c-paper);
  border: 3px solid var(--c-ink);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

/* ---------- ロゴ ---------- */

.logo {
  margin: 0;
  text-align: center;
  font-weight: 900;
  line-height: 1.1;
}

.logo__sub {
  display: inline-block;
  padding: 2px 14px;
  border: 3px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-green);
  color: #fff;
  font-size: clamp(16px, 3.6vmin, 24px);
  transform: rotate(-3deg);
}

.logo__main {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-top: 6px;
  font-size: clamp(40px, 11vmin, 84px);
}

.logo__char {
  display: inline-block;
  color: var(--c-snow);
  text-shadow:
    0 4px 0 var(--c-ink),
    3px 0 0 var(--c-ink), -3px 0 0 var(--c-ink),
    0 3px 0 var(--c-ink), 0 -3px 0 var(--c-ink),
    3px 3px 0 var(--c-ink), -3px 3px 0 var(--c-ink),
    3px -3px 0 var(--c-ink), -3px -3px 0 var(--c-ink);
  animation: logo-bob 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.12s);
}

.logo__char--red { color: var(--c-red); }
.logo__char--gold { color: var(--c-gold); }

/* ---------- タイトル ---------- */

.screen--title {
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(#7fc4f0, #e9f6ff 60%, #f6fbff);
  text-align: center;
}

.title__santa {
  width: clamp(110px, 26vmin, 200px);
  aspect-ratio: 1;
  animation: logo-bob 1.6s ease-in-out infinite;
}


/* ---------- このゲームの変数 ---------- */

:root {
  --c-ally: #3f86e8;
  --c-ally-deep: #2a5fb0;
  --c-enemy: #e8413b;
  --c-enemy-deep: #a32a2a;
  --c-move: rgba(63, 134, 232, 0.42);
  --c-attack: rgba(232, 65, 59, 0.42);
  --c-heal: rgba(63, 166, 106, 0.45);
  --c-danger: rgba(150, 70, 190, 0.34);
  --c-hp: #45b36f;
  --c-hp-mid: #f2b632;
  --c-hp-low: #e8413b;
  --hud-h: 48px;
  --dock-h: 138px;
}

.logo__char--green { color: #5ccb88; }
.logo__main { flex-wrap: wrap; }
.logo__row { display: inline-flex; gap: 2px; white-space: nowrap; }
.screen--title .logo__main { flex-direction: column; align-items: center; }
.screen--title .title__hero { width: min(340px, 92vw, 44dvh); aspect-ratio: 5 / 3; }
.title__tools { position: absolute !important; top: calc(12px + var(--safe-top)); right: calc(12px + var(--safe-right)); display: flex; gap: 8px; }
.screen--title { overflow-x: hidden; justify-content: safe center; }
.title__actions .btn { flex-shrink: 0; }
.title__row { display: flex; gap: 10px; }
.title__row .btn { flex: 1; padding-inline: 8px; white-space: nowrap; }
.btn small { font-size: 12px; font-weight: 700; opacity: 0.9; }

/* 難易度の切り替え */
.seg { display: flex; border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-paper); overflow: hidden; box-shadow: 0 4px 0 var(--c-ink); }
.seg__item { flex: 1; min-height: 44px; border: 0; background: transparent; font-weight: 800; font-size: 15px; cursor: pointer; padding: 0 14px; }
.seg__item[aria-pressed="true"] { background: var(--c-gold); }
.choice:focus-visible, .seg__item:focus-visible { outline: 4px solid var(--c-gold); outline-offset: -4px; }

/* ---------- ステージ選択 ---------- */

.screen--stages { gap: 16px; background: linear-gradient(#cfe7fb, #f6fbff); }
.stages__head { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 900px; margin: 0 auto; }
.stages__title { flex: 1; margin: 0; font-size: 22px; font-weight: 900; }
.stages__total { display: inline-flex; align-items: center; gap: 4px; font-size: 18px; font-weight: 800; }
.stages__list { display: grid; grid-template-columns: 1fr; gap: 18px; width: 100%; max-width: 900px; margin: 0 auto; padding: 8px 0 12px; list-style: none; }
.stage-card {
  position: relative; display: grid; grid-template-columns: 104px 1fr; gap: 2px 14px; align-items: center; text-align: left;
  width: 100%; padding: 12px; border: 3px solid var(--c-ink); border-radius: var(--radius-m);
  background: var(--c-paper); box-shadow: 0 6px 0 var(--c-ink); cursor: pointer;
  animation: pop-in var(--dur-mid) var(--ease-pop) both; animation-delay: calc(var(--i, 0) * 0.07s);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.stage-card:active { transform: translateY(6px); box-shadow: none; }
.stage-card__thumb { grid-row: 1 / span 4; width: 104px; aspect-ratio: 4 / 5; border: 3px solid var(--c-ink); border-radius: var(--radius-s); background: #f2f8ff; }
.stage-card__num { position: absolute; top: -12px; left: -8px; display: grid; place-items: center; width: 38px; height: 38px; border: 3px solid var(--c-ink); border-radius: 50%; background: var(--c-red); color: #fff; font-size: 18px; }
.stage-card__name { font-size: 19px; font-weight: 900; }
.stage-card__goal { font-size: 13px; color: var(--c-ink-sub); }
.stage-card__best { font-size: 12px; color: var(--c-ink-sub); }
.stage-card__stars { display: flex; gap: 3px; }
.stage-card.is-locked { cursor: not-allowed; background: #e6e8ee; }
.stage-card.is-locked .stage-card__thumb { filter: grayscale(1) opacity(0.45); }
.stage-card.is-locked .stage-card__num { background: #a7a9b8; }
.star {
  position: relative; display: inline-block; width: 24px; height: 24px; background: var(--c-ink);
  clip-path: polygon(50% 0%, 64% 33%, 100% 37%, 73% 61%, 81% 97%, 50% 78%, 19% 97%, 27% 61%, 0% 37%, 36% 33%);
}
.star::before { content: ""; position: absolute; inset: 3px; background: #e6dccb; clip-path: inherit; }
.star.is-on::before { background: var(--c-gold); }

/* ---------- プレイ画面 ---------- */

.screen--play {
  display: grid; gap: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  grid-template: "hud" var(--hud-h) "map" minmax(0, 1fr) "dock" var(--dock-h) / minmax(0, 1fr);
  background: #2c3f66; overflow: hidden; touch-action: none; transform: none;
}
.screen--play:is([data-theme="forest"], [data-theme="ice"]) { background: #24506a; }
.screen--play[data-theme="castle"] { background: #3b3050; }

/* JS は .map のサイズから cell = min(w/列, h/行) を決め、.map__canvas に px 幅高さを設定する */
.map { grid-area: map; position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }
.map__canvas { display: block; touch-action: none; background: #f2f8ff; }

.hud { grid-area: hud; display: flex; align-items: center; gap: 6px; padding: 0 8px; min-width: 0; color: #fff; }
.hud__turn {
  flex: none; display: inline-flex; align-items: baseline; gap: 4px; height: 34px; padding: 3px 10px;
  border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-gold); color: var(--c-ink); font-size: 12px; font-weight: 800; white-space: nowrap;
}
.hud__turn .num { font-size: 18px; line-height: 1.2; }
.hud__turn.is-enemy { background: var(--c-enemy); color: #fff; }
.hud__goal { flex: 1; min-width: 0; font-size: 13px; font-weight: 800; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hud__tools { flex: none; display: flex; gap: 6px; }
.hud .icon-btn { color: var(--c-ink); width: 40px; height: 40px; box-shadow: 0 3px 0 var(--c-ink); font-size: 15px; }
.hud .icon-btn.is-on { background: #d9b3f5; }
.hud .icon-btn::before { content: ""; position: absolute; inset: -5px -4px; }

.dock { grid-area: dock; position: relative; display: flex; flex-direction: column; gap: 8px; padding: 6px 8px 10px; min-width: 0; min-height: 0; background: var(--c-paper); border-top: 4px solid var(--c-ink); color: var(--c-ink); }

/* ユニット情報 */
.unit-info { flex: 1; min-height: 0; display: grid; grid-template-columns: 60px 1fr; gap: 10px; align-items: center; }
.unit-info__face { width: 60px; height: 60px; border: 3px solid var(--c-ally-deep); border-radius: 14px; background: #dcebff; }
.unit-info.is-enemy .unit-info__face { border-color: var(--c-enemy-deep); background: #ffe1dd; }
.unit-info__body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.unit-info__head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.unit-info__name { font-size: 16px; font-weight: 900; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-info__lv { flex: none; font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }
.unit-info__elem { flex: none; width: 24px; height: 24px; }
.unit-info__hp { margin-left: auto; flex: none; font-size: 14px; }
.unit-info__stats { display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 13px; font-weight: 700; color: var(--c-ink-sub); line-height: 1.25; }
.unit-info__stats b { color: var(--c-ink); font-family: var(--font-num); }
.unit-info__terrain { font-size: 12px; color: var(--c-ink-sub); white-space: nowrap; }
.unit-info__empty { grid-column: 1 / -1; margin: 0; text-align: center; font-weight: 700; font-size: 14px; color: var(--c-ink-sub); }

.hpbar { position: relative; height: 12px; border: 2.5px solid var(--c-ink); border-radius: 999px; background: #4b4140; overflow: hidden; }
.hpbar__fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--hp, 1) * 100%); background: var(--c-hp); transition: width 0.35s ease; }
.hpbar__loss { position: absolute; inset: 0 auto 0 calc(var(--after, 0) * 100%); width: calc((var(--hp, 1) - var(--after, 0)) * 100%); background: #ffd9d5; animation: blink 0.8s steps(2) infinite; }
.hpbar.is-mid .hpbar__fill { background: var(--c-hp-mid); }
.hpbar.is-low .hpbar__fill { background: var(--c-hp-low); }
.expbar { height: 6px; border-radius: 999px; background: #e6dccb; overflow: hidden; }
.expbar__fill { display: block; height: 100%; width: calc(var(--exp, 0) * 100%); background: var(--c-gold); }

/* 行動メニュー: 画面下のボタン列（マップに重ねない） */
.actions { flex: none; display: flex; gap: 8px; }
.actions .btn { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 4px 6px; font-size: 15px; letter-spacing: 0; white-space: nowrap; --btn-depth: 4px; }
.actions .btn::after { top: 3px; height: 4px; }
.actions .btn--wide { flex-grow: 1.5; }
.btn--blue { --btn-bg: var(--c-ally); --btn-edge: var(--c-ally-deep); }
.btn--purple { --btn-bg: #8d59c9; --btn-edge: #63399a; }
.btn__count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 999px; background: var(--c-ink); color: #fff; font: 900 12px/1 var(--font-num); }
.actions .btn.is-nudge { animation: nudge 1s ease-in-out infinite; }

/* ---------- 戦闘予測 ---------- */

.forecast {
  grid-area: dock; align-self: end; justify-self: center; z-index: 12;
  width: 100%; max-width: 520px; min-height: var(--dock-h);
  display: grid; grid-template-columns: 1fr 52px 1fr; gap: 6px 4px; align-items: stretch;
  padding: 8px 8px 10px; border-top: 4px solid var(--c-ink); background: var(--c-paper);
  animation: sheet-in 0.18s ease-out both;
}
.forecast[hidden] { display: none; }
.forecast.is-top { grid-area: map; align-self: start; border-top: 0; border-bottom: 4px solid var(--c-ink); min-height: 0; }
.fc-side { position: relative; display: grid; grid-template-columns: 48px 1fr; gap: 2px 8px; align-items: center; padding: 6px 8px; border: 3px solid var(--c-ally-deep); border-radius: 14px; background: #e6f0ff; min-width: 0; }
.fc-side--enemy { border-color: var(--c-enemy-deep); background: #ffeae7; }
.fc-side__face { grid-row: 1 / span 2; width: 48px; height: 48px; }
.fc-side__name { font-size: 13px; font-weight: 900; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-side__hp { font-size: 14px; white-space: nowrap; }
.fc-side__hp b { font-size: 19px; }
.fc-side__hp.is-ko b { color: var(--c-enemy); }
.fc-side .hpbar { grid-column: 1 / -1; }
.fc-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; text-align: center; }
.fc-mid__dmg { font-size: 20px; line-height: 1; white-space: nowrap; }
.fc-mid__dmg small { font-size: 12px; }
.fc-mid__dmg--ally { color: var(--c-ally-deep); }
.fc-mid__dmg--enemy { color: var(--c-enemy-deep); }
.fc-mid__dmg.is-none { color: #9a9088; font-size: 12px; }
.fc-mid__adv { width: 44px; height: 28px; }
.forecast__note { grid-column: 1 / -1; margin: 0; font-size: 12px; font-weight: 700; text-align: center; color: var(--c-ink-sub); line-height: 1.2; }
.forecast__note.is-good { color: #24754a; }
.forecast__note.is-bad { color: var(--c-enemy-deep); }
.forecast__actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.forecast__actions .btn { flex: 1; min-height: 44px; padding: 4px 8px; font-size: 16px; --btn-depth: 4px; }
.forecast__actions .btn--go { flex: 2; }

/* ---------- ターン表示・お知らせ ---------- */

.turn-banner { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none; }
.turn-banner[hidden] { display: none; }
.turn-banner__ribbon {
  display: flex; align-items: center; gap: 12px; padding: 8px 30px; border: 4px solid var(--c-ink); border-radius: 18px;
  background: var(--c-ally); color: #fff; font-size: clamp(24px, 7vmin, 40px); font-weight: 900; transform: rotate(-2deg);
  box-shadow: 0 8px 0 var(--c-ally-deep), 0 8px 0 4px var(--c-ink); animation: banner 1.1s var(--ease-pop) both;
}
.turn-banner__ribbon canvas { width: 52px; height: 52px; }
.turn-banner.is-enemy .turn-banner__ribbon { background: var(--c-enemy); box-shadow: 0 8px 0 var(--c-enemy-deep), 0 8px 0 4px var(--c-ink); transform: rotate(2deg); }
.toast { position: absolute; left: 50%; top: calc(var(--hud-h) + 10px + var(--safe-top)); transform: translateX(-50%); z-index: 15; max-width: calc(100% - 24px); width: max-content; padding: 7px 16px; border: 3px solid var(--c-ink); border-radius: 999px; background: var(--c-paper); font-size: 14px; font-weight: 800; pointer-events: none; animation: pop-in var(--dur-mid) var(--ease-pop) both; }
.toast[hidden] { display: none; }
.skip-enemy { position: absolute; right: calc(10px + var(--safe-right)); bottom: calc(12px + var(--safe-bottom)); z-index: 16; }

/* レベルアップの小さな札 */
.levelup { position: absolute; left: 50%; top: 42%; z-index: 18; width: min(280px, 84vw); transform: translate(-50%, -50%); padding: 12px 16px; border: 4px solid var(--c-ink); border-radius: var(--radius-m); background: #fff6d6; box-shadow: 0 8px 0 var(--c-gold-deep), 0 8px 0 4px var(--c-ink); text-align: center; }
.levelup[hidden] { display: none; }
.levelup__title { margin: 0 0 4px; font-size: 22px; font-weight: 900; color: var(--c-red); }
.levelup__list { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 0; padding: 0; list-style: none; font-weight: 800; }
.levelup__list b { color: #24754a; }

/* ---------- 会話（吹き出しカードを積む） ---------- */

.talk { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: calc(60px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); background: rgba(27, 41, 96, 0.78); }
.talk[hidden] { display: none; }
.talk__skip { position: absolute !important; top: calc(10px + var(--safe-top)); right: calc(10px + var(--safe-right)); }
.talk__list { display: flex; flex-direction: column; justify-content: flex-end; gap: 12px; width: 100%; max-width: 560px; margin: 0 auto; min-height: 0; overflow: hidden; }
.talk__line { display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: center; animation: pop-in var(--dur-mid) var(--ease-pop) both; }
.talk__line--right { grid-template-columns: 1fr 76px; }
.talk__line--right .talk__face { order: 2; }
.talk__face { width: 76px; height: 76px; border: 4px solid var(--c-ink); border-radius: 50%; background: #dcebff; }
.talk__line--right .talk__face { background: #ffe1dd; }
.talk__bubble { position: relative; padding: 10px 14px; border: 3px solid var(--c-ink); border-radius: 18px; background: var(--c-paper); font-size: 16px; font-weight: 700; line-height: 1.55; }
.talk__bubble::before { content: ""; position: absolute; left: -11px; top: 50%; width: 16px; height: 16px; margin-top: -8px; background: var(--c-paper); border: solid var(--c-ink); border-width: 0 0 3px 3px; transform: rotate(45deg); }
.talk__line--right .talk__bubble::before { left: auto; right: -11px; transform: rotate(225deg); }
.talk__name { display: block; font-size: 12px; font-weight: 900; color: var(--c-ally-deep); }
.talk__line--right .talk__name { color: var(--c-enemy-deep); }
.talk__line.is-old { opacity: 0.55; }
.talk__next { align-self: center; color: #fff; font-size: 14px; font-weight: 800; animation: nudge 1s ease-in-out infinite; }

/* ---------- ダイアログ: ルール・ポーズ・確認・結果 ---------- */

.overlay { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(12px + var(--safe-top)) 14px calc(12px + var(--safe-bottom)); background: rgba(27, 41, 96, 0.55); }
.overlay[hidden] { display: none; }
.dialog { width: min(420px, 100%); max-height: 100%; overflow-y: auto; padding: 18px 18px 22px; border: 4px solid var(--c-ink); border-radius: var(--radius-l); background: var(--c-paper); box-shadow: 0 8px 0 rgba(59, 47, 47, 0.4); animation: pop-in var(--dur-mid) var(--ease-pop) both; }
.dialog__title { margin: 0 0 12px; text-align: center; font-size: 22px; font-weight: 900; }
.dialog__actions { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; padding-bottom: 6px; }
.dialog__row { display: flex; gap: 10px; }
.dialog__row .btn { flex: 1; padding-inline: 8px; }
.dialog .btn { min-height: 48px; font-size: 17px; }

.rules { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.rules__item { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; font-size: 15px; font-weight: 700; line-height: 1.45; }
.rules__item canvas, .rules__item img { width: 64px; height: 64px; border: 3px solid var(--c-ink); border-radius: 14px; background: #e6f3ff; }
.rules__item b { color: var(--c-red-deep); }
.rules__wheel { display: block; width: min(240px, 100%); aspect-ratio: 6 / 5; margin: 4px auto; }
.swatch { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--c-ink); border-radius: 4px; vertical-align: -3px; }
.swatch--move { background: #8fb9f2; } .swatch--attack { background: #f19a96; } .swatch--danger { background: #cda6e6; } .swatch--heal { background: #93d3ad; }

/* 結果: 下からのシート。上のマップ演出を隠さない */
.overlay--result { place-items: end center; background: linear-gradient(transparent 20%, rgba(27, 41, 96, 0.6)); padding-bottom: calc(14px + var(--safe-bottom)); }
.overlay--result .dialog { animation: sheet-in 0.35s var(--ease-pop) both; }
.result__stars { display: flex; justify-content: center; gap: 8px; margin-top: 2px; }
.result__stars .star { width: 52px; height: 52px; animation: star-in 0.45s var(--ease-pop) both; animation-delay: calc(var(--i) * 0.2s + 0.2s); }
.result__stars .star:nth-child(2) { width: 62px; height: 62px; margin-top: -8px; }
.result__list { display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 15px; font-weight: 700; }
.result__list li { display: flex; align-items: center; gap: 8px; }
.result__list li > :last-child { margin-left: auto; }
.result__list .is-ok::before { content: "✓"; color: #24754a; font-weight: 900; }
.result__list .is-ng::before { content: "–"; color: var(--c-ink-sub); font-weight: 900; }
.result__hint { margin: 10px 0 0; padding: 8px 12px; border-radius: 12px; background: #fff1c7; font-size: 14px; font-weight: 800; text-align: center; }
.result__team { display: flex; justify-content: center; gap: 4px; margin-top: 10px; }
.result__team canvas { width: 46px; height: 46px; border: 3px solid var(--c-ink); border-radius: 50%; background: #dcebff; }
.result__team canvas.is-out { filter: grayscale(1) opacity(0.45); }
.is-lose .dialog__title { color: var(--c-ally-deep); }
.is-win .dialog__title { color: var(--c-red); }

/* ---------- エンディング ---------- */

.screen--ending { align-items: center; justify-content: safe center; gap: 16px; background: linear-gradient(#1b2960, #4a63a8 60%, #f6fbff 60.2%); text-align: center; }
.ending__stage { width: min(520px, 100%, 58dvh); aspect-ratio: 5 / 4; }
.ending__text { max-width: 480px; margin: 0; padding: 12px 18px; border: 3px solid var(--c-ink); border-radius: var(--radius-m); background: var(--c-paper); font-size: 16px; font-weight: 700; line-height: 1.7; }
.ending__title { margin: 0; color: var(--c-gold); font-size: 28px; font-weight: 900; text-shadow: 0 3px 0 var(--c-ink); }
.ending__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* ---------- 横向き・PC: 左右パネル ---------- */

@media (min-aspect-ratio: 1 / 1) {
  .screen--play { grid-template: "hud map dock" minmax(0, 1fr) / minmax(0, 1fr) auto minmax(0, 1fr); }
  /* 列幅は JS が --map-w に設定（行数×cell）。未設定なら 80dvh */
  .map { width: var(--map-w, 80dvh); }
  .hud { flex-direction: column; align-items: stretch; justify-self: end; width: min(100%, 300px); gap: 14px; padding: 16px 14px; }
  .hud__turn { align-self: flex-start; }
  .hud__goal { flex: none; font-size: 16px; line-height: 1.5; -webkit-line-clamp: 5; }
  .hud__tools { margin-top: auto; flex-wrap: wrap; }
  .hud .icon-btn { width: 48px; height: 48px; font-size: 18px; }
  .dock { width: min(100%, 340px); margin: 12px; border: 4px solid var(--c-ink); border-radius: var(--radius-m); padding: 12px; align-self: end; width: calc(min(100%, 340px) - 24px); min-height: 200px; }
  .unit-info__stats { font-size: 14px; }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 28%; }
  .forecast { width: calc(min(100%, 340px) - 24px); margin: 12px; justify-self: start; border: 4px solid var(--c-ink); border-radius: var(--radius-m); min-height: 200px; }
  .forecast.is-top { grid-area: dock; align-self: end; border: 4px solid var(--c-ink); }
  .fc-side { grid-template-columns: 1fr; padding: 6px; }
  .fc-side__face { grid-row: auto; justify-self: center; }
  .toast { top: 14px; }
  .stages__list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-card { grid-template-columns: 1fr; }
  .stage-card__thumb { grid-row: auto; width: 100%; aspect-ratio: 8 / 7; }
}

@media (min-aspect-ratio: 1 / 1) and (max-height: 500px) {
  .hud { gap: 8px; padding: 10px 10px 14px; }
  .hud__goal { font-size: 14px; line-height: 1.35; }
  .hud .icon-btn { width: 42px; height: 42px; }
  .dock, .forecast { margin: 6px; width: calc(min(100%, 340px) - 12px); padding: 8px; min-height: 0; }
  .dialog { width: min(640px, 100%); padding: 12px 16px 16px; }
  .dialog__title { margin-bottom: 6px; font-size: 19px; }
  .dialog__actions:not(.dialog__actions--col) { flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .dialog__actions:not(.dialog__actions--col) > * { flex: 1 1 40%; width: auto; }
  .rules { grid-template-columns: 1fr 1fr; }
  .rules__item { grid-template-columns: 52px 1fr; font-size: 13px; }
  .rules__item canvas, .rules__item img { width: 52px; height: 52px; }
  .result__stars .star { width: 38px; height: 38px; }
  .result__stars .star:nth-child(2) { width: 46px; height: 46px; }
  .result__list { gap: 0; margin-top: 4px; font-size: 14px; }
  .dialog__actions > .dialog__row { flex-basis: 50% !important; }
  .dialog .btn { font-size: 15px; white-space: nowrap; }
  .talk { padding-top: calc(50px + var(--safe-top)); }
  .talk__line, .talk__line--right { grid-template-columns: 60px 1fr; }
  .talk__line--right { grid-template-columns: 1fr 60px; }
  .talk__face { width: 60px; height: 60px; }
  .screen--title { display: grid; grid-template-columns: 1fr min(320px, 40%); align-items: center; align-content: safe center; justify-items: center; gap: 8px 20px; }
  .screen--title .logo { grid-column: 1; }
  .screen--title .title__hero { grid-column: 1; width: min(100%, 60dvh); }
  .screen--title .title__actions { grid-column: 2; grid-row: 1 / span 2; }
  .screen--title .title__note { grid-column: 1 / -1; }
  .stage-card { grid-template-columns: 1fr; }
  .stage-card__thumb { aspect-ratio: 2 / 1; }
  .ending__stage { width: min(50dvh, 100%); }
}

@media (min-width: 700px) and (max-aspect-ratio: 1 / 1) {
  :root { --hud-h: 64px; --dock-h: 170px; }
  .hud__goal { font-size: 17px; }
  .hud__turn { height: 42px; font-size: 15px; align-items: center; }
  .hud .icon-btn { width: 48px; height: 48px; }
  .dock { padding: 10px max(10px, calc(50% - 300px)) 14px; }
  .unit-info { grid-template-columns: 76px 1fr; }
  .unit-info__face { width: 76px; height: 76px; }
  .forecast { max-width: 620px; border-inline: 4px solid var(--c-ink); border-radius: 18px 18px 0 0; }
}

@media (max-height: 620px) and (max-aspect-ratio: 1 / 1) {
  :root { --dock-h: 126px; --hud-h: 46px; }
}

@keyframes logo-bob { 50% { transform: translateY(-6px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.85) translateY(8px); } }
.toast { animation-name: toast-in !important; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@keyframes star-in { from { transform: scale(0) rotate(-60deg); } }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes nudge { 50% { transform: translateY(-3px); } }
@keyframes banner { 0% { transform: translateX(-80vw) rotate(-2deg); opacity: 0; } 25%, 75% { transform: translateX(0) rotate(-2deg); opacity: 1; } 100% { transform: translateX(80vw) rotate(-2deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .turn-banner__ribbon { animation: none; }
}

.title__actions { display: flex; flex-direction: column; gap: 14px; width: min(320px, 100%); }
.title__note { margin: 0; font-size: 13px; color: var(--c-ink-sub); }
@media (min-aspect-ratio: 1 / 1) and (min-height: 501px) { .stages__list { margin-block: auto; } }
