/* 巫の対戦盤 — 夜の社殿と金の縁取り。札は和紙のカードとして盤上に置く。 */
:root {
  color-scheme: dark;
  --night: #0f1530;
  --gold: #e3c27a;
  --gold-soft: #e3c27a73;
  --gold-faint: #e3c27a2e;
  --shu: #cf4433;
  --shu-deep: #8e2a22;
  --ink: #231e1b;
  --ink-sub: #4a3f38;
  --cream: #fff6e4;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", Meiryo, sans-serif;
  --font-mincho: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif CJK JP", serif;
  --font-number: "Avenir Next Condensed", "Roboto Condensed", "sans-serif-condensed", "Arial Narrow", var(--font-sans);
  font-family: var(--font-sans);
  background: var(--night);
  color: var(--cream);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(90% 55% at 50% 50%, #26306a8c 0%, transparent 72%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'%3E%3Cg fill='%230f1530' stroke='%23e3c27a' stroke-opacity='.075'%3E%3Cg id='w'%3E%3Ccircle cx='0' cy='0' r='20'/%3E%3Ccircle cx='0' cy='0' r='14'/%3E%3Ccircle cx='0' cy='0' r='8'/%3E%3C/g%3E%3Cuse href='%23w' x='40'/%3E%3Cuse href='%23w' x='20' y='10'/%3E%3Cuse href='%23w' y='20'/%3E%3Cuse href='%23w' x='40' y='20'/%3E%3C/g%3E%3C/svg%3E"),
    var(--night);
  background-attachment: fixed;
}
/* 盤の器。端末を横に倒して縦の盤を使うときは、器ごと回して端末に対する向きを保つ */
.stage {
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  container: board / size;
  position: relative;
  display: grid;
  width: 100%;
  height: 100svh;
  height: 100dvh;
}
.stage[data-turn] {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 100vh;
  width: 100dvh;
  height: 100vw;
  height: 100dvw;
}
.stage[data-turn="left"] {
  --safe-top: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-right);
  --safe-left: env(safe-area-inset-bottom);
  transform: translate(-50%, -50%) rotate(-90deg);
}
.stage[data-turn="right"] {
  --safe-top: env(safe-area-inset-right);
  --safe-right: env(safe-area-inset-bottom);
  --safe-bottom: env(safe-area-inset-left);
  --safe-left: env(safe-area-inset-top);
  transform: translate(-50%, -50%) rotate(90deg);
}
body:has(.stage[data-turn]) { height: 100dvh; overflow: hidden; }
body:has(.stage[data-turn="left"]) dialog { width: min(360px, 88vh); max-height: 90vw; transform: rotate(-90deg); }
body:has(.stage[data-turn="right"]) dialog { width: min(360px, 88vh); max-height: 90vw; transform: rotate(90deg); }

button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h2, h3, p { margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- 盤面の骨組み ---------- */
.table {
  margin: auto;
  display: grid;
  width: min(100%, 460px);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "two" "bar" "one";
  gap: 8px;
  padding: max(8px, var(--safe-top)) max(8px, var(--safe-right))
           max(8px, var(--safe-bottom)) max(8px, var(--safe-left));
}
.table[data-layout="landscape"] {
  width: min(100%, 950px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas: "bar bar" "one two";
  gap: 9px;
}

/* ---------- 中央の操作 ---------- */
.table-bar { grid-area: bar; display: grid; place-items: center; min-width: 0; padding-top: 3px; }
.table-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; width: min(100%, 306px); }
.table-tools button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 8px;
  color: #f4e6c4;
  background: linear-gradient(180deg, #262f5e, #161c3d);
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 #ffffff1f, 0 3px 0 #070a1a, 0 5px 12px #0007;
  white-space: nowrap;
  font-size: .78rem;
  font-weight: 750;
  letter-spacing: .05em;
  transition: transform .08s, box-shadow .08s;
}
.table-tools button:active { transform: translateY(2px); box-shadow: inset 0 1px 0 #ffffff1f, 0 1px 0 #070a1a, 0 2px 6px #0007; }
.table-tools #orientation { gap: 3px; padding-inline: 4px; }
.orientation-icon { font-size: 1rem; line-height: 1; color: var(--gold); }
.table-tools .gate {
  gap: 5px;
  color: #fff3dc;
  background: linear-gradient(180deg, #c8402f, #8a241a);
  border-color: #f0a98a;
  box-shadow: inset 0 1px 0 #ffffff40, 0 3px 0 #4a120c, 0 5px 14px #c5402f55;
  font-family: var(--font-mincho);
  font-size: .92rem;
  font-weight: 800;
  letter-spacing: .14em;
}
.torii { flex: none; width: 19px; height: 16px; fill: #ffe6c2; filter: drop-shadow(0 1px 0 #0006); }
.die {
  position: relative;
  width: 15px;
  height: 15px;
  flex: none;
  border: 1px solid var(--gold);
  border-radius: 4px;
  transform: rotate(-10deg);
  color: var(--gold);
}
.die::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: -3px -3px currentColor, 3px 3px currentColor, 3px -3px currentColor, -3px 3px currentColor;
}

/* ---------- 各プレイヤーの盤 ---------- */
.player {
  --aura: #5a73e0;
  --lacquer: #1d2552;
  --lacquer-deep: #10152f;
  --flash: transparent;
  --badge: 26px;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-width: 0;
  color: var(--cream);
  background: linear-gradient(180deg, var(--lacquer), var(--lacquer-deep) 62%);
  border: 1px solid var(--gold-soft);
  border-radius: 16px;
  box-shadow: 0 0 0 1px #0009, inset 0 1px 0 #ffffff17, 0 12px 28px #0008, 0 0 26px -8px var(--aura);
}
/* 内側の金の細枠 */
.player::before {
  content: "";
  position: absolute;
  inset: 4px;
  z-index: -1;
  border: 1px solid var(--gold-faint);
  border-radius: 12px;
  pointer-events: none;
}
/* 被弾・回復時の縁の光 */
.player::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--flash), inset 0 0 26px var(--flash);
  opacity: 0;
  pointer-events: none;
}
.player-one { grid-area: one; }
.player-two { grid-area: two; }
.table[data-facing="true"] .player-two { transform: rotate(180deg); }

.life-zone {
  --life-w: clamp(78px, 24cqw, 104px);
  position: relative;
  display: grid;
  padding: 10px 10px calc(var(--badge) / 2 + 3px);
  border-radius: 15px 15px 0 0;
}
/* 盤の区切り（金線） */
.life-zone::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft) 20%, var(--gold-soft) 80%, transparent);
  pointer-events: none;
}
/* 区切りの菱（先後が決まると先・後の印に替わる） */
.life-zone::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 1;
  width: 7px;
  height: 7px;
  background: var(--gold);
  box-shadow: 0 0 8px #e3c27a99;
  transform: translate(-50%, 50%) rotate(45deg);
  pointer-events: none;
}
.life-zone:is([data-order="first"], [data-order="second"])::before { display: none; }
.turn-order {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--badge);
  height: var(--badge);
  border: 1px solid #c9d3e8aa;
  border-radius: 50%;
  color: #e4eaf8;
  background: radial-gradient(circle at 50% 35%, #3a4677, #1a2045);
  font-family: var(--font-mincho);
  font-size: calc(var(--badge) * .52);
  font-weight: 800;
  line-height: 1;
  transform: translate(-50%, 50%);
  box-shadow: 0 0 0 3px #10152f, 0 2px 6px #0008;
}
.turn-order[data-role="first"] {
  color: #2a1d08;
  background: radial-gradient(circle at 50% 35%, #fbe8b0, #c19545);
  border-color: #f8e7b5;
  box-shadow: 0 0 0 3px #10152f, 0 0 14px #e3c27a99;
}

/* ---------- ライフ ---------- */
.life-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--life-w) minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}
.life-buttons { display: flex; gap: 5px; min-width: 0; }
.life-core { position: relative; display: grid; place-items: center; min-width: 0; }
.life-total {
  display: block;
  color: var(--cream);
  font-family: var(--font-number);
  font-size: calc(var(--life-w) * .76);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -.02em;
  white-space: nowrap;
  text-shadow: 0 0 18px #e3c27a59, 0 2px 0 #0008;
}
.life-zone[data-digits="3"] .life-total { font-size: calc(var(--life-w) * .5); }
.life-zone[data-danger="true"] .life-total { color: #ff9a96; text-shadow: 0 0 18px #ff4a4a80, 0 2px 0 #0008; }
.life-zone[data-zero="true"] .life-total { color: #8d93ad; text-shadow: none; }
.life-delta {
  position: absolute;
  left: 50%;
  top: -2px;
  z-index: 2;
  font-family: var(--font-number);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  text-shadow: 0 0 2px #000, 0 1px 3px #000;
}
.life-delta[data-kind="damage"] { color: #ff8a8a; }
.life-delta[data-kind="heal"] { color: #7ff0c6; }

.life-button {
  flex: 1 1 0;
  min-width: 44px;
  min-height: 52px;
  padding: 0 2px;
  border: 1px solid;
  border-radius: 12px;
  color: #fff;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 1px #0006;
  transition: transform .07s, box-shadow .07s, filter .07s;
}
.life-decrease .life-button {
  --press: #5c1520;
  background: linear-gradient(180deg, #d9525f, #962636);
  border-color: #f39aa2;
  box-shadow: inset 0 1px 0 #ffffff45, 0 3px 0 var(--press), 0 5px 10px #0006;
}
.life-increase .life-button {
  --press: #0f4033;
  background: linear-gradient(180deg, #46b391, #1e6d57);
  border-color: #8fe2c6;
  box-shadow: inset 0 1px 0 #ffffff45, 0 3px 0 var(--press), 0 5px 10px #0006;
}
.life-decrease .life-ten { background: linear-gradient(180deg, #6f2834, #4a1822); border-color: #d9757f; color: #ffd9dc; }
.life-increase .life-ten { background: linear-gradient(180deg, #1f5a4b, #123b31); border-color: #6fc9aa; color: #d4fff0; }
.life-ten { font-size: 1.02rem; letter-spacing: -.03em; }
.life-button:enabled:active { transform: translateY(3px); box-shadow: inset 0 1px 0 #ffffff45, 0 0 0 var(--press), 0 1px 4px #0006; filter: brightness(1.15); }
.life-button:disabled { opacity: .38; filter: saturate(.3); }

/* ---------- 先後・開門の大きな表示 ---------- */
.match-reveal:not([hidden]) {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: inherit;
  background: radial-gradient(70% 90% at 50% 50%, #2b3570, #121735 75%);
  font-family: var(--font-mincho);
  font-size: clamp(2.3rem, 10cqw, 3.4rem);
  font-weight: 800;
  letter-spacing: .2em;
  text-indent: .2em;
  pointer-events: none;
}
.match-reveal[data-role="first"] {
  background: radial-gradient(70% 90% at 50% 50%, #5a4415, #1a1532 78%);
  color: #ffe6a3;
  text-shadow: 0 0 22px #ffcf5c, 0 0 2px #fff6;
}
.match-reveal[data-role="second"] {
  background: radial-gradient(70% 90% at 50% 50%, #2f3e6e, #121735 78%);
  color: #dce6ff;
  text-shadow: 0 0 18px #8fb0ff;
}
.match-reveal[data-role="rolling"] { color: #f4e6c4b3; }
/* 開門：血の気の引いた文字が明滅する */
.match-reveal[data-role="gate"] {
  background:
    radial-gradient(60% 80% at 50% 55%, #3d0a0d 0%, #160406 70%, #070102 100%);
  color: #e9dfcf;
  font-size: clamp(2.6rem, 11cqw, 3.8rem);
  letter-spacing: .32em;
  text-indent: .32em;
  text-shadow: 0 0 3px #ff2a2a, 0 0 18px #b3000c, 0 0 42px #6b0008;
}
.match-reveal[data-role="gate"]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 40%, #000c 100%);
  pointer-events: none;
}
/* 光の帯 */
.match-reveal::after {
  content: "";
  position: absolute;
  inset: -20% -60%;
  background: linear-gradient(105deg, transparent 42%, #ffffff40 50%, transparent 58%);
  transform: translateX(-60%);
  pointer-events: none;
}
.match-reveal[data-role="gate"]::after { display: none; }

/* ---------- 行動札 ---------- */
.player-record { display: grid; grid-template-rows: 1fr auto; align-content: center; padding: calc(var(--badge) / 2 + 6px) 10px 8px; }
.action-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.action-card, .refresh-card {
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 6px;
  border-radius: 10px;
  text-align: center;
  transition: transform .08s, box-shadow .08s, background-color .18s;
}
.action-card {
  color: var(--ink);
  background-color: var(--card-surface);
  background-image: linear-gradient(160deg, #ffffff8c, transparent 45%);
  border: 2px solid var(--card-frame);
  box-shadow: inset 0 0 0 1px #ffffffa6, 0 3px 0 #0006, 0 6px 12px #0005;
}
/* 未使用は札の色がはっきり付いた状態、使用済みは黒く沈んだ状態 */
.action-card[data-card-kind="place"] { --card-frame: #c23540; --card-surface: #f7c3c7; --card-mark: #e0525d; }
.action-card[data-card-kind="apparition"] { --card-frame: #8a4fb3; --card-surface: #e2cdf5; --card-mark: #a56fd0; }
.action-card[data-card-kind="season"] { --card-frame: #c99a0a; --card-surface: #fbe27e; --card-mark: #e3b520; }
.action-card[data-card-kind="tool"] { --card-frame: #b3bdc9; --card-surface: #ffffff; --card-mark: #c9d2dd; }
.action-card:active, .refresh-card:enabled:active { transform: translateY(2px); box-shadow: inset 0 0 0 1px #ffffffa6, 0 1px 0 #0006, 0 2px 5px #0005; }
.action-card[aria-pressed="true"] {
  color: #b4b0c2;
  background-color: #191b27;
  background-image: linear-gradient(160deg, #ffffff0d, transparent 50%);
  border-color: color-mix(in srgb, var(--card-frame) 45%, #191b27);
  transform: translateY(2px);
  box-shadow: inset 0 2px 8px #000000a6, 0 1px 0 #0006;
}
.action-card[aria-pressed="true"] .action-type { color: #aeaac0; }
/* 使用済みは札の種類の前の◆が、札の色の✓に替わる */
.action-card[aria-pressed="true"] .action-type::before {
  content: "✓" / "";
  width: auto;
  height: auto;
  transform: none;
  background: none;
  outline: 0;
  color: var(--card-mark);
  font-family: var(--font-sans);
  font-size: 1.25em;
  font-weight: 900;
  line-height: 1;
}
.action-type {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ink-sub);
  font-family: var(--font-mincho);
  font-size: var(--card-label, .8rem);
  font-weight: 700;
  line-height: 1.15;
}
.action-type::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  transform: rotate(45deg);
  background: var(--card-frame);
  outline: 1px solid #00000026;
}
.action-card strong, .refresh-card strong { white-space: nowrap; font-size: var(--card-name, 1.2rem); font-weight: 800; line-height: 1.08; letter-spacing: .06em; text-indent: .06em; }
/* 使用済みの印（朱印風の✓） */
.done { display: none; }

.action-card::after, .refresh-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, #ffffffb3 50%, transparent 65%);
  transform: translateX(-120%);
  pointer-events: none;
}

.refresh-card {
  color: #2a1d08;
  background: linear-gradient(180deg, #f5dc95, #c4974a);
  border: 2px solid #f8e7b5;
  box-shadow: inset 0 1px 0 #ffffff80, 0 3px 0 #5a4116, 0 6px 14px #e3c27a40;
}
.refresh-card strong { display: flex; align-items: center; justify-content: center; gap: 3px; text-indent: 0; font-size: calc(var(--card-name, 1.2rem) * .82); }
.refresh-icon { font-size: 1.05em; font-weight: 900; }
.refresh-card > span { color: #4a3510; font-size: var(--card-label, .8rem); font-weight: 750; }
.refresh-card:disabled {
  color: #8f94ad;
  background: #ffffff0a;
  border: 1px dashed #e3c27a40;
  box-shadow: none;
}
.refresh-card:disabled > span { color: #7b809a; }

/* ---------- 魂の季節 ---------- */
.season-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--gold-faint);
}
.season-caption {
  flex: none;
  margin: 0;
  color: var(--gold);
  font-family: var(--font-mincho);
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0;
  writing-mode: vertical-rl;
}
/* 季節が１つもないと灯る「四季なし」のランプ */
.season-status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 4px 2px;
  border-radius: 10px;
  color: #a3a7c4;
  font-size: .7rem;
  font-weight: 750;
  letter-spacing: -.02em;
  white-space: nowrap;
  transition: color .25s, background-color .25s;
}
.season-lamp {
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #4a5070, #1d2240);
  box-shadow: inset 0 0 0 1px #ffffff1a;
  transition: background .25s, box-shadow .25s;
}
.season-status[data-lit="true"] { color: #ffe7b0; background: #ffb84a14; }
.season-status[data-lit="true"] .season-lamp {
  background: radial-gradient(circle at 40% 35%, #fffbe6, #ffc25a 55%, #e0801c);
  box-shadow: 0 0 8px #ffb84a, 0 0 18px #ff9a2a99;
}
.season-buttons { flex: none; display: flex; gap: 4px; }
.season {
  --season-size: 44px;
  position: relative;
  width: var(--season-size);
  height: var(--season-size);
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--season-glow) 55%, transparent);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #ffffff14, #00000040);
  color: #e9e4f2;
  font-family: var(--font-mincho);
  font-weight: 800;
  font-size: calc(var(--season-size) * .37);
  transition: transform .08s, background-color .2s, box-shadow .2s;
}
.season:active { transform: scale(.93); }
.spring { --season-fill: #b8456a; --season-glow: #ff8fb1; }
.summer { --season-fill: #217d67; --season-glow: #59e0b8; }
.autumn { --season-fill: #b0601d; --season-glow: #ffad5c; }
.winter { --season-fill: #3d64a6; --season-glow: #9cc4ff; }
.season[aria-pressed="true"] {
  border-color: var(--season-glow);
  color: #fff;
  background: radial-gradient(circle at 50% 32%, color-mix(in srgb, var(--season-glow) 55%, var(--season-fill)), var(--season-fill) 70%);
  box-shadow: 0 0 14px color-mix(in srgb, var(--season-glow) 70%, transparent), inset 0 1px 0 #ffffff50;
  text-shadow: 0 1px 2px #0007;
}
.season[aria-pressed="true"]::after { content: '✓' / ''; position: absolute; right: 2px; top: 0; font-family: var(--font-sans); font-size: .62rem; }

/* ---------- 開門の確認 ---------- */
dialog {
  width: min(360px, calc(100% - 28px));
  padding: 18px 18px 16px;
  border: 1px solid #8e2a2280;
  border-radius: 14px;
  background: linear-gradient(180deg, #2a1218, #120709);
  color: var(--cream);
  box-shadow: inset 0 0 0 4px #120709, inset 0 0 0 5px #8e2a2240, 0 20px 50px #000c;
}
dialog::backdrop { background: #030104d9; }
dialog h2 { color: #f0d9b5; font-family: var(--font-mincho); font-size: 1.12rem; letter-spacing: .06em; text-shadow: 0 0 10px #b3000c; }
dialog p { margin-top: 9px; color: #ddd2c4; font-size: .84rem; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-actions button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid #e3c27a59;
  border-radius: 9px;
  color: #f4e6c4;
  background: #ffffff0f;
  font-size: .84rem;
  font-weight: 700;
}
.dialog-actions .confirm-button {
  color: #fff3dc;
  background: linear-gradient(180deg, #b7362b, #6e1a14);
  border-color: #d9725f;
  box-shadow: 0 3px 0 #3a0c09, 0 0 16px #b3000c66;
  font-family: var(--font-mincho);
  font-weight: 800;
  letter-spacing: .2em;
}

/* ---------- 開門の扉（朽ちた社の扉と御札） ---------- */
.gate-curtain {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  pointer-events: auto;
  touch-action: none;
}
/* 闇 */
.gate-curtain::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, #12020466, #000000f2 75%);
  opacity: 0;
}
.gate-door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.5%;
  background:
    linear-gradient(180deg, transparent 12%, #0d0a09 12% 15.5%, transparent 15.5% 84.5%, #0d0a09 84.5% 88%, transparent 88%),
    repeating-linear-gradient(90deg, transparent 0 6px, #00000038 6px 7px, #ffffff07 7px 8px, transparent 8px 13px),
    radial-gradient(ellipse 70% 40% at 35% 30%, #6a1d1566, transparent 70%),
    radial-gradient(ellipse 60% 30% at 65% 75%, #5a161066, transparent 70%),
    linear-gradient(180deg, #2b120e, #170908 50%, #24100c);
  box-shadow: inset 0 0 70px #000, inset 0 0 0 2px #3a1410;
}
.gate-door-left { left: 0; border-right: 2px solid #050202; transform: translateX(-101%); }
.gate-door-right { right: 0; border-left: 2px solid #050202; transform: translateX(101%); }
/* 扉の合わせ目に貼られた御札 */
.gate-ofuda {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: min(56vh, 380px);
  transform: translate(-50%, -50%);
  background:
    radial-gradient(ellipse 30% 12% at 30% 20%, #8a6a3a33, transparent),
    radial-gradient(ellipse 40% 10% at 70% 82%, #7a552a33, transparent),
    linear-gradient(90deg, #cfc1a0, #e6dbc0 30%, #ddd0b0 70%, #c4b590);
  box-shadow: 0 0 0 1px #6d5d40, 0 4px 18px #000c;
  opacity: 0;
}
.gate-ofuda span {
  position: absolute;
  inset: 10px 8px;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 9px, #9e1410 9.5px 12px, transparent 12.5px),
    radial-gradient(circle at 50% 50%, #9e1410 0 3.5px, transparent 4px),
    linear-gradient(90deg, transparent 44%, #1d1512 44% 56%, transparent 56%) 50% 0 / 100% 34% no-repeat,
    linear-gradient(90deg, transparent 44%, #1d1512 44% 56%, transparent 56%) 50% 100% / 100% 34% no-repeat,
    linear-gradient(180deg, transparent 10%, #1d151299 10% 11.5%, transparent 11.5% 88.5%, #1d151299 88.5% 90%, transparent 90%);
  opacity: .88;
}
/* 霧 */
.gate-fog {
  position: absolute;
  inset: -25%;
  background:
    radial-gradient(ellipse 35% 22% at 30% 40%, #8fb3a833, transparent 70%),
    radial-gradient(ellipse 40% 25% at 70% 60%, #6e8f8a2e, transparent 70%),
    radial-gradient(ellipse 30% 20% at 50% 80%, #a9c7c026, transparent 70%);
  filter: blur(8px);
  opacity: 0;
}
/* 扉の隙間から漏れる冷たい光 */
.gate-curtain::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  margin-left: -1.5px;
  background: #e6f4ff;
  box-shadow: 0 0 24px 10px #9fd0ff99, 0 0 80px 30px #5a8fb855;
  opacity: 0;
}

/* ---------- 演出（動きを減らす設定では出さない） ---------- */
@media (prefers-reduced-motion: no-preference) {
  .is-ready .life-total.is-hit { animation: life-hit .32s ease-out; }
  .is-ready .life-total.is-heavy-hit { animation: life-heavy-hit .42s ease-out; }
  .is-ready .life-total.is-heal { animation: life-heal .36s ease-out; }
  .is-ready .life-zone[data-danger="true"] .life-total { animation: life-danger 1.1s ease-in-out infinite; }
  .life-delta.is-showing { animation: delta-float 1.1s ease-out forwards; }
  .player.is-damaged::after { --flash: #ff4d5e; animation: panel-flash .45s ease-out; }
  .player.is-healed::after { --flash: #5ff0c0; animation: panel-flash .45s ease-out; }

  .action-card.is-stamped[aria-pressed="true"] .action-type::before { animation: stamp .32s cubic-bezier(.2, 1.6, .4, 1); }
  .action-card.is-stamped[aria-pressed="true"]::after { animation: sweep .45s ease-out; }
  .action-grid.is-refreshing :is(.action-card, .refresh-card)::after { animation: sweep .55s ease-out; }
  .action-grid.is-refreshing .action-card:nth-child(2)::after { animation-delay: .05s; }
  .action-grid.is-refreshing .action-card:nth-child(3)::after { animation-delay: .1s; }
  .action-grid.is-refreshing .action-card:nth-child(4)::after { animation-delay: .08s; }
  .action-grid.is-refreshing .action-card:nth-child(5)::after { animation-delay: .13s; }
  .season.is-lit[aria-pressed="true"] { animation: season-ignite .38s ease-out; }
  .season-status[data-lit="true"] .season-lamp { animation: lamp-flicker 4.8s 1s ease-in-out infinite; }
  .season-status.is-lit[data-lit="true"] .season-lamp { animation: lamp-on .5s ease-out, lamp-flicker 4.8s 1s ease-in-out infinite; }

  .match-reveal[data-role="rolling"]:not([hidden]) { animation: rolling-flicker .14s linear infinite; }
  .match-reveal:is([data-role="first"], [data-role="second"]):not([hidden]) { animation: reveal-slam .42s cubic-bezier(.2, 1.4, .4, 1); }
  .match-reveal[data-role="first"]:not([hidden])::after { animation: sweep-wide .9s .25s ease-out both; }
  .match-reveal[data-role="gate"]:not([hidden]) { animation: gate-text-flicker 2.8s linear both; }
  .die.is-rolling { animation: die-roll .6s cubic-bezier(.3, .7, .4, 1); }

  /* 御札で封じられた扉が現れ、御札が燃え落ちて、扉がきしみながら開く */
  .gate-curtain[data-state="opening"]::before { animation: dark-fade 1.6s ease-in both; }
  .gate-curtain[data-state="opening"] .gate-door-left { animation: creak-left 1.6s ease-in both; }
  .gate-curtain[data-state="opening"] .gate-door-right { animation: creak-right 1.6s ease-in both; }
  .gate-curtain[data-state="opening"] .gate-ofuda { animation: ofuda-burn .45s .2s ease-in both; }
  .gate-curtain[data-state="opening"] .gate-fog { animation: fog-drift 1.6s ease-out both; }
  .gate-curtain[data-state="opening"]::after { animation: cold-light 1.6s ease-out both; }
}

@keyframes life-hit {
  0% { transform: translateX(0) scale(1.08); color: #ff9a96; }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
  100% { transform: none; }
}
@keyframes life-heavy-hit {
  0% { transform: scale(1.22); color: #ff6b6b; }
  20% { transform: translateX(-7px) scale(1.1); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
  100% { transform: none; }
}
@keyframes life-heal {
  0% { transform: scale(1.16); color: #9ff7d6; text-shadow: 0 0 24px #5ff0c0; }
  100% { transform: none; }
}
@keyframes life-danger {
  0%, 100% { text-shadow: 0 0 14px #ff4a4a66, 0 2px 0 #0008; }
  50% { text-shadow: 0 0 28px #ff4a4acc, 0 2px 0 #0008; }
}
@keyframes delta-float {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(.8); }
  12% { opacity: 1; transform: translate(-50%, -2px) scale(1.12); }
  70% { opacity: 1; transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -18px) scale(1); }
}
@keyframes panel-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes stamp {
  0% { transform: scale(2.2); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes sweep {
  from { transform: translateX(-120%); }
  to { transform: translateX(120%); }
}
@keyframes sweep-wide {
  from { transform: translateX(-60%); }
  to { transform: translateX(60%); }
}
@keyframes season-ignite {
  0% { transform: scale(.82); box-shadow: 0 0 0 0 var(--season-glow); }
  60% { transform: scale(1.08); box-shadow: 0 0 0 7px color-mix(in srgb, var(--season-glow) 0%, transparent), 0 0 18px var(--season-glow); }
  100% { transform: none; }
}
@keyframes lamp-on {
  0% { opacity: .2; }
  20% { opacity: 1; }
  30% { opacity: .4; }
  45%, 100% { opacity: 1; }
}
@keyframes lamp-flicker {
  0%, 88%, 100% { opacity: 1; }
  90% { opacity: .55; }
  93% { opacity: .9; }
  95% { opacity: .7; }
}
@keyframes rolling-flicker {
  0%, 100% { color: #f4e6c466; transform: translateY(-2px); }
  50% { color: #fff6e4; transform: translateY(2px); }
}
@keyframes reveal-slam {
  0% { transform: scale(1.9); opacity: 0; filter: blur(6px); }
  60% { transform: scale(.96); opacity: 1; filter: none; }
  100% { transform: none; }
}
@keyframes gate-text-flicker {
  0% { opacity: 0; filter: blur(4px); }
  6% { opacity: .9; filter: none; }
  8% { opacity: .15; }
  11% { opacity: 1; }
  13% { opacity: .3; transform: translateX(2px) skewX(-6deg); }
  15% { opacity: 1; transform: none; }
  52% { opacity: 1; }
  54% { opacity: .45; transform: translateX(-2px); }
  56% { opacity: 1; transform: none; }
  83% { opacity: 1; }
  85% { opacity: .35; }
  87%, 100% { opacity: 1; }
}
@keyframes die-roll {
  0% { transform: rotate(-10deg); }
  100% { transform: rotate(710deg); }
}
@keyframes dark-fade {
  0%, 45% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes ofuda-burn {
  0% { opacity: 1; transform: translate(-50%, -50%); filter: brightness(1) drop-shadow(0 0 6px #ff3a1a); }
  40% { opacity: 1; filter: brightness(1.8) sepia(1) drop-shadow(0 0 22px #ff5a1a); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.9, 1.15); filter: brightness(.2) blur(4px); }
}
@keyframes fog-drift {
  0% { opacity: .75; transform: none; }
  40% { opacity: .8; transform: translate(-1%, -1%); }
  50% { opacity: .9; transform: translate(-3%, -4%) scale(1.08); }
  100% { opacity: 0; transform: translate(-6%, -8%) scale(1.18); }
}
@keyframes creak-left {
  0%, 40% { transform: none; }
  48% { transform: translateX(-5%); }
  54% { transform: translateX(-4%); }
  60% { transform: translateX(-9%); }
  100% { transform: translateX(-103%); }
}
@keyframes creak-right {
  0%, 40% { transform: none; }
  48% { transform: translateX(5%); }
  54% { transform: translateX(4%); }
  60% { transform: translateX(9%); }
  100% { transform: translateX(103%); }
}
@keyframes cold-light {
  0%, 38% { opacity: 0; }
  48% { opacity: 1; width: 3px; margin-left: -1.5px; }
  100% { opacity: 0; width: 80%; margin-left: -40%; }
}

/* 縦の盤を横に倒した画面で使うときの確認画面 */
@media (max-width: 650px) and (orientation: portrait) {
  body:has(.table[data-layout="landscape"]) dialog { width: min(360px, 88svh); max-height: 90svw; transform: rotate(90deg); }
}

/* ---------- スマホ縦（盤の器の大きさで切り替える） ---------- */
@container board (max-width: 650px) and (orientation: portrait) {
  .table[data-layout="portrait"] {
    --side-clearance: max(8px, var(--safe-left), var(--safe-right));
    --action-row: 50px;
    width: min(clamp(296px, 86cqw, 366px), calc(100% - var(--side-clearance) - var(--side-clearance)));
    min-height: 100cqh;
    grid-template-rows: minmax(min-content, 1fr) auto minmax(min-content, 1fr);
    padding-inline: 0;
  }
  .table[data-layout="portrait"] .player {
    grid-template-rows: minmax(min-content, 1fr) auto;
    --card-label: clamp(.78rem, 1.7cqh, .95rem);
    --card-name: clamp(1.25rem, 3.3cqh, 1.8rem);
  }
  .table[data-layout="portrait"] .life-controls { max-height: clamp(56px, 8.4cqh, 74px); align-self: center; height: 100%; }
  .table[data-layout="portrait"] .season { --season-size: clamp(44px, 13.4cqw, 56px); }
  .table[data-layout="portrait"] .season-caption { font-size: .74rem; }
  .table[data-layout="portrait"] .action-grid { grid-template-rows: repeat(2, clamp(var(--action-row), calc(13cqh - 30px), 92px)); }
  .table[data-layout="portrait"] :is(.action-card, .refresh-card) { min-height: var(--action-row); }
  .stage:has(.table[data-layout="landscape"]) { overflow: clip; }
  .table[data-layout="landscape"] {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(100cqh, 950px);
    padding: max(8px, var(--safe-left)) max(8px, var(--safe-top))
             max(8px, var(--safe-right)) max(8px, var(--safe-bottom));
    transform: translate(-50%, -50%) rotate(90deg);
  }
  .table[data-layout="landscape"] .life-zone { --life-w: 76px; }
}

@container board ((max-width: 620px) and (orientation: landscape)) or ((max-height: 620px) and (orientation: portrait)) {
  .table[data-layout="landscape"] { gap: 5px; }
  .table[data-layout="landscape"] .player { --badge: 20px; }
  .table[data-layout="landscape"] .life-zone { --life-w: 68px; padding: 4px 7px 12px; }
  .table[data-layout="landscape"] .life-controls { gap: 3px; }
  .table[data-layout="landscape"] .life-buttons { gap: 2px; }
  .table[data-layout="landscape"] .life-button { min-height: 44px; }
  .table[data-layout="landscape"] .player-record { padding-inline: 6px; padding-bottom: 4px; }
  .table[data-layout="landscape"] .action-grid { gap: 4px; }
  .table[data-layout="landscape"] :is(.action-card, .refresh-card) { min-height: 44px; padding-block: 2px; gap: 0; }
  .table[data-layout="landscape"] .season-row { gap: 4px; margin-top: 4px; padding-top: 3px; }
  .table[data-layout="landscape"] .season-row { gap: 3px; }
  .table[data-layout="landscape"] .refresh-card > span { font-size: .62rem; letter-spacing: -.04em; white-space: nowrap; }
  .table[data-layout="landscape"] :is(.action-card, .refresh-card) { padding-inline: 6px; }
  .table[data-layout="landscape"] .season-status { gap: 3px; padding: 2px 0; font-size: .62rem; letter-spacing: -.04em; }
  .table[data-layout="landscape"] .season-buttons { gap: 1px; }
  .table[data-layout="landscape"] .table-bar { padding-top: 1px; }
}

/* 中くらいの高さ（SE・小型Android・アドレスバー表示中） */
@container board (max-width: 650px) and (max-height: 700px) and (orientation: portrait) {
  .table[data-layout="portrait"] {
    --action-row: 46px;
    gap: 5px;
    padding-block: max(5px, var(--safe-top)) max(5px, var(--safe-bottom));
  }
  .table[data-layout="portrait"] .player { --badge: 24px; }
  .table[data-layout="portrait"] .life-zone { padding-top: 7px; }
  .table[data-layout="portrait"] .player-record { padding-inline: 9px; padding-bottom: 5px; }
  .table[data-layout="portrait"] .action-grid { gap: 5px; }
  .table[data-layout="portrait"] :is(.action-card, .refresh-card) { padding-block: 2px; }
  .table[data-layout="portrait"] .season-row { margin-top: 5px; padding-top: 4px; }
}

@container board (max-width: 650px) and (max-height: 620px) and (orientation: portrait) {
  .table[data-layout="portrait"] {
    --action-row: 44px;
    gap: 4px;
    padding-block: max(4px, var(--safe-top)) max(4px, var(--safe-bottom));
  }
  .table[data-layout="portrait"] .table-bar { padding-top: 3px; }
  .table[data-layout="portrait"] .player { --badge: 22px; }
  .table[data-layout="portrait"] .life-zone { padding-top: 5px; }
  .table[data-layout="portrait"] .life-button { min-height: 48px; }
  .table[data-layout="portrait"] .player-record { padding-bottom: 3px; }
  .table[data-layout="portrait"] :is(.action-card, .refresh-card) { gap: 0; padding-block: 2px; }
  .table[data-layout="portrait"] .season-row { margin-top: 3px; padding-top: 2px; }
}

/* 極端に短い画面（アドレスバー表示中の小型機など） */
@container board (max-width: 650px) and (max-height: 540px) and (orientation: portrait) {
  .table[data-layout="portrait"] { gap: 2px; }
  .table[data-layout="portrait"] .season-row { margin-top: 2px; padding-top: 2px; }
  .table[data-layout="portrait"] .player-record { padding-top: calc(var(--badge) / 2 + 4px); }
  .table[data-layout="portrait"] .player { grid-template-rows: auto auto; --card-label: .72rem; --card-name: 1.15rem; }
  .table[data-layout="portrait"] .player { --badge: 20px; }
  .table[data-layout="portrait"] .life-zone { --life-w: 68px; padding-top: 3px; padding-bottom: calc(var(--badge) / 2 + 2px); }
  .table[data-layout="portrait"] .life-button { min-height: 46px; }
  .table[data-layout="portrait"] .player-record { padding-inline: 7px; padding-bottom: 3px; }
  .table[data-layout="portrait"] .action-grid { gap: 4px; }
}
/* 横の盤を小さい縦画面で使うとき：ライフの４ボタンの44pxを確保する */
@container board (max-width: 380px) and (orientation: portrait) {
  .table[data-layout="landscape"] { gap: 4px; padding-inline: max(4px, var(--safe-bottom)) max(4px, var(--safe-top)); }
  .table[data-layout="landscape"] .life-zone { --life-w: 64px; padding-inline: 4px; }
  .table[data-layout="landscape"] .life-controls { gap: 3px; }
  .table[data-layout="landscape"] .life-buttons { gap: 2px; }
}
@container board (max-width: 380px) and (max-height: 540px) and (orientation: portrait) {
  .table[data-layout="landscape"] .life-zone { --life-w: 56px; }
}

@container board (max-width: 380px) and (orientation: portrait) {
  .table[data-layout="portrait"] .life-zone { padding-inline: 8px; }
  .table[data-layout="portrait"] .life-controls { gap: 4px; }
  .table[data-layout="portrait"] .life-buttons { gap: 4px; }
  .table[data-layout="portrait"] .player-record { padding-inline: 8px; }
  .table[data-layout="portrait"] .season-buttons { gap: 3px; }
  .table[data-layout="portrait"] .season-row { gap: 4px; }
  .table[data-layout="portrait"] .season-status { font-size: .64rem; }
}

/* 先後・開門の大きな表示の間は、区切りの印を隠す */
.life-zone:has(.match-reveal:not([hidden])) .turn-order { visibility: hidden; }
