:root {
  --kl-bg: #0a1f3a;
  --kl-surface: #0f2a4a;
  --kl-surface-2: #102f57;
  --kl-accent: #4ecdc4;
  --kl-accent-2: #ffd166;
  --kl-card-red: #d9534f;
  --kl-card-blue: #14213d;
  --kl-text: #ecf2ff;
  --kl-muted: #9bb6d8;
  --kl-empty: rgba(255, 255, 255, 0.09);
  --kl-radius: 18px;
  --kl-font: "Poppins", "Manrope", "Inter", "Segoe UI", "Noto Sans TC", "Microsoft YaHei", sans-serif;
  --kl-card-radius: 12px;
  --kl-card-shadow-soft: 0 14px 28px rgba(0, 0, 0, 0.32);
  --kl-card-shadow-inset: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  --kl-card-shadow-thick: 0 8px 16px rgba(0, 0, 0, 0.34), 0 1px 0 rgba(255, 255, 255, 0.22) inset;
  --kl-rank-size: clamp(0.7rem, 1.2vw, 0.84rem);
  --kl-suit-size: clamp(1rem, 2vw, 1.2rem);
  --kl-card-step-mobile: 14px;
  --kl-card-step-mobile-mid: 12px;
  --tableau-selection-gutter: 8px;
}

body[data-game-id="klondike-solitaire"],
body[data-wp-game-id="klondike-solitaire"] {
  font-family: var(--kl-font);
  margin: 0;
  min-height: 100%;
  background-color: #071728;
  background-image: linear-gradient(180deg, rgba(5, 16, 28, 0.22), rgba(5, 16, 28, 0.62)), url("../../assets/klondike-solitaire-background.webp");
  background-position: center, center;
  background-size: cover, cover;
  background-attachment: fixed;
  color: var(--kl-text);
  font-feature-settings: "liga" 1, "kern" 1;
  text-rendering: geometricPrecision;
}

body[data-game-id="klondike-solitaire"] .game-page-info,
body[data-wp-game-id="klondike-solitaire"] .game-page-info {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-right: 0;
}

body[data-game-id="klondike-solitaire"] .loading-card,
body[data-wp-game-id="klondike-solitaire"] .loading-card {
  box-sizing: border-box;
  max-width: calc(100% - 36px);
}

body[data-game-id="klondike-solitaire"].wp-shell-battle-active,
body[data-wp-game-id="klondike-solitaire"].wp-shell-battle-active {
  background-image: linear-gradient(180deg, #071728, #0a1f3a 46%, #071728);
  background-position: center;
  background-size: cover;
}

#loadingPanel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #06101e;
  color: var(--kl-text);
  z-index: 9999;
}
#loadingPanel[hidden], #mainScreen[hidden], #battleScreen[hidden] {
  display: none !important;
}

body[data-wp-game-id="klondike-solitaire"] .wp-shell-settings-popover {
  box-sizing: border-box;
}

body[data-wp-game-id="klondike-solitaire"] .wp-shell-language-row .settings-locale-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 44px;
  height: auto;
}

body[data-wp-game-id="klondike-solitaire"] .wp-shell-language-row .settings-locale-row svg {
  width: 24px;
  height: 24px;
}

body[data-wp-game-id="klondike-solitaire"] .wp-shell-language-row .settings-locale-row > span {
  display: none !important;
}

body[data-wp-game-id="klondike-solitaire"] .wp-shell-language-row .settings-locale-row select {
  grid-column: 2;
  width: 100% !important;
  max-width: none !important;
}

.loading-card {
  width: min(86vw, 380px);
  background: rgba(14, 39, 72, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--kl-radius);
  padding: 1.2rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  animation: kl-float-in 420ms cubic-bezier(.17,.75,.3,1) both;
}

.loading-card strong {
  font-size: 1.2rem;
}

.loading-track {
  margin-top: 0.85rem;
  height: 0.45rem;
  border-radius: 99rem;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

#loadingFill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #3d7fff, #4ecdc4);
}

.main-screen {
  max-width: 920px;
  margin: 0 auto;
  box-sizing: border-box;
  width: 100%;
}

.main-header,
.battle-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.main-header {
  padding: 1rem 1.1rem;
}

.main-return {
  display: inline-flex;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: var(--kl-text);
  text-decoration: none;
}

.main-header strong {
  margin-inline: auto;
  font-size: 1.1rem;
}

.poster-frame {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.poster-frame img.cover {
  width: 100%;
  max-width: 200px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  object-position: center;
  border-radius: var(--kl-radius);
  object-fit: cover;
  box-shadow: var(--kl-card-shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.main-hero {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) minmax(0, 240px);
  gap: 1rem;
  padding: 0 1rem 1.4rem;
  animation: kl-fade-in 420ms cubic-bezier(.17,.75,.3,1) both;
}

@media (max-width: 768px) {
  .main-hero {
    grid-template-columns: 1fr;
  }
  .poster-frame img.cover {
    max-width: 160px;
  }
}

.main-copy .eyebrow,
.feature-list strong {
  color: var(--kl-accent-2);
  font-size: 0.85rem;
}

.main-copy p,
.menu-hint {
  color: var(--kl-muted);
  margin-bottom: 0.85rem;
  line-height: 1.5;
}

.main-copy .stats-panel {
  margin-bottom: 0.8rem;
  background: rgba(16, 46, 80, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  color: var(--kl-text);
  backdrop-filter: blur(5px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), var(--kl-card-shadow-soft);
}

.main-copy .stats-panel div {
  margin: 0.2rem 0;
}

.main-progress {
  display: flex;
  min-height: 40px;
  box-sizing: border-box;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  margin: 10px 0 0;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  color: var(--kl-text);
  background: rgba(16, 46, 80, 0.5);
  font-size: 0.78rem;
  line-height: 1.3;
}

.main-progress strong {
  color: var(--kl-accent-2);
  font-size: 0.82rem;
}

.main-actions,
.control-row,
.result-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.result-actions > button {
  min-height: 50px;
}

button {
  font: inherit;
  border: none;
  border-radius: 12px;
  padding: 0.63rem 0.95rem;
  min-height: 40px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms cubic-bezier(.2,.8,.2,1), filter 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.25);
}

button:hover {
  filter: brightness(1.06);
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.32);
}

button:active {
  transform: scale(0.985);
}

button:focus-visible {
  outline: 2px solid rgba(78, 205, 196, 0.9);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(120deg, #4ecdc4, #45b7d1);
  color: #06131f;
  font-weight: 700;
}

button.secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

button.control-mini,
button.mini-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 0.52rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  min-height: 42px;
}

.battle-screen {
  min-height: var(--wp-battle-viewport-height, 100vh);
  background: linear-gradient(180deg, #071728, #0a1f3a 46%, #071728);
}

.battle-canvas {
  --card-width: clamp(64px, 8.9vw, 78px);
  --card-height: calc(var(--card-width) * 1.42);
  --card-step: clamp(14px, 3.6vw, 29px);
  --tableau-gap: 0.65rem;
  width: 100%;
  height: calc(100vh - 56px);
  max-width: min(100%, 920px);
  margin: 0 auto;
  position: relative;
  padding: 0.9rem 0.9rem 0.7rem;
  box-sizing: border-box;
  animation: kl-board-enter 360ms cubic-bezier(.17,.75,.3,1) both;
}

.battle-header {
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0 0.2rem 0.6rem;
}

.battle-header .header-stat {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  min-width: 82px;
  text-align: center;
}

.battle-header .header-stat small {
  display: block;
  color: var(--kl-muted);
  font-size: 0.74rem;
}

.battle-header .header-stat strong {
  font-size: 0.96rem;
}

.board-shell {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 130px);
  border-radius: var(--kl-radius);
  overflow: hidden;
  margin: 0 auto;
  background: radial-gradient(120% 120% at 50% -10%, rgba(255, 255, 255, 0.03), transparent 34%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 16px 24px rgba(0, 0, 0, 0.28);
  background-color: rgba(10, 31, 58, 0.84);
  backdrop-filter: blur(2px);
}

.foundation-row,
.stock-row,
.tableau-row {
  display: grid;
  align-items: start;
  gap: 0.75rem;
}

.foundation-row {
  grid-template-columns: repeat(4, var(--card-width));
  justify-content: center;
  gap: clamp(0.5rem, 2.2vw, 0.75rem);
  margin-bottom: 0.8rem;
  padding-inline: 4px;
  box-sizing: border-box;
}

.stock-row {
  grid-template-columns: 130px 130px auto;
  align-items: center;
  margin-bottom: 0.85rem;
  padding-inline: 4px;
  box-sizing: border-box;
}

.battle-tip {
  margin: -0.15rem 0 0.7rem;
  color: var(--kl-muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.tableau-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--tableau-gap);
  align-items: start;
  min-height: calc(100% - 250px);
}

.pile {
  border-radius: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  min-height: calc(var(--card-height) + 6px);
  background: linear-gradient(160deg, rgba(13, 39, 70, 0.34), rgba(9, 27, 53, 0.36));
  position: relative;
  overflow: hidden;
  min-width: var(--card-width);
  touch-action: none;
  box-shadow: var(--kl-card-shadow-inset), var(--kl-card-shadow-soft);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.tableau-pile {
  max-width: calc(var(--card-width) * 1.02);
}

.pile.stock,
.pile.waste {
  width: 100%;
  max-width: none;
}

.pile.waste {
  --kl-waste-step: max(14px, calc(var(--card-step) * 0.62));
  min-width: calc(var(--card-width) + var(--kl-waste-step) + var(--kl-waste-step));
}

.pile.stock {
  border-style: solid;
}

.tableau-pile,
.foundation-slot {
  position: relative;
  min-height: min(64vh, calc(var(--card-height) + 9 * var(--card-step)));
}

.foundation-slot {
  min-height: calc(var(--card-height) + 10px);
  display: block;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}

.tableau-pile.hint-target,
.foundation-slot.hint-target,
.stock-row .pile.hint-target {
  box-shadow: 0 0 0 3px var(--kl-accent);
  z-index: 3;
}

.tableau-pile.drag-hover,
.foundation-slot.drag-hover {
  box-shadow: 0 0 0 3px rgba(255, 241, 168, 0.95), 0 0 18px rgba(255, 241, 168, 0.5);
  transform: translateY(-2px) scale(1.01);
  z-index: 2;
}

.tableau-pile.hint-source,
.foundation-slot.hint-source {
  outline: 2px solid #fff1a8;
  outline-offset: 3px;
  z-index: 3;
}

.card-stack-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--kl-muted);
  font-size: 0.84rem;
  pointer-events: auto;
}

.card {
  position: absolute;
  left: 0;
  width: var(--card-width);
  aspect-ratio: 63 / 88;
  border-radius: var(--kl-card-radius);
  box-shadow: var(--kl-card-shadow-thick);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: grid;
  align-content: space-between;
  padding: 0.2rem;
  box-sizing: border-box;
  text-align: left;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
  transform-style: preserve-3d;
  will-change: transform, opacity, top, left;
  transition: top 130ms cubic-bezier(.2,.8,.2,1), left 130ms cubic-bezier(.2,.8,.2,1), transform 130ms cubic-bezier(.2,.8,.2,1), box-shadow 130ms ease, opacity 130ms ease;
}

.card.back {
  background: linear-gradient(135deg, #18416b, #0d2849);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2), 0 6px 12px rgba(0, 0, 0, 0.4);
  background-size: 150% 120%;
}

.card.front {
  background-color: #f6efde;
  background-image: linear-gradient(180deg, #f5f2e9, #f6efde), url("../../assets/klondike-solitaire-cards.webp");
  color: #132437;
  background-size: 100% 120%, cover;
  background-position: center, center;
  background-blend-mode: normal, soft-light;
}

.card.back .card-back-pattern {
  opacity: 0.95;
  background: url("../../assets/klondike-solitaire-card-back.webp") center / cover no-repeat;
}

.card .suit {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.card.front::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: calc(var(--kl-card-radius) - 2px);
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.card.front.red {
  color: var(--kl-card-red);
}

.card.front::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: calc(var(--kl-card-radius) - 2px);
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 32%);
}

.card .rank-top,
.card .rank-bottom {
  font-size: var(--kl-rank-size);
  font-weight: 700;
}

.card .rank-top {
  justify-self: start;
  align-self: start;
  text-align: left;
}

.card .rank-bottom {
  justify-self: end;
  align-self: end;
  text-align: right;
}

.card .suit {
  justify-self: center;
  align-self: center;
  text-align: center;
  font-size: var(--kl-suit-size);
}

.card.back .card-back-pattern {
  width: 76%;
  height: 76%;
  border-radius: 7px;
  background: url("../../assets/klondike-solitaire-card-back.webp") center / cover no-repeat;
}

.card-deal {
  animation: kl-deal 230ms cubic-bezier(.2,.75,.3,1) both;
}

.card-flip {
  animation: kl-flip 210ms cubic-bezier(.2,.7,.2,1) both;
}

@media (prefers-reduced-motion: reduce) {
  .battle-canvas,
  .main-hero,
  .card,
  .card-deal,
  .card-flip,
  .ghost-card,
  .result-enter,
  .result-enter .result-card,
  .result-card,
  .victory-card {
    animation: none !important;
    transition: none !important;
  }

  .loading-card,
  #loadingFill,
  .battle-header button {
    animation: none !important;
    transition: none !important;
  }
}

.ghost-card {
  pointer-events: none;
  animation: kl-card-pop 180ms cubic-bezier(.15,.85,.25,1.25) both;
}

.result-overlay[hidden],
.hint-overlay[hidden] {
  display: none;
}

.result-enter {
  animation: kl-result 240ms cubic-bezier(.2,.7,.2,1) both;
}

.result-enter .result-card,
.result-card {
  animation: kl-card-pop 260ms cubic-bezier(.2,.7,.2,1) both;
}

.victory-card {
  animation: kl-victory 340ms cubic-bezier(.2,.8,.2,1) both;
}

.hint-source,
.hint-target {
  filter: saturate(1.14);
}

.hint-source {
  box-shadow: 0 0 0 2px #fff1a8, 0 0 12px rgba(255, 241, 168, 0.45);
}

.hint-source-card {
  box-shadow: 0 0 0 3px #fff1a8, 0 0 16px rgba(255, 241, 168, 0.58);
  z-index: 4;
}

.hint-target {
  box-shadow: 0 0 0 3px var(--kl-accent), 0 0 14px rgba(78, 205, 196, 0.35);
  transform: translateY(-1px);
}

button.mini-btn,
button.control-mini {
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.battle-header .battle-utility {
  box-sizing: border-box;
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 44px;
}

@keyframes kl-deal {
  from {
    opacity: 0;
    transform: translateY(-22px) scale(0.96);
  }

  60% {
    opacity: 1;
    transform: translateY(2px) scale(1.01);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes kl-flip {
  from {
    transform: rotateY(90deg) scale(0.99);
    opacity: 0.75;
  }

  to {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
  }
}

@keyframes kl-card-pop {
  from {
    transform: translateY(6px) scale(0.98);
    opacity: 0.85;
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes kl-result {
  from {
    backdrop-filter: blur(0);
    background: rgba(7, 18, 34, 0);
  }

  to {
    backdrop-filter: blur(2px);
  }
}

@keyframes kl-fade-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes kl-float-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
    filter: blur(2px);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes kl-board-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.995);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes kl-victory {
  from {
    transform: translateY(2px) scale(0.92);
    box-shadow: 0 0 0 0 rgba(255, 214, 102, 0);
  }

  55% {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 0 0 7px rgba(255, 214, 102, 0.48);
  }

  to {
    transform: translateY(0) scale(1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  }
}

.drag-layer {
  position: fixed;
  pointer-events: none;
  inset: 0;
  z-index: 2600;
}

.ghost-card {
  position: absolute;
  width: var(--card-width);
  aspect-ratio: 63 / 88;
  border-radius: 10px;
  background: linear-gradient(180deg, #f5f2e9, #f6efde);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #14263a;
  box-shadow: 0 14px 20px rgba(0, 0, 0, 0.4);
  display: grid;
  align-content: space-between;
  padding: 0.2rem;
  box-sizing: border-box;
}

.ghost-card.red {
  color: var(--kl-card-red);
}

.ghost-card .suit {
  justify-self: center;
  align-self: center;
}

.ghost-card .rank-top,
.ghost-card .rank-bottom {
  font-size: var(--kl-ghost-rank-size, 0.7rem);
}

.ghost-card .suit {
  font-size: var(--kl-ghost-suit-size, var(--kl-suit-size));
}

.selected-group .front {
  box-shadow: 0 0 0 3px #ffd166;
  transform: translateY(-2px);
}

.card.selected {
  box-shadow: 0 0 0 4px #ffd166, 0 0 18px rgba(255, 209, 102, 0.62);
  z-index: 5;
}

.result-overlay,
.hint-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  z-index: 2400;
  display: grid;
  place-items: center;
  background: rgba(7, 18, 34, 0.6);
}

.result-overlay[hidden],
.hint-overlay[hidden] {
  display: none;
}

.result-card {
  background: rgba(13, 31, 57, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 1rem;
  width: min(90vw, 420px);
}

.result-card p {
  color: var(--kl-muted);
}

.hint-overlay {
  color: #fff;
  text-align: center;
  inset: auto 0 0;
  height: auto;
  min-height: 0;
  padding: 0.5rem 0.75rem;
  place-items: center;
  pointer-events: auto;
}

.hint-overlay p {
  margin: 0;
  padding: 0.35rem 0.7rem;
  width: fit-content;
  max-width: calc(100% - 1.5rem);
  box-sizing: border-box;
  background: rgba(8, 27, 53, 0.92);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  pointer-events: auto;
}

.hint-overlay .hint-reason {
  display: block;
  margin-top: 0.25rem;
  color: var(--kl-muted);
  font-size: 0.88em;
  line-height: 1.35;
}

@media (max-width: 740px) {
  .main-hero {
    grid-template-columns: 1fr;
  }

  .battle-header .control-mini,
  .battle-header .header-stat {
    min-height: 42px;
  }

  .battle-canvas {
    --card-width: clamp(44px, calc((100vw - 1.25rem - 6 * 0.42rem) / 7), 68px);
    --card-step: clamp(25px, 6.4vw, 31px);
    --tableau-gap: 0.38rem;
    --kl-card-step-mobile: 12px;
    padding-bottom: 0.4rem;
    padding-left: 0.62rem;
    padding-right: 0.62rem;
    --kl-rank-size: clamp(0.58rem, 3.2vw, 0.72rem);
    --kl-suit-size: clamp(0.84rem, 4vw, 1rem);
  }

  .foundation-row {
    margin-bottom: 0.55rem;
  }

  .stock-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .stock-row .control-row {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .stock-row .control-row button {
    min-width: calc(33.333% - 0.33rem);
    min-height: 44px;
    border-radius: 11px;
  }

  .tableau-row {
    gap: 0.45rem;
  }

  button {
    min-height: 44px;
  }
}

@media (max-width: 390px) {
  .battle-canvas {
    --card-width: clamp(48px, calc((100vw - 0.72rem - 6 * 0.34rem) / 7), 64px);
    --card-step: clamp(27px, 7.2vw, 32px);
    --tableau-gap: 0.3rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    --kl-rank-size: clamp(0.56rem, 3.35vw, 0.68rem);
    --kl-suit-size: clamp(0.78rem, 4.2vw, 0.94rem);
  }

  .stock-row .control-row button {
    min-height: 46px;
    font-size: 0.88rem;
  }

  .battle-header .header-stat {
    min-width: 74px;
  }

  .battle-header .header-stat small {
    font-size: 0.72rem;
  }
}

/* Keep the complete tableau inside the logical Battle Canvas.  The shared
   Canvas owns the viewport height; this game only needs to let the board
   consume the space that remains below its HUD instead of sizing piles from
   the physical viewport (which can extend past the logical canvas). */
.battle-canvas {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow: hidden;
}

.board-shell {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  height: auto;
  max-height: none;
}

.tableau-row {
  flex: 0 0 auto;
  min-height: 0;
  padding-inline: 4px;
  box-sizing: border-box;
}

.tableau-pile {
  min-height: calc(var(--card-height) + 9 * var(--card-step) + 2px);
}

@media (orientation: landscape) and (max-width: 900px) {
  .battle-canvas {
    --card-width: clamp(36px, 5vw, 46px);
    --card-height: calc(var(--card-width) * 1.42);
    --card-step: clamp(5px, 0.7vw, 6px);
    --tableau-gap: 0.45rem;
    --tableau-selection-gutter: 2px;
    padding: 0.5rem 0.6rem 0.35rem;
    gap: 0.3rem;
  }

  .battle-header {
    padding-bottom: 0.3rem;
  }

  .board-shell {
    border-radius: 12px;
    flex: 0 0 auto;
  }

  .foundation-row,
  .stock-row {
    gap: 0.4rem;
  }

  .foundation-row {
    margin-bottom: 0.3rem;
  }

  .stock-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(0, 2fr);
    margin-bottom: 0.35rem;
  }

  .pile,
  .foundation-slot {
    min-height: calc(var(--card-height) + 2px);
  }

  .tableau-pile {
    min-height: calc(var(--card-height) + 9 * var(--card-step) + 2px);
  }

  .stock-row .control-row {
    flex-wrap: nowrap;
    gap: 0.3rem;
  }

  .stock-row .control-row button {
    min-height: 34px;
    padding: 0.3rem 0.45rem;
    font-size: 0.78rem;
  }
}

/* v23 responsive polish: keep the HUD intentional and every tableau card
   inside its own column on narrow screens. */
.battle-header .header-stat {
  min-width: 0;
}

.stock-row .control-row {
  min-width: 0;
}

@media (max-width: 740px) {
  .battle-header {
    display: grid;
    grid-template-columns: 48px repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: 0.45rem;
  }

  .battle-header .header-stat {
    width: auto;
    min-width: 0;
    padding-inline: 0.35rem;
  }

  .battle-header .control-mini {
    grid-column: 2 / -1;
    justify-self: end;
    min-height: 36px;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
  }

  .stock-row .control-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    width: 100%;
    flex-wrap: nowrap;
    justify-content: stretch;
  }

  .stock-row .control-row button {
    width: 100%;
    min-width: 0;
    padding-inline: 0.25rem;
    white-space: nowrap;
  }

  .tableau-pile {
    min-width: 0;
    max-width: none;
  }

  .tableau-pile > .card {
    width: 100%;
  }
}

@media (max-width: 390px) {
  .battle-header .header-stat small {
    font-size: 0.68rem;
  }

  .battle-header .header-stat strong {
    font-size: 0.88rem;
  }

  .stock-row .control-row button {
    font-size: 0.8rem;
  }
}

/* Keep Foundation hint frames inside the board shell without moving the
   Tableau down: the row's top inset is balanced by its bottom margin. */
.foundation-row {
  padding-top: 4px;
  margin-bottom: calc(0.8rem - 4px);
}

@media (max-width: 740px) {
  .foundation-row {
    margin-bottom: calc(0.55rem - 4px);
  }
}

@media (orientation: landscape) and (max-width: 900px) {
  .foundation-row {
    margin-bottom: calc(0.3rem - 4px);
  }
}

/* Keep the Battle sound utility usable after the compact HUD rules above. */
.battle-header .battle-utility {
  min-width: 48px;
  min-height: 44px !important;
}
