/*
 * 対戦の盤面。画面全体を盤面にし、カードを触るだけで遊べるようにする（参考: online-business-card-game の Unity 版）。
 * カードの大きさ（--cw, --ch）は main.js が画面の大きさから決める。
 */
.game {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    linear-gradient(#f3ead600, #f3ead600),
    url('/img/board.webp') center / cover no-repeat,
    var(--paper);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  --cw: 84px;
  --ch: 117px;
  --gap: 8px;
}

/* ---------- 上の帯 ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  background: linear-gradient(#1f2f4af2, #1f2f4ad9);
  color: var(--paper-hi);
  box-shadow: 0 2px 0 var(--gold);
  z-index: 3;
}
.top-btn {
  min-height: 40px;
  padding: 4px 14px;
  border: 1.5px solid #ffffff66;
  border-radius: 10px;
  background: #ffffff14;
  color: var(--paper-hi);
  font-weight: bold;
  font-size: 14px;
}
.top-btn[aria-pressed='false'] {
  border-color: var(--gold-hi);
  color: var(--gold-hi);
}
.top-right {
  display: flex;
  gap: 6px;
  align-items: center;
}
.room-badge {
  font-weight: bold;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #ffffff1f;
}
.room-badge.offline {
  background: var(--accent);
}
.turn-box {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.turn-no {
  font: 800 17px var(--mincho);
  white-space: nowrap;
}
.phases {
  display: flex;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  font-weight: bold;
}
.phases li {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  color: #ffffff80;
}
.phases b {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  background: #ffffff26;
  color: var(--paper-hi);
}
.phases li.done {
  color: #ffffffb3;
}
.phases li.now {
  background: var(--paper-hi);
  color: var(--accent-deep);
}
.phases li.now b {
  background: var(--accent);
}

/* ---------- 盤面 ---------- */
.board {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: center;
  justify-items: center;
  gap: 2px;
  padding: 2px 10px max(8px, env(safe-area-inset-bottom));
  min-height: 0;
}
.side {
  display: grid;
  justify-items: center;
  gap: 4px;
}
.row {
  display: grid;
  grid-template-columns: var(--cw) auto var(--cw);
  align-items: center;
  gap: calc(var(--gap) * 1.6);
}
.field {
  display: grid;
  grid-template-columns: repeat(5, var(--cw));
  gap: var(--gap);
}
.slot {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  border-radius: 8px;
  border: 2px dashed #8d7a5a80;
  background: #fffaf04d;
}
.slot.filled {
  border-color: transparent;
  background: transparent;
}
.stack-depth {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: #3b3326;
  pointer-events: none;
}
.stack-count {
  position: absolute;
  left: -6px;
  bottom: -6px;
  z-index: 3;
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--navy);
  color: white;
  font-size: 13px;
  font-weight: bold;
  box-shadow: 0 0 0 2px var(--paper-hi);
  pointer-events: none;
}

/* カード */
.card {
  position: relative;
  display: block;
  width: var(--cw);
  height: var(--ch);
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: #e8dfcc center / cover no-repeat;
  box-shadow:
    0 2px 4px #0003,
    0 0 0 1px #0000001a;
  transition:
    transform 0.18s,
    box-shadow 0.18s;
  touch-action: none;
}
.card.back {
  background-image: url('/img/card-back.webp');
}
.card .face-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6px;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  color: var(--navy);
}
.card .power {
  position: absolute;
  right: 3px;
  bottom: 3px;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: calc(var(--cw) * 0.15);
  font-weight: 800;
  background: #000000b3;
  color: white;
}
.card .power.up {
  background: var(--accent);
}
.card .power.down {
  background: #3a6ea5;
}
.card .tag {
  position: absolute;
  left: 50%;
  top: -10px;
  transform: translateX(-50%);
  z-index: 2;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  background: var(--navy);
  color: white;
}
.slot > .card {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.card.rested {
  transform: rotate(90deg) scale(0.72);
  filter: saturate(0.75) brightness(0.92);
}
.card.peeked::after {
  content: '見た';
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  background: var(--gold);
  color: white;
}

/* 触れるもの・落とせる先 */
.can-act {
  box-shadow:
    0 0 0 3px var(--gold-hi),
    0 0 16px 4px #e9c46acc;
  animation: glow 1.4s ease-in-out infinite;
}
.card.rested.can-act {
  animation: none;
}
@keyframes glow {
  50% {
    box-shadow:
      0 0 0 3px var(--gold-hi),
      0 0 4px 1px #e9c46a80;
  }
}
.target {
  border: 3px solid var(--accent) !important;
  background: #c8452b26 !important;
  box-shadow: 0 0 0 4px #c8452b40;
  animation: none;
}
.target.hover {
  background: #c8452b59 !important;
  transform: scale(1.04);
}
.card.target {
  border: 0 !important;
  box-shadow:
    0 0 0 4px var(--accent),
    0 0 20px 6px #c8452bb3;
}
.selected {
  transform: translateY(-14px) scale(1.06) !important;
  z-index: 5;
  box-shadow:
    0 0 0 4px var(--accent),
    0 14px 24px #0006 !important;
  animation: none;
}
.dragging-source {
  opacity: 0.35;
}
.drag-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, -60%) rotate(-4deg) scale(1.08);
  box-shadow: 0 18px 30px #0008;
}

/* 山札・墓地 */
.pile {
  position: relative;
  width: var(--pw, var(--cw));
  height: var(--ph, var(--ch));
  border-radius: 8px;
}
.pile.deck .card {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pile.deck .card:nth-child(1) {
  transform: translate(4px, 4px);
}
.pile.deck .card:nth-child(2) {
  transform: translate(2px, 2px);
}
.pile.empty {
  border: 2px dashed #8d7a5a80;
}
.pile-count {
  position: absolute;
  inset: auto 0 -2px;
  z-index: 3;
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.pile-count strong {
  font: 900 calc(var(--cw) * 0.38) / 1 var(--gothic);
  color: white;
  -webkit-text-stroke: 1px #0006;
  text-shadow:
    0 2px 0 #000a,
    0 0 10px #000a;
}
.pile-count span {
  margin-top: 2px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--navy);
  color: white;
  font-size: 12px;
  font-weight: bold;
}
.pile.deck.low .pile-count strong {
  color: #ffb4a3;
}
.gauge {
  position: absolute;
  left: 6%;
  right: 6%;
  top: -10px;
  height: 7px;
  border-radius: 999px;
  background: #00000040;
  overflow: hidden;
  z-index: 3;
}
.gauge i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold-hi));
  transition: width 0.4s;
}
.pile.grave {
  border: 2px solid #3b332680;
  background: #3b33261f;
  display: grid;
  place-items: center;
}
.pile.grave .grave-label {
  position: absolute;
  top: 8%;
  font: 800 calc(var(--cw) * 0.2) var(--mincho);
  color: #3b3326b3;
  letter-spacing: 0.2em;
}
.pile.grave .card {
  position: absolute;
  inset: 0;
  filter: grayscale(0.6) brightness(0.85);
}

/* 相手の手札（裏向きで上に少しだけ見せる） */
.opp-hand {
  display: flex;
  justify-content: center;
  height: calc(var(--ch) * 0.3);
  overflow: visible;
}
.opp-hand .card {
  width: calc(var(--ch) * 0.28 * 63 / 88);
  height: calc(var(--ch) * 0.28);
  margin: 0 -3px;
  border-radius: 3px;
  pointer-events: none;
}
.opp-hand .count {
  align-self: end;
  margin-left: calc(var(--cw) * 0.3);
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--navy);
  color: white;
  font-size: 12px;
  font-weight: bold;
  height: fit-content;
}

/* 真ん中の線（手番・できごと） */
.midline {
  position: relative;
  width: 100%;
  min-height: 56px;
  display: grid;
  justify-items: center;
  align-content: center;
}
.midline::before {
  content: '';
  position: absolute;
  left: 4%;
  right: 4%;
  top: 17px;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--gold) 15%,
    var(--gold) 85%,
    transparent
  );
}
.banner {
  position: relative;
  padding: 4px 18px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--paper-hi);
  font: 800 16px var(--mincho);
  box-shadow: 0 0 0 2px var(--gold);
  white-space: nowrap;
}
.banner.mine {
  background: var(--accent);
}
.banner.flash {
  animation: banner-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes banner-in {
  from {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* 手札とボタン */
.hand-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  width: 100%;
  max-width: calc(var(--cw) * 7 + var(--gap) * 14 + 220px);
  margin-top: 6px;
}
.hand {
  display: flex;
  justify-content: center;
  min-height: calc(var(--ch) * 0.92);
  padding-top: 14px;
}
.hand .card {
  width: calc(var(--cw) * 0.95);
  height: calc(var(--ch) * 0.95);
  margin: 0 var(--overlap, 2px);
  flex-shrink: 0;
}
.hand .card:hover {
  transform: translateY(-8px);
}
.hand .card.marked {
  transform: translateY(-14px);
  filter: brightness(0.75);
}
.hand .card.marked::before {
  content: '引き直す';
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
}
.buttons {
  display: grid;
  gap: 8px;
  justify-items: stretch;
  padding-bottom: 4px;
}
.btn-next {
  min-width: 170px;
  min-height: 72px;
  padding: 8px 18px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(#d4553a, var(--accent-deep));
  color: var(--paper-hi);
  font: 800 22px var(--mincho);
  letter-spacing: 2px;
  box-shadow:
    0 5px 0 #6e200f,
    0 10px 20px #6e200f55,
    inset 0 1px 0 #ffffff50;
  display: grid;
  place-items: center;
  line-height: 1.2;
}
.btn-next small {
  font: bold 12px var(--gothic);
  letter-spacing: 0;
  opacity: 0.9;
}
.btn-next:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #6e200f;
}
.btn-next:disabled {
  background: #1f2f4acc;
  box-shadow: 0 4px 0 #0b1424;
  color: #ffffffb3;
}
.btn-next.ready {
  animation: invite 1.6s ease-in-out infinite;
}
.btn-alt {
  min-height: 48px;
  padding: 6px 14px;
  border: 2px solid var(--navy);
  border-radius: 12px;
  background: var(--paper-hi);
  color: var(--navy);
  font-weight: bold;
  font-size: 15px;
}

/* ---------- その場に出す説明・選択 ---------- */
.hint {
  position: relative;
  margin-top: 2px;
  padding: 1px 12px;
  border-radius: 999px;
  background: #fffaf0d9;
  color: var(--navy);
  font-weight: bold;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  max-width: 92vw;
}
.hint:empty {
  display: none;
}
.sheet {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: min(480px, 92vw);
  padding: 18px;
  border-radius: 18px;
  background: var(--paper-hi);
  box-shadow:
    0 0 0 3px var(--gold),
    0 24px 60px #0b1424a0;
}
.sheet-title {
  margin: 0 0 10px;
  font: 800 19px var(--mincho);
  color: var(--navy);
  text-align: center;
}
.sheet-actions {
  display: grid;
  gap: 8px;
}
.sheet-actions button,
.menu button {
  min-height: 50px;
  padding: 8px 14px;
  border: 2px solid var(--navy);
  border-radius: 12px;
  background: white;
  color: var(--navy);
  font-weight: bold;
  font-size: 16px;
  text-align: left;
}
.sheet-actions button:active,
.menu button:active {
  background: var(--paper);
}
.menu {
  position: absolute;
  z-index: 25;
  display: grid;
  gap: 6px;
  width: max-content;
  max-width: min(320px, 90vw);
  padding: 10px;
  border-radius: 14px;
  background: var(--paper-hi);
  box-shadow:
    0 0 0 3px var(--gold),
    0 18px 40px #0b1424a0;
}
.menu .act {
  background: linear-gradient(#d4553a, var(--accent-deep));
  border-color: var(--accent-deep);
  color: white;
}
.menu .info {
  border-style: dashed;
}
.tray {
  position: absolute;
  inset: 12% 6% auto;
  z-index: 15;
  padding: 14px;
  border-radius: 18px;
  background: #1f2f4af2;
  box-shadow:
    0 0 0 3px var(--gold),
    0 24px 60px #0008;
}
.tray-title {
  margin: 0 0 10px;
  color: var(--paper-hi);
  font: 800 18px var(--mincho);
  text-align: center;
}
.tray-cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- アニメーション用の層 ---------- */
.fx {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
.fx .card {
  position: fixed;
  margin: 0;
  transition: none;
}
.fx .float {
  position: fixed;
  font: 900 34px var(--gothic);
  color: white;
  -webkit-text-stroke: 1px #0006;
  text-shadow: 0 3px 0 #000a;
}
.fx .float.damage {
  color: #ffb4a3;
}
.fx .float.good {
  color: #fff2b3;
}
.fx .slash {
  position: fixed;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fff0, #fff, var(--gold-hi));
  transform-origin: 0 50%;
  box-shadow: 0 0 12px var(--gold-hi);
}
.shake {
  animation: shake 0.4s;
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-5px);
  }
  40%,
  80% {
    transform: translateX(5px);
  }
}

/* ---------- チュートリアル ---------- */
.guide {
  position: absolute;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 35;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(560px, calc(100vw - 24px));
  pointer-events: none;
}
.guide.top {
  bottom: auto;
  top: 64px;
}
.guide-face {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid var(--paper-hi);
  box-shadow: 0 6px 16px #0006;
  flex-shrink: 0;
}
.guide-bubble {
  position: relative;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--paper-hi);
  box-shadow:
    0 0 0 3px var(--accent),
    0 14px 30px #0b1424a0;
  pointer-events: auto;
}
.guide-name {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: bold;
  color: var(--accent);
}
.guide-text {
  margin: 0;
  font-size: 17px;
  line-height: 1.7;
  font-weight: bold;
  color: var(--ink);
}
.guide-text em {
  font-style: normal;
  color: var(--accent-deep);
  background: linear-gradient(transparent 60%, #e9c46a80 60%);
}
.guide-next {
  margin-top: 8px;
  float: right;
  min-height: 42px;
  padding: 4px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--navy);
  color: white;
  font-weight: bold;
}
.spot {
  position: absolute;
  z-index: 34;
  border-radius: 12px;
  box-shadow:
    0 0 0 4px var(--gold-hi),
    0 0 0 9999px #0b142466;
  pointer-events: none;
  transition: all 0.3s;
}
.game.tutorial-lock .board,
.game.tutorial-lock .topbar {
  pointer-events: none;
}
.game.tutorial-lock .allowed {
  pointer-events: auto;
}

/* ---------- 縦向き・小さい画面 ---------- */
@media (max-width: 820px) {
  .phases li {
    font-size: 0;
    padding: 2px;
    gap: 0;
  }
  .phases li.now {
    font-size: 13px;
    padding-right: 8px;
    gap: 5px;
  }
  .hand-row {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .buttons {
    grid-auto-flow: column;
    width: 100%;
    justify-content: end;
  }
  .btn-next {
    min-height: 60px;
  }
}
@media (max-width: 520px) {
  .turn-no {
    display: none;
  }
  .top-btn {
    padding: 4px 10px;
    font-size: 13px;
  }
  .guide-face {
    width: 54px;
    height: 54px;
  }
  .guide-text {
    font-size: 15px;
  }
}

/* 攻撃先の山札は、はっきり分かるように */
.pile.target::after {
  content: 'ここに攻撃';
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
  box-shadow: 0 4px 10px #0005;
}
.pile.target {
  box-shadow:
    0 0 0 4px var(--accent),
    0 0 24px 8px #c8452bb3 !important;
}

/* 何が起きたか（新しい記録）を、盤面の真ん中に少しだけ出す */
.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 28;
  display: grid;
  gap: 4px;
  justify-items: center;
  pointer-events: none;
  opacity: 0;
}
.toast div {
  padding: 8px 18px;
  border-radius: 999px;
  background: #1f2f4aeb;
  color: white;
  font-weight: bold;
  font-size: 17px;
  box-shadow:
    0 0 0 2px var(--gold),
    0 10px 24px #0006;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show {
  animation: toast 2.2s ease-out forwards;
}
@keyframes toast {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%);
  }
  10%,
  78% {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  100% {
    opacity: 0;
  }
}

/* 端末の交代中は、アニメーション・通知も隠す（次の人の手札が見えないように） */
body:has(#handoff[open]) .fx,
body:has(#handoff[open]) .toast {
  visibility: hidden;
}

/* ---------- 縦向き: 場の5枠に横幅を全部使い、山札・墓地は上下の行へ ---------- */
.game.portrait {
  --pw: calc(var(--cw) * 0.7);
  --ph: calc(var(--ch) * 0.7);
}
.portrait .board {
  align-content: space-evenly;
}
.portrait .side {
  width: 100%;
  grid-template-columns: var(--pw) minmax(0, 1fr) var(--pw);
  column-gap: 12px;
  justify-items: stretch;
}
.portrait .row {
  display: contents;
}
.portrait .field {
  grid-column: 1 / -1;
  justify-content: center;
}
.portrait .side.opp #opp-deck {
  grid-row: 1;
  grid-column: 1;
}
.portrait .side.opp .opp-hand {
  grid-row: 1;
  grid-column: 2;
  align-self: center;
  height: auto;
}
.portrait .side.opp #opp-grave {
  grid-row: 1;
  grid-column: 3;
}
.portrait .side.opp .field {
  grid-row: 2;
}
.portrait .side.self .field {
  grid-row: 1;
}
.portrait .side.self #self-deck {
  grid-row: 2;
  grid-column: 1;
}
.portrait .side.self #self-grave {
  grid-row: 2;
  grid-column: 3;
}
.portrait .side.self .hand-row {
  display: contents;
}
.portrait .side.self .buttons {
  grid-row: 2;
  grid-column: 2;
  align-self: center;
  justify-content: center;
  grid-auto-flow: column;
}
.portrait .side.self .hand {
  grid-row: 3;
  grid-column: 1 / -1;
}
.portrait .pile-count strong {
  font-size: calc(var(--pw) * 0.42);
}
.portrait .gauge {
  top: -9px;
}
.pile .card {
  width: 100%;
  height: 100%;
}

.spot.ring {
  box-shadow:
    0 0 0 4px var(--gold-hi),
    0 0 18px 6px #e9c46acc;
}
.spot {
  animation: spot 1.4s ease-in-out infinite;
}
@keyframes spot {
  50% {
    outline: 4px solid #e9c46a80;
    outline-offset: 6px;
  }
}

/* 最初のターンはセット・攻撃ができない。上の流れで、鍵をかけたように見せる */
.phases li.locked {
  position: relative;
  color: #ffffff59;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.phases li.locked b::before {
  content: '🔒';
  font-size: 10px;
}
.phases li.locked b {
  font-size: 0;
  background: #ffffff1f;
}
.phases li.locked small {
  position: absolute;
  left: 50%;
  top: calc(100% + 2px);
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--navy);
  font-size: 10px;
  white-space: nowrap;
  text-decoration: none;
}
.phases li.locked.now {
  background: #ffffffcc;
  color: var(--ink-soft);
}

/* ===================================================================
 * フェーズの色。いまのフェーズが、盤面のふち・上の帯・手番の表示・右下のボタンの色で分かるように。
 * ドロー=藍 / 召喚=緑 / 効果=紫 / セット=山吹 / 攻撃=朱 / 守る=紅
 * =================================================================== */
.game {
  --phase: #2f6db5;
  --phase-deep: #1d4a80;
}
.game[data-phase='draw'],
.game[data-phase='mulligan'],
.phase-cut[data-phase='draw'] {
  --phase: #2f6db5;
  --phase-deep: #1d4a80;
}
.game[data-phase='summon'],
.phase-cut[data-phase='summon'] {
  --phase: #2e8b57;
  --phase-deep: #1c5e3a;
}
.game[data-phase='effect'],
.phase-cut[data-phase='effect'] {
  --phase: #7b4bb7;
  --phase-deep: #52307e;
}
.game[data-phase='set'],
.phase-cut[data-phase='set'] {
  --phase: #c8901c;
  --phase-deep: #8a6110;
}
.game[data-phase='attack'],
.game[data-phase='defend'],
.phase-cut[data-phase='attack'] {
  --phase: #c8452b;
  --phase-deep: #8e2a16;
}
.game[data-phase='end'] {
  --phase: #5b5a55;
  --phase-deep: #3a3935;
}

/* 自分の番は、盤面のふちをフェーズの色で囲む（相手の番は落ち着いた紺） */
.board::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  box-shadow:
    inset 0 0 0 4px #1f2f4a40,
    inset 0 0 60px #1f2f4a26;
  transition: box-shadow 0.4s;
}
.game.my-turn .board::before {
  box-shadow:
    inset 0 0 0 5px var(--phase),
    inset 0 0 90px color-mix(in srgb, var(--phase) 45%, transparent);
}
.game.my-turn .topbar {
  box-shadow: 0 3px 0 var(--phase);
}
.phases li.now {
  background: var(--phase);
  color: white;
}
.phases li.now b {
  background: #ffffff40;
}
.game.my-turn .banner.mine {
  background: var(--phase);
  box-shadow: 0 0 0 2px var(--paper-hi);
}

/* 右下のボタン: まだできることがある時は控えめ。何もなければフェーズの色で光らせる */
.game.my-turn .btn-next:not(:disabled) {
  background: linear-gradient(
    color-mix(in srgb, var(--phase) 85%, white),
    var(--phase-deep)
  );
  box-shadow:
    0 5px 0 color-mix(in srgb, var(--phase-deep) 70%, black),
    inset 0 1px 0 #ffffff50;
}
.game.my-turn .btn-next.calm:not(:disabled) {
  background: var(--paper-hi);
  color: var(--phase-deep);
  border: 3px solid var(--phase);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--phase) 40%, transparent);
  font-size: 19px;
}
.game.my-turn .btn-next.ready:not(:disabled) {
  animation: next-glow 1.1s ease-in-out infinite;
}
@keyframes next-glow {
  0%,
  100% {
    transform: translateY(0);
    box-shadow:
      0 5px 0 color-mix(in srgb, var(--phase-deep) 70%, black),
      0 0 0 4px #ffe08a,
      0 0 22px 8px #ffd75ecc;
  }
  50% {
    transform: translateY(-3px);
    box-shadow:
      0 8px 0 color-mix(in srgb, var(--phase-deep) 70%, black),
      0 0 0 6px #fff1b8,
      0 0 40px 16px #ffd75eee;
  }
}

/* 触れるもの: 光を強く */
.can-act {
  box-shadow:
    0 0 0 4px #ffd75e,
    0 0 0 7px #ffffffb3,
    0 0 28px 12px #ffc83ce6;
  animation: glow-strong 1s ease-in-out infinite;
}
/* 選んで持ち上げたカード・攻撃先は、それぞれの見た目を優先する */
.can-act.selected,
.can-act.target {
  animation: none;
}
@keyframes glow-strong {
  0%,
  100% {
    box-shadow:
      0 0 0 4px #ffd75e,
      0 0 0 7px #ffffffb3,
      0 0 28px 12px #ffc83ce6;
  }
  50% {
    box-shadow:
      0 0 0 5px #fff1b8,
      0 0 0 9px #ffd75e99,
      0 0 44px 20px #ffc83cff;
  }
}
.slot.can-act {
  border: 3px solid #ffd75e !important;
  background: #fff5cc80;
}

/* フェーズが変わった時に、真ん中に大きく出すフェーズ名 */
.phase-cut {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  z-index: 29;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 14px 0 16px;
  transform: translateY(-50%);
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--phase, #1f2f4a) 92%, transparent) 18%,
    color-mix(in srgb, var(--phase, #1f2f4a) 92%, transparent) 82%,
    transparent
  );
  color: white;
  text-shadow: 0 3px 0 #0005;
}
.phase-cut.theirs {
  --phase: #1f2f4a;
}
.phase-cut .cut-no {
  font: 800 clamp(18px, 3vh, 26px) var(--gothic);
  opacity: 0.9;
}
.phase-cut .cut-name {
  font:
    800 clamp(44px, 9vh, 84px) / 1.1 'Kaisei Tokumin Title',
    var(--mincho);
  letter-spacing: 0.12em;
}
.phase-cut .cut-sub {
  font: bold clamp(15px, 2.2vh, 19px) var(--gothic);
}
.phase-cut .cut-no:empty,
.phase-cut .cut-sub:empty {
  display: none;
}
.phase-cut.show {
  animation: phase-cut 1.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
@keyframes phase-cut {
  0% {
    opacity: 0;
    transform: translateY(-50%) scaleY(0.2);
  }
  14% {
    opacity: 1;
    transform: translateY(-50%) scaleY(1.06);
  }
  22%,
  72% {
    opacity: 1;
    transform: translateY(-50%) scaleY(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-50%) scaleY(1);
  }
}
body:has(#handoff[open]) .phase-cut {
  visibility: hidden;
}

/* メニュー・中央の選択肢は、チュートリアルの暗い幕（.spot）より手前に */
.menu,
.sheet {
  z-index: 36;
}

/* 重なっているカードの、すぐ下の1枚（少しずらして見せる） */
.slot > .card.under {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: translate(5px, 5px);
  filter: brightness(0.7);
  pointer-events: none;
}
.slot > .card.under.rested {
  transform: translate(5px, 5px) rotate(90deg) scale(0.72);
}

/* 墓地にカードがある時は裏面。文字は上に */
.pile.grave .card {
  filter: grayscale(0.4) brightness(0.8);
}
.pile.grave .grave-label {
  z-index: 2;
  color: #fffaf0;
  text-shadow: 0 1px 3px #000c;
}
.pile.grave.empty .grave-label {
  color: #3b3326b3;
  text-shadow: none;
}

/* 効果を使った時の光と効果名 */
.fx .cast-ring {
  position: fixed;
  border-radius: 50%;
  border: 4px solid #ffd75e;
  box-shadow:
    0 0 24px 8px #ffc83c,
    inset 0 0 18px 4px #ffc83c99;
}
.fx .cast-name {
  position: fixed;
  padding: 4px 14px;
  border-radius: 999px;
  background: #1f2f4aee;
  color: #ffe08a;
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  box-shadow: 0 0 0 2px #ffd75e;
}

/* 今できないこと: 禁止マーク（タップで理由） */
.hint-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.hint-row .hint {
  margin-top: 0;
}
.blocked {
  width: 34px;
  height: 34px;
  border: 2px solid #c8452b;
  border-radius: 50%;
  background: #fffaf0;
  font-size: 17px;
  line-height: 1;
  box-shadow: 0 2px 6px #0003;
  animation: blocked-in 0.4s ease-out;
}
@keyframes blocked-in {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
}
.blocked-tip {
  position: relative;
  z-index: 6;
  margin-top: 6px;
  max-width: min(92vw, 520px);
  padding: 8px 14px;
  border-radius: 12px;
  background: #fff3ee;
  border: 2px solid var(--accent);
  color: var(--accent-deep);
  font-weight: bold;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 6px 16px #0003;
}
