.freecell-shell {
  width: min(100%, 64rem);
  height: var(--game-visible-height, 100dvh);
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.freecell-stage {
  min-height: 0;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  place-items: stretch;
  overflow: hidden;
}
.game-help {
  min-height: 1.4rem;
  margin: 0 0 .35rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-align: center;
}
.game-help.hint-pop { animation: hint-pop .35s ease; }
.freecell-board {
  --stack-step: clamp(1.25rem, 4.25cqh, 2.3rem);
  width: 100%;
  max-width: min(100%, 172cqh);
  height: 100%;
  min-height: 0;
  justify-self: center;
  padding: clamp(.4rem, 1.4vw, .85rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid #17324d;
  border-radius: 1rem;
  background: #277565;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.09), 5px 5px 0 rgba(23,50,77,.13);
  touch-action: none;
}
.top-row,
.tableau {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(.16rem, .75vw, .5rem);
}
.free-cell-row,
.foundation-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(.16rem, .75vw, .5rem);
}
.free-cell-row { grid-column: 1 / span 4; }
.foundation-row { grid-column: 5 / span 4; }
.tableau {
  flex: 1;
  min-height: 0;
  margin-top: clamp(.65rem, 1.8vw, 1.1rem);
}
.tableau-pile {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.playing-card,
.empty-pile {
  width: 100%;
  height: auto;
}
.playing-card { font-size: clamp(.62rem, 1.9vw, 1.15rem); }
.empty-pile {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1.42;
  padding: 0;
  border: 2px dashed rgba(255,255,255,.38);
  border-radius: clamp(.3rem, .8vw, .55rem);
  background: rgba(8,49,44,.15);
  color: rgba(255,255,255,.44);
  cursor: pointer;
  font-family: Georgia, serif;
  font-size: clamp(1rem, 2.7vw, 1.8rem);
  font-weight: 800;
}
.empty-pile:not(:disabled):hover { background: rgba(255,255,255,.08); }
.empty-pile:focus-visible {
  z-index: 90 !important;
  outline: 3px solid #ffd65a;
  outline-offset: 2px;
}
.free-cell .empty-pile { font-family: inherit; font-size: clamp(.55rem, 1.4vw, .75rem); text-transform: uppercase; }
.tableau-pile .playing-card {
  position: absolute;
  top: calc(var(--card-index) * var(--stack-step));
  left: 0;
  z-index: calc(var(--card-index) + 1);
}
.tableau-pile > .empty-pile { position: absolute; inset: 0 auto auto 0; }
.playing-card.dragging-source { opacity: .48; }
.card-drag-ghost {
  position: fixed;
  z-index: 1000;
  width: var(--drag-width);
  height: var(--drag-height);
  margin: 0;
  pointer-events: none;
  opacity: .92;
  transform: translate(-50%, -42%) rotate(2deg) scale(1.04);
  box-shadow: 0 12px 24px rgba(8,29,35,.38), 0 0 0 3px #ffd65a;
}
.card-drag-ghost::after {
  content: attr(data-card-count);
  position: absolute;
  right: -.45rem;
  bottom: -.45rem;
  display: grid;
  place-items: center;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 .25rem;
  border-radius: 999px;
  background: #ffd65a;
  color: #17324d;
  font: 950 .75rem/1 "Avenir Next", sans-serif;
}
.card-drag-ghost[data-card-count="1"]::after { display: none; }
.action-button:disabled { cursor: default; opacity: .42; transform: none; box-shadow: none; }
@keyframes hint-pop { 50% { color: #17324d; transform: scale(1.025); } }
@keyframes deal-card {
  0% { opacity: 0; transform: translate(-8rem, -6rem) rotate(-12deg) scale(.75); }
  72% { opacity: 1; transform: translate(.1rem, -.15rem) rotate(1deg) scale(1.03); }
  100% { transform: translate(0) rotate(0) scale(1); }
}
@keyframes home-card {
  0% { transform: translateY(2.5rem) rotate(-10deg) scale(.72); opacity: .35; }
  62% { transform: translateY(-.35rem) rotate(3deg) scale(1.12); opacity: 1; box-shadow: 0 0 0 8px rgba(255,214,90,.45), 0 0 2rem #ffd65a; }
  100% { transform: translateY(0) rotate(0) scale(1); }
}
.deal-arrival { animation: deal-card .4s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--deal-order) * 18ms); }
.home-arrival { animation: home-card .56s cubic-bezier(.2,.85,.2,1) both; }

@media (max-width: 620px) {
  .freecell-shell { padding-left: .35rem; padding-right: .35rem; gap: .5rem; }
  .freecell-board { padding: .3rem; border-radius: .7rem; }
  .scorebar { padding: .5rem .65rem; }
  .game-help { font-size: .68rem; line-height: 1.2; }
  .top-row, .tableau, .free-cell-row, .foundation-row { gap: .1rem; }
  .tableau { margin-top: .5rem; }
  .playing-card { font-size: clamp(.54rem, 2.65vw, .78rem); }
  .game-actions { gap: .3rem; }
  .game-actions .action-button { min-width: 0; padding: .5rem .65rem; font-size: .82rem; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .freecell-shell { width: min(100%, 78rem); grid-template-columns: 13rem 1fr; }
  .freecell-stage { grid-column: 2; grid-row: 1 / span 3; }
  .game-help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .deal-arrival, .home-arrival { animation: none; }
}
