/* Freecell-specific layout. common.css provides tokens, reset, header, modal,
   toast, and shared rules. This file owns everything the game adds. */

/* ── Board layout ───────────────────────────────────────────────────────────── */

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vh, 16px);
  padding: clamp(8px, 1.5vh, 16px) clamp(6px, 1.5vw, 14px) 0;
}

/* ── Top row: free cells (left) + foundations (right) ────────────────────────── */

.top-row {
  display: flex;
  gap: clamp(6px, 1.2vw, 12px);
}

.top-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(4px, 0.9vw, 9px);
  flex: 1;
}

/* Free cell slots — Stars and Stripes: red vertical stripes + blue canton with stars */
.freecell-slot {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: 9px;
  border: 1px dashed var(--slot-line);
  overflow: hidden;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 70' preserveAspectRatio='xMidYMid slice'><rect width='50' height='70' fill='%23ddc99d'/><g fill='%237a2e2e'><rect x='0' width='3.85' height='70'/><rect x='7.7' width='3.85' height='70'/><rect x='15.4' width='3.85' height='70'/><rect x='23.1' width='3.85' height='70'/><rect x='30.75' width='3.85' height='70'/><rect x='38.45' width='3.85' height='70'/><rect x='46.15' width='3.85' height='70'/></g><rect width='28' height='40' fill='%23253560'/><g fill='%23ddc99d'><circle cx='2.35' cy='2.2' r='0.65'/><circle cx='7' cy='2.2' r='0.65'/><circle cx='11.65' cy='2.2' r='0.65'/><circle cx='16.35' cy='2.2' r='0.65'/><circle cx='21' cy='2.2' r='0.65'/><circle cx='25.65' cy='2.2' r='0.65'/><circle cx='4.65' cy='6.65' r='0.65'/><circle cx='9.35' cy='6.65' r='0.65'/><circle cx='14' cy='6.65' r='0.65'/><circle cx='18.65' cy='6.65' r='0.65'/><circle cx='23.35' cy='6.65' r='0.65'/><circle cx='2.35' cy='11.1' r='0.65'/><circle cx='7' cy='11.1' r='0.65'/><circle cx='11.65' cy='11.1' r='0.65'/><circle cx='16.35' cy='11.1' r='0.65'/><circle cx='21' cy='11.1' r='0.65'/><circle cx='25.65' cy='11.1' r='0.65'/><circle cx='4.65' cy='15.55' r='0.65'/><circle cx='9.35' cy='15.55' r='0.65'/><circle cx='14' cy='15.55' r='0.65'/><circle cx='18.65' cy='15.55' r='0.65'/><circle cx='23.35' cy='15.55' r='0.65'/><circle cx='2.35' cy='20' r='0.65'/><circle cx='7' cy='20' r='0.65'/><circle cx='11.65' cy='20' r='0.65'/><circle cx='16.35' cy='20' r='0.65'/><circle cx='21' cy='20' r='0.65'/><circle cx='25.65' cy='20' r='0.65'/><circle cx='4.65' cy='24.45' r='0.65'/><circle cx='9.35' cy='24.45' r='0.65'/><circle cx='14' cy='24.45' r='0.65'/><circle cx='18.65' cy='24.45' r='0.65'/><circle cx='23.35' cy='24.45' r='0.65'/><circle cx='2.35' cy='28.9' r='0.65'/><circle cx='7' cy='28.9' r='0.65'/><circle cx='11.65' cy='28.9' r='0.65'/><circle cx='16.35' cy='28.9' r='0.65'/><circle cx='21' cy='28.9' r='0.65'/><circle cx='25.65' cy='28.9' r='0.65'/><circle cx='4.65' cy='33.35' r='0.65'/><circle cx='9.35' cy='33.35' r='0.65'/><circle cx='14' cy='33.35' r='0.65'/><circle cx='18.65' cy='33.35' r='0.65'/><circle cx='23.35' cy='33.35' r='0.65'/><circle cx='2.35' cy='37.8' r='0.65'/><circle cx='7' cy='37.8' r='0.65'/><circle cx='11.65' cy='37.8' r='0.65'/><circle cx='16.35' cy='37.8' r='0.65'/><circle cx='21' cy='37.8' r='0.65'/><circle cx='25.65' cy='37.8' r='0.65'/></g><rect width='50' height='70' fill='%23a07050' opacity='0.22'/></svg>");
  background-color: #ddc99d;
  background-size: 100% 100%;
}

/* Foundation slots */
.foundation-slot {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: 9px;
  border: 1px dashed var(--slot-line);
  background: var(--slot-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
  font-size: clamp(18px, 3.8vw, 32px);
  line-height: 1;
  cursor: pointer;
}

.foundation-slot[data-suit="hearts"],
.foundation-slot[data-suit="diamonds"] {
  color: rgba(178, 34, 52, 0.32);
}

.foundation-slot[data-suit="spades"],
.foundation-slot[data-suit="clubs"] {
  color: rgba(201, 169, 97, 0.28);
}

/* ── Tableau ─────────────────────────────────────────────────────────────────── */

.tableau {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: clamp(4px, 0.9vw, 9px);
  flex: 1;
  min-height: 0;
  align-items: start;
  padding-bottom: clamp(60px, 10vh, 90px);
}

.tableau-col {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: clamp(48px, 11vw, 88px);
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(180deg, #fbf5ea 0%, var(--card) 50%, #ede2cf 100%);
  color: var(--ink);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 -1px 0 rgba(0, 0, 0, 0.05) inset,
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 3px 8px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  border: 1px solid var(--card-edge);
}

/* Overlap: subsequent cards slide under the previous */
.tableau-col .card + .card {
  margin-top: clamp(-40px, -10.6vw, -18px);
}

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

/* ── Card face ──────────────────────────────────────────────────────────────── */

.card .corner {
  position: absolute;
  line-height: 1;
  font-family: var(--serif);
}
.card .corner.tl { top: 2%; left: 7%; }

.card .rank {
  font-family: 'Oswald', sans-serif;
  font-size: clamp(11px, 4.2vw, 28px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
}

.card .suit-tr {
  position: absolute;
  top: 2%;
  right: 7%;
  font-family: Georgia, serif;
  font-size: clamp(11px, 4.3vw, 28px);
  line-height: 1;
}

.card .center {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-family: Georgia, serif;
  font-size: clamp(14px, 7.5vw, 76px);
  line-height: 1;
  pointer-events: none;
}

.card.k .center,
.card.q .center,
.card.j .center {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(14px, 8.5vw, 88px);
}

/* ── Card states ────────────────────────────────────────────────────────────── */

.card:hover {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 5px 14px rgba(0, 0, 0, 0.28);
}

.card.selected {
  outline: 2px solid var(--gold-bright);
  outline-offset: 1px;
  z-index: 500 !important;
  transform: translateY(-5px) scale(1.02);
  box-shadow:
    0 0 0 1px rgba(201, 169, 97, 0.4),
    0 0 24px rgba(224, 196, 122, 0.4),
    0 10px 20px rgba(0, 0, 0, 0.4);
}

.card.in-selection {
  z-index: 499 !important;
  transform: translateY(-4px);
  box-shadow:
    0 0 16px rgba(224, 196, 122, 0.22),
    0 6px 14px rgba(0, 0, 0, 0.28);
}

/* Slots in the top row use absolute positioning for the card overlay */
.freecell-slot .card,
.foundation-slot .card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: unset;
  margin-top: 0;
  border-radius: 8px;
}

/* ── Auto-finish button ─────────────────────────────────────────────────────── */

.auto-finish {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.3, 1);
  background: var(--bg-3);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.65),
    0 0 0 3px rgba(201, 169, 97, 0.35),
    0 10px 28px rgba(0, 0, 0, 0.6);
}
.auto-finish.show { transform: translateX(-50%) translateY(0); }
.auto-finish:hover {
  background: var(--gold);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.7),
    0 0 0 3px rgba(224, 196, 122, 0.6),
    0 12px 32px rgba(0, 0, 0, 0.7);
}

/* ── Sparks ─────────────────────────────────────────────────────────────────── */

.spark {
  position: fixed;
  width: 6px;
  height: 6px;
  pointer-events: none;
  z-index: 999;
  border-radius: 50%;
  animation: spark-fall 2.5s ease-in forwards;
}
@keyframes spark-fall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), 100vh) rotate(720deg); opacity: 0; }
}

/* ── Confirming state ────────────────────────────────────────────────────────── */

.icon-btn.confirming {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: rgba(201, 169, 97, 0.15);
  animation: confirm-pulse 1s ease infinite;
}
@keyframes confirm-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201, 169, 97, 0.45); }
  50%       { box-shadow: 0 0 0 6px rgba(201, 169, 97, 0); }
}

/* ── Tooltip ─────────────────────────────────────────────────────────────────── */

.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: var(--bg-3);
  color: var(--card);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  border: 1px solid var(--gold-faint);
  font-family: var(--serif);
  font-style: italic;
  letter-spacing: 0.05em;
  z-index: 100;
}
.tooltip:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (hover: none) { .tooltip:hover::after { opacity: 0; } }

/* ── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .board { padding: 6px 4px 0; gap: 6px; }
  .top-row { gap: 4px; }
  .top-group { gap: 3px; }
  .tableau { gap: 3px; }
  .card .rank { font-size: clamp(9px, 3.8vw, 22px); }
  .card .suit-tr { font-size: clamp(9px, 3.8vw, 22px); }
}

@media (orientation: landscape) and (max-height: 480px) {
  .board { padding: 4px 8px 0; gap: 5px; }
  .tableau-col .card + .card { margin-top: clamp(-30px, -8.5vw, -14px); }
}

@media (prefers-reduced-motion: reduce) {
  .spark { animation: none; opacity: 0; }
  .card { transition: none; }
  .auto-finish { transition: none; }
}

/* ── PWA install banner ─────────────────────────────────────────────────────── */

#pwa-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--bg-2);
  border-top: 2px solid var(--gold);
  padding: 14px 16px 20px;
  box-shadow: 0 -6px 32px rgba(0,0,0,0.55);
  animation: pwa-slide-up 0.3s ease-out;
}
@keyframes pwa-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.pwa-row { display: flex; align-items: center; gap: 12px; }
.pwa-icon { width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0; }
.pwa-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.pwa-text strong { font-family: var(--serif); font-size: 1.05rem; color: var(--gold); }
.pwa-text span { font-size: 0.82rem; color: var(--cream); opacity: 0.85; line-height: 1.3; }
.pwa-share-icon { display: inline-block; vertical-align: middle; width: 14px; height: 14px; margin: 0 1px; }
#pwa-install-btn {
  background: var(--gold); color: var(--bg-1); border: none; border-radius: 8px;
  font-family: var(--sans); font-weight: 700; font-size: 0.9rem;
  padding: 10px 18px; cursor: pointer; flex-shrink: 0; white-space: nowrap;
}
#pwa-install-btn:hover { background: #e0c47a; }
#pwa-dismiss-btn {
  background: none; border: none; color: var(--cream); opacity: 0.55;
  font-size: 1.2rem; cursor: pointer; padding: 4px 6px; flex-shrink: 0; line-height: 1;
}
#pwa-dismiss-btn:hover { opacity: 1; }
