@font-face {
  font-family: "Yuji Syuku";
  src: url("../assets/fonts/yuji-syuku.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "BIZ UDPGothic";
  src: url("../assets/fonts/biz-udpgothic.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "BIZ UDPGothic";
  src: url("../assets/fonts/biz-udpgothic-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #221d18;
  --ink2: #3a332b;
  --ink3: #6b6157;
  --paper: #f6f0e3;
  --paper2: #ebe2cf;
  --paper3: #d9ccb2;
  --tou: #a33327;
  --tou-l: #d0604f;
  --tou-d: #7f2821;
  --shin: #2e6e80;
  --shin-l: #4aa3bf;
  --shin-d: #1b5a6e;
  --gold: #c9a86a;
  --gold-l: #e6cf98;
  --night: #0d111b;
  --night2: #151c2c;
  --night3: #222b40;
  --brush: "Yuji Syuku", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --ui: "BIZ UDPGothic", "Yu Gothic", "Hiragino Sans", "Meiryo", sans-serif;
  --mm: 3px;
  --spd: 1;
  --hand-card: 92px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: radial-gradient(120% 90% at 50% 0%, #1b2338 0%, var(--night) 60%) fixed, var(--night);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button {
  font: inherit;
  color: inherit;
}
img {
  user-select: none;
  -webkit-user-drag: none;
}
[hidden] {
  display: none !important;
}
.brush {
  font-family: var(--brush);
  font-weight: 400;
}

/* ---------- 汎用ボタン ---------- */
.btn {
  appearance: none;
  border: 1px solid rgba(201, 168, 106, 0.55);
  background: linear-gradient(180deg, #2b3247, #1c2233);
  color: var(--paper);
  padding: 0.55em 1.1em;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: transform 0.12s, box-shadow 0.12s, background 0.2s, opacity 0.2s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  min-height: 40px;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
.btn.primary {
  border-color: var(--gold);
  background: linear-gradient(180deg, #d9b977, #b48f4c);
  color: #1e1710;
}
.btn.tou {
  border-color: #e08a7d;
  background: linear-gradient(180deg, var(--tou-l), var(--tou));
  color: #fff8ef;
}
.btn.shin {
  border-color: #7cc4d9;
  background: linear-gradient(180deg, var(--shin-l), var(--shin));
  color: #f2fbff;
}
.btn.ghost {
  background: transparent;
  border-color: rgba(246, 240, 227, 0.25);
  box-shadow: none;
}
.btn.small {
  padding: 0.3em 0.75em;
  min-height: 32px;
  font-size: 13px;
}
.icon-btn {
  appearance: none;
  border: 1px solid rgba(246, 240, 227, 0.18);
  background: rgba(255, 255, 255, 0.04);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--paper);
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.icon-btn svg {
  width: 19px;
  height: 19px;
}

/* ---------- タイトル ---------- */
#title-screen {
  position: fixed;
  inset: 0;
  overflow: hidden auto;
  background: var(--night);
}
.title-bg {
  position: absolute;
  inset: 0;
  background: url("../assets/kv.jpg") center 30% / cover no-repeat;
  filter: saturate(0.9) brightness(0.72);
  transform: scale(1.04);
  animation: kvDrift 40s ease-in-out infinite alternate;
}
@keyframes kvDrift {
  from {
    transform: scale(1.04) translate(0, 0);
  }
  to {
    transform: scale(1.1) translate(-1.5%, -1%);
  }
}
.title-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 10, 18, 0.15) 0%, rgba(8, 10, 18, 0.25) 40%, rgba(8, 10, 18, 0.88) 78%, rgba(8, 10, 18, 0.96) 100%);
}
.title-inner {
  position: relative;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 24px 16px 28px;
  gap: 14px;
  text-align: center;
}
.title-logo {
  width: min(560px, 82vw);
  filter: invert(0.94) sepia(0.25) drop-shadow(0 4px 18px rgba(0, 0, 0, 0.7));
  margin-bottom: 0;
}
.title-tag {
  font-family: var(--brush);
  font-size: clamp(16px, 2.4vw, 22px);
  letter-spacing: 0.3em;
  color: var(--gold-l);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  margin: -4px 0 4px;
}
.title-sub {
  font-size: 13px;
  color: rgba(246, 240, 227, 0.75);
  letter-spacing: 0.08em;
}
.title-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(560px, 100%);
}
.side-btn {
  appearance: none;
  border-radius: 12px;
  padding: 14px 12px 12px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 10px;
  text-align: left;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
.side-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
.side-btn img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
}
.side-btn b {
  font-family: var(--brush);
  font-weight: 400;
  font-size: 22px;
  display: block;
  line-height: 1.2;
}
.side-btn span {
  font-size: 12px;
  opacity: 0.88;
  display: block;
  line-height: 1.45;
  margin-top: 2px;
}
.side-btn.tou {
  background: linear-gradient(160deg, rgba(208, 96, 79, 0.92), rgba(127, 40, 33, 0.92));
}
.side-btn.shin {
  background: linear-gradient(160deg, rgba(74, 163, 191, 0.92), rgba(27, 90, 110, 0.92));
}
.title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  width: min(560px, 100%);
}
.seg {
  display: inline-flex;
  border: 1px solid rgba(246, 240, 227, 0.25);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: rgba(246, 240, 227, 0.8);
  min-height: 34px;
}
.seg button[aria-pressed="true"] {
  background: var(--gold);
  color: #1e1710;
  font-weight: 700;
}
.seg-label {
  font-size: 12px;
  color: rgba(246, 240, 227, 0.7);
}
.title-foot {
  font-size: 12px;
  color: rgba(246, 240, 227, 0.6);
  line-height: 1.7;
}
.title-foot a {
  color: var(--gold-l);
}
.site-home {
  margin-top: 10px;
  font-size: 14px;
}
.event-badge {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(201, 168, 106, 0.5);
  border-radius: 999px;
  padding: 4px 14px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 12.5px;
  color: var(--gold-l);
  text-decoration: none;
}

/* ---------- ゲーム画面の骨組み ---------- */
#game {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(196px, 250px) minmax(0, 1fr) minmax(196px, 250px);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "hud hud hud"
    "tou board shin"
    "prompt prompt prompt"
    "hand hand hand";
  gap: 0;
}
#hud {
  grid-area: hud;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.15));
  border-bottom: 1px solid rgba(201, 168, 106, 0.2);
  min-height: 50px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
}
.hud-logo {
  height: 26px;
  filter: invert(0.94) sepia(0.25);
  cursor: pointer;
}
.hud-phase {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--brush);
  font-size: 19px;
  letter-spacing: 0.08em;
}
.hud-phase img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  padding: 3px;
  border-radius: 50%;
  background: radial-gradient(circle, #f7efd9 0%, #e7d8b4 100%);
}
.hud-step {
  font-size: 12.5px;
  color: rgba(246, 240, 227, 0.72);
  font-family: var(--ui);
  letter-spacing: 0;
  margin-left: 4px;
}
.kiun-bar {
  width: 220px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  position: relative;
}
.kiun-bar .tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(13, 17, 27, 0.55);
}
.hud-float {
  position: fixed;
  z-index: 70;
  font-size: 30px;
}
.kiun-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #e3a35b, var(--tou-l));
  border-radius: 999px;
  transition: width calc(0.6s * var(--spd));
}
.kiun-num {
  white-space: nowrap;
  font-family: var(--brush);
  font-size: 20px;
  min-width: 64px;
}
.kiun-num small {
  font-size: 12px;
  font-family: var(--ui);
  color: rgba(246, 240, 227, 0.6);
}
.hud-tools {
  display: flex;
  gap: 6px;
}

/* ---------- 人物パネル ---------- */
.panel {
  padding: 8px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
#panel-tou {
  grid-area: tou;
}
#panel-shin {
  grid-area: shin;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px 4px;
  border-bottom: 2px solid currentColor;
}
.panel-head .brush {
  font-size: 19px;
  letter-spacing: 0.1em;
}
.panel-head small {
  font-size: 11.5px;
  color: rgba(246, 240, 227, 0.7);
}
.panel.tou .panel-head {
  color: var(--tou-l);
}
.panel.shin .panel-head {
  color: var(--shin-l);
}
.persons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.person {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 5px 6px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
.person.selectable {
  border-color: var(--gold);
  background: rgba(201, 168, 106, 0.12);
  cursor: pointer;
}
.person.selected {
  background: rgba(201, 168, 106, 0.28);
}
.person .pcard {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  cursor: zoom-in;
}
.person .pcard > * {
  width: 41px;
  height: 60px;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform calc(0.45s * var(--spd)) cubic-bezier(0.3, 1.4, 0.6, 1);
}
.person.active .pcard > * {
  transform: rotate(90deg);
}
.person.injured .pcard > * {
  filter: grayscale(0.85) brightness(0.7);
}
.pinfo {
  min-width: 0;
}
.pname {
  font-family: var(--brush);
  font-size: 16px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 6px;
}
.patk {
  font-family: var(--ui);
  font-weight: 700;
  font-size: 12px;
  border-radius: 999px;
  padding: 0 7px;
  background: rgba(255, 255, 255, 0.12);
}
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}
.badge {
  font-size: 11px;
  border-radius: 4px;
  padding: 0 5px;
  line-height: 18px;
  background: rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}
.badge.active {
  background: var(--gold);
  color: #1e1710;
  font-weight: 700;
}
.badge.injured {
  background: #8f1f1f;
  color: #fff;
  font-weight: 700;
}
.badge.where {
  background: rgba(74, 163, 191, 0.25);
}
.uniques {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.mini-card {
  width: 26px;
  height: 38px;
  border-radius: 2px;
  background-size: cover;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  cursor: zoom-in;
  position: relative;
  border: 0;
  padding: 0;
}
.mini-card.playable {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  animation: pulse 1.6s ease-in-out infinite;
  cursor: pointer;
}
.toggle-ability {
  margin-top: 4px;
}
.side-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  color: rgba(246, 240, 227, 0.78);
  padding: 2px 4px;
}
.opp-hand {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 2px 4px;
}
.opp-hand .back {
  width: 22px;
  height: 32px;
  border-radius: 2px;
  background: url("../assets/cards/back.jpg") center / cover;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  margin-right: -10px;
}
.opp-hand .face {
  width: 48px;
  height: 70px;
  border-radius: 2px;
  background-size: cover;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  cursor: zoom-in;
  border: 0;
  padding: 0;
}
.opp-hand .label {
  font-size: 12px;
  margin-left: 14px;
  color: rgba(246, 240, 227, 0.75);
}

/* ---------- 盤面 ---------- */
#board-wrap {
  grid-area: board;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
  min-width: 0;
  padding: 6px;
  position: relative;
}
#board {
  position: relative;
  width: 728px;
  height: 528px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(201, 168, 106, 0.25);
  user-select: none;
  touch-action: manipulation;
}
#board .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity calc(1.4s * var(--spd)) ease;
}
#board .layer.night {
  opacity: 0;
}
#board.is-night .layer.night {
  opacity: 1;
}
#board {
  background: #d8cfb9;
}
#board .layer {
  filter: saturate(0.92);
}
.fac {
  position: absolute;
  border-radius: calc(var(--mm) * 2);
  background: rgba(255, 253, 245, 0.74);
  border: calc(var(--mm) * 0.6) solid #514838;
  box-shadow: 0 calc(var(--mm) * 0.8) calc(var(--mm) * 3) rgba(30, 24, 16, 0.35);
  transition: box-shadow 0.25s, background 0.25s;
}
#board.is-night .fac {
  background: rgba(222, 224, 236, 0.74);
  border-color: #2f3346;
  box-shadow: 0 calc(var(--mm) * 0.8) calc(var(--mm) * 4) rgba(0, 0, 0, 0.55);
}
.fac-name {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--mm) * 0.8);
  text-align: center;
  font-family: var(--brush);
  font-size: calc(var(--mm) * 7.4);
  line-height: 1.05;
  color: #302c25;
  pointer-events: none;
}
.fac-name small {
  display: block;
  font-family: var(--ui);
  font-weight: 700;
  font-size: calc(var(--mm) * 3.4);
  line-height: 1.2;
  color: #4e4538;
}
#hud {
  position: relative;
}
.hud-tools {
  margin-left: auto;
}
.kiun-gauge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 18px;
  border-radius: 999px;
  background: rgba(13, 17, 27, 0.72);
  border: 1px solid rgba(201, 168, 106, 0.55);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  max-width: 100%;
}
.kg-label {
  font-family: var(--brush);
  font-size: 18px;
  letter-spacing: 0.1em;
  color: var(--gold-l);
  white-space: nowrap;
}
.kg-num {
  font-family: var(--brush);
  font-weight: 400;
  font-size: 32px;
  line-height: 1;
  min-width: 1.3em;
  text-align: center;
  color: #ffb4a6;
  text-shadow: 0 0 12px rgba(208, 96, 79, 0.6);
  font-variant-numeric: tabular-nums;
}
.kg-num.bump {
  animation: kgBump calc(0.5s * var(--spd)) ease-out;
}
@keyframes kgBump {
  40% {
    transform: scale(1.35);
    color: #fff;
  }
}
.kg-goal {
  font-size: 13px;
  color: rgba(246, 240, 227, 0.6);
  margin-left: -6px;
}
.kg-bar {
  display: flex;
  gap: 3px;
}
.kg-bar i {
  width: 22px;
  height: 14px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.3s, box-shadow 0.3s;
}
.kg-bar i.on {
  background: linear-gradient(180deg, var(--tou-l), var(--tou));
  box-shadow: 0 0 6px rgba(208, 96, 79, 0.6);
}
.kg-bar i.goal {
  outline: 1px solid rgba(208, 96, 79, 0.9);
  outline-offset: 1px;
}
.reserve-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  max-width: 100%;
}
.reserve {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 12px;
  border-radius: 8px;
  background: rgba(255, 253, 245, 0.06);
  border: 1px solid rgba(208, 96, 79, 0.55);
}
.reserve.shin {
  border-color: rgba(74, 163, 191, 0.55);
}
.rlabel {
  font-family: var(--brush);
  font-size: 14px;
  color: var(--tou-l);
  white-space: nowrap;
}
.reserve.shin .rlabel {
  color: var(--shin-l);
}
.rlabel .short {
  display: none;
}
.reserve .slots {
  display: flex;
  gap: 4px;
}
.reserve .slot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px dashed rgba(208, 96, 79, 0.6);
  position: relative;
  --d: 26px;
}
.reserve.shin .slot {
  border-color: rgba(74, 163, 191, 0.6);
}
.reserve .slot .piece {
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transition: none;
}
.rcount {
  font-size: 12px;
  color: rgba(246, 240, 227, 0.7);
  font-variant-numeric: tabular-nums;
  min-width: 2.4em;
}
.links {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.link {
  position: absolute;
  background: #d54736;
  box-shadow: 0 0 0 calc(var(--mm) * 0.7) #fffaf0;
  border-radius: 999px;
}
.link.h {
  width: var(--len);
  height: calc(var(--mm) * 1.4);
  transform: translateY(-50%);
}
.link.v {
  width: calc(var(--mm) * 1.4);
  height: var(--len);
  transform: translateX(-50%);
}
.fac.selectable {
  cursor: pointer;
  box-shadow: 0 0 0 calc(var(--mm) * 0.8) var(--gold), 0 0 calc(var(--mm) * 6) rgba(230, 207, 152, 0.75);
  background-image: linear-gradient(rgba(230, 207, 152, 0.2), rgba(230, 207, 152, 0.2));
  animation: facPulse 1.5s ease-in-out infinite;
}
.fac:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.fac.selectable:hover {
  background-image: linear-gradient(rgba(230, 207, 152, 0.38), rgba(230, 207, 152, 0.38));
}
.fac.picked {
  box-shadow: 0 0 0 calc(var(--mm) * 1.1) #fff, 0 0 calc(var(--mm) * 8) rgba(255, 255, 255, 0.8);
  background-image: linear-gradient(rgba(255, 246, 220, 0.45), rgba(255, 246, 220, 0.45));
}
.fac.battle {
  box-shadow: 0 0 0 calc(var(--mm) * 1) #ff6a4a, 0 0 calc(var(--mm) * 10) rgba(255, 106, 74, 0.8);
}
.fac.dim {
  background-image: linear-gradient(rgba(10, 12, 20, 0.35), rgba(10, 12, 20, 0.35));
}
@keyframes facPulse {
  50% {
    box-shadow: 0 0 0 calc(var(--mm) * 0.8) var(--gold), 0 0 calc(var(--mm) * 2) rgba(230, 207, 152, 0.3);
  }
}
@keyframes pulse {
  50% {
    outline-color: rgba(201, 168, 106, 0.35);
  }
}
.fac .blockade {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(45deg, rgba(20, 16, 14, 0.55) 0 calc(var(--mm) * 2), rgba(20, 16, 14, 0.42) calc(var(--mm) * 2) calc(var(--mm) * 4));
  display: grid;
  place-items: center;
  pointer-events: none;
}
.seal {
  font-family: var(--brush);
  color: #fff3ea;
  background: #b0281c;
  border-radius: calc(var(--mm) * 1.5);
  font-size: calc(var(--mm) * 9);
  line-height: 1;
  padding: calc(var(--mm) * 2) calc(var(--mm) * 2.4);
  box-shadow: 0 0 0 calc(var(--mm) * 0.6) #fff3ea inset, 0 2px 8px rgba(0, 0, 0, 0.5);
  transform: rotate(-8deg);
  opacity: 0.94;
}
.fac .count {
  position: absolute;
  right: calc(var(--mm) * 2);
  top: calc(var(--mm) * 1.5);
  font-size: calc(var(--mm) * 4.2);
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  padding: 0 calc(var(--mm) * 1.6);
  line-height: calc(var(--mm) * 6.4);
  pointer-events: none;
}
.fac .results {
  position: absolute;
  left: 50%;
  bottom: calc(var(--mm) * -2);
  transform: translate(-50%, 0);
  pointer-events: none;
}
.setcards {
  position: absolute;
  left: 2.5%;
  top: 2.5%;
  display: flex;
  pointer-events: auto;
  z-index: 1;
}
.setcard {
  width: calc(var(--mm) * 9);
  height: calc(var(--mm) * 13.1);
  border-radius: calc(var(--mm) * 0.6);
  background-size: cover;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  margin-right: calc(var(--mm) * -3.5);
  cursor: zoom-in;
  border: 0;
  padding: 0;
  position: relative;
}
.setcard.kaiju-stack::after {
  content: attr(data-n);
  position: absolute;
  right: -4px;
  bottom: -4px;
  background: var(--tou);
  color: #fff;
  font-size: calc(var(--mm) * 3.4);
  line-height: calc(var(--mm) * 5);
  min-width: calc(var(--mm) * 5);
  border-radius: 999px;
  text-align: center;
  font-weight: 700;
}

.piece {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  transition: left calc(0.55s * var(--spd)) cubic-bezier(0.3, 0.9, 0.4, 1), top calc(0.55s * var(--spd)) cubic-bezier(0.3, 0.9, 0.4, 1), width 0.3s, height 0.3s, opacity 0.3s;
  pointer-events: none;
  will-change: left, top;
}
.piece .disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 calc(var(--mm) * 0.6) calc(var(--mm) * 1.4) rgba(0, 0, 0, 0.55), inset 0 0 0 calc(var(--mm) * 0.35) rgba(0, 0, 0, 0.25);
}
.piece.red .disc {
  background: radial-gradient(circle at 34% 30%, #d8685a 0%, #ae3b32 52%, #7a251f 100%);
}
.piece.blue .disc {
  background: radial-gradient(circle at 34% 30%, #4aa8c4 0%, #287d98 52%, #17505f 100%);
}
.piece.ink .disc {
  background: radial-gradient(circle at 34% 30%, #7a746c 0%, #3a3632 55%, #191715 100%);
  box-shadow: 0 calc(var(--mm) * 0.6) calc(var(--mm) * 1.6) rgba(0, 0, 0, 0.7), 0 0 0 calc(var(--mm) * 0.5) var(--gold) inset;
}
.piece .face {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 calc(var(--mm) * 0.4) rgba(0, 0, 0, 0.4);
}
.piece .glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--brush);
  color: #fff4e6;
  font-size: calc(var(--d) * 0.5);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.piece .glyph small {
  position: absolute;
  right: 12%;
  bottom: 8%;
  font-family: var(--ui);
  font-weight: 700;
  font-size: calc(var(--d) * 0.24);
}
.piece.marker .glyph {
  font-size: calc(var(--d) * 0.56);
  color: #f6e7c4;
}
.piece.extra .disc {
  box-shadow: 0 calc(var(--mm) * 0.6) calc(var(--mm) * 1.4) rgba(0, 0, 0, 0.55), inset 0 0 0 calc(var(--mm) * 0.5) rgba(255, 238, 210, 0.7);
}
/* 自分だけが知っている伏せチップ */
.piece.secret .disc {
  filter: brightness(0.62) saturate(0.8);
}
.piece.secret .face {
  opacity: 0.88;
  filter: brightness(0.8);
}
.piece.secret::after {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  border: calc(var(--mm) * 0.45) dashed rgba(255, 220, 200, 0.75);
}
.piece.draft {
  pointer-events: auto;
  cursor: pointer;
}
.piece.draft:hover::before {
  content: "×";
  position: absolute;
  right: -10%;
  top: -10%;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: calc(var(--d) * 0.3);
  display: grid;
  place-items: center;
  z-index: 2;
}
.piece.injured .disc,
.piece.injured .face {
  filter: grayscale(0.9) brightness(0.65);
}
.piece.injured::before {
  content: "傷";
  position: absolute;
  right: -12%;
  top: -12%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: #8f1f1f;
  color: #fff;
  font-family: var(--brush);
  font-size: calc(var(--d) * 0.28);
  display: grid;
  place-items: center;
  z-index: 2;
  box-shadow: 0 0 0 1px #fff;
}
.piece.drop {
  animation: drop calc(0.42s * var(--spd)) cubic-bezier(0.3, 1.5, 0.6, 1) both;
}
@keyframes drop {
  from {
    transform: translate(-50%, -110%) scale(1.5);
    opacity: 0;
  }
  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}
.piece.lift {
  z-index: 5;
}

/* ---------- 指示バーと手札 ---------- */
#prompt {
  grid-area: prompt;
  background: linear-gradient(180deg, #f8f2e5, #ece2cd);
  color: var(--ink);
  border-top: 3px solid var(--gold);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 62px;
  position: relative;
  z-index: 3;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
}
#prompt.tou {
  border-top-color: var(--tou);
}
#prompt.shin {
  border-top-color: var(--shin);
}
.prompt-who {
  font-family: var(--brush);
  font-size: 15px;
  border-radius: 6px;
  padding: 2px 10px;
  color: #fff;
  background: var(--ink2);
  white-space: nowrap;
}
.prompt-who.tou {
  background: var(--tou);
}
.prompt-who.shin {
  background: var(--shin);
}
.prompt-text {
  flex: 1 1 260px;
  min-width: 0;
  font-size: 14.5px;
  line-height: 1.55;
}
.prompt-text b {
  color: var(--tou-d);
}
.prompt-text .note {
  display: block;
  font-size: 12.5px;
  color: var(--ink3);
}
.prompt-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
#prompt .btn.ghost {
  color: var(--ink);
  border-color: rgba(34, 29, 24, 0.3);
}
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink3);
}
.thinking i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1s infinite;
}
.thinking i:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking i:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  50% {
    opacity: 0.2;
  }
}
.tray {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
}
.tray-item {
  appearance: none;
  border: 2px solid transparent;
  background: rgba(34, 29, 24, 0.06);
  border-radius: 10px;
  padding: 4px 8px 4px 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  min-height: 44px;
}
.tray-item:disabled {
  opacity: 0.35;
  cursor: default;
}
.tray-item.on {
  border-color: var(--gold);
  background: rgba(201, 168, 106, 0.3);
}
.tray-item .tchip {
  width: 34px;
  height: 34px;
  position: relative;
  --d: 34px;
}
.tray-item .tchip .piece {
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  transition: none;
}

#hand {
  grid-area: hand;
  background: linear-gradient(180deg, #1a2030, #121725);
  border-top: 1px solid rgba(201, 168, 106, 0.2);
  padding: 8px 12px 10px;
  display: flex;
  gap: 14px;
  align-items: flex-end;
  overflow-x: auto;
  min-height: calc(var(--hand-card) * 1.46 + 30px);
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.hand-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hand-label {
  font-size: 11.5px;
  color: rgba(246, 240, 227, 0.65);
  letter-spacing: 0.06em;
}
.hand-cards {
  display: flex;
  gap: 6px;
}
.card {
  width: var(--hand-card);
  aspect-ratio: 59 / 86;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  cursor: zoom-in;
  position: relative;
  border: 0;
  padding: 0;
  transition: transform 0.18s, box-shadow 0.18s, filter 0.2s;
  flex: 0 0 auto;
}
.card:hover {
  transform: translateY(-4px);
}
.card.playable {
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--gold), 0 6px 18px rgba(201, 168, 106, 0.45);
}
.card.selected {
  transform: translateY(-14px);
  box-shadow: 0 0 0 3px #fff, 0 10px 24px rgba(255, 255, 255, 0.35);
}
.card.dim {
  filter: brightness(0.55) saturate(0.6);
}
.card.new {
  animation: dealIn calc(0.5s * var(--spd)) cubic-bezier(0.3, 1.3, 0.6, 1) both;
}
@keyframes dealIn {
  from {
    transform: translateY(-60px) rotate(-8deg) scale(0.6);
    opacity: 0;
  }
}
.card .tagline {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -18px;
  text-align: center;
  font-size: 10.5px;
  color: rgba(246, 240, 227, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hand-group.uniq .hand-cards {
  padding-bottom: 18px;
}
.hand-group.uniq .card {
  width: calc(var(--hand-card) * 0.83);
}
.hand-empty {
  font-size: 13px;
  color: rgba(246, 240, 227, 0.55);
  padding: 20px 6px;
}
.pile {
  display: flex;
  gap: 10px;
  margin-left: auto;
  align-self: center;
  font-size: 12px;
  color: rgba(246, 240, 227, 0.7);
}
.pile div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.pile .back {
  width: 34px;
  height: 50px;
  border-radius: 3px;
  background: url("../assets/cards/back.jpg") center / cover;
  box-shadow: 2px 2px 0 #2a2a2a, 3px 3px 6px rgba(0, 0, 0, 0.5);
}
.pile .discard {
  width: 34px;
  height: 50px;
  border-radius: 3px;
  border: 1px dashed rgba(246, 240, 227, 0.3);
  background-size: cover;
}

/* ---------- モーダル ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.62);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 14px;
  animation: fadeIn 0.2s both;
}
.backdrop.clear {
  background: rgba(6, 8, 14, 0.3);
  backdrop-filter: none;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
}
.modal {
  background: linear-gradient(180deg, #faf5ea, #efe6d2);
  color: var(--ink);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(201, 168, 106, 0.6);
  width: min(560px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 18px 20px;
  position: relative;
  animation: popIn calc(0.28s * var(--spd)) cubic-bezier(0.3, 1.3, 0.6, 1) both;
}
@keyframes popIn {
  from {
    transform: translateY(14px) scale(0.96);
    opacity: 0;
  }
}
.modal h2 {
  font-family: var(--brush);
  font-weight: 400;
  font-size: 24px;
  margin: 0 0 8px;
  letter-spacing: 0.06em;
}
.modal h3 {
  font-size: 15px;
  margin: 14px 0 4px;
  border-left: 4px solid var(--gold);
  padding-left: 8px;
}
.modal p {
  margin: 6px 0;
}
.modal .close {
  position: absolute;
  right: 10px;
  top: 10px;
  appearance: none;
  border: 0;
  background: rgba(0, 0, 0, 0.06);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  color: var(--ink);
}
.modal .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}
.modal .btn.ghost {
  color: var(--ink);
  border-color: rgba(34, 29, 24, 0.3);
}
.card-zoom {
  display: grid;
  grid-template-columns: minmax(0, 300px) 1fr;
  gap: 18px;
  align-items: start;
  width: min(760px, 100%);
}
.card-zoom img {
  width: 100%;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.card-zoom .ctext {
  font-size: 14px;
  white-space: pre-line;
}
.card-zoom .side-text {
  margin-top: 8px;
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-line;
  font-size: 13.5px;
}
.side-text.tou {
  background: rgba(163, 51, 39, 0.1);
  border-left: 4px solid var(--tou);
}
.side-text.shin {
  background: rgba(46, 110, 128, 0.1);
  border-left: 4px solid var(--shin);
}
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.choice {
  appearance: none;
  border: 2px solid rgba(34, 29, 24, 0.15);
  background: #fff;
  border-radius: 10px;
  padding: 10px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}
.choice img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
}
.choice .cimg {
  width: 80px;
  border-radius: 6px;
  height: auto;
}
.choice.on {
  border-color: var(--gold);
  background: #fff6df;
}
.choice:disabled {
  opacity: 0.4;
  cursor: default;
}

/* 戦闘 */
.battle {
  width: min(980px, 100%);
  padding: 16px 18px 18px;
  background: radial-gradient(130% 120% at 50% 0%, #2a2230 0%, #15121b 70%);
  color: var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(201, 168, 106, 0.5);
}
.battle h2 {
  text-align: center;
  font-size: 30px;
  margin: 0;
  color: var(--gold-l);
}
.battle .bsub {
  text-align: center;
  font-size: 12.5px;
  color: rgba(246, 240, 227, 0.65);
  margin-bottom: 10px;
}
.bgrid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: stretch;
}
.bside {
  border-radius: 12px;
  padding: 10px;
  min-width: 0;
}
.bside.tou {
  background: linear-gradient(180deg, rgba(163, 51, 39, 0.35), rgba(163, 51, 39, 0.12));
  border: 1px solid rgba(208, 96, 79, 0.45);
}
.bside.shin {
  background: linear-gradient(180deg, rgba(46, 110, 128, 0.38), rgba(46, 110, 128, 0.12));
  border: 1px solid rgba(74, 163, 191, 0.45);
}
.bside h3 {
  margin: 0 0 6px;
  font-family: var(--brush);
  font-weight: 400;
  font-size: 18px;
  border: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;
}
.bfighters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.bfighter {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 64px;
  font-size: 11.5px;
  text-align: center;
  position: relative;
}
.bfighter img {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.bfighter.injured img {
  filter: grayscale(1) brightness(0.6);
}
.bfighter .stamp {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%) rotate(-12deg);
  font-family: var(--brush);
  background: #8f1f1f;
  color: #fff;
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px #fff;
  animation: stampIn calc(0.35s * var(--spd)) cubic-bezier(0.3, 1.6, 0.6, 1) both;
}
.bfighter .escaped {
  background: #6b6157;
}
@keyframes stampIn {
  from {
    transform: translateX(-50%) rotate(-12deg) scale(2.4);
    opacity: 0;
  }
}
.bitems {
  font-size: 12.5px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 10px;
  margin: 4px 0;
}
.bitems .v {
  text-align: right;
  font-weight: 700;
}
.bitems .card-item {
  color: var(--gold-l);
}
.bitems .null {
  text-decoration: line-through;
  opacity: 0.55;
}
.bcards {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 74px;
  margin-top: 6px;
}
.bcard {
  width: 52px;
  aspect-ratio: 59 / 86;
  border-radius: 4px;
  background-size: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  position: relative;
  border: 0;
  padding: 0;
  cursor: zoom-in;
}
.bcard.back {
  background-image: url("../assets/cards/back.jpg");
}
.bcard.nullified::after {
  content: "無効";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 14, 0.62);
  color: #ffdcd2;
  font-family: var(--brush);
  font-size: 16px;
  border-radius: 4px;
}
.bcard.flip {
  animation: cardFlip calc(0.5s * var(--spd)) ease both;
}
@keyframes cardFlip {
  0% {
    transform: rotateY(90deg);
  }
  100% {
    transform: rotateY(0);
  }
}
.bvs {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 110px;
}
.bscore {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--brush);
}
.bscore .t {
  font-size: 46px;
  color: #ff9a86;
}
.bscore .s {
  font-size: 46px;
  color: #8fd3ea;
}
.bscore .x {
  font-size: 18px;
  color: rgba(246, 240, 227, 0.6);
}
.bwinner {
  font-family: var(--brush);
  font-size: 26px;
  padding: 2px 14px;
  border-radius: 8px;
  animation: stampWin calc(0.45s * var(--spd)) cubic-bezier(0.3, 1.6, 0.6, 1) both;
  text-align: center;
  line-height: 1.3;
}
.bwinner small {
  display: block;
  font-family: var(--ui);
  font-size: 11px;
}
.bwinner.tou {
  background: var(--tou);
}
.bwinner.shin {
  background: var(--shin);
}
@keyframes stampWin {
  from {
    transform: scale(2.2) rotate(-6deg);
    opacity: 0;
  }
}
.bpick {
  margin-top: 12px;
  border-top: 1px solid rgba(246, 240, 227, 0.15);
  padding-top: 10px;
}
.bpick .hand-cards {
  flex-wrap: wrap;
}
.bpick .card {
  --hand-card: 84px;
}
.bpick-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 13.5px;
}
.bpick-head b {
  font-family: var(--brush);
  font-weight: 400;
  font-size: 17px;
  color: var(--gold-l);
}
.preview {
  font-size: 13px;
  color: rgba(246, 240, 227, 0.85);
}
.battle .actions .btn.ghost {
  color: var(--paper);
  border-color: rgba(246, 240, 227, 0.3);
}

/* 集計 */
.tally-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-top: 6px;
}
.tally-table th,
.tally-table td {
  padding: 6px 6px;
  border-bottom: 1px solid rgba(34, 29, 24, 0.12);
  text-align: left;
  vertical-align: top;
}
.tally-table td:first-child,
.tally-table th {
  white-space: nowrap;
}
.tally-table td.num {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}
.tally-table .plus {
  color: var(--tou);
}
.tally-table .minus {
  color: var(--shin);
}
.tally-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 15px;
}
.tally-total .big {
  font-family: var(--brush);
  font-size: 30px;
}
.res-tag {
  white-space: nowrap;
  font-size: 11.5px;
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 700;
  color: #fff;
}
.res-tag.success {
  background: var(--tou);
}
.res-tag.fail {
  background: var(--shin);
}

/* 演出 */
.banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 38%;
  z-index: 60;
  pointer-events: none;
  display: grid;
  place-items: center;
}
.banner .inner {
  font-family: var(--brush);
  font-size: clamp(34px, 7vw, 72px);
  letter-spacing: 0.25em;
  padding: 10px 60px 10px 80px;
  color: #fff8ec;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
  background: linear-gradient(90deg, transparent, rgba(10, 10, 16, 0.78) 18%, rgba(10, 10, 16, 0.78) 82%, transparent);
  animation: bannerIn calc(1.6s * var(--spd)) ease both;
  display: flex;
  align-items: center;
  gap: 16px;
}
.banner .inner img {
  width: 0.9em;
  height: 0.9em;
  object-fit: contain;
}
.banner .inner small {
  font-size: 0.35em;
  letter-spacing: 0.1em;
  display: block;
  opacity: 0.8;
}
.banner.tou .inner {
  background: linear-gradient(90deg, transparent, rgba(127, 40, 33, 0.85) 18%, rgba(127, 40, 33, 0.85) 82%, transparent);
}
.banner.shin .inner {
  background: linear-gradient(90deg, transparent, rgba(27, 90, 110, 0.85) 18%, rgba(27, 90, 110, 0.85) 82%, transparent);
}
@keyframes bannerIn {
  0% {
    opacity: 0;
    transform: translateX(-40px);
    letter-spacing: 0.6em;
  }
  20% {
    opacity: 1;
    transform: none;
    letter-spacing: 0.25em;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(30px);
  }
}
.toasts {
  position: fixed;
  top: 60px;
  right: 14px;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
  width: min(380px, 92vw);
}
@media (max-width: 860px) {
  .toasts {
    right: 50%;
    transform: translateX(50%);
    align-items: center;
  }
}
.toast {
  background: rgba(16, 18, 28, 0.92);
  border: 1px solid rgba(201, 168, 106, 0.4);
  color: var(--paper);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.3s both;
  text-align: center;
}
.toast.tou {
  border-color: var(--tou-l);
}
.toast.shin {
  border-color: var(--shin-l);
}
.toast.out {
  animation: toastOut 0.4s both;
}
@keyframes toastIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
}
@keyframes toastOut {
  to {
    transform: translateY(-10px);
    opacity: 0;
  }
}
.showcard {
  position: fixed;
  inset: 0;
  z-index: 58;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.showcard .wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: showCard calc(1.5s * var(--spd)) ease both;
}
.showcard img {
  width: min(220px, 46vw);
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}
.showcard .who {
  font-family: var(--brush);
  font-size: 18px;
  padding: 2px 14px;
  border-radius: 6px;
  color: #fff;
}
.showcard .who.tou {
  background: var(--tou);
}
.showcard .who.shin {
  background: var(--shin);
}
@keyframes showCard {
  0% {
    transform: translateY(30px) scale(0.85) rotateY(70deg);
    opacity: 0;
  }
  18% {
    transform: none;
    opacity: 1;
  }
  80% {
    transform: none;
    opacity: 1;
  }
  100% {
    transform: translateY(-20px) scale(0.9);
    opacity: 0;
  }
}
.float {
  position: absolute;
  z-index: 8;
  font-family: var(--brush);
  font-size: calc(var(--mm) * 9);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 2px #000;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: floatUp calc(1.4s * var(--spd)) ease-out both;
  white-space: nowrap;
}
.float.tou {
  color: #ffb4a6;
}
.float.shin {
  color: #a8e6f8;
}
@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(1);
  }
}

/* ログ */
#log {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(380px, 92vw);
  background: rgba(14, 17, 27, 0.97);
  border-left: 1px solid rgba(201, 168, 106, 0.3);
  z-index: 45;
  transform: translateX(100%);
  transition: transform 0.3s;
  display: flex;
  flex-direction: column;
}
#log.open {
  transform: none;
}
#log header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--brush);
  font-size: 18px;
}
#log ol {
  list-style: none;
  margin: 0;
  padding: 8px 12px 20px;
  overflow: auto;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#log li {
  padding: 2px 0 2px 8px;
  border-left: 3px solid rgba(255, 255, 255, 0.15);
}
#log li.tou {
  border-left-color: var(--tou-l);
}
#log li.shin {
  border-left-color: var(--shin-l);
}
#log li.phase {
  border: 0;
  padding: 8px 0 2px;
  font-family: var(--brush);
  font-size: 15px;
  color: var(--gold-l);
}
#log li.win {
  font-weight: 700;
  color: var(--gold-l);
}

/* ルール */
.rules {
  width: min(820px, 100%);
}
.rules-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}
.rules-tabs button {
  appearance: none;
  border: 1px solid rgba(34, 29, 24, 0.2);
  background: transparent;
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  min-height: 32px;
}
.rules-tabs button[aria-pressed="true"] {
  background: var(--ink2);
  color: var(--paper);
}
.rules-body {
  font-size: 14px;
}
.rules-body ul,
.rules-body ol {
  padding-left: 1.3em;
  margin: 4px 0;
}
.rules-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 6px 0;
}
.rules-body td,
.rules-body th {
  border-bottom: 1px solid rgba(34, 29, 24, 0.12);
  padding: 4px 6px;
  text-align: left;
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.gallery .card {
  width: 100%;
}
.kbd-hint {
  font-size: 12px;
  color: var(--ink3);
}

/* 結果 */
.result {
  width: min(620px, 100%);
  text-align: center;
  background: radial-gradient(120% 100% at 50% 0%, #2a2230, #121018);
  color: var(--paper);
}
.result .verdict {
  font-family: var(--brush);
  font-size: clamp(36px, 8vw, 60px);
  letter-spacing: 0.15em;
  line-height: 1.2;
  margin: 6px 0 2px;
}
.result .verdict.tou {
  color: #ff9a86;
}
.result .verdict.shin {
  color: #8fd3ea;
}
.result .why {
  font-size: 14px;
  color: rgba(246, 240, 227, 0.8);
}
.result .stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.result .stats div {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
}
.result .stats b {
  display: block;
  font-family: var(--brush);
  font-size: 24px;
  font-weight: 400;
}
.result .kiun-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 90px;
  justify-content: center;
  margin: 22px 0 26px;
}
.result .kiun-chart div {
  width: 34px;
  background: linear-gradient(180deg, var(--tou-l), var(--tou));
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 2px;
}
.result .kiun-chart span {
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  font-size: 12px;
}
.result .kiun-chart em {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  font-size: 11px;
  font-style: normal;
  color: rgba(246, 240, 227, 0.6);
}
.result .actions {
  justify-content: center;
}
.result .actions .btn.ghost {
  color: var(--paper);
  border-color: rgba(246, 240, 227, 0.3);
}

/* 読み込み */
#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--night);
  z-index: 100;
  font-family: var(--brush);
  font-size: 20px;
  color: var(--gold-l);
  transition: opacity 0.5s;
}
#loading.done {
  opacity: 0;
  pointer-events: none;
}

/* ---------- 画面用のカードとチップ（?design=print で印刷版の画像に戻る） ---------- */
.dcard {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  background-color: #f7f1e3;
  border: 2px solid #8a7a5a;
  padding: 0;
}
.dcard.p-tou,
.dcard.u-tou {
  border-color: var(--tou);
}
.dcard.p-shin,
.dcard.u-shin {
  border-color: var(--shin);
}
.dcard .dart {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  background-size: cover;
  background-position: center;
  border-radius: 3px 3px 0 0;
}
.dcard .dname {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--brush);
  color: #2a241d;
  line-height: 1.1;
  padding: 0 4cqw;
  white-space: nowrap;
  font-size: 21cqw;
}
.dcard .dname.n1,
.dcard .dname.n2 {
  font-size: 30cqw;
}
.dcard .dname.n3 {
  font-size: 26cqw;
}
.dcard .dname.two {
  font-size: 19cqw;
}
@container (max-width: 44px) {
  .dcard .dname {
    display: none;
  }
  .dcard .dart {
    aspect-ratio: auto;
    flex: 1 1 auto;
    border-radius: 2px;
  }
}
.dcard .dart {
  position: relative;
}
.dcard .datk {
  position: absolute;
  right: 3cqw;
  bottom: 3cqw;
  display: flex;
  align-items: center;
  gap: 2cqw;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
.dcard .datk b {
  width: 31cqw;
  height: 31cqw;
  display: grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  clip-path: polygon(29% 0, 71% 0, 100% 29%, 100% 71%, 71% 100%, 29% 100%, 0 71%, 0 29%);
  background: #c9a86a;
  color: #fff;
  font-family: var(--ui);
  font-weight: 700;
  font-size: 18cqw;
  line-height: 1;
}
.dcard .datk b::before {
  content: "";
  position: absolute;
  inset: 9%;
  z-index: -1;
  clip-path: inherit;
  background: #1d3550;
}
.dcard .datk.minus b {
  font-size: 15cqw;
}
.dcard .datk.minus b::before {
  background: #9e2324;
}
.dcard .datk i {
  font-style: normal;
  font-family: var(--ui);
  font-weight: 700;
  font-size: 14cqw;
  line-height: 1;
  color: #fff;
  padding: 2.5cqw 3cqw;
  border-radius: 2cqw;
}
.dcard .datk i.tou {
  background: var(--tou);
}
.dcard .datk i.shin {
  background: var(--shin);
}
@container (max-width: 44px) {
  .dcard .datk {
    display: none;
  }
}
.person .pcard .pcard-face {
  background-size: cover;
  background-position: center;
  display: flex;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.showcard .show-face {
  width: min(220px, 46vw);
  aspect-ratio: 59 / 86;
  border-radius: 10px;
  background-size: cover;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}
.choice .choice-card {
  width: 80px;
  aspect-ratio: 59 / 86;
  border-radius: 6px;
  background-size: cover;
}
.dchip {
  container-type: inline-size;
  position: relative;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff4e6;
  font-family: var(--brush);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(0, 0, 0, 0.22);
}
.dchip.red {
  background: radial-gradient(circle at 34% 30%, #d8685a 0%, #ae3b32 52%, #7a251f 100%);
}
.dchip.blue {
  background: radial-gradient(circle at 34% 30%, #4aa8c4 0%, #287d98 52%, #17505f 100%);
}
.dchip.neutral {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), inset 0 0 0 3px var(--gold);
}
.dchip b {
  font-weight: 400;
  font-size: 34cqw;
  line-height: 1;
  margin-top: -6cqw;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.dchip.s1 b {
  font-size: 50cqw;
}
.dchip small {
  position: absolute;
  right: 6cqw;
  bottom: 4cqw;
  width: 32cqw;
  height: 32cqw;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  font-family: var(--ui);
  font-weight: 700;
  font-size: 21cqw;
  line-height: 1;
}
.dchip.fchip {
  width: 54px;
  height: 54px;
}
.bfighter.injured .dchip {
  filter: grayscale(1) brightness(0.6);
}
.dchip.choice-chip {
  width: 64px;
  height: 64px;
}
.piece.named .glyph {
  font-size: calc(var(--d) * 0.34);
  padding-bottom: calc(var(--d) * 0.08);
}
.piece.named.s1 .glyph {
  font-size: calc(var(--d) * 0.5);
}
.piece.named .glyph small {
  right: 5%;
  bottom: 3%;
  width: calc(var(--d) * 0.32);
  height: calc(var(--d) * 0.32);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  font-size: calc(var(--d) * 0.21);
  line-height: 1;
}
.piece.neutral .disc {
  box-shadow: 0 calc(var(--mm) * 0.6) calc(var(--mm) * 1.4) rgba(0, 0, 0, 0.55), inset 0 0 0 calc(var(--d) * 0.07) var(--gold);
}
.piece.secret .glyph {
  opacity: 0.82;
}

/* ---------- 画面幅に合わせる ---------- */
@media (max-width: 1100px) {
  #game {
    grid-template-columns: minmax(170px, 210px) minmax(0, 1fr) minmax(170px, 210px);
  }
  .person {
    grid-template-columns: 52px 1fr;
  }
  .person .pcard {
    width: 52px;
    height: 52px;
  }
  .person .pcard > * {
    width: 34px;
    height: 50px;
  }
}

@media (max-width: 860px), (max-height: 560px) and (max-width: 1000px) {
  body {
    overflow: auto;
  }
  #game {
    position: static;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-bottom: 0;
  }
  #hud {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 20;
    background: rgba(13, 17, 27, 0.96);
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 6px 10px;
  }
  .hud-logo {
    height: 20px;
  }
  .hud-phase {
    font-size: 16px;
  }
  .hud-step {
    display: none;
  }
  .kiun-gauge {
    position: static;
    transform: none;
    order: 3;
    flex: 1 0 100%;
    justify-content: center;
    padding: 2px 12px;
  }
  .kiun-bar {
    width: 80px;
  }
  .hud-tools .icon-btn {
    width: 34px;
    height: 34px;
  }
  #board-wrap {
    order: 1;
    padding: 4px 0;
  }
  #prompt {
    order: 2;
    position: sticky;
    bottom: 0;
    z-index: 15;
    padding: 6px 10px 8px;
    gap: 6px 8px;
    min-height: 0;
  }
  #game.me-tou #panel-tou,
  #game.me-shin #panel-shin,
  #game.watch #panel-tou {
    order: 3;
  }
  #hand {
    order: 4;
    min-height: auto;
    padding-bottom: 12px;
  }
  #game.me-tou #panel-shin,
  #game.me-shin #panel-tou,
  #game.watch #panel-shin {
    order: 5;
    padding-bottom: 24px;
  }
  .prompt-who {
    font-size: 13px;
    padding: 1px 8px;
  }
  .prompt-text {
    flex-basis: 100%;
    order: -1;
    font-size: 13.5px;
  }
  .prompt-text .note {
    font-size: 11.5px;
    line-height: 1.45;
  }
  .prompt-actions .btn {
    min-height: 36px;
    padding: 0.4em 0.9em;
  }
  .tray {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .tray-item {
    flex: 0 0 auto;
    min-height: 40px;
    font-size: 12px;
  }
  .bside h3 {
    flex-direction: column;
    font-size: 15px;
  }
  .panel {
    overflow: visible;
    padding: 6px 8px;
  }
  .persons {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
  }
  .person {
    grid-template-columns: 40px auto;
    flex: 0 0 auto;
    padding: 4px 6px;
    gap: 6px;
    min-width: 128px;
  }
  .person .pcard {
    width: 40px;
    height: 40px;
  }
  .person .pcard > * {
    width: 27px;
    height: 39px;
  }
  .pname {
    font-size: 14px;
  }
  .person .uniques .mini-card {
    width: 20px;
    height: 29px;
  }
  .ability-text {
    display: none;
  }
  :root {
    --hand-card: 74px;
  }
  .bgrid {
    grid-template-columns: 1fr 1fr;
  }
  .bvs {
    grid-column: 1 / -1;
    order: -1;
    flex-direction: row;
    min-width: 0;
  }
  .bscore .t,
  .bscore .s {
    font-size: 36px;
  }
  .card-zoom {
    grid-template-columns: 1fr;
  }
  .card-zoom img {
    max-width: 260px;
    margin: 0 auto;
    display: block;
  }
  .battle h2 {
    font-size: 24px;
  }
  .bfighter {
    width: 54px;
  }
  .bfighter img,
  .dchip.fchip {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 520px) {
  .title-buttons {
    grid-template-columns: 1fr;
  }
  .kiun-gauge {
    gap: 6px;
    padding: 3px 12px;
  }
  .kg-label {
    font-size: 15px;
  }
  .kg-num {
    font-size: 28px;
  }
  .kg-bar {
    gap: 2px;
  }
  .kg-bar i {
    width: 13px;
    height: 12px;
  }
  .reserve {
    padding: 2px 8px;
    gap: 5px;
  }
  .reserve-strip {
    gap: 6px;
    flex-wrap: nowrap;
  }
  .rlabel {
    font-size: 13px;
  }
  .rlabel .long {
    display: none;
  }
  .rlabel .short {
    display: inline;
  }
  .reserve .slots {
    gap: 3px;
  }
  .reserve .slot {
    width: 20px;
    height: 20px;
    --d: 20px;
  }
  .rcount {
    min-width: 0;
  }
  .hud-logo {
    display: none;
  }
  #hud {
    gap: 6px;
  }
  .kiun-bar {
    width: 44px;
  }
  .kiun-num {
    min-width: 0;
    font-size: 17px;
  }
  .hud-tools {
    gap: 4px;
  }
  .hud-tools .icon-btn {
    width: 32px;
    height: 32px;
  }
  .prompt-text {
    font-size: 13.5px;
  }
  .tray-item .tchip {
    width: 30px;
    height: 30px;
    --d: 30px;
  }
  .tray-item .tchip .piece {
    width: 30px;
    height: 30px;
  }
  .result .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --spd: 0.01;
  }
  .title-bg {
    animation: none;
  }
}
