:root {
  --bg: #0c1330;
  --bg2: #16204a;
  --panel: #1d2a5c;
  --text: #eef1ff;
  --sub: #a8b2d8;
  --accent: #ffd23f;
  --hp: #ef4444;
  --mp: #3b82f6;
  --weapon: #c2410c;
  --boost: #b45309;
  --armor: #0f766e;
  --magic: #7c3aed;
  --item: #15803d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at top, #24306b 0%, var(--bg) 60%) fixed;
}

/* フェーズ色：フェーズバー・ステージ枠・自分エリア枠が連動する */
body { --phase: #3b4a8a; --phase-ink: var(--text); }
body[data-phase="turn"] { --phase: #ffd23f; --phase-ink: #1a1a1a; }
body[data-phase="defend"] { --phase: #ef4444; --phase-ink: #fff; }
body[data-phase="cpu"] { --phase: #475569; --phase-ink: #f1f5f9; }
body[data-phase="self"] { --phase: #ffd23f80; --phase-ink: #1a1a1a; }
body[data-phase="over"] { --phase: #64748b; --phase-ink: #fff; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 16px;
  border-bottom: 1px solid #2c3a78;
}
header h1 { margin: 0; font-size: 18px; color: var(--accent); letter-spacing: .05em; white-space: nowrap; }
header h1 small { font-size: 12px; color: var(--sub); }
header button { padding: 4px 12px; }

button {
  font: inherit;
  font-weight: bold;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1a1a;
  cursor: pointer;
}
button:disabled { color: #8b93b8; background: #3a4470; box-shadow: none; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid #4a5a9a; }

/* フェーズバー */
#phaseBar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 16px;
  overflow: hidden;
  white-space: nowrap;
  font-weight: bold;
  font-size: 16px;
  color: var(--phase-ink);
  background: var(--phase);
  border-left: 8px solid var(--actor, transparent);
  transition: background-color .2s;
}
.ph-icon { font-size: 20px; }
.ph-text { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ph-text small { font-size: 13px; font-weight: normal; }
#phaseBar .avatar { width: 24px; height: 24px; font-size: 11px; border-width: 1px; }
#phaseBar .avatar.long { font-size: 8px; }
body[data-phase="defend"] #phaseBar { animation: phaseBlink 1.2s infinite; }
@keyframes phaseBlink { 50% { background-color: #991b1b; } }

main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 24px; }

/* プレイヤーパネル */
#opponents { position: relative; z-index: 3; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
#opponents.duel { grid-template-columns: minmax(0, 360px); justify-content: center; }

.pl {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  grid-template-areas: "av head" "av stats" "av bar";
  align-items: center;
  column-gap: 10px;
  height: 96px;
  padding: 8px 10px;
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 12px;
  transition: border-color .2s, box-shadow .2s;
}
.pl.current { border-color: var(--phase); }
.pl.targetable { cursor: pointer; border-color: #ff6b6b; animation: aimPulse 1s ease-in-out infinite; }
.pl.targetable > .avatar { box-shadow: 0 0 0 3px #ef4444, 0 0 12px #ef4444; }
.pl.targetable > .avatar::after {
  content: "🎯";
  position: absolute;
  left: -8px;
  top: -8px;
  font-size: 16px;
  text-shadow: 0 0 3px #000;
}
@keyframes aimPulse {
  0%, 100% { box-shadow: 0 0 6px #ff6b6b88; }
  50% { box-shadow: 0 0 18px #ff6b6b; border-color: #ef4444; }
}
.pl.targetable:hover { background: #2b3c80; }
.pl.hit { animation: shake .4s; }
.pl.role-atk { border-color: #fb923c; box-shadow: 0 0 14px #fb923caa; }
.pl.role-tgt { border-color: #ef4444; box-shadow: 0 0 14px #ef4444aa; }
.pl.role-heal { border-color: #22c55e; box-shadow: 0 0 14px #22c55eaa; }
.pl.dead > :not(.deadmark):not(.bubble):not(.pop) { filter: grayscale(1); opacity: .4; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); background: #7f1d1d; }
  75% { transform: translateX(6px); }
}

.avatar {
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: bold;
  font-size: 18px;
  color: #fff;
  border: 2px solid #ffffff55;
}
.avatar.long { font-size: 13px; }
.pl > .avatar { grid-area: av; }
.pl.current > .avatar::before {
  content: "▶";
  position: absolute;
  top: -6px;
  left: -8px;
  font-size: 14px;
  color: var(--phase);
  text-shadow: 0 0 3px #000;
}
.deadmark { grid-area: av; justify-self: center; font-size: 44px; font-weight: 900; line-height: 1; color: #ef4444; text-shadow: 0 0 4px #000; pointer-events: none; }
.phead { grid-area: head; display: flex; align-items: center; gap: 6px; min-width: 0; }
.pname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold; }
.you { flex: none; padding: 0 5px; font-size: 10px; font-style: normal; font-weight: bold; line-height: 16px; color: #fff; background: #2563eb; border-radius: 4px; }
.pstats { grid-area: stats; display: flex; align-items: baseline; gap: 12px; min-width: 0; white-space: nowrap; color: var(--sub); }
.pstats b { margin-left: 2px; }
.php { color: #fca5a5; font-size: 16px; }
.php b { font-size: 24px; color: #fff; }
.pl.low .php b { color: #ef4444; }
.pmp { color: #93c5fd; font-size: 13px; }
.pmp b { font-size: 16px; color: #93c5fd; }
.phand { font-size: 12px; }
.pbar { grid-area: bar; display: flex; align-items: center; gap: 4px; min-width: 0; }
.bar { flex: 1; min-width: 0; height: 6px; background: #0b1026; border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--hp); transition: width .4s; }
.st { flex: none; padding: 0 4px; border-radius: 4px; font-size: 12px; font-weight: bold; line-height: 18px; color: #fff; }
.st.heat { background: #c2410c; }
.st.confuse { background: #7c3aed; }
.prole {
  position: absolute;
  top: -8px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 14px;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 1px 4px #0008;
}
.role-atk .prole { background: #ea580c; }
.role-tgt .prole { background: #dc2626; }
.role-heal .prole { background: #16a34a; }
.role-mp .prole { background: #2563eb; }
.role-ref .prole { background: #16a34a; }
.pl.role-mp { border-color: #3b82f6; box-shadow: 0 0 14px #3b82f6aa; }
.pl.role-ref { border-color: #22c55e; box-shadow: 0 0 14px #22c55eaa; }
.pop {
  position: absolute;
  top: 16px;
  right: 8px;
  z-index: 4;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 2px 4px #000, 0 0 2px #000;
  animation: floatUp .9s ease-out forwards;
}
.pop.bad { color: #ff4d4d; }
.pop.good { color: #4ade80; }
.pop.mp { color: #60a5fa; }
@keyframes floatUp {
  0% { opacity: 1; transform: scale(1.2); }
  20% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-24px); }
}

/* 吹き出し（ステージに出ていない人だけ）：名前の行に重ねる。HP・MP の行にはかからない */
.phead { position: relative; }
.bubble {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: 50%;
  overflow: hidden;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: bold;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #111;
  background: #fff;
  border-radius: 9px;
  box-shadow: 0 2px 6px #0008;
  transform: translateY(-50%);
}

/* バトル場 */
#stage {
  --actor: transparent;
  position: relative;
  display: grid;
  grid-template-rows: 98px 46px minmax(0, 1fr);
  height: 220px;
  margin-top: 22px;
  padding: 6px 12px;
  overflow: hidden;
  background: #070b1e;
  border: 2px solid var(--phase);
  border-radius: 14px;
  transition: border-color .2s, box-shadow .2s;
}
#stage.glow { box-shadow: 0 0 0 2px var(--actor), 0 0 18px var(--actor); }
body[data-phase="defend"] #stage { animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px #ef4444, 0 0 6px #ef4444; }
  50% { box-shadow: 0 0 0 4px #ef4444, 0 0 26px #ef4444; }
}
.st-row { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; transition: opacity .2s; }
#stage.faded .st-row { opacity: .25; }
#stTurn { position: absolute; top: 6px; left: 8px; z-index: 2; max-width: 40%; }
#stFx { position: absolute; inset: 0; pointer-events: none; }
.st-turn { display: flex; align-items: center; gap: 4px; height: 28px; max-width: 100%; overflow: hidden; white-space: nowrap; padding: 2px 10px 2px 4px; font-size: 13px; font-weight: bold; color: var(--accent); background: #0c1330e0; border-radius: 14px; }
.st-turn .avatar { width: 24px; height: 24px; font-size: 11px; border-width: 1px; }
.st-turn .avatar.long { font-size: 8px; }
.st-turn span { overflow: hidden; text-overflow: ellipsis; }
.st-idle { font-size: 30px; font-weight: 900; letter-spacing: .15em; color: var(--accent); text-shadow: 0 0 18px #ffd23f66; }
.st-idle2 { font-size: 22px; letter-spacing: .4em; opacity: .7; }

.st-who { position: relative; display: flex; flex-direction: column; align-items: center; flex: none; width: 76px; min-width: 0; }
.st-who .avatar { width: 56px; height: 56px; font-size: 20px; }
.st-who .avatar.long { font-size: 14px; }
.st-av { position: relative; }
.st-av .you { position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%); }
.st-nm { position: relative; max-width: 100%; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--sub); }
.st-tgt { position: absolute; top: -6px; right: -10px; font-size: 20px; font-style: normal; }
.st-bub {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 56px;
  max-width: min(300px, 30vw);
  overflow: hidden;
  padding: 1px 8px;
  font-size: 13px;
  font-weight: bold;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #111;
  background: #fff;
  border-radius: 9px;
  box-shadow: 0 2px 6px #000a;
  transform: translateX(-50%);
}
.st-gav { position: relative; }
.st-gav .st-bub { top: auto; bottom: -20px; transform: translateX(-50%); }
.st-cost { font-size: 11px; font-weight: bold; color: #93c5fd; }
.st-who.healglow .avatar { box-shadow: 0 0 0 4px #22c55e88, 0 0 22px #22c55e; }
.avatar.q { background: transparent; border: 2px dashed #94a3b8; color: #94a3b8; font-size: 26px; }
.st-ghost { position: absolute; top: -10px; left: -30px; opacity: .45; }
.st-ghost .avatar { width: 24px; height: 24px; font-size: 10px; border-width: 1px; }
.st-ghost::after { content: "✖"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; color: #f87171; }
.st-hit { position: absolute; left: -18px; top: -8px; padding: 0 4px; font-size: 15px; font-weight: 900; font-style: normal; white-space: nowrap; border-radius: 6px; background: #000c; }
.st-hit.bad { color: #ff4d4d; }
.st-hit.good { color: #4ade80; }
.st-hit.dark { font-size: 22px; }
.st-pray { font-size: 56px; line-height: 1; }

/* 矢印（ステージ内だけで完結） */
.st-arrow, .st-fork { position: relative; flex: 1 1 24px; min-width: 16px; max-width: 150px; height: 40px; margin-bottom: 22px; }
.st-fork { max-width: 64px; }
.st-arrow i {
  position: absolute;
  left: 0;
  right: 10px;
  top: 17px;
  height: 6px;
  background: var(--ac);
  border-radius: 3px;
  transform-origin: left center;
  animation: grow .3s ease-out;
}
.st-arrow i::after {
  content: "";
  position: absolute;
  right: -10px;
  top: -6px;
  border: 9px solid transparent;
  border-right: 0;
  border-left: 12px solid var(--ac);
}
.st-arrow.rev i { left: 10px; right: 0; background: #22c55e; transform-origin: right center; }
.st-arrow.rev i::after { right: auto; left: -10px; border-left: 0; border-right: 12px solid #22c55e; }
.st-arrow.bent i { top: 8px; transform: rotate(-14deg); }
.st-arrow.uturn i { top: 26px; left: 10px; right: 0; transform-origin: right center; }
.st-arrow.uturn i::after { right: auto; left: -10px; border-left: 0; border-right: 12px solid var(--ac); }
.st-q { position: absolute; left: 50%; top: -10px; transform: translateX(-50%); font-size: 18px; }
.st-fork i {
  position: absolute;
  left: 0;
  right: 8px;
  top: 17px;
  height: 4px;
  background: var(--ac);
  border-radius: 2px;
  transform-origin: left center;
  animation: grow .3s ease-out;
}
.st-fork i::after { content: ""; position: absolute; right: -8px; top: -5px; border: 7px solid transparent; border-right: 0; border-left: 10px solid var(--ac); }
.st-fork i:nth-child(1) { transform: rotate(-22deg); }
.st-fork i:nth-child(3) { transform: rotate(22deg); }
.st-group { display: flex; gap: 4px; flex: none; }
.st-gav { position: relative; }
.st-gav .avatar { width: 40px; height: 40px; font-size: 15px; }
.st-gav .avatar.long { font-size: 11px; }
.st-gav .st-tgt { top: -8px; right: -2px; font-size: 14px; }
@keyframes grow { from { transform: scaleX(0); } }

/* ステージ内の縮小カード */
.st-card { position: relative; flex: none; width: 120px; padding-bottom: 22px; animation: slideIn .3s ease-out; }
.mcard { min-height: 60px; padding: 4px 6px; border-radius: 8px; border: 2px solid #ffffff30; }
.mcard .ctop { min-height: 18px; }
.mcard .ctype { font-size: 13px; }
.mcard .cbadge { height: 18px; font-size: 14px; line-height: 18px; padding: 0 5px; }
.mcard .cname {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  font-size: 11px;
  line-height: 1.25;
}
.st-boosts { position: absolute; left: 50%; bottom: 0; display: flex; flex-wrap: nowrap; justify-content: center; gap: 2px; white-space: nowrap; transform: translateX(-50%); }
.st-boost { padding: 0 5px; font-size: 11px; font-weight: bold; line-height: 16px; background: linear-gradient(160deg, var(--boost), #451a03); border: 1px solid #fdba74; border-radius: 5px; }
.st-plus { padding: 0 5px; font-size: 10px; font-weight: bold; line-height: 15px; color: #1a1a1a; background: #fb923c; border-radius: 8px; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-40px); } }

/* 中段：攻撃力・効果 */
.st-mid { display: flex; align-items: center; justify-content: center; gap: 10px; white-space: nowrap; }
.st-pow { font-size: 44px; font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 10px #fb923c; }
.st-chip { padding: 2px 10px; font-size: 16px; font-weight: bold; border-radius: 14px; }
.st-chip.light { color: #1a1a1a; background: linear-gradient(135deg, #fde047, #f59e0b); }
.st-chip.dark { color: #fff; background: linear-gradient(135deg, #3b0764, #0a0014); border: 1px solid #a855f7; }
.st-chip.big { font-size: 30px; padding: 2px 16px; }
.st-chip.void { color: #cbd5e1; background: #475569; border-color: #64748b; text-decoration: line-through 3px; opacity: .4; }
.st-big { font-size: 30px; font-weight: 900; line-height: 1.1; }
.st-big.good { color: #4ade80; }
.st-big.mp { color: #60a5fa; }
.st-big.heat { color: #fb923c; }
.st-big.heat.tick { font-size: 40px; }
.st-big.confuse { color: #c084fc; }
.st-big.draw { color: #e2e8f0; }
.st-big.steal { position: relative; color: #fbbf24; }
.st-big.miss { color: #94a3b8; }
.cback { display: inline-block; margin-right: 6px; font-style: normal; color: #93c5fd; animation: steal .4s ease-out; }
@keyframes steal { from { opacity: 0; transform: translateX(80px); } }

/* 下段：⚔ − 🛡 = 💥 の式（ドックと共用） */
#stBot { gap: 8px; }
.st-eq { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; }
.st-res { justify-content: center; }
.st-res .avatar { width: 32px; height: 32px; font-size: 12px; }
.st-res .avatar.long { font-size: 9px; }
.eq-g1, .eq-g2 { display: inline-flex; align-items: center; gap: 6px; }
.eq-a { font-size: 26px; font-weight: 900; line-height: 1; color: #fff; }
.eq-op { font-size: 24px; font-weight: bold; color: var(--sub); }
.eq-d { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-weight: 900; white-space: nowrap; }
.eq-d b { font-size: 36px; line-height: 1; color: #5eead4; }
.eq-d.slot { padding: 0 8px; font-size: 22px; color: #94a3b8; border: 2px dashed #64748b; border-radius: 10px; }
.eq-d.none { font-size: 26px; color: #94a3b8; }
.eq-d.ref { font-size: 30px; color: #4ade80; }
.st-dchip { flex: 0 1 auto; min-width: 0; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; font-size: 11px; line-height: 18px; border-radius: 5px; background: linear-gradient(160deg, var(--armor), #042f2e); border: 1px solid #ffffff40; }
.st-dchip.light { border-color: #ffd23f; }
.st-dchip.sum { font-size: 13px; font-weight: 900; }
.st-eq, .st-eq * { white-space: nowrap; }
.aux-alt { display: none; }
.eq-r { display: inline-flex; align-items: baseline; gap: 4px; font-size: 56px; font-weight: 900; line-height: 1; white-space: nowrap; }
.eq-r small { font-size: 14px; font-weight: bold; }
.eq-r.txt { font-size: 26px; }
.eq-r.txt.big { font-size: 40px; }
.eq-r.bad { color: #ff4d4d; text-shadow: 0 0 12px #ef444488; }
.eq-r.good { color: #4ade80; }
.eq-r.gold { color: #fde047; text-shadow: 0 0 12px #f59e0b; }
.eq-r.dark { padding: 0 12px; color: #fff; background: linear-gradient(135deg, #3b0764, #0a0014); border-radius: 12px; font-size: 40px; }
.eq-r.wait { font-size: 22px; color: #64748b; }
.eq-r.blink { animation: blinkTxt .8s infinite; }
#stage .eq-d:not(.slot) { animation: slideD .25s ease-out; }
#stage .eq-r:not(.wait):not(.blink) { transform-origin: left center; animation: popR .25s ease-out; }
@keyframes slideD { from { opacity: 0; transform: translateX(30px); } }
@keyframes popR { from { transform: scale(1.4); } }
@keyframes blinkTxt { 50% { opacity: .35; } }
.st-to { font-size: 18px; color: var(--sub); }
.st-res > .st-ko { position: absolute; right: 8px; bottom: 4px; }
.st-x { display: none; }
.st-blk .b1 { position: relative; }
.st-ko { padding: 2px 10px; font-size: 14px; font-weight: bold; color: #fff; background: #991b1b; border-radius: 6px; white-space: nowrap; }
/* 全体攻撃の小ブロック：1 行目アバター、2 行目 🛡5→💥2 */
.st-blk { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; flex: 1 1 0; min-width: 0; white-space: nowrap; }
.st-blk .b2 { display: flex; align-items: center; gap: 3px; }
.st-blk .avatar { width: 28px; height: 28px; font-size: 11px; border-width: 1px; }
.st-blk .avatar.long { font-size: 8px; }
.st-blk .eq-d, .st-blk .eq-d.none, .st-blk .eq-d.slot { padding: 0 3px; font-size: 16px; border-width: 1px; }
.st-blk .eq-d b { font-size: 16px; }
.st-blk .eq-r { font-size: 20px; }
.st-blk .eq-r.txt { font-size: 14px; }
.st-blk .eq-r.wait { font-size: 14px; }
.st-blk .st-ko { padding: 0 4px; font-size: 12px; }
.st-blk .st-to { font-size: 14px; }
.st-blk.live { padding: 0 4px; border: 2px solid #ef4444; border-radius: 8px; }

/* フラッシュ */
.st-fx { position: absolute; inset: 0; opacity: 0; }
.st-fx.dark { background: #3b0764; animation: flash .4s ease-out; }
.st-fx.light { background: #fde047; animation: flash .3s ease-out; }
.st-fx.pray { background: #fff; animation: flash .3s ease-out; }
@keyframes flash { from { opacity: .7; } }

/* 再描画で作り直したセルはアニメしない（防御選択中・プレビュー） */
.nofx:not(.blink), .nofx *:not(.blink) { animation: none !important; }

/* ログ */
#logTicker { height: 28px; margin-top: 6px; }
#btnTicker {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: normal;
  text-align: left;
  color: var(--text);
  background: #070b1e;
  border: 1px solid #2c3a78;
  border-radius: 8px;
}
#tickerText { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tickerText::before { content: "▸ "; color: var(--sub); }
#tickerText span { animation: tickIn .2s; }
@keyframes tickIn { from { opacity: 0; } }
.tk-open { flex: none; color: var(--sub); }
.tk-open::after { content: " ▾"; }
body.log-open .tk-open::after { content: " ▴"; }
#tickerText .turn, #log .turn { color: var(--accent); font-weight: bold; }
#tickerText .quote, #log .quote { color: #fca5a5; }
#tickerText .dmg, #log .dmg { color: #ff8080; }
#tickerText .good, #log .good { color: #86efac; }
#logDrawer, #logBackdrop, .drawer-head { display: none; }
body.log-open #logDrawer { display: block; }
#log {
  height: 200px;
  margin-top: 6px;
  padding: 8px 12px;
  overflow-y: auto;
  background: #070b1e;
  border: 1px solid #2c3a78;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
#log .turn { margin-top: 4px; }

/* 自分 */
#mePanel {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 10px;
  height: 120px;
  margin-top: 10px;
  padding: 6px;
  border: 2px solid var(--phase);
  border-radius: 14px;
  transition: border-color .2s;
}
#me { min-width: 0; }
#me .pl { height: 100%; border: 2px solid #3b82f680; }
body[data-phase="turn"] #me .pl, body[data-phase="defend"] #me .pl { border-color: var(--phase); }
#control {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 6px 12px;
  background: var(--bg2);
  border-radius: 12px;
}
#hint {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  color: var(--sub);
}
#hint b { color: var(--accent); }
#waitNote { font-size: 16px; color: var(--sub); opacity: .55; }
#waitNote[hidden] { display: none; }

/* 2 カラム：左にバトル場・ログ・手札、右に相手と自分を縦積み */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
  max-width: 1200px;
}
#field { min-width: 0; }
#field #stage { margin-top: 0; }
#side {
  position: sticky;
  top: 48px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
#side #opponents, #side #opponents.duel { grid-template-columns: minmax(0, 1fr); gap: 8px; }
#side #mePanel { grid-template-columns: minmax(0, 1fr); height: auto; margin-top: 0; }
#side #me .pl { height: 96px; }
#side #control { min-height: 56px; }

/* 攻・防の文字アイコン（周りの文字サイズに合わせて伸縮） */
.ic {
  display: inline-grid;
  place-items: center;
  width: 1.3em;
  height: 1.3em;
  margin-right: .1em;
  font-size: .78em;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  vertical-align: .1em;
  border-radius: .28em;
}
.ic-atk { background: #dc2626; box-shadow: inset 0 -.12em 0 #991b1b; }
.ic-def { background: #0d9488; box-shadow: inset 0 -.12em 0 #115e59; }

/* アクションドック（カードの上。自分のターンと防御の番だけ表示し、それ以外も場所は空けておく） */
#dock {
  min-height: 68px;
  margin-top: 8px;
  background: var(--bg2);
  border: 2px solid var(--phase);
  border-radius: 12px;
  box-shadow: 0 4px 16px #0006;
}
#dock:not(.show) { visibility: hidden; }
.dock-in { display: flex; align-items: center; gap: 12px; padding: 8px 12px; }
#dockInfo { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; min-width: 0; }
.dk-line { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.dk-who { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.dk-who i { font-style: normal; color: var(--sub); }
.dk-who .avatar, .dk-tg .avatar { width: 24px; height: 24px; font-size: 11px; border-width: 1px; }
.dk-who .avatar.long, .dk-tg .avatar.long { font-size: 8px; }
.dk-eq { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.dk-eq > b, .dk-eq .eq-a { font-size: 22px; font-weight: 900; color: #fff; }
.dk-eq small { font-size: 13px; font-weight: bold; color: var(--sub); }
.dk-eq .eq-g { color: #4ade80; }
.dk-eq .eq-m { color: #60a5fa; }
#dock .eq-op { font-size: 18px; }
#dock .eq-d b { font-size: 22px; }
#dock .eq-d.none, #dock .eq-d.slot { font-size: 18px; }
#dock .eq-d.ref { font-size: 22px; }
#dock .eq-r { font-size: 30px; }
#dock .eq-r.txt { font-size: 17px; }
#dock .eq-r small { font-size: 12px; }
#dock .st-chip { font-size: 13px; padding: 1px 8px; }
.dk-hp { flex: none; font-size: 17px; font-weight: bold; white-space: nowrap; color: #fca5a5; }
.dk-hp b { font-size: 20px; color: #fff; }
.dk-hp b.bad { color: #ff4d4d; }
.dk-hp b.good { color: #4ade80; }
.dk-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--sub); }
#dockTargets { display: flex; gap: 8px; min-width: 0; }
#dockTargets:empty { display: none; }
.dk-tg { display: flex; align-items: center; justify-content: center; gap: 6px; height: 48px; padding: 0 12px 0 6px; color: #fff; background: #3b1424; border: 2px solid #ef4444; }
.dk-tg .avatar { width: 28px; height: 28px; }
.dk-tg span { color: #fca5a5; font-size: 14px; }
.dk-tg b { margin-left: 2px; font-size: 18px; color: #fff; }
/* 自分に使うボタン・自分のパネル（道具の対象として選べる時）は緑 */
.dk-tg.self { background: #0f2e1d; border-color: #22c55e; }
.dk-tg.self span { color: #86efac; font-weight: bold; }
#me .pl.targetable { border-color: #22c55e; animation: none; box-shadow: 0 0 12px #22c55e; }
#me .pl.targetable > .avatar { box-shadow: 0 0 0 3px #22c55e, 0 0 12px #22c55e; }
#me .pl.targetable > .avatar::after { content: "👆"; }
#buttons { display: flex; align-items: center; gap: 8px; flex: none; }
#buttons button { height: 48px; padding: 0 22px; font-size: 17px; }
#buttons button[hidden] { display: none; }
#dock[data-mode="target"] #btnUse, #dock[data-mode="idle"] #btnUse, #dock[data-mode="discard"] #btnUse { display: none; }
#dock[data-mode="idle"] #buttons, #dock[data-mode="discard"] #buttons { margin-left: auto; }
/* 所持枚数（手札＋魔法）。上限に達したら赤 */
.dk-count { flex: none; font-size: 15px; font-weight: bold; white-space: nowrap; color: var(--sub); }
.dk-count.full { color: #f87171; }
#btnDiscard.on { color: #1a1a1a; background: #f87171; border-color: #f87171; }
#btnDefend { min-width: 260px; color: #fff; background: linear-gradient(180deg, #ef4444, #b91c1c); border: 2px solid #fff; font-size: 19px; }

/* 魔法ストック（覚えた魔法。使っても消えない） */
#spells {
  margin-top: 12px;
  padding: 8px;
  background: #2e106540;
  border: 1px solid #7c3aed80;
  border-radius: 12px;
}
#spells[hidden] { display: none; }
.sp-head { margin-bottom: 6px; font-size: 13px; font-weight: bold; color: #c4b5fd; }
.sp-head small { margin-left: 6px; font-weight: normal; color: var(--sub); }
#spellList { display: flex; flex-wrap: wrap; gap: 8px; }

/* 手札 */
#hand { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.card {
  position: relative;
  width: 128px;
  min-height: 150px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 2px solid #ffffff30;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, opacity .12s;
  user-select: none;
}
.card:hover { transform: translateY(-4px); }
.card.weapon, .mcard.weapon { background: linear-gradient(160deg, var(--weapon), #431407); }
.card.boost, .mcard.boost { background: linear-gradient(160deg, var(--boost), #451a03); }
.card.armor, .mcard.armor { background: linear-gradient(160deg, var(--armor), #042f2e); }
.card.magic, .mcard.magic { background: linear-gradient(160deg, var(--magic), #2e1065); }
.card.item, .mcard.item { background: linear-gradient(160deg, var(--item), #052e16); }
.card.light, .mcard.light { border-color: #ffd23f; box-shadow: 0 0 10px #ffd23f88; }
.card.dark, .mcard.dark { border-color: #c084fc; background: #120a1f; box-shadow: 0 0 12px #a855f7, inset 0 0 10px #a855f755; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 14px var(--accent); transform: translateY(-8px); }
.card.usable { border-color: #22c55e; box-shadow: inset 0 0 0 1px #22c55e, 0 10px 16px #22c55e55, 0 0 12px #22c55e; }
.card.usable.selected { border-color: var(--accent); }
.card.stackable { outline: 3px dashed #fb923c; outline-offset: -5px; }
.card.disabled { opacity: .35; }
/* 捨てるモード：どのカードもタップで捨てられる */
.card.discardable { outline: 2px dashed #f87171; outline-offset: -4px; }
.card.disabled:hover { transform: none; }

/* 引いたカードの登場演出：上から落ちてきて光る */
.card.drawn { animation: cardDraw .55s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes cardDraw {
  0% { opacity: 0; transform: translateY(-32px) scale(.6) rotate(-8deg); }
  55% { opacity: 1; transform: translateY(3px) scale(1.06); box-shadow: 0 0 22px #ffd23f, 0 0 0 3px #ffd23f; }
}

.ctop { display: flex; flex-wrap: nowrap; align-items: center; gap: 3px; min-height: 28px; }
.mcard .ctop { flex-wrap: nowrap; }
.ctype { font-size: 16px; line-height: 1; }
.celem { font-size: 14px; line-height: 1; }
.celem.dark { display: grid; place-items: center; flex: none; width: 18px; height: 18px; font-size: 10px; background: #e9d5ff; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 6px #a855f7; }
.cbadge {
  margin-left: auto;
  min-width: 0;
  height: 28px;
  overflow: hidden;
  padding: 0 6px;
  font-size: 18px;
  font-weight: 900;
  line-height: 28px;
  white-space: nowrap;
  color: var(--accent);
  background: #000b;
  border-radius: 14px;
}
.cbadge.mp, .cbadge .mpv { color: #93c5fd; }
.cbadge .hpv { color: #86efac; }
.cbadge i { font-style: normal; }
.cbadge i + i { margin-left: 3px; }
.cbadge small { margin-left: 2px; font-size: 11px; line-height: 1; color: #fff; }
/* 補足付き・値が 2 つのバッジは少し小さくして 1 行に収める */
.cbadge:has(small), .cbadge:has(i + i) { padding: 0 4px; font-size: 16px; }
.cbadge i:not(:only-of-type) { font-size: 14px; }
.cimgwrap { position: relative; }
.cimg {
  display: block;
  width: 100%;
  aspect-ratio: 12 / 7;
  margin: 3px 0 4px;
  object-fit: cover;
  background: #0004;
  border-radius: 6px;
}
.cname { font-weight: bold; font-size: 13px; line-height: 1.3; margin: 2px 0 6px; overflow-wrap: anywhere; }
.cval {
  display: inline-block;
  padding: 1px 7px;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: bold;
  background: #0006;
  border-radius: 10px;
  color: var(--sub);
}
.ctext { font-size: 10.5px; line-height: 1.4; opacity: .85; }
.cno { position: absolute; left: 4px; right: 4px; bottom: 6px; padding: 1px 4px; font-size: 11px; font-weight: bold; text-align: center; color: #fff; background: #7f1d1d; border-radius: 5px; }

/* オーバーレイ */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #000a;
}
#overlay[hidden] { display: none; }
#overlay .box {
  max-width: 440px;
  padding: 28px 24px;
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 16px;
}
#overlay h2 { margin-top: 0; color: var(--accent); font-size: 28px; }
#overlay .version { margin: -6px 0 0; font-size: 12px; letter-spacing: .05em; color: var(--sub); }
#overlay p { line-height: 1.7; }
#overlay .box[hidden] { display: none; }
#overlay .row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

#nameForm { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
#nameForm label { font-size: 13px; color: var(--sub); }
#nameInput {
  font: inherit;
  font-size: 18px;
  text-align: center;
  padding: 10px 12px;
  color: var(--text);
  background: var(--bg);
  border: 2px solid #4a5a9a;
  border-radius: 8px;
}
#nameInput:focus { outline: none; border-color: var(--accent); }

.modes { display: grid; gap: 12px; margin: 18px 0; }
button.mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  color: var(--text);
  background: var(--bg2);
  border: 2px solid #4a5a9a;
  text-align: left;
}
button.mode:hover { border-color: var(--accent); }
button.mode b { font-size: 20px; color: var(--accent); }
button.mode span { font-size: 13px; font-weight: normal; color: var(--sub); }

dialog {
  max-width: 560px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 14px;
}
dialog::backdrop { background: #000a; }
dialog h2 { margin-top: 0; color: var(--accent); }
dialog li { margin-bottom: 6px; line-height: 1.5; font-size: 14px; }

.hd-btns { display: flex; gap: 8px; }

/* カード一覧 */
#cardList {
  width: min(880px, calc(100vw - 32px));
  max-width: none;
  max-height: 86vh;
  padding: 16px;
  overflow: hidden;
}
#cardList[open] { display: flex; flex-direction: column; }
.cat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cat-head h2 { margin: 0; }
.cat-head button { padding: 2px 14px; font-size: 20px; }
#catTabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cat-tab { padding: 6px 14px; font-size: 14px; color: var(--text); background: var(--bg2); border: 1px solid #4a5a9a; }
.cat-tab small { margin-left: 6px; font-size: 11px; color: var(--sub); }
.cat-tab.on { color: #1a1a1a; background: var(--accent); border-color: var(--accent); }
.cat-tab.on small { color: #1a1a1a; }
#catList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}
.cat-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  background: var(--bg2);
  border: 1px solid #2c3a78;
  border-left: 6px solid var(--sub);
  border-radius: 10px;
}
.cat-row.weapon { border-left-color: var(--weapon); }
.cat-row.boost { border-left-color: var(--boost); }
.cat-row.armor { border-left-color: var(--armor); }
.cat-row.item { border-left-color: var(--item); }
.cat-row.magic { border-left-color: var(--magic); }
.cat-row.light { box-shadow: inset 0 0 0 1px #ffd23f88; }
.cat-row.dark { box-shadow: inset 0 0 0 1px #c084fc; }
.cat-img { width: 120px; aspect-ratio: 12 / 7; object-fit: cover; background: #0004; border-radius: 6px; }
.cat-info { min-width: 0; }
.cat-info .ctop { min-height: 24px; }
.cat-info .cbadge { height: 24px; font-size: 16px; line-height: 24px; }
.cat-name { margin: 2px 0 4px; font-size: 15px; font-weight: bold; overflow-wrap: anywhere; }
.cat-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; font-size: 12px; }
.cat-meta span { padding: 1px 8px; background: #0006; border-radius: 10px; }
.cat-type { color: var(--text); }
.cat-val { color: var(--accent); font-weight: bold; }
.cat-rate { color: var(--sub); }
.cat-text { font-size: 12.5px; line-height: 1.5; color: var(--sub); }

@media (max-width: 760px) {
  header { padding: 0 12px; }
  .hd-btns { gap: 6px; }
  header button { padding: 4px 8px; font-size: 13px; }
  #cardList { width: calc(100vw - 16px); max-height: 90vh; padding: 12px; }
  #catList { grid-template-columns: minmax(0, 1fr); }
  .cat-row { grid-template-columns: 84px minmax(0, 1fr); gap: 8px; padding: 6px; }
  .cat-img { width: 84px; }
  .cat-info .cbadge { height: 20px; font-size: 13px; line-height: 20px; }
  .cat-name { font-size: 13px; }
  header h1 small { display: none; }
  #phaseBar { padding: 0 12px; font-size: 15px; }
  main { display: flex; flex-direction: column; align-items: stretch; padding: 8px 12px 24px; }

  /* スマホは 1 カラム：相手→バトル場→ログ→自分→手札 の順に並べ直す */
  #field, #side { display: contents; }
  #field > *, #side > * { min-width: 0; }
  #opponents { order: 1; }
  #stage { order: 2; }
  #logTicker, #logBackdrop, #logDrawer { order: 3; }
  #mePanel { order: 4; }
  #dock { order: 5; }
  #spells { order: 6; }
  #hand { order: 7; }
  #side #opponents:not(.duel) { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #side #mePanel { grid-template-columns: minmax(0, 1fr); height: 100px; margin-top: 8px; }
  #side #me .pl { height: 44px; }
  #side #control { min-height: 0; }
  #field #stage { margin-top: 10px; }

  /* 相手は横3列のチップ */
  #opponents { gap: 6px; }
  #opponents:not(.duel) .pl {
    grid-template-columns: 28px minmax(0, 1fr);
    grid-template-areas: "av head" "stats stats" "bar bar";
    column-gap: 5px;
    height: 84px;
    padding: 6px;
  }
  #opponents:not(.duel) .avatar { width: 28px; height: 28px; font-size: 13px; border-width: 1px; }
  #opponents:not(.duel) .avatar.long { font-size: 9px; }
  #opponents:not(.duel) .pname { font-size: 12px; }
  #opponents:not(.duel) .phand, #opponents:not(.duel) .pspell { display: none; }
  #opponents:not(.duel) .pstats { gap: 6px; }
  #opponents:not(.duel) .deadmark { font-size: 28px; }
  #opponents.duel { grid-template-columns: minmax(0, 1fr); }
  #opponents.duel .pl { height: 84px; }
  .php b { font-size: 20px; }
  .pmp b { font-size: 13px; }
  .php { font-size: 13px; }
  .pmp { font-size: 11px; }
  .pl.current > .avatar::before { left: -6px; font-size: 11px; }
  .prole { right: 2px; width: 20px; height: 20px; font-size: 12px; }

  #opponents:not(.duel) .pop { top: -4px; right: 24px; font-size: 18px; }
  #me .pop { top: -14px; right: auto; left: 44px; font-size: 20px; }

  /* バトル場 */
  #stage { grid-template-rows: 84px 34px minmax(0, 1fr); height: 188px; margin-top: 10px; padding: 6px 8px; }
  .st-row { gap: 4px; }
  .st-who { width: 58px; }
  .st-who .avatar { width: 40px; height: 40px; font-size: 15px; }
  .st-who .avatar.long { font-size: 11px; }
  .st-nm { font-size: 10px; }
  .st-tgt { font-size: 16px; right: -8px; }
  .st-cost { font-size: 10px; }
  .st-card { width: 84px; }
  .mcard { padding: 3px 4px; }
  .mcard .ctop { min-height: 15px; }
  .mcard .ctype { font-size: 11px; }
  .mcard .celem { font-size: 10px; }
  .mcard .cbadge { height: 15px; font-size: 11px; line-height: 15px; padding: 0 3px; }
  .mcard .cbadge small { font-size: 9px; }
  .mcard { min-height: 46px; }
  .mcard .cname { font-size: 10px; line-height: 1.2; }
  .st-arrow, .st-fork { min-width: 14px; height: 30px; }
  .st-arrow i, .st-fork i { top: 13px; }
  .st-arrow.bent i { top: 6px; }
  .st-arrow.uturn i { top: 20px; }
  .st-gav .avatar { width: 28px; height: 28px; font-size: 11px; }
  .st-gav .avatar.long { font-size: 8px; }
  .st-group { gap: 3px; }
  .st-pow { font-size: 32px; }
  .st-chip { font-size: 13px; padding: 1px 8px; }
  .st-chip.big { font-size: 22px; }
  .st-big { font-size: 22px; }
  .st-pray { font-size: 40px; }
  .st-idle { font-size: 22px; }
  .st-idle2 { font-size: 16px; }
  #stBot { gap: 4px; }
  .st-bub { top: 40px; font-size: 12px; }
  .st-hit { left: -6px; top: -10px; font-size: 13px; }
  .st-gav .st-bub { top: auto; }
  .st-big.heat.tick { font-size: 40px; }
  .st-eq { gap: 4px; }
  .eq-g1, .eq-g2 { gap: 4px; }
  .eq-a { font-size: 18px; }
  .eq-op { font-size: 18px; }
  .eq-d b { font-size: 24px; }
  .eq-d.slot { font-size: 16px; padding: 0 6px; }
  .eq-d.none { font-size: 18px; }
  .eq-d.ref { font-size: 22px; }
  .st-dchip { max-width: 64px; font-size: 10px; line-height: 15px; }
  .st-dchip.sum { font-size: 12px; }
  /* スマホは式の後ろの補助文字を出さない */
  #stage .aux { display: none; }
  #stage .aux-alt { display: inline; font: inherit; }
  .eq-r { font-size: 38px; }
  .eq-r.txt { font-size: 17px; }
  .eq-r.txt.big { font-size: 24px; }
  .eq-r.dark { font-size: 24px; padding: 0 8px; }
  .eq-r.wait { font-size: 16px; }
  .eq-r small { font-size: 11px; }
  .st-res .avatar { width: 24px; height: 24px; font-size: 10px; }
  /* スマホは撃破帯を出さず、ステージのアバターに赤い ✖ を重ねる */
  .st-ko { display: none; }
  .st-x { position: absolute; inset: 0; z-index: 2; display: block; pointer-events: none; }
  .st-x::before, .st-x::after {
    content: "";
    position: absolute;
    left: -6%;
    right: -6%;
    top: 50%;
    height: 5px;
    margin-top: -2.5px;
    background: #ef4444;
    border-radius: 3px;
    box-shadow: 0 0 0 1px #000a;
    transform: rotate(45deg);
  }
  .st-x::after { transform: rotate(-45deg); }
  .st-blk .st-x::before, .st-blk .st-x::after { height: 4px; margin-top: -2px; }
  .st-blk .avatar { width: 22px; height: 22px; font-size: 9px; }
  .st-blk .avatar.long { font-size: 7px; }
  .st-blk .eq-d, .st-blk .eq-d.slot, .st-blk .eq-d.none, .st-blk .eq-d b { font-size: 14px; }
  .st-blk .eq-r { font-size: 16px; }
  .st-blk .eq-r.txt { font-size: 11px; }
  .st-blk .st-to { font-size: 11px; }
  .st-blk .st-ko { font-size: 10px; padding: 0 3px; }

  /* ログはドロワー */
  body.log-open #logBackdrop { display: block; position: fixed; inset: 0; z-index: 15; background: #000a; }
  body.log-open #logDrawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 16;
    display: flex;
    flex-direction: column;
    height: 50vh;
    padding: 8px 12px 12px;
    background: var(--bg2);
    border-top: 2px solid #4a5a9a;
    border-radius: 14px 14px 0 0;
  }
  body.log-open .drawer-head { display: flex; align-items: center; justify-content: space-between; }
  .drawer-head button { padding: 2px 12px; font-size: 18px; }
  body.log-open #log { flex: 1; height: auto; min-height: 0; }

  /* 自分エリア */
  #mePanel { grid-template-columns: minmax(0, 1fr); grid-template-rows: 44px 1fr; gap: 6px; height: 100px; margin-top: 8px; }
  #me .pl {
    grid-template-columns: 28px minmax(0, 1fr) auto auto;
    grid-template-areas: "av head stats bar";
    column-gap: 8px;
    height: 44px;
    padding: 4px 10px;
  }
  #me .avatar { width: 28px; height: 28px; font-size: 13px; border-width: 1px; }
  #me .pbar .bar { display: none; }
  #me .deadmark { font-size: 28px; }
  #control { flex-direction: row; align-items: center; gap: 8px; padding: 2px 8px; }
  #hint { flex: 1; -webkit-line-clamp: 1; font-size: 12px; }
  #waitNote { flex: none; font-size: 13px; }

  /* ドック（112px 以内） */
  .dock-in { flex-wrap: wrap; gap: 4px 6px; padding: 4px 8px; }
  #dockInfo { flex: 1 1 0; }
  #dock[data-mode="defend"] #dockInfo { flex-basis: 100%; flex-direction: column; align-items: flex-start; gap: 0; }
  #dock[data-mode="defend"] #buttons, #dock[data-mode="use"] #buttons { flex-basis: 100%; }
  #dock[data-mode="use"] #dockInfo { flex-basis: 100%; }
  #btnDefend, #btnUse { flex: 1 1 0; min-width: 0; }
  #buttons button { padding: 0 12px; font-size: 16px; }
  .dk-line { height: 30px; gap: 6px; }
  .dk-eq > b, .dk-eq .eq-a { font-size: 19px; }
  #dock .eq-r { font-size: 26px; }
  #dock .eq-r.txt { font-size: 15px; }
  .dk-hp { font-size: 14px; line-height: 18px; }
  .dk-hp b { font-size: 16px; }
  #dock[data-mode="target"] #buttons button { height: 44px; padding: 0 14px; font-size: 15px; }
  #dockTargets { order: 3; flex-basis: 100%; gap: 6px; }
  .dk-tg { flex: 1 1 0; min-width: 0; height: 44px; padding: 0 6px; }

  /* 手札・魔法ストック：1 行に 5 枚。説明文と小さい数値表示は隠し、文字を小さくする */
  #hand, #spellList { gap: 4px; }
  #spells { padding: 6px; }
  .sp-head { font-size: 12px; }
  .card { width: calc((100% - 16px) / 5); min-height: 0; padding: 3px 4px; border-radius: 8px; }
  .card.selected { transform: translateY(-4px); }
  .ctop { gap: 2px; min-height: 18px; }
  .ctype { font-size: 11px; }
  .celem { font-size: 10px; }
  .celem.dark { width: 16px; height: 16px; font-size: 9px; border-width: 1px; }
  .cbadge { max-width: 100%; padding: 0 4px; font-size: 12px; line-height: 16px; white-space: normal; text-align: right; border-radius: 8px; }
  .cbadge small { margin-left: 1px; font-size: 9px; }
  .cimg { margin: 2px 0 3px; border-radius: 4px; }
  .cname {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0 0 2px;
    font-size: 9.5px;
    line-height: 1.25;
  }
  .cval, .ctext { display: none; }
  .cno { left: 2px; right: 2px; bottom: 3px; padding: 0 2px; font-size: 8.5px; }

  /* ===== 1 画面に収める：ページはスクロールせず、入りきらない時は手札の枠の中だけスクロールする ===== */
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
  header { flex: none; height: 32px; }
  header h1 { font-size: 15px; }
  header button { padding: 2px 8px; font-size: 12px; }
  #phaseBar { flex: none; gap: 6px; height: 28px; padding: 0 10px; font-size: 13px; border-left-width: 6px; }
  .ph-icon { font-size: 15px; }
  .ph-text small { font-size: 11px; }
  #phaseBar .avatar { width: 20px; height: 20px; font-size: 9px; }
  main { flex: 1; gap: 4px; width: 100%; min-height: 0; padding: 4px 8px 6px; }
  #cards { order: 6; display: flex; flex-direction: column; flex: 1; gap: 4px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #cards #hand { order: 1; }
  #cards #spells { order: 2; }

  /* プレイヤーは 1 行のチップ（高さ 40px 固定） */
  #side #opponents, #side #opponents.duel { flex: none; gap: 4px; }
  #opponents.duel .pl, #side #me .pl {
    grid-template-columns: 26px minmax(0, 1fr) auto auto;
    grid-template-areas: "av head stats bar";
    column-gap: 6px;
    height: 40px;
    padding: 2px 8px;
    border-width: 2px;
  }
  #opponents.duel .pbar .bar, #side #me .pbar .bar { display: none; }
  #opponents:not(.duel) .pl {
    grid-template-columns: 22px minmax(0, 1fr);
    grid-template-areas: "av stats" "av bar";
    column-gap: 4px;
    row-gap: 2px;
    align-content: center;
    height: 40px;
    padding: 2px 5px;
  }
  /* 3 人のときは名前を出さない（アバターで見分ける）。吹き出しはチップ全体に重ねる */
  #opponents:not(.duel) .phead { position: absolute; inset: 0 4px; }
  #opponents:not(.duel) .pname, #opponents:not(.duel) .you { visibility: hidden; }
  #opponents .pl > .avatar, #me .pl > .avatar { width: 26px; height: 26px; font-size: 12px; border-width: 1px; }
  #opponents:not(.duel) .pl > .avatar { width: 22px; height: 22px; font-size: 11px; }
  #opponents .pl > .avatar.long, #me .pl > .avatar.long { font-size: 8px; }
  #opponents:not(.duel) .pl > .avatar.long { font-size: 7px; }
  .pname { font-size: 13px; }
  .you { padding: 0 3px; font-size: 9px; line-height: 14px; }
  .pstats { gap: 6px; }
  .php { font-size: 11px; }
  .php b { font-size: 18px; }
  .pmp { font-size: 10px; }
  .pmp b { font-size: 13px; }
  .phand, .pspell { font-size: 10px; }
  #opponents:not(.duel) .pstats { gap: 4px; }
  #opponents:not(.duel) .php b { font-size: 16px; }
  #opponents:not(.duel) .bar { height: 3px; }
  .st { padding: 0 3px; font-size: 10px; line-height: 15px; }
  .deadmark, #opponents:not(.duel) .deadmark, #me .deadmark { font-size: 24px; }
  .pl.current > .avatar::before { top: -5px; left: -6px; font-size: 9px; }
  .pl.targetable > .avatar::after { left: -6px; top: -7px; font-size: 12px; }
  .prole { top: -6px; right: 2px; width: 18px; height: 18px; font-size: 11px; }
  /* ダメージ・回復の数字はチップの上に浮かせて、HP・MP の数字に重ねない */
  .pop, #opponents:not(.duel) .pop, #me .pop { top: -12px; right: 24px; left: auto; z-index: 6; font-size: 16px; }
  .bubble { padding: 0 6px; font-size: 11px; line-height: 16px; }

  /* バトル場（高さ 132px 固定） */
  #field #stage { flex: none; grid-template-rows: 58px 30px minmax(0, 1fr); height: 132px; margin-top: 0; padding: 4px 6px; border-radius: 10px; }
  #stTurn { top: 3px; left: 4px; }
  .st-turn { gap: 3px; height: 20px; padding: 1px 7px 1px 2px; font-size: 10px; }
  .st-turn .avatar { width: 16px; height: 16px; font-size: 8px; }
  .st-who { width: 52px; }
  .st-who .avatar { width: 34px; height: 34px; font-size: 13px; }
  .st-who .avatar.long { font-size: 10px; }
  .st-av .you { bottom: -3px; }
  .st-nm { margin-top: 0; font-size: 9px; line-height: 11px; }
  .st-tgt { top: -5px; right: -7px; font-size: 13px; }
  .st-card { width: 76px; padding-bottom: 15px; }
  .mcard { min-height: 36px; padding: 2px 3px; border-radius: 6px; }
  .mcard .ctop { min-height: 13px; }
  .mcard .ctype, .mcard .celem { font-size: 9px; }
  .mcard .cbadge { height: 13px; padding: 0 3px; font-size: 10px; line-height: 13px; }
  .mcard .cbadge small { font-size: 8px; }
  .mcard .cname { font-size: 9px; line-height: 1.15; }
  .st-boost { padding: 0 3px; font-size: 9px; line-height: 12px; }
  .st-plus { padding: 0 3px; font-size: 8px; line-height: 12px; }
  .st-arrow, .st-fork { min-width: 12px; height: 22px; margin-bottom: 15px; }
  .st-arrow i, .st-fork i { top: 9px; height: 4px; }
  .st-arrow i::after { right: -8px; top: -5px; border-width: 7px; border-left-width: 9px; }
  .st-arrow.bent i { top: 4px; }
  .st-arrow.uturn i { top: 14px; }
  .st-q { top: -8px; font-size: 13px; }
  .st-gav .avatar { width: 24px; height: 24px; font-size: 10px; }
  .st-gav .avatar.long { font-size: 7px; }
  .st-gav .st-tgt { font-size: 11px; }
  .st-group { gap: 2px; }
  .st-gav .st-bub { top: 26px; bottom: auto; }
  .st-ghost .avatar { width: 18px; height: 18px; font-size: 8px; }
  .st-cost { font-size: 9px; line-height: 11px; }
  .st-bub { top: 34px; max-width: 42vw; padding: 0 6px; font-size: 10px; line-height: 15px; }
  .st-hit { left: -6px; top: -8px; padding: 0 3px; font-size: 11px; }
  .st-hit.dark { font-size: 14px; }
  .st-mid { gap: 6px; }
  .st-pow { font-size: 26px; }
  .st-chip { padding: 1px 6px; font-size: 11px; }
  .st-chip.big { padding: 1px 10px; font-size: 17px; }
  .st-big { font-size: 18px; }
  .st-big.heat.tick { font-size: 24px; }
  .st-pray { font-size: 28px; }
  .st-idle { font-size: 18px; }
  .st-idle2 { font-size: 13px; }
  #stBot { gap: 3px; }
  .st-eq, .eq-g1, .eq-g2, .eq-d { gap: 3px; }
  .eq-a { font-size: 16px; }
  .eq-op { font-size: 14px; }
  .eq-d b { font-size: 20px; }
  .eq-d.none { font-size: 15px; }
  .eq-d.slot { padding: 0 4px; font-size: 13px; border-radius: 7px; }
  .eq-d.ref { font-size: 17px; }
  .st-dchip { max-width: 54px; padding: 0 4px; font-size: 9px; line-height: 14px; }
  .st-dchip.sum { font-size: 10px; }
  .eq-r { font-size: 26px; }
  .eq-r small { font-size: 9px; }
  .eq-r.txt { font-size: 13px; }
  .eq-r.txt.big { font-size: 17px; }
  .eq-r.dark { padding: 0 6px; font-size: 17px; }
  .eq-r.wait { font-size: 12px; }
  .st-res .avatar { width: 20px; height: 20px; font-size: 8px; }
  .st-to { font-size: 12px; }
  .st-blk .avatar { width: 18px; height: 18px; font-size: 8px; }
  .st-blk .eq-d, .st-blk .eq-d.slot, .st-blk .eq-d.none, .st-blk .eq-d b { font-size: 12px; }
  .st-blk .eq-r { font-size: 14px; }
  /* 全体攻撃の小ブロックは 2 行で 32px に収める（強調枠は外側の線にして高さを増やさない） */
  .st-blk { gap: 1px; }
  .st-blk .b1 { height: 16px; }
  .st-blk .avatar { width: 16px; height: 16px; font-size: 7px; }
  .st-blk .b2 { height: 14px; line-height: 14px; }
  .st-blk .eq-r, .st-blk .eq-r.wait { font-size: 12px; }
  .st-blk .eq-d, .st-blk .eq-d.slot, .st-blk .eq-d.none, .st-blk .eq-d b { font-size: 11px; }
  .st-blk.live { border: none; outline: 2px solid #ef4444; outline-offset: -1px; }
  /* 端の人の吹き出しはステージの内側に寄せる（はみ出して切れないように） */
  #stTop > .st-who:first-child .st-bub { left: 0; transform: none; }
  #stTop > .st-who:last-child .st-bub, #stTop > .st-group .st-gav:last-child .st-bub { left: auto; right: 0; transform: none; }

  /* ログは 1 行 */
  #logTicker { flex: none; height: 22px; margin-top: 0; }
  #btnTicker { height: 22px; padding: 0 8px; font-size: 11px; border-radius: 6px; }

  /* 自分は 1 行のチップだけ（操作の案内はドックとフェーズバーで足りるので出さない） */
  #side #mePanel { flex: none; display: block; height: auto; margin-top: 0; padding: 0; border: none; }
  #side #control { display: none; }

  /* ドック：高さ 52px 固定・1 行。ボタンは高さ 44px */
  #dock { flex: none; height: 52px; min-height: 0; margin-top: 0; border-radius: 10px; }
  .dock-in { flex-wrap: nowrap; gap: 6px; height: 100%; padding: 2px 6px; }
  #dockInfo, #dock[data-mode="defend"] #dockInfo, #dock[data-mode="use"] #dockInfo {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
  }
  #dock[data-mode="defend"] #buttons, #dock[data-mode="use"] #buttons { flex: none; }
  #dockTargets { order: 0; flex: 0 1 auto; flex-basis: auto; gap: 4px; }
  .dk-line { flex: 0 1 auto; gap: 4px; height: auto; min-width: 0; }
  /* だれ→だれ はすぐ上のバトル場に大きく出ているので、ドックでは数字だけにする */
  #dock .dk-who { display: none; }
  #dock .eq-r small, #dock .dk-boost { display: none; }
  .dk-who { gap: 1px; }
  .dk-who .avatar, .dk-tg .avatar { width: 18px; height: 18px; font-size: 8px; }
  .dk-who .avatar.long, .dk-tg .avatar.long { font-size: 6px; }
  .dk-eq { gap: 3px; }
  .dk-eq > b, .dk-eq .eq-a, #dock .eq-d b, #dock .eq-d.ref { font-size: 15px; }
  #dock .eq-op { font-size: 12px; }
  #dock .eq-d.none, #dock .eq-d.slot { font-size: 12px; }
  #dock .eq-r { font-size: 20px; }
  #dock .eq-r small { font-size: 9px; }
  #dock .eq-r.txt { font-size: 12px; }
  #dock .st-chip { padding: 0 5px; font-size: 10px; }
  #dock .st-dchip { display: none; }
  .dk-eq small, .dk-boost { font-size: 10px; }
  .dk-hp { flex: none; font-size: 11px; line-height: 1; }
  .dk-hp b { font-size: 14px; }
  .dk-tg { flex: 0 1 auto; gap: 3px; height: 44px; padding: 0 6px 0 4px; }
  .dk-tg span { font-size: 11px; }
  .dk-tg b { font-size: 15px; }
  #buttons { gap: 4px; }
  #buttons button, #dock[data-mode="target"] #buttons button { height: 44px; padding: 0 10px; font-size: 14px; }
  #btnDefend, #btnUse { flex: none; min-width: 84px; }
  #btnDefend { font-size: 14px; border-width: 1px; }

  /* 手札・魔法ストック：画像なしの小さいカードを 1 行に 6 枚（高さをそろえる） */
  #hand, #spellList { gap: 4px; margin-top: 0; }
  #spells { margin-top: 0; padding: 4px; border-radius: 8px; }
  .sp-head { margin-bottom: 3px; font-size: 11px; }
  .sp-head small { display: none; }
  .card { width: calc((100% - 16px) / 5); padding: 3px 4px; border-width: 1px; border-radius: 6px; }
  .card.usable { box-shadow: inset 0 0 0 1px #22c55e, 0 0 6px #22c55e; }
  .card:hover, .card.selected { transform: none; }
  .card.selected { box-shadow: 0 0 0 2px var(--accent), 0 0 10px var(--accent); }
  .card.stackable, .card.discardable { outline-width: 2px; outline-offset: -3px; }
  .dk-count { font-size: 13px; }
  #btnDiscard { padding: 0 10px; }
  .cimgwrap { display: none; }
  /* 種類アイコンは色とバッジで分かるので隠し、バッジを 1 行に収めて高さをそろえる */
  #hand, #spellList { align-items: flex-start; }
  .ctop { flex-wrap: nowrap; gap: 1px; min-height: 18px; }
  .card .ctype { display: none; }
  /* 光・闇はカードの枠の色で分かるので、マークは隠してバッジの幅を確保する */
  .card .celem { display: none; }
  .cbadge i + i { margin-left: 1px; }
  .cbadge:has(small), .cbadge:has(i + i) { padding: 0 3px; font-size: 11.5px; }
  .cbadge i:not(:only-of-type) { font-size: 10.5px; }
  .cat-info .cbadge:has(small), .cat-info .cbadge:has(i + i) { padding: 0 5px; font-size: 13px; }
  .cat-info .cbadge i:not(:only-of-type) { font-size: 12px; }
  .cbadge { height: 18px; overflow: hidden; padding: 0 3px; font-size: 12.5px; line-height: 18px; letter-spacing: -.02em; white-space: nowrap; border-radius: 7px; }
  .cbadge small { margin-left: 0; font-size: 9px; }
  .cname { height: 2.5em; margin: 2px 0 0; font-size: 10.5px; line-height: 1.25; }
}

/* 動きを減らす設定：スライド・脈動・フラッシュを止め、情報は静的に表示 */
@media (prefers-reduced-motion: reduce) {
  #stage, #stage *, #phaseBar, .pl, .pl *, #tickerText span, .card, #dock * {
    animation: none !important;
    transition: none !important;
  }
  .st-fx { display: none; }
  body[data-phase="defend"] #stage { box-shadow: 0 0 0 4px #ef4444, 0 0 16px #ef4444; }
  .pop { transform: none; }
  #dock, #dock:not(.show) { transition: none; }
}
