/* Battle table: a bright, readable play mat with physical cards. */
body.is-battling {
  background: #c7e7e3;
  color: #15383b;
}
body.is-battling .site-header {
  max-width: none;
  height: 58px;
  padding: 7px clamp(14px, 2.5vw, 36px);
  background: #123b42;
  border-bottom: 3px solid #d1a86e;
  color: #f7faf3;
}
body.is-battling .brand-mark { font-size: 31px; }
body.is-battling .brand small { font-size: 9px; margin-bottom: 0; }
body.is-battling .brand b { font-size: 16px; }
body.is-battling .nav-item { min-height: 38px; padding: 7px 13px; color: #e6f3ee; }

.battle-main {
  max-width: 1800px;
  padding: 20px clamp(18px, 2.5vw, 40px) 28px;
}
.battle-main .battle-heading {
  margin: 0 8px 12px;
  color: #245057;
  font-weight: 800;
  font-size: 13px;
}
.battle-heading .battle-mode { color: #346e72; }
.battle-main .arena {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(28px, 3vw, 40px);
  border: 11px solid #93663e;
  border-radius: 32px;
  background:
    radial-gradient(ellipse at 50% 47%, #b7e9dc 0, #a2dcd3 47%, #7fc1bd 100%);
  box-shadow: inset 0 0 0 3px #d9af74, inset 0 0 0 8px #145b61, 0 12px 24px #174c4e39;
}
.arena::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 7px;
  border: 2px solid #ffffff85;
  border-radius: 17px;
  pointer-events: none;
}
.arena::after {
  content: "✦";
  position: absolute;
  z-index: -1;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: #4b9b9960;
  font: 140px/1 Georgia, serif;
  pointer-events: none;
}
.player-zone {
  grid-template-columns: minmax(140px, 160px) minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(24px, 2.8vw, 42px);
  position: relative;
  padding: 8px 0;
}
.pile-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.pile-area .side-label {
  color: #1a5055;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
  line-height: 1.25;
  margin-bottom: 5px;
}
.deck-pile, .grave-pile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: min(132px, 100%);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #1b474b;
  text-align: center;
}
.deck-stack, .grave-stack { position: relative; display: block; width: 80px; height: 110px; }
.stack-layer, .stack-top {
  position: absolute;
  display: grid;
  place-items: center;
  left: 0; top: 0;
  width: 80px; height: 110px;
  border: 2px solid #f5dfb4;
  border-radius: 6px;
  background: linear-gradient(145deg, #216a72, #16434b);
  box-shadow: 0 1px 0 #092c33, 1px 2px 4px #13393d4d;
  transform: translate(calc(var(--layer, 0) * .5px), calc(var(--layer, 0) * -.65px));
}
.stack-layer { pointer-events: none; }
.stack-top {
  z-index: 1;
}
.stack-top .card-back-face {
  display: grid;
  place-items: center;
  gap: 2px;
  width: 100%; height: 100%;
  color: #fce8b0;
  font: 44px/1 Georgia, serif;
  outline: 1px solid #dfc58a;
  outline-offset: -7px;
}
.stack-top .card-back-face small { font: 800 10px/1 system-ui; white-space: nowrap; }
.deck-pile:not(:disabled):hover .stack-top { margin-top: -6px; }
.deck-pile:disabled { opacity: 1; }
.empty-pile {
  display: grid;
  place-items: center;
  width: 100%; height: 100%;
  border: 2px dashed #5b9696;
  border-radius: 6px;
  color: #326f73;
  font-size: 11px;
  font-weight: 800;
}
.pile-caption {
  display: block;
  min-width: 120px;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  color: #1d4e52;
}
.pile-caption b { font-size: 25px; color: #103d43; }
.grave-pile { min-height: 0; flex-direction: row; gap: 9px; }
.grave-pile .pile-caption { min-width: 0; text-align: left; font-size: 13px; }
.grave-pile .pile-caption b { font-size: 22px; }
.grave-stack { width: 46px; height: 62px; }
.grave-stack .mana-card { width: 46px; height: 62px; }
.grave-stack .mana-card .mana-symbol { font-size: 31px; }
.grave-stack .mana-card .mana-word,
.grave-stack .mana-card .mana-corner { display: none; }
.grave-stack .empty-pile { font-size: 0; }
.grave-stack .empty-pile::after { content: "—"; font-size: 17px; }
.grave-empty {
  display: grid;
  place-items: center;
  width: 31px; height: 41px;
  border: 2px dashed #549798;
  border-radius: 4px;
  color: #347c7f;
  font-size: 20px;
}

.monster-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: clamp(24px, 2.8vw, 40px);
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
}
.monster-station { min-width: 0; max-width: 260px; width: 100%; position: relative; justify-self: center; }
.battle-card {
  z-index: 2;
  border: 2px solid #f8f5df;
  border-radius: 12px;
  background: #fff9e7;
  box-shadow: 0 0 0 2px #4c7774, 0 5px 0 #b5a58a, 0 9px 13px #17494d4d;
  overflow: hidden;
}
.battle-card.can-target {
  border-color: #fff5bf;
  box-shadow: 0 0 0 3px #f1b63f, 0 0 0 7px #fff19c8c, 0 8px 14px #17494d55;
}
.battle-card.can-target:hover { transform: translateY(-4px); }
.battle-card.casting { box-shadow: 0 0 0 3px #4aadb6, 0 0 20px #b9fff4, 0 5px 0 #9da98a; }
.monster-target {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  text-align: left;
  color: #1d3839;
}
.battle-art {
  width: min(130px, calc(100% - 16px));
  aspect-ratio: 1;
  align-self: center;
  margin: 7px auto 4px;
  border: 2px solid #d6c99f;
  border-radius: 6px;
  overflow: hidden;
  background: #e6ede2;
}
.battle-art .portrait { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 1; }
.monster-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0 10px 7px;
}
.monster-details .monster-name {
  display: block;
  min-height: 0;
  padding: 0;
  color: #123e40;
  font-size: clamp(14px, 1.35vw, 17px);
  line-height: 1.25;
  font-weight: 900;
  text-align: left;
}
.monster-details .cost-row {
  justify-content: flex-start;
  min-height: 0;
  gap: 2px;
  margin: 4px 0 3px;
  padding: 0;
}
.monster-details .cost-row .mana {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: #fff;
  font-size: 14px;
}
.monster-details .skill-text {
  display: block;
  margin: 0;
  color: #254346;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
  text-align: left;
  overflow-wrap: anywhere;
}
.monster-details .ready-label {
  margin-top: 2px;
  padding: 3px 0 0;
  color: #397579;
  font-size: 10px;
  font-weight: 900;
}
.battle-card.casting .ready-label { color: #ac641d; }
.battle-info {
  top: 3px; right: 3px;
  width: 25px; height: 25px;
  border: 1px solid #fef7db;
  font-size: 16px;
  background: #18555dde;
}
.attached-mana {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: start;
  justify-content: center;
  min-height: 45px;
  margin-top: -7px;
  padding: 0 6px;
}
.attached-card {
  display: block;
  flex: none;
  margin-left: -6px;
  transform: rotate(calc((var(--card-index, 0) - 2) * 3deg));
}
.attached-card:first-child { margin-left: 0; }
.attached-mana .mana-card {
  width: 35px;
  height: 49px;
  box-shadow: 0 2px 3px #2d686866;
}
.attached-mana .mana-card .mana-symbol { font-size: 24px; }
.attached-mana .mana-card .mana-corner,
.attached-mana .mana-card .mana-word { display: none; }
.attachment-hint {
  align-self: center;
  color: #316e70;
  font-size: 11px;
  font-weight: 800;
}
.attached-mana:has(.attachment-hint) { min-height: 27px; margin-top: 0; }

.mana-card {
  --mana-paper: #eff9ff;
  --mana-ink: #3678aa;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 56px;
  height: 78px;
  aspect-ratio: 5 / 7;
  border: 2px solid #fffdf2;
  border-radius: 7px;
  background: var(--mana-paper);
  color: var(--mana-ink);
  box-shadow: 0 0 0 1px #668a8b, 2px 4px 0 #aac8c0, 3px 7px 8px #1d4b4a55;
  line-height: 1;
  user-select: none;
}
.mana-card.cross { --mana-paper: #fff0f2; --mana-ink: #c4495b; }
.mana-card.triangle { --mana-paper: #eafbed; --mana-ink: #2f9267; }
.mana-card.square { --mana-paper: #f3efff; --mana-ink: #7967b6; }
.mana-card.star { --mana-paper: #fff8dc; --mana-ink: #b77e18; }
.mana-card::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid currentColor;
  border-radius: 3px;
  opacity: .55;
}
.mana-card .mana-corner { position: absolute; top: 5px; left: 6px; font-size: 12px; font-weight: 900; }
.mana-card .mana-symbol { font: 900 37px/1 system-ui; }
.mana-card .mana-word { position: absolute; bottom: 5px; font-size: 9px; font-weight: 900; }
.mana-card.empty { background: #e9eee7; color: #7a9d9e; border-style: dashed; box-shadow: none; }

.battle-main .action-zone {
  position: relative;
  z-index: 3;
  width: min(660px, 100%);
  min-height: 96px;
  margin: clamp(24px, 2.5vw, 30px) auto;
  padding: 14px clamp(16px, 2vw, 26px);
  border: 2px solid #ffffffa8;
  border-radius: 18px;
  background: #f8fbefde;
  box-shadow: 0 4px 12px #2d787624;
  color: #1b4145;
}
.action-zone h2 { margin: 0 0 3px; font-size: clamp(17px, 1.8vw, 21px); }
.action-zone .result h2, .action-zone .result-symbol { color: #84511d; }
.action-zone .result .subtle { color: #245e61; background: #d9eee8; border: 1px solid #8abcb7; border-radius: 10px; }
.action-zone p { color: #3a6568; font-size: 13px; line-height: 1.4; }
.action-zone .eyebrow { color: #317d80; }
.draw-prompt { width: min(650px, 100%); }
.draw-button { min-height: 58px; background: #ffcf6e; color: #164044; box-shadow: 0 4px 0 #c79039; }
.draw-button:hover { background: #ffdc90; }
.draw-button .card-back { width: 30px; height: 42px; font-size: 24px; }
.drawn-mana { display: inline-grid; place-items: center; min-width: 54px; }
.drawn-mana .mana-card { width: 49px; height: 69px; transform: rotate(-5deg); }
.drawn-mana .mana-card .mana-symbol { font-size: 32px; }
.turn-message { gap: 17px; }
.thinking-rune { color: #368b89; }
.rps-hands button { background: #fff9e5; }
.grave-option { background: #c3e3dc; }
.grave-option .mana-card { width: 30px; height: 42px; }
.grave-option .mana-symbol { font-size: 21px; }
.grave-option .mana-corner, .grave-option .mana-word { display: none; }
.last-event { margin: 7px 0 5px; min-height: 18px; color: #29565a; font-size: 12px; font-weight: 700; }
.battle-log { background: #ecf9f1; color: #3e6366; font-size: 12px; padding: 7px 13px; }
.modal { color: #f2f4ec; }

.collection-skill {
  display: block;
  padding: 0 10px 10px;
  color: #e8f0e9;
  font-size: 13px;
  line-height: 1.45;
  min-height: 52px;
}

@media (max-width: 1000px) {
  .battle-main .arena { padding: 24px; border-width: 9px; }
  .player-zone { grid-template-columns: 128px minmax(0, 1fr); gap: 20px; }
  .monster-target { min-height: 0; }
  .monster-details { padding: 0 8px 7px; }
  .monster-details .skill-text { font-size: 14px; }
  .monster-details .cost-row .mana { width: 16px; height: 16px; font-size: 13px; }
  .pile-caption { min-width: 100px; font-size: 14px; }
  .pile-caption b { font-size: 24px; }
}
@media (max-width: 900px) {
  body.is-battling .site-header { height: 58px; }
  .battle-main { padding: 14px 14px 24px; }
  .battle-main .arena { padding: 24px; border-radius: 26px; }
  .player-zone { grid-template-columns: 1fr; gap: 18px; }
  .pile-area { flex-direction: row; justify-content: center; gap: 24px; min-height: 116px; }
  .pile-area .side-label { min-width: 76px; margin-bottom: 0; }
  .deck-pile, .grave-pile { width: auto; gap: 10px; flex-direction: row; }
  .deck-pile { gap: 20px; }
  .pile-caption { min-width: 0; font-size: 13px; }
  .pile-caption b { font-size: 24px; }
  .grave-stack, .grave-stack .mana-card { width: 44px; height: 61px; }
  .monster-row { gap: 18px; }
  .monster-target { display: flex; flex-direction: column; min-height: 0; }
  .battle-art { width: min(130px, calc(100% - 12px)); max-width: none; margin: 6px auto 3px; }
  .monster-details { padding: 0 8px 6px; }
  .monster-details .monster-name { font-size: 14px; }
  .monster-details .skill-text { font-size: 14px; line-height: 1.35; }
  .monster-details .cost-row .mana { width: 15px; height: 15px; font-size: 12px; }
  .attached-mana .mana-card { width: 35px; height: 49px; }
  .attached-mana .mana-card .mana-symbol { font-size: 24px; }
  .battle-main .action-zone { width: min(600px, 100%); min-height: 90px; margin: 28px auto; padding: 12px; }
  .draw-button { min-height: 55px; padding: 8px 12px; }
}
@media (min-width: 1200px) {
  .deck-stack, .stack-layer, .stack-top { width: 92px; height: 126px; }
  .stack-top .card-back-face { font-size: 49px; }
  .grave-stack, .grave-stack .mana-card { width: 46px; height: 62px; }
  .grave-stack .mana-card .mana-symbol { font-size: 31px; }
  .pile-caption b { font-size: 28px; }
}
@media (max-width: 600px) {
  .battle-main { padding: 10px 8px 20px; }
  .battle-main .arena { padding: 16px 10px; border-width: 7px; }
  .pile-area { flex-wrap: wrap; gap: 8px 14px; min-height: 98px; }
  .pile-area .side-label { flex-basis: 100%; }
  .deck-stack, .stack-layer, .stack-top { width: 52px; height: 72px; }
  .stack-top .card-back-face { font-size: 28px; outline-offset: -5px; }
  .stack-top .card-back-face small { display: none; }
  .grave-stack, .grave-stack .mana-card { width: 35px; height: 49px; }
  .pile-caption b { font-size: 22px; }
  .monster-row { gap: 7px; }
  .battle-main .action-zone { width: 100%; margin: 20px auto; }
  .attached-mana .mana-card { width: 26px; height: 37px; }
  .attached-mana .mana-card .mana-symbol { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .battle-card, .stack-top, .mana-card { transition: none !important; animation: none !important; }
}

/* Keep the sound preference legible alongside the navigation on small tablets. */
.site-header .sound-toggle, body.is-battling .site-header .sound-toggle { white-space: nowrap; min-height: 44px; }
@media (max-width: 700px) {
  .site-header, body.is-battling .site-header { height: auto; min-height: 58px; flex-wrap: wrap; gap: 6px 12px; }
  .site-header nav { flex-wrap: wrap; }
}

.audio-controls { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.audio-controls .sound-toggle { border: 1px solid #ffffff30; border-radius: 10px; padding: 7px 10px; min-height: 44px; font-size: 13px; }
.audio-controls .sound-toggle[aria-pressed="false"] { opacity: .65; }
.cutin-audio { margin-top: 14px; text-align: center; }
.cutin-audio .sound-toggle { background: #173a45; color: #f5faf5; min-width: 90px; }
@media (max-width: 900px) {
  .site-header, body.is-battling .site-header { height: auto; min-height: 58px; flex-wrap: wrap; gap: 6px 12px; }
  .site-header nav { flex-wrap: wrap; }
}

/* Reserve the largest progress state before the first turn, at each screen width. */
.battle-main .action-zone {
  height: 240px;
  min-height: 240px;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: auto;
}
.action-zone > * { flex-shrink: 0; margin-block: auto; margin-inline: auto; max-width: 100%; }
@media (max-width: 600px) {
  .battle-main .action-zone { height: 448px; min-height: 448px; }
}
@media (max-width: 360px) {
  .battle-main .action-zone { height: 512px; min-height: 512px; }
}

/* Keep tablet cards readable while reserving a compact action lane. */
@media (min-width: 768px) and (max-width: 1366px) {
  .battle-main .arena { padding: 14px 22px; border-width: 9px; }
  .battle-main .player-zone { grid-template-columns: 116px minmax(0, 1fr); gap: 22px; padding: 4px 0; }
  .battle-main .pile-area { flex-direction: column; gap: 12px; min-height: 0; }
  .battle-main .deck-pile { flex-direction: column; gap: 7px; }
  .battle-main .grave-pile { flex-direction: row; gap: 8px; }
  .battle-main .monster-row { gap: 22px; }
  .battle-main .action-zone {
    width: min(660px, 100%);
    height: 100px;
    min-height: 100px;
    margin: 12px auto;
    padding: 10px 18px;
  }
  .battle-main .action-zone:has(.rps-panel, .attach-prompt, .result) { overflow: visible; }
  .battle-main .action-zone .rps-panel,
  .battle-main .action-zone .result {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    padding: 18px;
    border: 2px solid #fff;
    border-radius: 18px;
    background: #f8fbef;
    box-shadow: 0 8px 30px #194b4e55;
  }
  .battle-main .action-zone .result { justify-content: center; text-align: center; }
  .battle-main .action-zone .result-actions { margin: 0; justify-content: center; }
  .battle-main .action-zone .grave-options {
    position: absolute;
    left: -2px; right: -2px; bottom: calc(100% - 8px);
    margin: 0;
    padding: 14px;
    border: 2px solid #fff;
    border-radius: 18px 18px 0 0;
    background: #f8fbef;
    box-shadow: 0 -8px 24px #194b4e22;
    justify-content: center;
    max-height: 230px;
    overflow-y: auto;
  }
}

@media (min-width: 768px) and (max-width: 1366px) {
  .battle-main .attached-mana,
  .battle-main .attached-mana:has(.attachment-hint) { height: 56px; min-height: 56px; margin-top: -7px; }
}
@media (min-width: 768px) and (max-width: 1366px) and (max-height: 900px) and (orientation: landscape) {
  .battle-main .arena { padding-block: 10px; }
  .battle-main .player-zone { padding-block: 0; }
  .battle-main .battle-art { width: min(110px, calc(100% - 16px)); }
  .battle-main .action-zone { margin-block: 8px; }
}
