.game-main {
  display: grid;
  gap: 0.95rem;
}

.game-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.8rem;
  align-items: center;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.toolbar-actions .btn {
  font-size: 0.86rem;
  padding: 0.48rem 0.78rem;
  border-radius: 12px;
}

.game-stats {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.game-stat {
  min-width: 84px;
  display: grid;
  gap: 0.1rem;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.54);
  border-radius: 12px;
  padding: 0.42rem 0.55rem;
}

.game-stat span {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.game-stat strong {
  font-family: var(--font-display);
  font-size: 1rem;
}

.game-table-wrap {
  background: var(--table-bg, radial-gradient(circle at 18% 12%, #2f9f7a, #117051 58%, #0a4c36 100%));
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  padding: clamp(0.75rem, 2vw, 1.15rem);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 18px 42px rgba(10, 48, 36, 0.3);
}

.game-table {
  --card-w: clamp(56px, 10.8vw, 103px);
  --card-h: calc(var(--card-w) * 1.4);
  --tableau-down-gap: clamp(10px, 1.9vw, 17px);
  --tableau-up-gap: clamp(18px, 3.4vw, 29px);
  --deal-anim: 220ms;
  position: relative;
  min-height: min(78vh, 860px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  user-select: none;
  touch-action: none;
}

body[data-animation-speed="slow"] .game-table {
  --deal-anim: 330ms;
}

body[data-animation-speed="fast"] .game-table {
  --deal-anim: 120ms;
}

.top-piles {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.stock-waste,
.foundations {
  display: flex;
  gap: 0.65rem;
}

body.left-handed .top-piles {
  flex-direction: row-reverse;
}

.tableau-piles {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(0.3rem, 1.2vw, 0.72rem);
  align-items: start;
}

.pile {
  width: var(--card-w);
  min-height: var(--card-h);
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.36);
  position: relative;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.pile--tableau {
  width: 100%;
  min-height: max(calc(var(--card-h) + 170px), 300px);
  border-color: rgba(255, 255, 255, 0.2);
  border-style: solid;
  background: rgba(0, 0, 0, 0.1);
}

.pile.is-highlight {
  border-color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.13);
}

.pile.is-selected {
  border-color: rgba(255, 255, 255, 0.58);
}

.pile.is-hint {
  box-shadow: 0 0 0 2px rgba(255, 214, 10, 0.84), inset 0 0 0 1px rgba(255, 214, 10, 0.55);
}

.playing-card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 11px;
  border: 1px solid rgba(18, 28, 33, 0.2);
  position: absolute;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.24rem 0.28rem;
  background: linear-gradient(180deg, #fff 0%, #f9fbfb 62%, #f1f4f6 100%);
  color: #152026;
  box-shadow: var(--shadow-card);
  cursor: grab;
  transform: translate3d(0, 0, 0);
  transition: top var(--deal-anim), left var(--deal-anim), transform var(--deal-anim), box-shadow var(--deal-anim), opacity var(--deal-anim);
}

.playing-card:active {
  cursor: grabbing;
}

.playing-card--face-down {
  border-color: rgba(255, 255, 255, 0.58);
  background: linear-gradient(145deg, #1a5875, #133f58);
  overflow: hidden;
}

body[data-deck-back="classic"] .playing-card--face-down::before,
body[data-deck-back="linen"] .playing-card--face-down::before,
body[data-deck-back="sunburst"] .playing-card--face-down::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.44);
}

body[data-deck-back="classic"] .playing-card--face-down::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 7px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%) 0 0 / 11px 11px,
    linear-gradient(-45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%) 0 0 / 11px 11px,
    rgba(13, 78, 110, 0.72);
}

body[data-deck-back="linen"] .playing-card--face-down {
  background: linear-gradient(145deg, #aa2c31, #6e181c);
}

body[data-deck-back="linen"] .playing-card--face-down::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.2), transparent 28%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0 2px, transparent 2px 4px),
    rgba(133, 26, 31, 0.82);
}

body[data-deck-back="sunburst"] .playing-card--face-down {
  background: linear-gradient(145deg, #265c35, #173a21);
}

body[data-deck-back="sunburst"] .playing-card--face-down::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 7px;
  background:
    conic-gradient(from 0deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.28)),
    rgba(26, 78, 44, 0.82);
}

.playing-card--red {
  color: #cb2b2b;
}

.playing-card--black {
  color: #111821;
}

.playing-card__corner {
  line-height: 1;
  display: grid;
  gap: 0.08rem;
}

.playing-card__corner--bottom {
  transform: rotate(180deg);
  align-self: flex-end;
}

.playing-card__rank {
  font-weight: 800;
  font-size: clamp(0.9rem, 1.9vw, 1.05rem);
}

.playing-card__suit {
  font-size: clamp(0.76rem, 1.6vw, 0.9rem);
}

.playing-card__center {
  display: grid;
  place-items: center;
  font-size: clamp(1.5rem, 3.6vw, 2.1rem);
  font-weight: 700;
}

body[data-card-face="minimal"] .playing-card {
  background: #fff;
}

body[data-card-face="minimal"] .playing-card__center {
  font-size: clamp(1.25rem, 2.8vw, 1.7rem);
}

body[data-card-face="vintage"] .playing-card {
  background: linear-gradient(180deg, #fbf6ed, #f4ead7 82%);
}

body[data-card-face="vintage"] .playing-card__center {
  font-family: "Georgia", serif;
}

.card-placeholder {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.45);
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 100;
}

.drag-ghost .playing-card {
  position: absolute;
}

.playing-card.is-drag-origin {
  opacity: 0.22;
}

.playing-card.is-selected {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.86), var(--shadow-card);
}

.playing-card.is-hint {
  box-shadow: 0 0 0 2px rgba(255, 214, 10, 0.9), var(--shadow-card);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 16, 22, 0.52);
  backdrop-filter: blur(7px);
}

.modal-layer.is-open {
  display: flex;
}

.modal {
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  padding: 1.1rem;
  box-shadow: var(--shadow-soft);
}

.modal__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.modal__title {
  font-size: 1.2rem;
}

.modal__close {
  border: 1px solid var(--border-color);
  background: transparent;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.settings-item {
  display: grid;
  gap: 0.34rem;
}

.settings-item label {
  font-size: 0.85rem;
  font-weight: 700;
}

.toggle {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.9rem;
}

.toggle input {
  width: 18px;
  height: 18px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.stats-panel .card {
  padding: 0.65rem;
}

.stats-panel strong {
  display: block;
  font-size: 1.05rem;
}

.hint-toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  pointer-events: none;
  z-index: 130;
  background: rgba(8, 14, 19, 0.86);
  color: #fff;
  padding: 0.6rem 0.85rem;
  border-radius: 11px;
  font-size: 0.86rem;
  transition: opacity 140ms ease, transform 140ms ease;
}

.hint-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.game-mobile-actions {
  display: none;
}

@keyframes pop {
  0% {
    transform: scale(0.94);
    opacity: 0.5;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pile .playing-card:last-child {
  animation: pop 150ms ease;
}

body.reduce-motion .pile .playing-card:last-child {
  animation: none;
}

@media (max-width: 1120px) {
  .game-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .game-table {
    --card-w: clamp(50px, 12.4vw, 84px);
    min-height: min(74vh, 760px);
  }

  .toolbar-actions {
    display: none;
  }

  .game-mobile-actions {
    display: flex;
    position: sticky;
    bottom: 0.4rem;
    z-index: 55;
    gap: 0.42rem;
    flex-wrap: wrap;
    border-radius: 14px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
    backdrop-filter: var(--surface-blur);
  }

  .game-mobile-actions .btn {
    flex: 1;
    min-width: 78px;
    padding: 0.52rem 0.65rem;
    font-size: 0.82rem;
  }

  .settings-grid,
  .stats-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 660px) {
  .game-table {
    --card-w: clamp(44px, 12.7vw, 66px);
    --tableau-down-gap: 9px;
    --tableau-up-gap: 18px;
    gap: 0.65rem;
    min-height: 69vh;
  }

  .top-piles {
    gap: 0.35rem;
  }

  .stock-waste,
  .foundations {
    gap: 0.36rem;
  }

  .game-stats {
    justify-content: space-between;
  }

  .game-stat {
    min-width: 72px;
    flex: 1;
  }

  .game-stat strong {
    font-size: 0.92rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .playing-card,
  .hint-toast {
    transition-duration: 1ms;
  }
}
