:root {
  --bg: #0c0a09;
  --bg-panel: rgba(22, 16, 14, 0.88);
  --bg-slot: rgba(40, 28, 22, 0.75);
  --gold: #d4a84b;
  --gold-bright: #f0d78c;
  --gold-dim: #8a6a28;
  --blood: #8b1a1a;
  --blood-bright: #e74c3c;
  --text: #f0e6d2;
  --muted: #a89070;
  --line: rgba(180, 140, 70, 0.35);
  --card-w: 58px;
  --card-h: 80px;
  --radius: 7px;
  --font: "Cinzel", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-ui: "Segoe UI", system-ui, sans-serif;
  --glow-gold: 0 0 18px rgba(212, 168, 75, 0.35);
  --art-bg: url("../../assets/art/generated/war-table-crown-v1.png");
  --art-back: url("../../assets/art/card-back.jpg");
  --art-crest: url("../../assets/art/crest.jpg");
  --art-court: url("../../assets/art/generated/royal-court-atlas-v1.png");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-ui);
  background: #050403;
}

body {
  background:
    linear-gradient(180deg, rgba(4, 4, 6, 0.50) 0%, rgba(7, 6, 7, 0.34) 42%, rgba(3, 3, 5, 0.68) 100%),
    var(--art-bg) center / cover no-repeat fixed;
  animation: bg-breathe 14s ease-in-out infinite alternate;
}

@keyframes bg-breathe {
  0% { filter: brightness(0.95) saturate(0.95); }
  100% { filter: brightness(1.05) saturate(1.05); }
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 6px 10px 8px;
  gap: 6px;
  max-width: 1440px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.app.screen-shake,
.play-area.screen-shake {
  animation: shake 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
.app.screen-shake-hard,
.play-area.screen-shake-hard {
  animation: shake-hard 0.48s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 1px, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, -1px, 0); }
}
@keyframes shake-hard {
  10%, 90% { transform: translate3d(-2px, 1px, 0); }
  20%, 80% { transform: translate3d(4px, -2px, 0); }
  30%, 50%, 70% { transform: translate3d(-5px, 2px, 0); }
  40%, 60% { transform: translate3d(5px, -1px, 0); }
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 42px;
  padding: 4px 8px;
  background: linear-gradient(90deg, rgba(20, 12, 10, 0.92), rgba(40, 22, 16, 0.85), rgba(20, 12, 10, 0.92));
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--glow-gold), inset 0 1px 0 rgba(255, 220, 150, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  white-space: nowrap;
  text-shadow: 0 0 12px rgba(212, 168, 75, 0.4);
}

.brand-crest {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--art-crest) center / cover;
  border: 1px solid var(--gold-dim);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.chip {
  background: rgba(12, 8, 6, 0.75);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: var(--font-ui);
}

.chip b {
  color: var(--gold);
  font-weight: 700;
  margin-left: 3px;
}

.chip.hp-you b { color: #7dcea0; }
.chip.hp-enemy b { color: #f1948a; }
.chip.castle b { color: #d2b4de; font-size: 0.66rem; }

.top-actions { flex-shrink: 0; }

/* ── Main layout ── */
.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(210px, 270px);
  gap: 8px;
  transition: grid-template-columns 0.25s ease;
}

.main.log-collapsed {
  grid-template-columns: 1fr 0fr;
  gap: 0;
}

.main.log-collapsed .log-panel {
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  padding: 0;
  border-width: 0;
  min-width: 0;
}

.play-area {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background:
    linear-gradient(180deg, rgba(18, 12, 10, 0.82) 0%, rgba(10, 7, 6, 0.88) 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), var(--glow-gold);
  position: relative;
}

/* Three.js 3D battlefield (optional render mode — Classic 2D is default) */
.three-root {
  display: none;
  flex: 1 1 auto;
  min-height: 220px;
  width: 100%;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(212, 168, 75, 0.28);
  background: radial-gradient(ellipse at 50% 30%, #1a100c 0%, #0a0706 70%);
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.55),
    0 0 24px rgba(212, 168, 75, 0.08);
}

.app.mode-three .three-root {
  display: block;
}

.app.mode-three .three-root[hidden] {
  display: block !important;
}

.three-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  cursor: crosshair;
}

.app.mode-three .board-2d {
  /* Classic board hidden; placement uses 3D raycast + hand dock */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  opacity: 0;
  pointer-events: none;
}

.app.mode-three .play-area {
  min-height: 320px;
  display: flex;
  flex-direction: column;
}

.app.mode-three .three-root {
  flex: 1 1 auto;
  min-height: 280px;
  height: min(52vh, 520px);
}

.app.mode-three .hand-bar {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

/* Soft vignette overlay so 3D board feels framed like a war table */
.app.mode-three .three-root::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.45);
  z-index: 1;
}

@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .app.mode-three .three-root {
    height: min(42vh, 360px);
    min-height: 220px;
  }
  .app.mode-three .hand-bar {
    /* keep fixed dock on phones even in 3D */
    position: fixed;
  }
}

/* Mobile no-overlay guarantee: the hand is part of document flow beneath the
   board. It can never cover a Killing Ground slot or intercept a board tap. */
@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .main { padding-bottom: 12px !important; }
  .hand-bar,
  .app.mode-three .hand-bar {
    position: relative !important;
    inset: auto !important;
    width: 100%;
    max-height: none !important;
    overflow: visible !important;
    z-index: 8;
    margin-top: 8px;
    border-radius: 12px;
  }
  .main:not(.log-collapsed) .log-panel {
    bottom: 8px;
  }
}

/* Battlefield status rails use the table's open flanks and keep the header calm. */
.topbar .chips { display: none; }
.top-actions { margin-left: auto; display: flex; gap: 5px; }
.field-hud {
  position: absolute;
  right: clamp(10px, 2.2vw, 34px);
  top: 50%;
  z-index: 4;
  width: clamp(128px, 10vw, 162px);
  transform: translateY(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px;
  border: 1px solid rgba(207,161,76,.31);
  border-radius: 10px;
  background: linear-gradient(150deg, rgba(17,14,13,.88), rgba(5,7,9,.82));
  box-shadow: 0 12px 35px rgba(0,0,0,.48), inset 0 1px rgba(255,228,169,.06);
  backdrop-filter: blur(8px);
}
.field-hud-enemy { border-color: rgba(89,145,164,.34); }
.field-hud-you {
  left: clamp(10px, 2.2vw, 34px);
  right: auto;
  border-color: rgba(191,91,53,.38);
}
.field-hud-title {
  grid-column: 1 / -1;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: var(--gold);
  font: 700 .58rem/1 var(--font);
  letter-spacing: .17em;
  text-align: center;
  text-transform: uppercase;
}
.field-hud > span:not(.field-hud-title) {
  min-width: 0;
  padding: 5px 4px;
  border-radius: 5px;
  background: rgba(255,255,255,.028);
  text-align: center;
}
.field-hud small {
  display: block;
  margin-bottom: 3px;
  color: #887e70;
  font: 600 .48rem/1 var(--font-ui);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.field-hud b {
  display: block;
  overflow: hidden;
  color: #e8d7b8;
  font: 700 .68rem/1.12 var(--font-ui);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-hud-enemy > span:nth-child(2) b { color: #ef9c91; }
.field-hud-you > span:nth-child(2) b { color: #89d1a3; }
.field-hud > span:nth-child(3) b { color: #d3b2df; font-size: .58rem; }

@media (max-width: 1100px) {
  .top-actions button { padding-inline: 7px; }
  #btn-fullscreen { font-size: 0; }
  #btn-fullscreen::first-letter { font-size: .72rem; }
  .field-hud { right: 8px; width: 124px; padding: 7px; gap: 4px; }
}

@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .topbar { flex-wrap: nowrap; }
  .top-actions { overflow-x: auto; scrollbar-width: none; }
  .top-actions::-webkit-scrollbar { display: none; }
  .top-actions button { flex: 0 0 auto; }
  #btn-render-mode, #btn-help { display: none; }
  #btn-fullscreen { display: inline-flex; font-size: 0 !important; min-width: 30px; justify-content: center; }
  #btn-fullscreen::first-letter { font-size: .72rem; }
  .board-2d .side { padding-top: 62px; }
  .field-hud {
    top: 5px;
    left: 5px;
    right: 5px;
    width: auto;
    transform: none;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 3px;
    padding: 5px;
  }
  .field-hud-enemy { grid-template-columns: 1fr 1fr; left: auto; width: 178px; }
  .field-hud-title { display: none; }
  .field-hud > span:not(.field-hud-title) { padding: 3px 1px; }
  .field-hud small { font-size: .39rem; letter-spacing: .03em; }
  .field-hud b { font-size: .53rem; }
  .field-hud > span:nth-child(3) b { font-size: .47rem; }
}

/* Layered war-table board: two readable armies divided by a ceremonial kill line. */
.board-2d {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: minmax(215px, 1fr) auto minmax(215px, 1fr);
  gap: 9px;
  min-height: 0;
  height: 100%;
  padding: 13px clamp(10px, 2vw, 30px);
  overflow: hidden;
  border: 1px solid rgba(195, 148, 65, .20);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(20, 29, 34, .54) 0 47%, rgba(6, 6, 7, .3) 49% 51%, rgba(46, 20, 15, .50) 53%),
    repeating-linear-gradient(90deg, transparent 0 89px, rgba(255,255,255,.012) 90px);
  box-shadow: inset 0 0 70px rgba(0,0,0,.5), inset 0 1px rgba(255,225,164,.05);
}
.board-2d::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 8px;
  border: 1px solid rgba(210,164,76,.12);
  border-radius: 10px;
  pointer-events: none;
}
.board-2d .side {
  position: relative;
  min-height: 0;
  padding: 25px 14px 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: linear-gradient(110deg, rgba(255,255,255,.025), transparent 34% 66%, rgba(255,255,255,.018));
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 10px 32px rgba(0,0,0,.18);
}
.board-2d .side::before {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font: 700 .58rem/1 var(--font);
  letter-spacing: .28em;
  white-space: nowrap;
  text-transform: uppercase;
  opacity: .72;
}
.board-2d .side.enemy {
  border-color: rgba(94, 141, 157, .22);
  background: linear-gradient(110deg, rgba(29,62,72,.19), transparent 38% 62%, rgba(29,62,72,.15));
}
.board-2d .side.enemy::before { content: "Crown Legion"; color: #9bc7d2; }
.board-2d .side.you {
  border-color: rgba(174, 84, 51, .28);
  background: linear-gradient(110deg, rgba(109,37,23,.18), transparent 38% 62%, rgba(109,37,23,.14));
}
.board-2d .side.you::before { content: "Your War Host"; color: #e0a178; }
.board-2d .slot {
  background-color: rgba(6,7,8,.48);
  box-shadow: inset 0 0 18px rgba(0,0,0,.42), 0 5px 16px rgba(0,0,0,.2);
}
.board-2d .slot.melee { border-color: rgba(157,74,45,.35); }
.board-2d .slot.ranged { border-color: rgba(64,118,140,.35); }
.board-2d .slot.castle { border-color: rgba(190,145,61,.4); }
.board-2d .divider {
  height: 3px;
  margin: 3px 2%;
  background: linear-gradient(90deg, transparent, #603329 12%, var(--gold) 50%, #603329 88%, transparent);
  box-shadow: 0 0 18px rgba(197,128,48,.3), 0 7px 24px rgba(0,0,0,.65);
}
.board-2d .divider span {
  padding: 4px 17px;
  border: 1px solid rgba(206,157,65,.42);
  border-radius: 99px;
  background: linear-gradient(180deg, #18110d, #080809);
  box-shadow: 0 5px 18px rgba(0,0,0,.65);
  letter-spacing: .24em;
}

@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .board-2d {
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 570px;
    padding: 8px 5px;
  }
  .board-2d .side { padding: 22px 4px 6px; }
  .board-2d .side::before { font-size: .48rem; letter-spacing: .18em; }
  .board-2d .divider span { padding: 3px 8px; letter-spacing: .13em; }
}

.play-area::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(212, 168, 75, 0.08);
  z-index: 0;
}

/* Ember / dust motes drifting over the board */
.play-area::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 30%, rgba(255, 180, 80, 0.45), transparent),
    radial-gradient(1px 1px at 40% 70%, rgba(255, 220, 150, 0.35), transparent),
    radial-gradient(1.5px 1.5px at 70% 25%, rgba(255, 160, 60, 0.4), transparent),
    radial-gradient(1px 1px at 85% 60%, rgba(255, 200, 120, 0.3), transparent),
    radial-gradient(1px 1px at 55% 45%, rgba(255, 240, 200, 0.25), transparent);
  animation: embers 9s linear infinite;
  opacity: 0.55;
}

@keyframes embers {
  0% { transform: translateY(0) translateX(0); opacity: 0.35; }
  50% { opacity: 0.65; }
  100% { transform: translateY(-18px) translateX(6px); opacity: 0.35; }
}

.play-area > * {
  position: relative;
  z-index: 1;
}

.side {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
}

.piles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.pile {
  width: 54px;
  text-align: center;
}

.pile-stack {
  width: 50px;
  height: 68px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(30, 20, 16, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  overflow: hidden;
  box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.45);
  position: relative;
}

.pile-stack.card-back-mini,
.card-back-mini {
  background: var(--art-back) center / cover no-repeat;
  border: 2px solid var(--gold-dim);
  color: transparent;
  font-size: 0;
}

.pile-stack .card-face {
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

.pile-stack .card-face .title { display: none; }
.pile-stack .card-face .rank { font-size: 0.9rem; }
.pile-stack .card-face .suit { font-size: 1rem; }

.pile-stack.empty-gy {
  border-style: dashed;
  opacity: 0.7;
}

.pile-stack.has-cards {
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3), 5px 5px 0 rgba(0, 0, 0, 0.2);
}

.pile-stack.depth-2 { box-shadow: 2px 2px 0 #3d2a1e, 4px 4px 0 rgba(0,0,0,0.35); }
.pile-stack.depth-3 { box-shadow: 2px 2px 0 #3d2a1e, 4px 4px 0 #2a1c14, 6px 6px 0 rgba(0,0,0,0.35); }
.pile-stack.depth-4 { box-shadow: 2px 2px 0 #3d2a1e, 4px 4px 0 #2a1c14, 6px 6px 0 #1a100c, 8px 8px 0 rgba(0,0,0,0.4); }

.gy-empty {
  font-size: 0.62rem;
  color: var(--muted);
  font-family: var(--font);
  letter-spacing: 0.08em;
}

.pile-label {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: 3px;
  font-family: var(--font);
  letter-spacing: 0.04em;
}

.army {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  justify-content: center;
}

.row-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.row-label {
  font-size: 0.58rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.divider {
  flex-shrink: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  position: relative;
  margin: 3px 0;
  box-shadow: 0 0 12px rgba(212, 168, 75, 0.35);
  animation: line-pulse 3.5s ease-in-out infinite;
}

@keyframes line-pulse {
  0%, 100% { opacity: 0.7; box-shadow: 0 0 8px rgba(212, 168, 75, 0.25); }
  50% { opacity: 1; box-shadow: 0 0 18px rgba(212, 168, 75, 0.55); }
}

.divider span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(12, 8, 6, 0.95);
  padding: 0 10px;
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  color: var(--gold);
  font-family: var(--font);
}

/* ── Slots / cards ── */
.slot {
  width: var(--card-w);
  height: var(--card-h);
  min-width: var(--card-w);
  min-height: var(--card-h);
  border-radius: 7px;
  border: 2px dashed rgba(180, 140, 70, 0.28);
  background: var(--bg-slot);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  /* Allow click/tap for tip + combat; drag still uses pointer handlers */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(212, 168, 75, 0.2);
}

.slot.has-card-tip,
.hand-card.has-card-tip {
  /* Larger hit area feel on touch */
  z-index: 1;
}

.slot:hover { border-color: var(--gold-dim); transform: translateY(-1px); }
.slot.melee {
  background:
    linear-gradient(160deg, rgba(90, 45, 28, 0.55), rgba(30, 18, 12, 0.85));
}
.slot.ranged {
  background:
    linear-gradient(160deg, rgba(35, 50, 70, 0.55), rgba(14, 18, 28, 0.85));
}
.slot.castle {
  background:
    linear-gradient(160deg, rgba(70, 40, 90, 0.55), rgba(22, 12, 28, 0.9));
  border-style: solid;
  border-color: rgba(180, 140, 70, 0.45);
  width: calc(var(--card-w) + 6px);
  height: calc(var(--card-h) + 6px);
  box-shadow: 0 0 14px rgba(120, 60, 160, 0.2);
}

.slot.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 168, 75, 0.45), var(--glow-gold);
}

.slot.attackable {
  border-color: var(--blood-bright);
  box-shadow: 0 0 14px rgba(231, 76, 60, 0.55);
  animation: pulse-atk 1.3s ease-in-out infinite;
  cursor: crosshair;
}

.slot.resolved { opacity: 0.55; cursor: default; }

/* Just-played cards stay face-up on the grid before going to GY */
.slot.played-linger {
  opacity: 1;
  cursor: default;
  border-style: solid;
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(212, 168, 75, 0.55);
  animation: reveal-pop 0.4s ease-out;
  z-index: 2;
}

.slot.played-linger .card-face {
  animation: card-flip-in 0.45s ease-out;
}

@keyframes card-flip-in {
  0% { transform: rotateY(85deg) scale(0.9); opacity: 0.3; }
  100% { transform: rotateY(0) scale(1); opacity: 1; }
}

@keyframes reveal-pop {
  0% { transform: scale(0.85); filter: brightness(1.6); }
  55% { transform: scale(1.06); filter: brightness(1.15); }
  100% { transform: scale(1); filter: brightness(1); }
}

.slot.drag-over {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(212, 168, 75, 0.6);
  transform: scale(1.05);
}

.slot.flash-attack {
  animation: flash-atk 0.55s ease-out;
}
.slot.flash-defend {
  animation: flash-def 0.55s ease-out;
}
.slot.flash-hit {
  animation: flash-hit 0.6s ease-out;
}
.slot.flash-castle {
  animation: flash-castle 0.75s ease-out;
}

/* Ruined castle — still on board briefly before GY */
.slot.castle-ruined {
  border-color: #8b1a1a !important;
  box-shadow: 0 0 22px rgba(192, 57, 43, 0.75), inset 0 0 20px rgba(80, 0, 0, 0.5);
  z-index: 6;
}

.slot.castle-ruined .card-face {
  filter: grayscale(0.55) brightness(0.65) sepia(0.35) contrast(1.15);
}

/* Permanent rubble token after the card leaves for the graveyard */
.slot.castle-rubble {
  cursor: default;
  border-style: solid !important;
  border-color: #5c4030 !important;
  background:
    radial-gradient(ellipse at 50% 70%, rgba(80, 40, 20, 0.5), transparent 70%),
    linear-gradient(160deg, #2a1c14 0%, #1a100c 50%, #0e0a08 100%) !important;
  box-shadow:
    inset 0 0 18px rgba(0, 0, 0, 0.65),
    0 0 12px rgba(100, 40, 20, 0.35) !important;
  opacity: 1 !important;
}

.castle-rubble-face {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  overflow: hidden;
  border-radius: 5px;
  pointer-events: none;
}

.rubble-stones {
  position: absolute;
  inset: 0;
  opacity: 0.85;
}

.rubble-stones span {
  position: absolute;
  background: linear-gradient(145deg, #6b5344, #3d2a1e 50%, #2a1c14);
  border: 1px solid #1a100c;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.rubble-stones span:nth-child(1) {
  width: 38%; height: 22%; left: 12%; bottom: 18%;
  transform: rotate(-12deg);
  border-radius: 2px;
}
.rubble-stones span:nth-child(2) {
  width: 28%; height: 18%; right: 14%; bottom: 22%;
  transform: rotate(18deg);
  border-radius: 2px;
}
.rubble-stones span:nth-child(3) {
  width: 32%; height: 16%; left: 30%; bottom: 8%;
  transform: rotate(4deg);
  border-radius: 1px;
}
.rubble-stones span:nth-child(4) {
  width: 18%; height: 14%; left: 18%; top: 28%;
  transform: rotate(-25deg);
  border-radius: 1px;
  opacity: 0.7;
}
.rubble-stones span:nth-child(5) {
  width: 22%; height: 12%; right: 20%; top: 32%;
  transform: rotate(30deg);
  border-radius: 2px;
  opacity: 0.65;
}

.rubble-icon {
  position: relative;
  z-index: 1;
  font-size: 1.1rem;
  line-height: 1;
  filter: grayscale(0.3);
  opacity: 0.9;
  text-shadow: 0 1px 2px #000;
}

.rubble-label {
  position: relative;
  z-index: 1;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #c4a574;
  text-shadow: 0 1px 2px #000;
}

.rubble-sub {
  position: relative;
  z-index: 1;
  font-size: 0.48rem;
  letter-spacing: 0.08em;
  color: #8b5a4a;
  font-family: var(--font);
  text-transform: uppercase;
}

.slot.castle-rubble-linger .card-face {
  opacity: 0.85;
}

/* Dramatic collapse — quake, crack, crumble */
.slot.castle-collapse {
  animation: castle-collapse 1.55s cubic-bezier(0.4, 0.05, 0.3, 1) forwards;
}

.slot.castle-collapse::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 8px;
  pointer-events: none;
  background:
    linear-gradient(125deg, transparent 40%, rgba(255, 60, 40, 0.55) 48%, transparent 52%),
    linear-gradient(55deg, transparent 42%, rgba(0, 0, 0, 0.5) 50%, transparent 58%);
  animation: castle-crack 1.55s ease-out forwards;
  z-index: 3;
}

@keyframes castle-collapse {
  0% {
    transform: scale(1) rotate(0);
    filter: brightness(1);
  }
  12% {
    transform: scale(1.18) rotate(-4deg);
    filter: brightness(1.8) saturate(1.6);
  }
  28% {
    transform: scale(1.05) rotate(5deg) translateY(-6px);
    filter: brightness(1.3);
  }
  45% {
    transform: scale(1.1) rotate(-6deg) translateY(2px);
    filter: brightness(0.9) sepia(0.4);
  }
  62% {
    transform: scale(0.95) rotate(8deg) translateY(8px);
    filter: brightness(0.55) grayscale(0.4);
    opacity: 1;
  }
  82% {
    transform: scale(0.7) rotate(-12deg) translateY(18px);
    opacity: 0.55;
    filter: brightness(0.35) grayscale(0.7);
  }
  100% {
    transform: scale(0.35) rotate(18deg) translateY(36px);
    opacity: 0;
    filter: brightness(0.2) grayscale(1);
  }
}

@keyframes castle-crack {
  0% { opacity: 0; transform: scale(0.8); }
  15% { opacity: 1; transform: scale(1.05); }
  50% { opacity: 0.85; }
  100% { opacity: 0; transform: scale(1.4); }
}

.castle-debris,
.castle-ember {
  position: fixed;
  pointer-events: none;
  z-index: 46;
  opacity: 0;
}
.castle-debris {
  width: 7px;
  height: 7px;
  background: linear-gradient(135deg, #6b5344, #2a1c14);
  box-shadow: 0 0 3px #000;
  border-radius: 1px;
}
.castle-ember {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff2a8 0%, #e74c3c 50%, transparent 70%);
  box-shadow: 0 0 8px #e67e22;
}
.castle-debris.go,
.castle-ember.go {
  animation: castle-debris-fly 0.95s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  animation-delay: var(--delay, 0s);
}
@keyframes castle-debris-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translate(var(--sx), var(--sy)) rotate(var(--rot, 200deg)) scale(0.3);
  }
}

.castle-shockwave {
  position: fixed;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 3px solid rgba(231, 76, 60, 0.85);
  box-shadow: 0 0 20px rgba(192, 57, 43, 0.7), inset 0 0 12px rgba(255, 100, 50, 0.4);
  pointer-events: none;
  z-index: 44;
  opacity: 0;
}
.castle-shockwave.go {
  animation: shockwave 0.75s ease-out forwards;
}
@keyframes shockwave {
  0% { opacity: 1; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(8); border-width: 1px; }
}

/* Combat motion */
.slot.anim-lunge {
  z-index: 5;
  animation: lunge 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
.slot.anim-impact {
  animation: impact-kick 0.45s ease-out;
}
.slot.anim-impact-heavy {
  animation: impact-kick-heavy 0.55s ease-out;
}

@keyframes lunge {
  0% { transform: translate(0, 0) scale(1); }
  35% { transform: translate(var(--lunge-x, 0), var(--lunge-y, -12px)) scale(1.12); filter: brightness(1.25); }
  100% { transform: translate(0, 0) scale(1); filter: brightness(1); }
}
@keyframes impact-kick {
  0% { transform: scale(1); }
  30% { transform: scale(1.12) rotate(-2deg); filter: brightness(1.4); }
  100% { transform: scale(1) rotate(0); filter: brightness(1); }
}
@keyframes impact-kick-heavy {
  0% { transform: scale(1); }
  25% { transform: scale(1.18) rotate(3deg); filter: brightness(1.6) saturate(1.3); }
  55% { transform: scale(0.96) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); filter: brightness(1); }
}

@keyframes pulse-atk {
  0%, 100% { box-shadow: 0 0 8px rgba(231, 76, 60, 0.35); }
  50% { box-shadow: 0 0 18px rgba(231, 76, 60, 0.75); }
}
@keyframes flash-atk {
  0% { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.9); transform: scale(1.08); }
  100% { box-shadow: 0 0 0 12px rgba(241, 196, 15, 0); transform: scale(1); }
}
@keyframes flash-def {
  0% { box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.9); }
  100% { box-shadow: 0 0 0 12px rgba(52, 152, 219, 0); }
}
@keyframes flash-hit {
  0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.95); filter: brightness(1.4); }
  100% { box-shadow: 0 0 0 14px rgba(231, 76, 60, 0); filter: brightness(1); }
}
@keyframes flash-castle {
  0% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 1); filter: brightness(1.5) saturate(1.3); }
  100% { box-shadow: 0 0 20px rgba(192, 57, 43, 0); filter: brightness(1); }
}

/* Spark particles */
.battle-spark {
  position: fixed;
  width: 5px;
  height: 5px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6d0 0%, #f0a020 40%, transparent 70%);
  box-shadow: 0 0 6px #ffaa33;
  pointer-events: none;
  z-index: 45;
  opacity: 0;
}
.battle-spark.go {
  animation: spark-fly 0.5s ease-out forwards;
}

.element-particle {
  position: fixed;
  z-index: 1002;
  width: var(--esize);
  height: var(--esize);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.35);
  filter: blur(.2px);
}
.element-particle.go { animation: element-burst .82s cubic-bezier(.12,.68,.2,1) forwards; }
.element-fire { background:#ff6a22; box-shadow:0 0 10px 3px rgba(255,75,18,.65); }
.element-wind { background:#f4d67a; box-shadow:0 0 9px 3px rgba(224,208,125,.58); }
.element-water { background:#67c9f2; box-shadow:0 0 10px 3px rgba(48,143,207,.62); }
.element-earth { background:#8fae55; border-radius:2px; box-shadow:0 0 8px 2px rgba(91,130,55,.55); }
@keyframes element-burst {
  0% { opacity:0; transform:translate(-50%,-50%) scale(.25); }
  18% { opacity:1; }
  100% { opacity:0; transform:translate(calc(-50% + var(--ex)),calc(-50% + var(--ey))) scale(.05) rotate(160deg); }
}
@keyframes spark-fly {
  0% { opacity: 1; transform: translate(0, 0) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--sx), var(--sy)) scale(0.2); }
}

.chip.hp-pulse {
  animation: hp-flash 0.65s ease-out;
}
@keyframes hp-flash {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 14px rgba(231, 76, 60, 0.85); background: rgba(80, 20, 16, 0.9); }
}

.pile-stack.gy-receive {
  animation: gy-pop 0.45s ease-out;
}
@keyframes gy-pop {
  0% { transform: scale(0.7); filter: brightness(1.5); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); filter: brightness(1); }
}

.pile-stack.card-back-mini {
  animation: deck-idle 4s ease-in-out infinite;
}
@keyframes deck-idle {
  0%, 100% { box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.45); }
  50% { box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.45), 0 0 10px rgba(212, 168, 75, 0.25); }
}

.card-face {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background:
    linear-gradient(165deg, #f8f0dc 0%, #e8d8b8 45%, #d4c4a0 100%);
  color: #1a120c;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5px 3px 4px;
  font-weight: 700;
  border: 1px solid #b8a070;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.35),
    0 2px 4px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  font-family: var(--font);
  position: relative;
  overflow: hidden;
  /* iOS Safari: promote layer so court atlas composites reliably */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.card-face::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(120, 90, 40, 0.25);
  border-radius: 3px;
  pointer-events: none;
}

.card-face .rank { font-size: 1rem; line-height: 1; position: relative; }
.card-face .suit { font-size: 1.2rem; line-height: 1; position: relative; }
.card-face .title {
  font-size: 0.48rem;
  font-weight: 600;
  text-transform: uppercase;
  opacity: 0.8;
  text-align: center;
  line-height: 1.1;
  letter-spacing: 0.02em;
  position: relative;
  font-family: var(--font-ui);
}

.card-face.court {
  color: #f4ead2;
  background: #100d0d;
  border-color: #94733d;
  text-shadow: 0 1px 3px #000;
}

.court-portrait {
  position: absolute;
  inset: 0;
  background-image: var(--art-court);
  background-size: 200% 200%;
  background-repeat: no-repeat;
  background-color: #100d0d;
  /* Avoid filter() on iOS when possible — causes blank/flicker on some WebKit builds */
  filter: saturate(0.85) contrast(1.05) brightness(0.88);
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
}

@supports (-webkit-touch-callout: none) {
  /* iOS / iPadOS Safari: filters on bg images often fail — keep portrait unfiltered */
  .court-portrait {
    filter: none;
  }
}

.card-face.rank-11 .court-portrait { background-position: 0 0; }
.card-face.rank-12 .court-portrait { background-position: 100% 0; }
.card-face.rank-13 .court-portrait { background-position: 0 100%; }
.card-face.rank-14 .court-portrait { background-position: 100% 100%; }

.card-face.court::after {
  content:""; position:absolute; inset:0;
  background:linear-gradient(180deg,rgba(0,0,0,.12),transparent 40%,rgba(0,0,0,.82));
}

.card-face.court .rank,
.card-face.court .suit,
.card-face.court .title { z-index:2; }
.card-face.court .rank { align-self:flex-start; padding:1px 3px; background:rgba(7,5,5,.7); border-radius:3px; }
.card-face.court .suit { position:absolute; top:5px; right:6px; }
.card-face.court .title { width:100%; color:#f2d99a; opacity:1; font-weight:800; }
.card-face.court.red .rank,
.card-face.court.red .suit { color:#ff8d61; }
.card-face.court.black .rank,
.card-face.court.black .suit { color:#b8d9ed; }

.card-face.red .suit,
.card-face.red .rank { color: #a93226; }
.card-face.black .suit,
.card-face.black .rank { color: #1c2833; }

/* Element tint strip */
.card-face.fire { box-shadow: inset 0 -3px 0 #c0392b, 0 2px 4px rgba(0,0,0,0.35); }
.card-face.wind { box-shadow: inset 0 -3px 0 #d68910, 0 2px 4px rgba(0,0,0,0.35); }
.card-face.water { box-shadow: inset 0 -3px 0 #2980b9, 0 2px 4px rgba(0,0,0,0.35); }
.card-face.earth { box-shadow: inset 0 -3px 0 #1e8449, 0 2px 4px rgba(0,0,0,0.35); }

.card-back {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: var(--art-back) center / cover no-repeat;
  border: 2px solid var(--gold-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.slot-hint {
  position: absolute;
  bottom: 3px;
  font-size: 0.5rem;
  color: var(--muted);
  pointer-events: none;
  font-family: var(--font);
  letter-spacing: 0.04em;
}

/* ── Hand ── */
.hand-bar {
  position: relative;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding-top: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

/* The current progression action rises above the hand as a clear, non-blocking prompt. */
.controls .progress-cta {
  position: absolute;
  left: 50%;
  top: -58px;
  z-index: 24;
  min-width: min(360px, 72vw);
  min-height: 45px;
  transform: translateX(-50%);
  border: 1px solid #e5bd63;
  border-radius: 999px;
  padding: 10px 28px;
  color: #1b1008;
  background:
    linear-gradient(180deg, rgba(255,236,164,.42), transparent 35%),
    linear-gradient(180deg, #d6a633, #987018);
  box-shadow:
    0 0 0 3px rgba(11,8,6,.72),
    0 0 0 4px rgba(207,159,63,.32),
    0 12px 34px rgba(0,0,0,.62),
    0 0 28px rgba(219,164,55,.28);
  font-size: .82rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  animation: progress-cta-arrive .38s cubic-bezier(.2,.8,.25,1) both;
}
.controls .progress-cta::before { content: "◆"; margin-right: 10px; font-size: .62em; }
.controls .progress-cta::after { content: "◆"; margin-left: 10px; font-size: .62em; }
.controls .progress-cta:hover {
  transform: translateX(-50%) translateY(-2px);
  filter: brightness(1.12);
  box-shadow:
    0 0 0 3px rgba(11,8,6,.78),
    0 0 0 4px rgba(237,190,89,.5),
    0 15px 40px rgba(0,0,0,.68),
    0 0 38px rgba(231,179,67,.42);
}
@keyframes progress-cta-arrive {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(.96); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .controls .progress-cta {
    top: -54px;
    width: calc(100vw - 28px);
    min-width: 0;
    min-height: 44px;
    padding: 9px 12px !important;
    font-size: .72rem !important;
  }
}

.hand-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.75rem;
}

.hand-meta strong {
  color: var(--gold);
  font-family: var(--font);
  letter-spacing: 0.06em;
}

.hint {
  color: var(--muted);
  font-size: 0.72rem;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hand {
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  align-items: center;
  min-height: var(--card-h);
  overflow-x: auto;
  padding: 2px 0 4px;
}

.hand.drag-over {
  outline: 2px dashed var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

.hand-card {
  width: var(--card-w);
  height: var(--card-h);
  cursor: grab;
  border-radius: 7px;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.3, 1), border-color 0.12s, box-shadow 0.12s;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
  animation: hand-deal 0.35s ease-out both;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hand-card.dragging,
.slot.dragging {
  opacity: 0.35;
}

/* Floating card while dragging (mouse + touch) */
.drag-ghost {
  position: fixed;
  width: var(--card-w);
  height: var(--card-h);
  margin: calc(var(--card-h) / -2) 0 0 calc(var(--card-w) / -2);
  z-index: 100;
  pointer-events: none;
  opacity: 0.95;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.55));
  transform: scale(1.08) rotate(3deg);
}

.hand-card:nth-child(1) { animation-delay: 0.02s; }
.hand-card:nth-child(2) { animation-delay: 0.05s; }
.hand-card:nth-child(3) { animation-delay: 0.08s; }
.hand-card:nth-child(4) { animation-delay: 0.11s; }
.hand-card:nth-child(5) { animation-delay: 0.14s; }
.hand-card:nth-child(6) { animation-delay: 0.17s; }
.hand-card:nth-child(7) { animation-delay: 0.2s; }

@keyframes hand-deal {
  from { opacity: 0; transform: translateY(16px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hand-card:hover { transform: translateY(-8px) scale(1.04); }
.hand-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(212, 168, 75, 0.55);
  transform: translateY(-6px);
}
.hand-card:active { cursor: grabbing; }
.hand-card.dragging { opacity: 0.4; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

button {
  font-family: var(--font);
  border: 1px solid var(--gold-dim);
  border-radius: 5px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: linear-gradient(180deg, #c9a227 0%, #8a6a12 100%);
  color: #1a1008;
  text-shadow: 0 1px 0 rgba(255, 240, 200, 0.25);
  box-shadow: 0 2px 0 #4a3808, 0 3px 8px rgba(0, 0, 0, 0.35);
}

button.tiny { padding: 4px 9px; font-size: 0.68rem; }
button:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 2px 0 #4a3808, 0 0 12px rgba(212, 168, 75, 0.4);
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.3); }
button.secondary {
  background: linear-gradient(180deg, #3a2e24 0%, #241c16 100%);
  color: var(--text);
  border-color: var(--line);
  text-shadow: none;
  box-shadow: 0 2px 0 #100c08;
}
button.danger {
  background: linear-gradient(180deg, #a93226 0%, #6b1510 100%);
  color: #fff;
  border-color: #7b241c;
  text-shadow: none;
}

/* ── Log sidebar ── */
.log-panel {
  min-height: 0;
  background: rgba(10, 7, 6, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--glow-gold);
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 8px;
}

.log-panel h2 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--gold);
  font-family: var(--font);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.log-collapse-btn {
  padding: 2px 8px !important;
  font-size: 0.7rem !important;
  min-width: 0;
  box-shadow: none !important;
  background: transparent !important;
  border: 1px solid var(--line) !important;
  color: var(--muted) !important;
  font-family: var(--font-ui) !important;
}

.log-collapse-btn:hover {
  color: var(--gold) !important;
  border-color: var(--gold-dim) !important;
}

.log-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.log-panel li {
  font-size: 0.72rem;
  color: #c4b090;
  padding: 5px 0;
  border-bottom: 1px solid rgba(74, 60, 46, 0.35);
  line-height: 1.35;
  font-family: var(--font-ui);
}

.log-panel li:first-child {
  color: var(--gold-bright);
  font-weight: 600;
}

.help-link {
  flex-shrink: 0;
  margin-top: 6px;
  width: 100%;
  font-size: 0.72rem !important;
  padding: 7px 8px !important;
  background: transparent !important;
  border: 1px dashed var(--line) !important;
  color: var(--gold-dim) !important;
  box-shadow: none !important;
  font-family: var(--font) !important;
  letter-spacing: 0.04em;
}

.help-link:hover {
  color: var(--gold-bright) !important;
  border-color: var(--gold-dim) !important;
}

.mode-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

/* ── Full rules / how to play ── */
.rules-screen {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(5px);
}

.rules-screen.open,
.rules-screen.open[hidden] {
  display: flex !important;
}

.rules-card {
  width: min(720px, 100%);
  max-height: min(88vh, 820px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(32, 22, 16, 0.98), rgba(12, 8, 6, 0.99));
  border: 2px solid var(--gold);
  border-radius: 14px;
  box-shadow: 0 0 50px rgba(212, 168, 75, 0.2), 0 24px 60px rgba(0, 0, 0, 0.75);
  overflow: hidden;
}

.rules-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.rules-top h1 {
  margin: 0;
  font-family: var(--font);
  font-size: 1.25rem;
  color: var(--gold-bright);
  letter-spacing: 0.08em;
}

.rules-lead {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.rules-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.25);
}

.rules-tab {
  font-family: var(--font) !important;
  font-size: 0.68rem !important;
  padding: 6px 10px !important;
  letter-spacing: 0.04em;
  background: #2a2118 !important;
  color: var(--muted) !important;
  border: 1px solid var(--line) !important;
  box-shadow: none !important;
}

.rules-tab:hover {
  color: var(--text) !important;
  border-color: var(--gold-dim) !important;
}

.rules-tab.active {
  color: #1a1008 !important;
  background: linear-gradient(180deg, #c9a227, #8a6a12) !important;
  border-color: var(--gold-dim) !important;
}

.rules-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px 8px;
}

.rules-panel {
  display: none;
  animation: rules-in 0.25s ease-out;
}

.rules-panel.active {
  display: block;
}

@keyframes rules-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.rules-panel h2 {
  margin: 0 0 8px;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.rules-panel h2:not(:first-child) {
  margin-top: 18px;
}

.rules-panel h3 {
  margin: 0 0 6px;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--gold-bright);
}

.rules-panel p,
.rules-panel li {
  font-size: 0.84rem;
  line-height: 1.5;
  color: #d4c4a8;
}

.rules-panel p {
  margin: 0 0 10px;
}

.rules-panel ol,
.rules-panel ul {
  margin: 0 0 10px;
  padding-left: 1.25rem;
}

.rules-panel li {
  margin-bottom: 4px;
}

.rules-panel b {
  color: var(--text);
}

.rules-diagram {
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--gold-dim);
  white-space: pre;
  overflow-x: auto;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: 0.8rem;
}

.rules-table th,
.rules-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.rules-table th {
  background: rgba(80, 55, 25, 0.35);
  color: var(--gold);
  font-family: var(--font);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.rules-table td {
  color: #d4c4a8;
}

.rules-table-wide td:first-child {
  white-space: nowrap;
  color: var(--gold-bright);
  font-weight: 600;
  width: 7rem;
}

.trump-list {
  list-style: none;
  padding-left: 0 !important;
}

.trump-list li {
  padding: 5px 10px;
  margin-bottom: 4px !important;
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--gold-dim);
  border-radius: 0 6px 6px 0;
}

.rules-note {
  font-size: 0.75rem !important;
  color: var(--muted) !important;
  font-style: italic;
}

.rules-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 560px) {
  .rules-mode-grid { grid-template-columns: 1fr; }
}

.rules-mode-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
}

.rules-mode-box p {
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.rules-foot {
  flex-shrink: 0;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
}

/* ── Floating combat text ── */
#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  overflow: hidden;
}

.floater {
  position: fixed;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  font-family: var(--font);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  white-space: nowrap;
  text-shadow:
    0 2px 0 #000,
    0 0 8px rgba(0, 0, 0, 0.8),
    0 0 18px rgba(0, 0, 0, 0.5);
  z-index: 41;
  transition: none;
  pointer-events: none;
}

.floater.show {
  animation: floater-rise 1.45s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.floater.fade {
  opacity: 0 !important;
}

.floater-dmg {
  color: #ff4d4d;
  font-size: 1.55rem;
}
.floater-critical {
  color: #ff2222;
  font-size: 1.35rem;
  text-shadow: 0 0 12px rgba(255, 40, 40, 0.7), 0 2px 0 #000;
}
.floater-block {
  color: #5dade2;
  font-size: 1.25rem;
}
.floater-trump {
  color: #f4d03f;
  font-size: 1.3rem;
  text-shadow: 0 0 14px rgba(244, 208, 63, 0.75), 0 2px 0 #000;
}
.floater-absorb {
  color: #a569bd;
  font-size: 1.2rem;
}
.floater-info {
  color: #f5e6c8;
  font-size: 1.05rem;
}
.floater-heal {
  color: #58d68d;
  font-size: 1.2rem;
}

@keyframes floater-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.5);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -55%) scale(1.15);
  }
  30% {
    transform: translate(-50%, -70%) scale(1);
  }
  75% {
    opacity: 1;
    transform: translate(-50%, -110%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(0.9);
  }
}

/* Banner toast for major events */
.combat-banner {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%) translateY(-10px);
  background: linear-gradient(90deg, transparent, rgba(20, 10, 8, 0.92), transparent);
  border-top: 1px solid var(--gold-dim);
  border-bottom: 1px solid var(--gold-dim);
  color: var(--gold-bright);
  font-family: var(--font);
  font-size: 1.1rem;
  letter-spacing: 0.14em;
  padding: 10px 48px;
  opacity: 0;
  pointer-events: none;
  z-index: 42;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(212, 168, 75, 0.5);
  transition: opacity 0.35s, transform 0.35s;
}
.combat-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Input lock during combat presentation */
.app.fx-busy .slot.attackable {
  pointer-events: none;
  animation: none;
  opacity: 0.85;
}

/* ── Card tooltip (minimal hover · pinned on mobile tap/hold) ── */
.card-tip {
  position: fixed;
  z-index: 120;
  max-width: min(260px, calc(100vw - 16px));
  min-width: 160px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--gold-dim);
  background: linear-gradient(180deg, rgba(28, 20, 14, 0.98), rgba(12, 8, 6, 0.99));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 12px rgba(212, 168, 75, 0.12);
  /* Allow reading/tapping on iOS without the tip vanishing under the finger */
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  transform: translate(-50%, calc(-100% - 10px));
  font-family: var(--font-ui);
}

/* Sticky tip after mobile tap/hold — easier to read damage + castle ability */
.card-tip.is-pinned {
  z-index: 130;
  max-width: min(300px, calc(100vw - 20px));
  padding: 12px 14px;
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(212, 168, 75, 0.22),
    0 0 20px rgba(212, 168, 75, 0.12);
  cursor: pointer;
}

/* Optional: brief ready state if ever armed without moving */
.hand-card.drag-ready,
.slot.drag-ready {
  outline: 2px solid rgba(244, 162, 97, 0.65);
  outline-offset: 2px;
}

.card-tip[hidden] {
  display: none !important;
}

@media (hover: none), (pointer: coarse) {
  .card-tip,
  .card-tip.is-pinned {
    font-size: 1rem;
    padding: 12px 14px;
    max-width: min(320px, calc(100vw - 20px));
  }
  .card-tip-title {
    font-size: 0.9rem;
  }
  .card-tip-body {
    font-size: 0.8rem;
    line-height: 1.45;
  }
}

.card-tip-title {
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(180, 140, 70, 0.25);
}

.card-tip-body {
  font-size: 0.68rem;
  line-height: 1.4;
  color: #cbb89a;
}

.card-tip-body .tip-line {
  margin: 0 0 3px;
}

.card-tip-body .tip-line:last-child {
  margin-bottom: 0;
  color: #a89070;
  font-style: italic;
}

.card-tip-body .tip-line.tip-castle {
  color: #d2b4de;
  font-style: normal;
  font-weight: 600;
}

/* ── Splash intro ── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #050302;
  color: var(--text);
  font-family: var(--font);
}

.splash.is-done {
  pointer-events: none;
  animation: splash-out 0.48s ease-in forwards;
}

@keyframes splash-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* ── Splash v2: soft fades + elemental realms (≈4.5s) ── */
.splash-v2 .splash-crest {
  width: 96px;
  height: 96px;
  margin-bottom: 20px;
  opacity: 0;
  transform: translateY(10px);
  will-change: opacity, transform;
}
.splash-v2.splash-beat-crest .splash-crest {
  animation: splash-v2-soft-in 1.15s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.splash-v2 .splash-kicker {
  margin: 0 0 12px;
  font-size: 0.7rem;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: rgba(232, 212, 160, 0.78);
  opacity: 0;
  transform: translateY(8px);
}
.splash-v2.splash-beat-crest .splash-kicker {
  animation: splash-v2-soft-in 1.1s cubic-bezier(0.22, 0.61, 0.36, 1) 0.2s forwards;
}

.splash-v2 .splash-title {
  opacity: 0;
  transform: translateY(14px);
  margin: 0.1em 0 0.45em;
  font-size: clamp(2rem, 8.5vw, 3.35rem);
  letter-spacing: 0.16em;
  will-change: opacity, transform;
}
.splash-v2.splash-beat-title .splash-title {
  animation: splash-v2-soft-in 1.25s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.splash-v2 .splash-tagline {
  margin: 0 0 1.25em;
  font-size: clamp(0.88rem, 2.4vw, 1.05rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(232, 220, 190, 0.88);
  text-shadow: none;
  opacity: 0;
  transform: translateY(10px);
}
.splash-v2.splash-beat-tag .splash-tagline {
  animation: splash-v2-soft-in 1.15s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@keyframes splash-v2-soft-in {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Soft ambient lift behind title — no flash/slash */
.splash-soft-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse 55% 40% at 50% 42%, rgba(212, 168, 75, 0.12), transparent 70%),
    radial-gradient(ellipse 30% 35% at 28% 55%, rgba(200, 70, 40, 0.08), transparent 65%),
    radial-gradient(ellipse 30% 35% at 72% 55%, rgba(60, 120, 160, 0.08), transparent 65%);
  transition: opacity 1.4s ease;
}
.splash-v2.splash-beat-title .splash-soft-glow {
  opacity: 1;
}

/* Elemental kingdoms — Fire & Wind vs Water & Earth (light chips inside glass) */
.splash-v2 .splash-realms {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: none;
  margin: 0 auto;
  opacity: 0;
  transform: translateY(14px);
}
.splash-v2.splash-beat-realms .splash-realms {
  animation: splash-v2-soft-in 1.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.splash-realm {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
  border-radius: 14px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.04);
  border: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.splash-realm-ash {
  background: rgba(200, 80, 40, 0.1);
  box-shadow: inset 0 0 0 1px rgba(230, 120, 70, 0.14);
}

.splash-realm-tide {
  background: rgba(50, 110, 150, 0.1);
  box-shadow: inset 0 0 0 1px rgba(100, 160, 200, 0.14);
}

.splash-realm-suits {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.splash-suit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35em;
  height: 1.35em;
  font-size: 1.35rem;
  line-height: 1;
  text-shadow: 0 0 14px currentColor, 0 2px 8px rgba(0, 0, 0, 0.65);
  opacity: 0.95;
}

.splash-suit-fire {
  color: #e74c3c;
}
.splash-suit-wind {
  color: #e8c04a;
}
.splash-suit-water {
  color: #5dade2;
}
.splash-suit-earth {
  color: #58d68d;
}

.splash-realm-label {
  font-family: var(--font);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #d8c9a8;
  white-space: nowrap;
}
.splash-realm-ash .splash-realm-label {
  color: #e8b896;
}
.splash-realm-tide .splash-realm-label {
  color: #a8c8d8;
}

.splash-realm-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  flex-shrink: 0;
}
.splash-realm-vs {
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-dim);
  opacity: 0.85;
}

.splash-v2.splash-beat-hold .splash-realm-ash {
  transition: background 1.4s ease;
  background: rgba(200, 80, 40, 0.14);
}
.splash-v2.splash-beat-hold .splash-realm-tide {
  transition: background 1.4s ease;
  background: rgba(50, 110, 150, 0.14);
}

.splash-v2 .splash-crest {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 8px 28px rgba(0, 0, 0, 0.35);
}

.splash-v2 .splash-skip {
  background: rgba(12, 10, 9, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: rgba(232, 220, 190, 0.8);
}

/* Exit fade — softer */
.splash-v2.is-done {
  animation: splash-out 0.7s ease-in forwards;
}

@media (max-width: 560px) {
  .splash-v2 .splash-crest {
    width: 72px;
    height: 72px;
    margin-bottom: 14px;
  }
  .splash-realm {
    padding: 12px 10px 10px;
  }
  .splash-realm-label {
    font-size: 0.62rem;
    letter-spacing: 0.1em;
  }
  .splash-suit {
    font-size: 1.15rem;
  }
  .splash-realm-divider {
    padding: 0 6px;
  }
}

.splash-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Deep warm base under the blurred fill (never pure black slabs) */
  background: radial-gradient(ellipse at center, #1a1410 0%, #0c0a08 55%, #070605 100%);
}

/*
 * Letterbox fill: same court art, blurred + enlarged so side/top bars
 * feel continuous with the piece instead of hard black gutters.
 */
.splash-court-fill {
  position: absolute;
  inset: -8%;
  width: 116%;
  height: 116%;
  object-fit: cover;
  object-position: center;
  filter: blur(42px) saturate(1.05) brightness(0.72);
  transform: scale(1.08);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

/* Square frame = atlas aspect; always shows full J|Q/K|A without cropping faces */
.splash-court-frame {
  position: relative;
  z-index: 1;
  width: min(100vw, 100vh);
  height: min(100vw, 100vh);
  max-width: 100%;
  max-height: 100%;
  flex-shrink: 0;
  overflow: hidden;
}

.splash-court-atlas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill; /* frame is already 1:1 matching the atlas */
  object-position: center;
  pointer-events: none;
  user-select: none;
  /* Soft outer blend into the blurred fill (kills hard image-edge cut) */
  -webkit-mask-image: radial-gradient(
    ellipse 78% 78% at 50% 50%,
    #000 58%,
    rgba(0, 0, 0, 0.85) 72%,
    rgba(0, 0, 0, 0.35) 88%,
    transparent 100%
  );
  mask-image: radial-gradient(
    ellipse 78% 78% at 50% 50%,
    #000 58%,
    rgba(0, 0, 0, 0.85) 72%,
    rgba(0, 0, 0, 0.35) 88%,
    transparent 100%
  );
}

/*
 * Soften the baked-in atlas cross (4-box gutters) so it reads as one tableau.
 * Gradients sit on the midlines of the square frame only.
 */
.splash-seam-veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    /* vertical gutter */
    linear-gradient(
      90deg,
      transparent 0%,
      transparent calc(50% - 22px),
      rgba(12, 9, 7, 0.22) calc(50% - 8px),
      rgba(10, 8, 6, 0.48) 50%,
      rgba(12, 9, 7, 0.22) calc(50% + 8px),
      transparent calc(50% + 22px),
      transparent 100%
    ),
    /* horizontal gutter */
    linear-gradient(
      180deg,
      transparent 0%,
      transparent calc(50% - 22px),
      rgba(12, 9, 7, 0.22) calc(50% - 8px),
      rgba(10, 8, 6, 0.48) 50%,
      rgba(12, 9, 7, 0.22) calc(50% + 8px),
      transparent calc(50% + 22px),
      transparent 100%
    ),
    /* center bloom softens the cross junction */
    radial-gradient(
      circle at 50% 50%,
      rgba(14, 11, 9, 0.35) 0%,
      rgba(14, 11, 9, 0.12) 8%,
      transparent 22%
    );
  mix-blend-mode: multiply;
  opacity: 0.92;
}

/* Extra edge atmosphere into the fill */
.splash-edge-feather {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  box-shadow: inset 0 0 80px 28px rgba(10, 8, 6, 0.35);
  background: radial-gradient(
    ellipse 85% 85% at 50% 50%,
    transparent 50%,
    rgba(8, 6, 5, 0.25) 78%,
    rgba(6, 5, 4, 0.55) 100%
  );
}

.splash-vignette {
  display: none;
}

.splash-embers {
  display: none;
}

.splash-soft-glow {
  display: none;
}

/* Type sits on glass — light shadow only, art stays fully visible around panel */
.splash-v2 .splash-stage {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.splash-v2 .splash-title {
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.45),
    0 0 22px rgba(212, 168, 75, 0.2);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .splash-v2 .splash-stage {
    background: rgba(14, 11, 9, 0.78);
  }
}

.splash-embers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 15% 80%, rgba(255, 120, 40, 0.7), transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, rgba(255, 200, 80, 0.5), transparent),
    radial-gradient(2px 2px at 65% 85%, rgba(255, 90, 30, 0.55), transparent),
    radial-gradient(1px 1px at 80% 60%, rgba(255, 180, 60, 0.4), transparent),
    radial-gradient(1.5px 1.5px at 30% 40%, rgba(255, 140, 50, 0.35), transparent);
  animation: splash-embers 7s linear infinite;
  opacity: 0.55;
  mix-blend-mode: screen;
}

@keyframes splash-embers {
  0% { transform: translateY(8%) translateX(0); opacity: 0.35; }
  50% { opacity: 0.7; }
  100% { transform: translateY(-12%) translateX(3%); opacity: 0.35; }
}

.splash-scratch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background:
    repeating-linear-gradient(
      -8deg,
      transparent,
      transparent 3px,
      rgba(255, 255, 255, 0.04) 3px,
      rgba(255, 255, 255, 0.04) 4px
    );
  animation: splash-flicker 0.12s steps(2) infinite;
}

@keyframes splash-flicker {
  0% { opacity: 0.05; }
  50% { opacity: 0.09; }
  100% { opacity: 0.06; }
}

.splash-stage {
  position: relative;
  z-index: 4;
  max-width: min(640px, 92vw);
  text-align: center;
  padding: 24px 16px;
}

/* Glass panel over court art — borderless frosted window */
.splash-v2 .splash-stage {
  max-width: min(520px, 90vw);
  padding: clamp(22px, 4vw, 36px) clamp(20px, 4.5vw, 40px) clamp(20px, 3.5vw, 32px);
  border: none;
  border-radius: 22px;
  background: rgba(12, 10, 9, 0.38);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  /* subtle edge light only — not a hard border */
  outline: 1px solid rgba(255, 255, 255, 0.06);
  outline-offset: -1px;
  /* iOS: isolate so backdrop-filter composites predictably */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* iOS often weakens backdrop-filter — slightly denser glass so text stays readable */
@supports (-webkit-touch-callout: none) {
  .splash-v2 .splash-stage {
    background: rgba(12, 10, 9, 0.55);
  }
  .splash-court-fill {
    /* Lighter blur cost on mobile Safari */
    filter: blur(28px) saturate(1.05) brightness(0.72);
  }
}

.splash-crest {
  width: 88px;
  height: 88px;
  margin: 0 auto 28px;
  border-radius: 50%;
  background: var(--art-crest) center / cover;
  border: 2px solid var(--gold-dim);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.8),
    0 0 40px rgba(180, 40, 20, 0.35),
    0 0 80px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: scale(0.7);
}

.splash-crest.is-in {
  animation: splash-crest-in 1.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes splash-crest-in {
  0% { opacity: 0; transform: scale(0.6) rotate(-8deg); filter: brightness(0.4); }
  60% { opacity: 1; transform: scale(1.08) rotate(2deg); filter: brightness(1.2); }
  100% { opacity: 1; transform: scale(1) rotate(0); filter: brightness(1); }
}

.splash-line {
  margin: 0 0 0.65em;
  font-size: clamp(0.95rem, 2.8vw, 1.2rem);
  line-height: 1.45;
  letter-spacing: 0.04em;
  color: #c4b08a;
  text-shadow: 0 2px 12px #000, 0 0 24px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: translateY(14px);
  min-height: 0;
}

.splash-line.is-in {
  animation: splash-line-in 0.85s ease-out forwards;
}

.splash-line.is-out {
  animation: splash-line-out 0.55s ease-in forwards;
}

@keyframes splash-line-in {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes splash-line-out {
  to { opacity: 0; transform: translateY(-10px); }
}

.splash-line-title {
  color: var(--gold-bright);
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 1.2em;
}

.splash-title {
  margin: 0.4em 0 0.2em;
  font-size: clamp(2rem, 8vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--gold-bright);
  text-shadow:
    0 0 20px rgba(200, 40, 20, 0.55),
    0 3px 0 #1a0a06,
    0 0 60px rgba(212, 168, 75, 0.35);
  opacity: 0;
  transform: scale(0.85);
}

.splash-title.is-in {
  animation: splash-title-in 1.2s cubic-bezier(0.2, 0.75, 0.25, 1) forwards;
}

@keyframes splash-title-in {
  0% { opacity: 0; transform: scale(0.8); letter-spacing: 0.4em; filter: blur(4px); }
  70% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: scale(1); letter-spacing: 0.14em; }
}

.splash-line-sub {
  color: var(--gold-dim);
  font-size: 0.85rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  margin-top: 0.5em;
}

.splash-enter {
  margin-top: 1.8em;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 14px 28px;
  min-height: 48px;
  border-radius: 6px;
  border: 1px solid var(--gold-dim);
  background: linear-gradient(180deg, #a83220 0%, #5c1410 100%);
  color: #f5e6c8;
  box-shadow: 0 4px 0 #2a0806, 0 0 24px rgba(160, 40, 20, 0.4);
  cursor: pointer;
}

.splash-enter.is-in {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity 0.6s ease, transform 0.6s ease, filter 0.15s;
}

.splash-enter.is-in:hover {
  filter: brightness(1.12);
}

.splash-skip {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 6;
  font-family: var(--font);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid rgba(180, 140, 70, 0.35);
  background: rgba(10, 6, 4, 0.65);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.splash-skip:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}

body.splash-active .app,
body.splash-active .mode-screen {
  visibility: hidden;
}

@media (max-width: 560px) {
  .splash-crest {
    width: 64px;
    height: 64px;
    margin-bottom: 18px;
  }
  .splash-line {
    font-size: 0.92rem;
  }
  .splash-skip {
    font-size: 0.7rem;
    padding: 8px 12px;
  }
}

/* ── Mode select ── */
.mode-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse at center, rgba(40, 20, 12, 0.55) 0%, rgba(0, 0, 0, 0.88) 70%),
    rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.mode-screen.open { display: flex; }

.mode-card {
  max-width: 560px;
  width: 100%;
  text-align: center;
  background: linear-gradient(180deg, rgba(36, 24, 18, 0.98), rgba(14, 10, 8, 0.98));
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 20px 16px 88px;
  margin: auto 0;
  box-shadow: 0 0 50px rgba(212, 168, 75, 0.22), 0 24px 60px rgba(0, 0, 0, 0.7);
  position: relative;
}

.mode-crest {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--art-crest) center / cover;
  border: 2px solid var(--gold-dim);
  box-shadow: 0 0 20px rgba(212, 168, 75, 0.35);
}

.mode-card h1 {
  margin: 0;
  font-family: var(--font);
  color: var(--gold-bright);
  letter-spacing: 0.1em;
  font-size: 1.6rem;
  text-shadow: 0 0 16px rgba(212, 168, 75, 0.4);
}

.mode-sub {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.mode-card-wide {
  max-width: 640px;
}

.mode-section-label {
  margin: 14px 0 8px;
  font-family: var(--font);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: var(--gold-dim);
  text-transform: uppercase;
  text-align: left;
}

.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-options-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 560px) {
  .mode-options { grid-template-columns: 1fr; }
  .mode-options-3 { grid-template-columns: 1fr; }
}

.mode-btn.active {
  border-color: var(--gold) !important;
  box-shadow: 0 0 16px rgba(212, 168, 75, 0.35) !important;
}

.join-fields {
  margin: 14px 0 8px;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.4);
}

.join-fields label {
  display: block;
  font-size: 0.8rem;
  color: var(--gold);
  font-family: var(--font);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.join-fields input {
  width: 100%;
  padding: 14px 12px;
  border-radius: 8px;
  border: 2px solid var(--gold-dim);
  background: rgba(0, 0, 0, 0.55);
  color: var(--gold-bright);
  font-size: 1.35rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-family: var(--font);
  text-align: center;
  margin-bottom: 12px;
  box-sizing: border-box;
}

.join-go-btn {
  width: 100% !important;
  padding: 16px 14px !important;
  font-size: 1.05rem !important;
  letter-spacing: 0.08em !important;
  background: linear-gradient(180deg, #c9a227 0%, #8a6a12 100%) !important;
  color: #1a1008 !important;
  border: 1px solid var(--gold-dim) !important;
  min-height: 52px;
}

.join-hint {
  margin: 10px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
  text-align: center;
}

/* Sticky Begin / Rules bar — always on screen */
.mode-actions-sticky {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  justify-content: stretch;
  padding: 12px 0 4px;
  margin-top: 12px;
  background: linear-gradient(180deg, transparent, rgba(14, 10, 8, 0.98) 28%);
  z-index: 5;
}

.mode-actions-sticky .btn-begin,
.mode-actions-sticky #btn-start-play {
  flex: 1;
  min-height: 48px;
  font-size: 1rem !important;
  padding: 12px 16px !important;
}

.mode-actions-sticky .secondary {
  flex: 0 0 auto;
  min-height: 48px;
}

/* Join mode: hide host-only element picker; show big join CTA */
.mode-card.join-mode #element-section {
  display: none;
}
.mode-card.join-mode #btn-start-play {
  display: none; /* use Join Match button instead */
}
.mode-card.join-mode .mode-actions-sticky {
  display: none; /* join panel has its own full-width button */
}

@media (max-width: 560px) {
  .mode-screen {
    align-items: stretch;
    padding: 8px;
  }
  .mode-card {
    max-width: none;
    border-radius: 12px;
    padding: 14px 12px 20px;
    margin: 0;
  }
  .mode-crest {
    width: 48px;
    height: 48px;
    margin-bottom: 6px;
  }
  .mode-card h1 {
    font-size: 1.25rem;
  }
  .mode-sub {
    font-size: 0.8rem;
    margin-bottom: 10px;
  }
  .mode-btn {
    padding: 10px 12px !important;
  }
  .mode-btn-desc {
    font-size: 0.72rem !important;
  }
  /* Solo / Host / Join as 3 compact columns */
  .mode-options-3 {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }
  .mode-options-3 .mode-btn-desc {
    display: none;
  }
  .mode-options-3 .mode-btn {
    align-items: center;
    text-align: center;
    padding: 12px 6px !important;
  }
  .mode-options-3 .mode-btn-title {
    font-size: 0.85rem;
  }
}

.host-waiting {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  text-align: left;
}

.host-waiting h3 {
  margin: 0 0 8px;
  color: var(--gold-bright);
  font-family: var(--font);
}

.host-urls a {
  display: block;
  color: #7dcea0;
  word-break: break-all;
  font-size: 0.82rem;
  margin: 4px 0;
}

.host-public {
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #27ae60;
  background: rgba(20, 60, 40, 0.35);
}

.host-public a {
  color: #82e0aa;
  font-weight: 600;
}

.host-public-warn {
  border-color: #c0392b;
  background: rgba(60, 20, 16, 0.4);
  color: #f5b7b1;
  font-size: 0.8rem;
  line-height: 1.4;
}

.host-lan {
  font-size: 0.78rem;
  color: var(--muted);
}

.host-copy-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

.mode-foot code {
  color: var(--gold);
  font-size: 0.85em;
}

.chip.mp-chip b {
  color: #85c1e9;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: left;
  padding: 14px 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(50, 36, 28, 0.95), rgba(22, 16, 12, 0.95));
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 3px 0 #100c08;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  font-family: var(--font-ui);
}

.mode-btn:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(212, 168, 75, 0.35), 0 4px 0 #100c08;
  filter: none;
}

.mode-btn.classic:hover { border-color: #e67e22; }
.mode-btn.chaos:hover { border-color: #9b59b6; }

.mode-btn-title {
  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--gold-bright);
}

.mode-btn.chaos .mode-btn-title { color: #d2b4de; }

.mode-btn-desc {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  font-weight: 500;
}

.mode-btn-desc b { color: var(--text); font-weight: 700; }

.mode-foot {
  margin: 16px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.mode-foot b { color: var(--gold-dim); }

.app.menu-dim .main,
.app.menu-dim .topbar {
  filter: brightness(0.45);
  pointer-events: none;
}

/* ── Online multiplayer overlay ── */
.online-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 12px 40px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
  /* Backdrop is visual only — panel closes via X, not outside click */
  pointer-events: auto;
}
.online-overlay.open { display: flex; }

.online-panel {
  width: min(520px, 100%);
  margin: auto;
  background:
    linear-gradient(180deg, rgba(36, 24, 18, 0.98), rgba(14, 10, 8, 0.98));
  border: 2px solid var(--gold);
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(212, 168, 75, 0.22), 0 24px 70px rgba(0, 0, 0, 0.75);
  padding: 18px 18px 22px;
  color: var(--text);
  /* Keep panel interactive; prevent parent handlers from treating drags as dismiss */
  position: relative;
  z-index: 1;
  pointer-events: auto;
  user-select: text;
}
.online-panel input,
.online-panel button {
  user-select: text;
}
.online-panel button {
  user-select: none;
}

.online-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.online-panel-head h2 {
  margin: 0;
  font-family: var(--font);
  color: var(--gold-bright);
  letter-spacing: 0.06em;
  font-size: 1.25rem;
}
.online-who {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.online-status {
  min-height: 1.2em;
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: #7dcea0;
}
.online-status.error { color: #f1948a; }

.online-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 10px;
}
.online-section h3 {
  margin: 10px 0 8px;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--gold);
  letter-spacing: 0.05em;
}
.online-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}
.online-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}
.online-field input {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
}
.online-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}
.online-mode-row button.active {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
  box-shadow: var(--glow-gold);
}
.online-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}
.online-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 4px;
}
.online-player,
.online-challenge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
}
.online-player-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.online-pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.online-pill.free {
  color: #7dcea0;
  border-color: rgba(125, 206, 160, 0.45);
}
.online-pill.busy {
  color: #f5b041;
  border-color: rgba(245, 176, 65, 0.45);
}
.online-rating {
  color: var(--muted);
  font-size: 0.8rem;
}
.online-challenge-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.online-reconnect {
  margin: 10px 0 14px;
  padding: 12px;
  border: 1px solid rgba(212, 168, 75, 0.45);
  border-radius: 10px;
  background: rgba(212, 168, 75, 0.08);
}
.online-reconnect p {
  margin: 0 0 8px;
  color: var(--gold-bright);
  font-size: 0.9rem;
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal.open { display: flex; }

.modal-card {
  background:
    linear-gradient(180deg, rgba(40, 28, 20, 0.98), rgba(18, 12, 10, 0.98));
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 28px 24px;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 0 40px rgba(212, 168, 75, 0.25), 0 20px 60px rgba(0, 0, 0, 0.7);
}

.modal-card h2 {
  margin: 0 0 10px;
  color: var(--gold-bright);
  font-family: var(--font);
  letter-spacing: 0.08em;
}
.modal-card p {
  color: var(--text);
  line-height: 1.45;
  font-size: 0.92rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.modal-actions button {
  min-width: min(140px, 42vw);
  border: 1px solid #e5bd63;
  border-radius: 999px;
}
.modal-status {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--gold-bright);
  min-height: 1.2em;
}
.modal-status.is-error {
  color: #f1948a;
}

#modal-btn {
  min-width: min(320px, 76vw);
  margin-top: 10px;
  border: 1px solid #e5bd63;
  border-radius: 999px;
  padding: 11px 28px;
  color: #1b1008;
  background:
    linear-gradient(180deg, rgba(255,236,164,.42), transparent 35%),
    linear-gradient(180deg, #d6a633, #987018);
  box-shadow:
    0 0 0 3px rgba(11,8,6,.72),
    0 0 0 4px rgba(207,159,63,.32),
    0 12px 34px rgba(0,0,0,.62),
    0 0 28px rgba(219,164,55,.28);
  font-size: .84rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}
#modal-btn::before { content: "◆"; margin-right: 11px; font-size: .62em; }
#modal-btn::after { content: "◆"; margin-left: 11px; font-size: .62em; }

@media (max-height: 780px) {
  :root { --card-w: 50px; --card-h: 70px; }
  .pile-stack { width: 44px; height: 60px; }
  .pile { width: 48px; }
  .floater-dmg { font-size: 1.3rem; }
}

@media (max-height: 680px) {
  :root { --card-w: 44px; --card-h: 62px; }
  .card-face .title { display: none; }
  .brand { font-size: 0.92rem; }
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .main:not(.log-collapsed) {
    grid-template-rows: 1fr minmax(72px, 18vh);
  }
  .log-panel { max-height: 18vh; }
}

/* ── Phone layout: scrollable board + fixed hand dock ── */
@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  :root {
    --card-w: 52px;
    --card-h: 72px;
    --hand-dock-h: clamp(168px, 27dvh, 220px);
  }

  html, body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body {
    animation: none;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    padding: 4px 6px 0;
    gap: 4px;
    overflow: visible;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 4px;
    min-height: 0;
    padding: 4px 6px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(90deg, rgba(20, 12, 10, 0.96), rgba(40, 22, 16, 0.94), rgba(20, 12, 10, 0.96));
  }

  .brand {
    font-size: 0.78rem;
    letter-spacing: 0.03em;
  }

  .brand-crest {
    width: 22px;
    height: 22px;
  }

  .chips {
    order: 3;
    width: 100%;
    gap: 3px;
  }

  .chip {
    padding: 2px 6px;
    font-size: 0.62rem;
  }

  .chip.castle {
    display: none;
  }

  .top-actions {
    margin-left: auto;
  }

  .top-actions button {
    padding: 4px 7px !important;
    font-size: 0.65rem !important;
  }

  .main {
    display: block !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    gap: 0 !important;
    flex: none;
    min-height: 0;
    overflow: visible;
    /* room so last board rows aren't hidden under fixed hand dock */
    padding-bottom: calc(var(--hand-dock-h) + 72px);
  }

  /* Log: overlay only when opened */
  .main .log-panel {
    display: none;
  }
  .main:not(.log-collapsed) .log-panel {
    display: flex;
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--hand-dock-h) + 8px);
    top: auto;
    max-height: 32vh;
    z-index: 35;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.65);
  }

  .play-area {
    padding: 6px 4px 8px;
    gap: 6px;
    border-width: 1px;
    overflow: visible;
    min-height: 0;
    height: auto;
  }

  .play-area::after {
    opacity: 0.2;
  }

  .side {
    position: relative;
    gap: 0;
    flex: 0 0 auto;
    justify-content: center;
    width: 100%;
  }

  /* Keep the card grid centered on the battle line; park piles on the left */
  .side .piles {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    gap: 6px;
    z-index: 2;
  }

  .side.enemy .piles {
    top: 42%;
  }

  .side.you .piles {
    top: 58%;
  }

  .pile {
    width: 40px;
  }

  .pile-stack {
    width: 38px;
    height: 52px;
  }

  .pile-label {
    font-size: 0.55rem;
  }

  .army {
    gap: 4px;
    margin: 0 auto;
    /* leave a little room so piles don't overlap leftmost cards */
    padding: 0 44px;
  }

  .row {
    gap: 6px;
  }

  .row-label {
    font-size: 0.55rem;
    letter-spacing: 0.06em;
  }

  .slot.castle {
    width: calc(var(--card-w) + 4px);
    height: calc(var(--card-h) + 4px);
  }

  .divider {
    margin: 4px 0;
  }

  .divider span {
    font-size: 0.5rem;
    padding: 0 6px;
  }

  .card-face .title {
    display: none;
  }

  .card-face .rank {
    font-size: 0.9rem;
  }

  .card-face .suit {
    font-size: 1.05rem;
  }

  /*
   * Hand dock — ALWAYS visible at bottom of the phone screen.
   * Board scrolls above it so placement is possible.
   */
  .hand-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 28;
    max-height: var(--hand-dock-h);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
    border-top: 2px solid var(--gold-dim);
    border-radius: 14px 14px 0 0;
    background:
      linear-gradient(180deg, rgba(36, 24, 16, 0.98) 0%, rgba(14, 10, 8, 0.99) 100%);
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.55);
  }

  .hand-meta {
    font-size: 0.72rem;
    flex-wrap: nowrap;
    min-height: 20px;
  }

  .hand-meta strong {
    font-size: 0.78rem;
    color: var(--gold-bright);
  }

  .hint {
    font-size: 0.62rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: auto;
  }

  .hand {
    min-height: var(--card-h);
    gap: 6px;
    padding: 4px 2px 6px;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    touch-action: pan-x;
  }

  .hand-card {
    width: var(--card-w);
    height: var(--card-h);
    flex-shrink: 0;
    touch-action: pan-x;
    scroll-snap-align: start;
  }

  .slot.drop-target {
    touch-action: none;
  }

  .hand-card:hover {
    transform: translateY(-4px) scale(1.03);
  }

  .controls {
    gap: 6px;
    flex-wrap: wrap;
  }

  .controls button {
    padding: 10px 12px !important;
    font-size: 0.78rem !important;
    min-height: 44px;
    flex: 1 1 auto;
  }

  /* On phones the primary action belongs inside the dock. Keeping it above
     the dock covered the player's castle row on shorter screens. */
  .controls .progress-cta {
    position: static;
    order: -1;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    transform: none;
    margin: 0;
    animation: none;
  }
  .controls .progress-cta:hover { transform: translateY(-1px); }
  .controls .progress-cta::before,
  .controls .progress-cta::after { margin-inline: 6px; }

  .floater-dmg { font-size: 1.15rem; }
  .floater-critical { font-size: 1.05rem; }
  .floater-info { font-size: 0.9rem; }
}

/* Very small phones */
@media (max-width: 400px) {
  :root {
    --card-w: 46px;
    --card-h: 64px;
    --hand-dock-h: clamp(160px, 29dvh, 205px);
  }
  .pile { width: 34px; }
  .pile-stack { width: 32px; height: 44px; }
}

/* Landscape phones: smaller dock, scroll board */
@media (max-width: 900px) and (max-height: 480px) {
  :root {
    --card-w: 40px;
    --card-h: 56px;
    --hand-dock-h: clamp(145px, 38dvh, 185px);
  }

  .splash-stage {
    max-width: min(540px, 82vw);
    padding: 6px 12px;
  }

  .splash-crest {
    width: 38px;
    height: 38px;
    margin-bottom: 6px;
  }

  .splash-line {
    margin-bottom: 0.3em;
    font-size: 0.76rem;
    line-height: 1.22;
  }

  .splash-line-title {
    margin-top: 0.45em;
    font-size: 0.9rem;
  }

  .splash-title {
    margin-top: 0.2em;
    font-size: 1.7rem;
  }

  .splash-line-sub {
    margin-top: 0.2em;
    font-size: 0.66rem;
  }

  .splash-enter {
    margin-top: 0.65em;
    min-height: 38px;
    padding: 8px 18px;
    font-size: 0.72rem;
  }

  .splash-skip {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 6px 9px;
    font-size: 0.62rem;
  }

  .mode-screen {
    padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left));
  }

  .mode-card {
    max-width: 720px;
    padding: 8px 10px 10px;
    margin: 0 auto;
  }

  .mode-crest { display: none; }
  .mode-card h1 { font-size: 1.05rem; }
  .mode-sub { margin: 3px 0 5px; font-size: 0.68rem; }
  .mode-section-label { margin: 5px 0 3px; font-size: 0.58rem; }
  .mode-options,
  .mode-options-3 { gap: 5px; }
  .mode-options-3 { grid-template-columns: repeat(3, 1fr); }
  .mode-btn { min-height: 0; padding: 5px 7px !important; }
  .mode-btn-title { font-size: 0.7rem !important; }
  .mode-btn-desc { font-size: 0.56rem !important; line-height: 1.18; }
  .mode-foot { margin: 4px 0; font-size: 0.6rem; }
  .mode-actions-sticky {
    position: static;
    margin-top: 4px;
    padding: 4px 0 0;
    gap: 5px;
  }
  .mode-actions-sticky .btn-begin,
  .mode-actions-sticky #btn-start-play,
  .mode-actions-sticky .secondary {
    min-height: 34px;
    padding: 6px 9px !important;
    font-size: 0.65rem !important;
  }
}

/* 2026 single-player review pass: forged crown visual system */
.topbar,
.play-area,
.log-panel,
.hand-bar {
  backdrop-filter: blur(10px) saturate(1.15);
}

.play-area {
  box-shadow: 0 20px 60px rgba(0, 0, 0, .48), inset 0 0 80px rgba(116, 18, 11, .08);
}

.board-2d::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 48%, rgba(0,0,0,.35) 100%);
  mix-blend-mode: multiply;
}

.slot.attackable {
  animation: war-ready 1.35s ease-in-out infinite;
}

@keyframes war-ready {
  0%, 100% { box-shadow: 0 0 0 1px rgba(240, 215, 140, .35), 0 0 10px rgba(212,168,75,.22); }
  50% { box-shadow: 0 0 0 2px rgba(255, 224, 132, .8), 0 0 26px rgba(229,171,54,.58); }
}

.mode-screen::before,
.rules-screen::before,
.tutorial-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 38%, rgba(147,38,17,.18), transparent 38%), linear-gradient(180deg, transparent, rgba(0,0,0,.55));
}

.mode-screen {
  background: radial-gradient(ellipse at center, rgba(18,12,10,.34) 0%, rgba(0,0,0,.70) 76%);
  backdrop-filter: blur(2px) saturate(.9);
}
.mode-card {
  background: linear-gradient(155deg, rgba(31,20,17,.94), rgba(8,8,10,.96));
  border-color: rgba(218,176,82,.82);
  box-shadow: 0 0 0 1px rgba(0,0,0,.8), 0 0 70px rgba(207,82,30,.18), 0 30px 85px rgba(0,0,0,.78);
}

.tutorial-screen {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(4, 3, 3, .88) var(--art-bg) center / cover no-repeat;
}

.tutorial-screen.open { display: grid; }

.tutorial-card {
  position: relative;
  width: min(680px, 94vw);
  min-height: 420px;
  padding: 34px 38px 28px;
  border: 1px solid rgba(212,168,75,.58);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(28,17,14,.98), rgba(8,7,8,.98));
  box-shadow: 0 30px 90px rgba(0,0,0,.75), inset 0 1px rgba(255,225,158,.12);
  overflow: hidden;
}

.tutorial-card::after {
  content: ""; position: absolute; right: -80px; bottom: -120px; width: 300px; height: 300px;
  border: 1px solid rgba(183,48,24,.18); transform: rotate(45deg); pointer-events:none;
}

.tutorial-kicker { color: #cf5634; text-transform: uppercase; letter-spacing: .24em; font-size: .72rem; font-weight: 800; }
.tutorial-card h1 { margin: 6px 0 16px; font: 800 clamp(1.7rem,5vw,2.7rem)/1 var(--font); color: var(--gold-bright); }
.tutorial-progress { height: 3px; background: rgba(255,255,255,.08); margin-bottom: 34px; overflow:hidden; }
.tutorial-progress span { display:block; width:20%; height:100%; background:linear-gradient(90deg,#8d1f17,#f0b64d); transition:width .3s ease; }
.tutorial-step { display:none; min-height: 185px; animation:tutorial-in .38s ease both; }
.tutorial-step.active { display:block; }
.tutorial-number { color:rgba(212,168,75,.28); font:800 4rem/1 var(--font); float:left; margin:0 22px 60px 0; }
.tutorial-step h2 { margin:0 0 12px; color:#f5ead2; font:700 1.45rem/1.1 var(--font); }
.tutorial-step p { color:#c6b79d; font-size:1.02rem; line-height:1.72; max-width:560px; }
.tutorial-actions { position:relative; z-index:2; display:flex; align-items:center; gap:12px; justify-content:flex-end; border-top:1px solid rgba(212,168,75,.18); padding-top:18px; }
.tutorial-actions span { margin-right:auto; color:var(--muted); font-size:.78rem; letter-spacing:.12em; }
@keyframes tutorial-in { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }

.mode-btn.difficulty.active { border-color:#d6512c; box-shadow:0 0 0 1px rgba(214,81,44,.42), 0 12px 30px rgba(0,0,0,.28); }
.mode-btn.difficulty.active .mode-btn-title { color:#f4bf62; }

@media (max-width: 600px) {
  .tutorial-card { padding:26px 22px 20px; min-height:430px; }
  .tutorial-number { font-size:3rem; margin-right:14px; }
  .tutorial-step p { font-size:.92rem; }
  .tutorial-actions { flex-wrap:wrap; }
  .mode-actions-sticky {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .mode-actions-sticky .btn-begin {
    grid-column: 1 / -1;
    min-height: 48px;
  }
  .mode-actions-sticky button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; scroll-behavior:auto !important; }
}

/* Floating, color-coded battle chronicle */
.main {
  display: block;
  position: relative;
}
.play-area { height: 100%; }
.log-panel {
  position: fixed;
  right: max(16px, calc((100vw - 1440px) / 2 + 16px));
  bottom: 18px;
  width: 340px;
  height: min(34vh, 330px);
  z-index: 32;
  border-color: rgba(190,145,67,.48);
  background: linear-gradient(155deg, rgba(14,11,12,.95), rgba(5,7,10,.94));
  box-shadow: 0 18px 55px rgba(0,0,0,.72), inset 0 1px rgba(255,220,150,.07);
  transition: opacity .2s ease, transform .25s ease;
}
.main.log-collapsed .log-panel {
  transform: translateY(18px) scale(.96);
}
.log-panel ul { display:flex; flex-direction:column; gap:3px; }
.log-panel li {
  border:0;
  border-left:3px solid rgba(130,120,105,.34);
  border-radius:4px;
  padding:6px 8px;
  background:rgba(255,255,255,.025);
  color:#b8ad9b;
}
.log-panel li:first-child { font-weight:700; }
.log-panel li.chronicle-player { color:#b8e3c3; border-left-color:#55ad70; }
.log-panel li.chronicle-enemy { color:#efb0a6; border-left-color:#bd4a3b; }
.log-panel li.chronicle-damage { color:#ff9b72; border-left-color:#f06432; background:rgba(119,30,16,.15); }
.log-panel li.chronicle-block { color:#9ecce1; border-left-color:#4a9abb; background:rgba(22,73,98,.14); }
.log-panel li.chronicle-castle { color:#ffd175; border-left-color:#d79e32; background:rgba(113,73,12,.16); }
.log-panel li.chronicle-ability { color:#d7b9ef; border-left-color:#8e5caf; }
.log-panel li.chronicle-round { color:#f0dca6; border-left-color:#c7a34d; }

@media (max-width: 700px), (max-width: 900px) and (max-height: 480px) {
  .main:not(.log-collapsed) .log-panel {
    display:flex;
    position:fixed;
    left:8px;
    right:8px;
    bottom:calc(var(--hand-dock-h) + 8px);
    top:auto;
    width:auto;
    height:min(34vh,300px);
    max-height:34vh;
    z-index:35;
  }
}
