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

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

.board {
  flex: 1;
  position: relative;
  z-index: 1;
  padding: 16px clamp(10px, 2vw, 22px);
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.5vh, 22px);
  min-height: 0;
}

.row-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(5px, 1.1vw, 12px);
}

.tableau-row {
  flex: 1;
  min-height: 0;
}

.cell {
  position: relative;
}

.tableau-row .cell {
  height: 100%;
}

/* ── Slot (empty pile) ──────────────────────────────────────────────────────── */

.slot {
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: 9px;
  border: 1px dashed var(--slot-line);
  background: var(--slot-bg);
  position: relative;
}

.slot.foundation::before {
  content: attr(data-icon);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(201, 169, 97, 0.35);
  font-family: Georgia, serif;
  font-size: clamp(20px, 4.2vw, 34px);
  font-weight: 300;
}

.slot.stock-empty::before {
  content: '↻';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--gold-dim);
  font-size: clamp(18px, 3.5vw, 26px);
}

.slot.tableau-empty::before {
  content: 'K';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(201, 169, 97, 0.18);
  font-family: var(--serif);
  font-size: clamp(28px, 6vw, 50px);
  font-weight: 400;
  font-style: italic;
}

.cell.drop-target .slot,
.card.drop-target {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 169, 97, 0.5), 0 0 24px rgba(201, 169, 97, 0.25);
}
.cell.drop-target .slot {
  background: rgba(201, 169, 97, 0.08);
}

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

.card {
  position: absolute;
  width: 100%;
  aspect-ratio: 5 / 7;
  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 4px 12px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  border: 1px solid var(--card-edge);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1.05),
              box-shadow 0.2s,
              top 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
  left: 0;
  top: 0;
}

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

.card.face-down {
  background:
    repeating-linear-gradient(45deg, rgba(201, 169, 97, 0.35) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(-45deg, rgba(201, 169, 97, 0.35) 0 1px, transparent 1px 6px),
    linear-gradient(135deg, #2e2a5e 0%, #1f1d3f 50%, #281b3a 100%);
  border: 1px solid var(--gold-dim);
  color: transparent;
}
.card.face-down::before {
  content: '';
  position: absolute;
  inset: 7%;
  border: 1px solid rgba(201, 169, 97, 0.45);
  border-radius: 5px;
  background: radial-gradient(ellipse at center, rgba(201, 169, 97, 0.12) 0%, transparent 60%);
}
.card.face-down::after {
  content: '';
  position: absolute;
  inset: 38% 30%;
  border: 1px solid rgba(201, 169, 97, 0.5);
  transform: rotate(45deg);
  background: radial-gradient(circle, rgba(201, 169, 97, 0.2), transparent 70%);
}

/* ── Card face — corner pips (BL-010: rank significantly larger) ───────────── */

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-family: var(--serif);
}
.card .corner.tl { top: 5%; left: 7%; }
.card .corner.br { bottom: 5%; right: 7%; transform: rotate(180deg); }

/* BL-010: rank bumped from clamp(11,2.6vw,18) → clamp(15,3.6vw,24); suit bumped proportionally. */
.card .corner .rank {
  font-size: clamp(15px, 3.6vw, 24px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1px;
}
.card .corner .suit-mini {
  font-size: clamp(12px, 2.8vw, 18px);
  font-family: Georgia, serif;
}

.card .center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: clamp(22px, 6vw, 42px);
  pointer-events: none;
}

.card.face-up.k .center,
.card.face-up.q .center,
.card.face-up.j .center {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(28px, 7vw, 52px);
}

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

.card.face-up:hover {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 6px 18px rgba(0, 0, 0, 0.3);
}

.card.selected {
  outline: 2px solid var(--gold-bright);
  outline-offset: 1px;
  z-index: 500 !important;
  transform: translateY(-6px) scale(1.02);
  box-shadow:
    0 0 0 1px rgba(201, 169, 97, 0.4),
    0 0 28px rgba(224, 196, 122, 0.4),
    0 12px 24px rgba(0, 0, 0, 0.4);
}
.card.in-selection {
  z-index: 500 !important;
  transform: translateY(-6px);
  box-shadow:
    0 0 18px rgba(224, 196, 122, 0.25),
    0 8px 18px rgba(0, 0, 0, 0.3);
}

.card.flipping { animation: flip 0.35s cubic-bezier(0.4, 0.1, 0.5, 1.2); }
@keyframes flip {
  0% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(90deg) scale(1.05); }
  100% { transform: rotateY(0deg) scale(1); }
}

.card.dealt { animation: deal-in 0.4s cubic-bezier(0.2, 0.8, 0.3, 1) backwards; }
@keyframes deal-in {
  0% { transform: translateY(-30px) scale(0.95); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ── 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);
}
.auto-finish.show { transform: translateX(-50%) translateY(0); }

/* Solid background + dark ring + drop shadow so the button reads
   clearly even when it overlaps tableau cards on short viewports. */
.auto-finish {
  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: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);
}

/* ── Confetti / sparkles (win celebration) ──────────────────────────────────── */

.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 on icon buttons (BL-006: non-blocking confirm) ────────── */

.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 (icon-btn helper) ──────────────────────────────────────────────── */

.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; }
}

/* ── Card-back picker ───────────────────────────────────────────────────────── */

.backs-menu {
  position: absolute;
  top: calc(100% - 1px);
  right: 14px;
  background: rgba(15, 18, 38, 0.96);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--gold-faint);
  border-top-color: transparent;
  border-radius: 0 0 10px 10px;
  padding: 14px 18px 16px;
  z-index: 60;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: menu-in 0.18s ease-out;
}
.backs-menu[hidden] { display: none; }
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.backs-menu-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 12px;
  text-align: center;
}
.backs-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 200px;
}
.back-option {
  background: transparent;
  border: 1px solid transparent;
  color: var(--card);
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: all 0.18s ease;
}
.back-option:hover {
  background: rgba(201, 169, 97, 0.08);
  border-color: var(--gold-faint);
}
.back-option.active {
  border-color: var(--gold);
  background: rgba(201, 169, 97, 0.12);
  color: var(--gold-bright);
}
.back-preview {
  width: 40px;
  height: 56px;
  border-radius: 4px;
  border: 1px solid var(--gold-dim);
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  overflow: hidden;
}

/* Card back: Patience (classic, diamond pattern) */
.card.face-down,
.back-preview.classic {
  background:
    repeating-linear-gradient(45deg, rgba(201, 169, 97, 0.35) 0 1px, transparent 1px 6px),
    repeating-linear-gradient(-45deg, rgba(201, 169, 97, 0.35) 0 1px, transparent 1px 6px),
    linear-gradient(135deg, #2e2a5e 0%, #1f1d3f 50%, #281b3a 100%);
}
.back-preview.classic::before {
  content: '';
  position: absolute;
  inset: 7%;
  border: 1px solid rgba(201, 169, 97, 0.45);
  border-radius: 3px;
}
.back-preview.classic::after {
  content: '';
  position: absolute;
  inset: 38% 30%;
  border: 1px solid rgba(201, 169, 97, 0.5);
  transform: rotate(45deg);
}

/* Card back: Royal (gold filigree on blue) */
body[data-back="royal"] .card.face-down,
.back-preview.royal {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 140' preserveAspectRatio='xMidYMid slice'><defs><pattern id='rd' x='0' y='0' width='8' height='8' patternUnits='userSpaceOnUse'><circle cx='4' cy='4' r='0.5' fill='%23304a8a' opacity='0.6'/></pattern></defs><rect width='100' height='140' fill='%23142555'/><rect width='100' height='140' fill='url(%23rd)'/><rect x='4' y='4' width='92' height='132' fill='none' stroke='%23c9a961' stroke-width='0.7'/><rect x='7' y='7' width='86' height='126' fill='none' stroke='%23c9a961' stroke-width='0.3' opacity='0.6'/><g transform='translate(50,70)'><circle r='25' fill='none' stroke='%23c9a961' stroke-width='0.5' opacity='0.7'/><circle r='18' fill='none' stroke='%23c9a961' stroke-width='0.4' opacity='0.85'/><polygon points='0,-23 4,-7 23,0 4,7 0,23 -4,7 -23,0 -4,-7' fill='%23c9a961' opacity='0.95'/><polygon points='0,-13 2.5,-4 13,0 2.5,4 0,13 -2.5,4 -13,0 -2.5,-4' fill='%23142555'/><circle r='4' fill='%23c9a961'/><circle r='1.4' fill='%23142555'/></g><g fill='%23c9a961' opacity='0.85'><circle cx='12' cy='12' r='1.3'/><circle cx='88' cy='12' r='1.3'/><circle cx='12' cy='128' r='1.3'/><circle cx='88' cy='128' r='1.3'/></g><g fill='%23c9a961' opacity='0.6'><polygon points='50,16 53,19 50,22 47,19'/><polygon points='50,124 53,121 50,118 47,121'/><polygon points='15,70 18,73 15,76 12,73'/><polygon points='85,70 88,73 85,76 82,73'/></g></svg>");
  background-size: 100% 100%;
  background-color: #142555;
}

/* Card back: Stars & Stripes (faded American flag) */
body[data-back="flag"] .card.face-down,
.back-preview.flag {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 140' preserveAspectRatio='xMidYMid slice'><rect width='100' height='140' fill='%23ddc99d'/><g fill='%237a2e2e'><rect x='0' width='7.7' height='140'/><rect x='15.4' width='7.7' height='140'/><rect x='30.8' width='7.7' height='140'/><rect x='46.2' width='7.7' height='140'/><rect x='61.5' width='7.7' height='140'/><rect x='76.9' width='7.7' height='140'/><rect x='92.3' width='7.7' height='140'/></g><rect width='56' height='80' fill='%23253560'/><g fill='%23ddc99d'><circle cx='4.7' cy='4.4' r='1.3'/><circle cx='14' cy='4.4' r='1.3'/><circle cx='23.3' cy='4.4' r='1.3'/><circle cx='32.7' cy='4.4' r='1.3'/><circle cx='42' cy='4.4' r='1.3'/><circle cx='51.3' cy='4.4' r='1.3'/><circle cx='9.3' cy='13.3' r='1.3'/><circle cx='18.7' cy='13.3' r='1.3'/><circle cx='28' cy='13.3' r='1.3'/><circle cx='37.3' cy='13.3' r='1.3'/><circle cx='46.7' cy='13.3' r='1.3'/><circle cx='4.7' cy='22.2' r='1.3'/><circle cx='14' cy='22.2' r='1.3'/><circle cx='23.3' cy='22.2' r='1.3'/><circle cx='32.7' cy='22.2' r='1.3'/><circle cx='42' cy='22.2' r='1.3'/><circle cx='51.3' cy='22.2' r='1.3'/><circle cx='9.3' cy='31.1' r='1.3'/><circle cx='18.7' cy='31.1' r='1.3'/><circle cx='28' cy='31.1' r='1.3'/><circle cx='37.3' cy='31.1' r='1.3'/><circle cx='46.7' cy='31.1' r='1.3'/><circle cx='4.7' cy='40' r='1.3'/><circle cx='14' cy='40' r='1.3'/><circle cx='23.3' cy='40' r='1.3'/><circle cx='32.7' cy='40' r='1.3'/><circle cx='42' cy='40' r='1.3'/><circle cx='51.3' cy='40' r='1.3'/><circle cx='9.3' cy='48.9' r='1.3'/><circle cx='18.7' cy='48.9' r='1.3'/><circle cx='28' cy='48.9' r='1.3'/><circle cx='37.3' cy='48.9' r='1.3'/><circle cx='46.7' cy='48.9' r='1.3'/><circle cx='4.7' cy='57.8' r='1.3'/><circle cx='14' cy='57.8' r='1.3'/><circle cx='23.3' cy='57.8' r='1.3'/><circle cx='32.7' cy='57.8' r='1.3'/><circle cx='42' cy='57.8' r='1.3'/><circle cx='51.3' cy='57.8' r='1.3'/><circle cx='9.3' cy='66.7' r='1.3'/><circle cx='18.7' cy='66.7' r='1.3'/><circle cx='28' cy='66.7' r='1.3'/><circle cx='37.3' cy='66.7' r='1.3'/><circle cx='46.7' cy='66.7' r='1.3'/><circle cx='4.7' cy='75.6' r='1.3'/><circle cx='14' cy='75.6' r='1.3'/><circle cx='23.3' cy='75.6' r='1.3'/><circle cx='32.7' cy='75.6' r='1.3'/><circle cx='42' cy='75.6' r='1.3'/><circle cx='51.3' cy='75.6' r='1.3'/></g><rect width='100' height='140' fill='%23a07050' opacity='0.22'/></svg>");
  background-size: 100% 100%;
  background-color: #ddc99d;
}

/* Card back: Crimson (gold filigree on wine red) */
body[data-back="crimson"] .card.face-down,
.back-preview.crimson {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 140' preserveAspectRatio='xMidYMid slice'><defs><pattern id='cd' x='0' y='0' width='10' height='10' patternUnits='userSpaceOnUse'><path d='M 5 0 L 10 5 L 5 10 L 0 5 Z' fill='none' stroke='%23320808' stroke-width='0.4'/></pattern></defs><rect width='100' height='140' fill='%235a1818'/><rect width='100' height='140' fill='url(%23cd)' opacity='0.7'/><rect x='4' y='4' width='92' height='132' fill='none' stroke='%23c9a961' stroke-width='0.6' opacity='0.85'/><rect x='7' y='7' width='86' height='126' fill='none' stroke='%23c9a961' stroke-width='0.25' opacity='0.6'/><g transform='translate(50,70)' fill='none' stroke='%23c9a961' stroke-width='0.5' opacity='0.9'><circle r='22'/><circle r='15'/></g><g transform='translate(50,70)'><path d='M 0,-22 Q 6,-14 0,-7 Q -6,-14 0,-22Z' fill='%23c9a961' opacity='0.75'/><path d='M 0,22 Q 6,14 0,7 Q -6,14 0,22Z' fill='%23c9a961' opacity='0.75'/><path d='M -22,0 Q -14,6 -7,0 Q -14,-6 -22,0Z' fill='%23c9a961' opacity='0.75'/><path d='M 22,0 Q 14,6 7,0 Q 14,-6 22,0Z' fill='%23c9a961' opacity='0.75'/><circle r='3' fill='%23c9a961'/><circle r='1' fill='%235a1818'/></g><g fill='%23c9a961' opacity='0.7'><circle cx='12' cy='12' r='1'/><circle cx='88' cy='12' r='1'/><circle cx='12' cy='128' r='1'/><circle cx='88' cy='128' r='1'/></g></svg>");
  background-size: 100% 100%;
  background-color: #5a1818;
}

/* Hide pseudo-element ornaments for SVG-based backs */
body[data-back="royal"] .card.face-down::before,
body[data-back="royal"] .card.face-down::after,
body[data-back="flag"] .card.face-down::before,
body[data-back="flag"] .card.face-down::after,
body[data-back="crimson"] .card.face-down::before,
body[data-back="crimson"] .card.face-down::after {
  display: none;
}

/* Border tint per back variant */
body[data-back="flag"]    .card.face-down { border-color: rgba(122, 46, 46, 0.6); }
body[data-back="crimson"] .card.face-down { border-color: rgba(201, 169, 97, 0.45); }
body[data-back="royal"]   .card.face-down { border-color: rgba(201, 169, 97, 0.45); }

/* ── Responsive (game-specific overrides only — common.css handles header/etc.) */

@media (max-width: 640px) {
  .board { padding: 10px 8px; gap: 10px; }
}
@media (max-width: 360px) {
  .backs-menu { right: 8px; padding: 12px 14px 14px; }
  .backs-menu-grid { width: 180px; gap: 8px; }
  .back-preview { width: 36px; height: 50px; }
}
@media (orientation: landscape) and (max-height: 480px) {
  .board { padding: 6px 12px; gap: 8px; }
}
