:root {
  --bg-grad-a: #eafff5;
  --bg-grad-b: #fff8ea;
  --card-panel: #ffffff;
  --text: #14251f;
  --muted: #5d7a72;
  --primary: #0f9d70;
  --primary-dark: #0b7a57;
  --primary-light: #4fd8a6;
  --accent: #f5a623;
  --accent-dark: #d98c0f;
  --accent-2: #e0384a;
  --border: #d9efe3;
  --shadow: 0 8px 24px rgba(11, 90, 64, 0.14);
  --radius: 16px;
  --felt-a: #1a7a5a;
  --felt-b: #0d4a37;
  --felt-c: #082e24;
  --suit-red: #d0242f;
  --suit-black: #1c2624;
  --card-w: clamp(50px, 7vw, 80px);
  --card-h: calc(var(--card-w) * 1.42);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-grad-a), var(--bg-grad-b));
  color: var(--text);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: transform 0.25s ease;
}

@media (orientation: portrait) {
  .site-header.header-hidden { transform: translateY(-100%); }
}

.brand a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  font-size: 22px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--accent);
  box-shadow: 0 4px 10px rgba(11, 122, 87, 0.35);
}

.brand-name {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--primary-dark), var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--card-panel);
  padding: 6px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.18s ease;
  white-space: nowrap;
  display: inline-block;
}

.tab-btn:hover { color: var(--primary-dark); }

.tab-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 12px rgba(15, 157, 112, 0.35);
}

/* Main content */
.content {
  flex: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.hero {
  max-width: 980px;
  width: 100%;
  text-align: center;
}

.hero h1 {
  font-size: clamp(22px, 3.6vw, 32px);
  margin: 4px 0 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-tagline {
  color: var(--muted);
  font-size: 14px;
  max-width: 680px;
  margin: 0 auto;
  line-height: 1.6;
}

.hero-tagline a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.hero-tagline a:hover { text-decoration: underline; }

.breadcrumb {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

.breadcrumb a {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 600;
}

.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 4px; }

/* Game switcher grid (homepage) */
.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  max-width: 980px;
  width: 100%;
}

.game-card {
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.game-card:hover { transform: translateY(-3px); border-color: var(--primary-light); }
.game-card .gc-icon { font-size: 26px; }
.game-card h3 { margin: 0; font-size: 16px; font-weight: 800; }
.game-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Game panel layout */
.game-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
  max-width: 1180px;
  width: 100%;
  animation: fadeIn 0.25s ease;
  scroll-margin-top: 100px;
}

.game-panel.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.game-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-header { width: 100%; max-width: 1180px; }
.board-header h2 { margin: 0 0 4px 0; font-size: 22px; font-weight: 800; }

.game-intro {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 760px;
}

.status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

/* Felt board area */
.board-area {
  flex: 1 1 640px;
  min-width: 300px;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,0.08), transparent 60%),
    linear-gradient(160deg, var(--felt-a), var(--felt-b) 55%, var(--felt-c));
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 0 6px rgba(0,0,0,0.12), inset 0 2px 10px rgba(255,255,255,0.08);
  padding: 20px;
  overflow-x: auto;
  overflow-y: visible;
}

.board-inner {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: fit-content;
}

.board-row {
  display: flex;
  gap: 10px;
}

.tableau-row {
  display: flex;
  gap: 10px;
}

.spacer { flex: 1 1 auto; }

/* Extra breathing room between the stock (stacked deck) and the next pile
   that shows revealed cards — the waste pile in Klondike, the tableau in
   Spider. Only Klondike and Spider have a #pile-stock element. */
#pile-stock { margin-right: 22px; }

/* Side panel */
.side-panel {
  flex: 0 0 220px;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: flex-start;
  height: fit-content;
}

.new-game-btn {
  border: none;
  padding: 13px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #ffcf6b);
  color: #402c00;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(245, 166, 35, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.new-game-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 18px rgba(245, 166, 35, 0.45); }
.new-game-btn:active { transform: translateY(0); }

.secondary-btn {
  border: 1px solid var(--border);
  background: #f5fbf8;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.secondary-btn:hover { background: #eafaf2; }
.secondary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; }
.btn-row .secondary-btn { flex: 1; }

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.stat-row span:last-child { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

/* ---------- Cards ---------- */
.pile {
  position: relative;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18);
  width: var(--card-w);
  height: var(--card-h);
  flex: 0 0 auto;
}

.pile.empty-outline { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.28); }

.pile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.35);
  font-size: calc(var(--card-w) * 0.4);
  pointer-events: none;
}

.pile.drop-target {
  box-shadow: inset 0 0 0 3px var(--accent), 0 0 12px rgba(245, 166, 35, 0.6);
}

.card {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.11);
  background: #fffdf8;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  border: 1px solid rgba(0,0,0,0.08);
  user-select: none;
  touch-action: none;
  cursor: grab;
  transition: box-shadow 0.12s ease, filter 0.12s ease;
}

.card.static { position: relative; }

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

.card.face-down {
  background:
    repeating-linear-gradient(45deg, var(--primary-dark), var(--primary-dark) 5px, var(--primary) 5px, var(--primary) 10px);
  border: 2px solid rgba(255,255,255,0.55);
  cursor: default;
}

.card.face-down::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: calc(var(--card-w) * 0.08);
}

/* FreeCell "peek": a press-and-hold clone shown above the whole board so a
   buried tableau card can be seen in full, uncropped by the cards stacked
   on top of it. */
.peek-card {
  z-index: 900;
  pointer-events: none;
  cursor: default;
  transform: scale(1.08);
  box-shadow: 0 14px 30px rgba(0,0,0,0.4), 0 0 0 3px var(--accent) inset;
  transition: transform 0.1s ease;
}

.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.24);
}

.card-corner.tl { top: 4%; left: 7%; }
.card-corner.br { bottom: 4%; right: 7%; transform: rotate(180deg); }
.card-corner .suit { font-size: calc(var(--card-w) * 0.22); margin-top: -2px; }

.card-pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.52);
  opacity: 0.9;
}

.card-pip .face-figure {
  width: calc(var(--card-w) * 0.58);
  height: calc(var(--card-w) * 0.58);
  overflow: visible;
}

.card.selected {
  box-shadow: 0 0 0 3px var(--accent), 0 6px 14px rgba(0,0,0,0.35);
  filter: brightness(1.04);
  z-index: 500 !important;
}

.card:hover:not(.face-down):not(.selected) { filter: brightness(1.03); }

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

.drag-ghost .card { box-shadow: 0 10px 24px rgba(0,0,0,0.45); cursor: grabbing; }

/* Board-specific sizing — all three boards share the same card scale;
   only the reserved vertical cascade room per board differs. */
.klondike-board .tableau-row .pile { height: 440px; }
.spider-board .tableau-row .pile { height: 500px; }
.freecell-board .tableau-row .pile { height: 440px; }

/* Spider deals straight onto the tableau (no waste pile), so the deck's
   "revealed cards" are the tableau row below it — give that row gap some
   extra room to match the stock/waste breathing room added in Klondike. */
.spider-board .board-inner { gap: 38px; }

@media (max-width: 560px) {
  .klondike-board .tableau-row .pile { height: 340px; }
  .spider-board .tableau-row .pile { height: 380px; }
  .freecell-board .tableau-row .pile { height: 340px; }
}

/* Free cells / foundations slot styling */
.slot-label {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Spider suit progress tray */
.suit-tray {
  display: flex;
  gap: 6px;
  align-items: center;
}

.suit-tray .tray-slot {
  width: calc(var(--card-w) * 0.55);
  height: calc(var(--card-h) * 0.55);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.26);
  background: rgba(255,255,255,0.05);
}

.suit-tray .tray-slot.filled { background: linear-gradient(135deg, var(--accent), #ffcf6b); color: #402c00; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 30, 22, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.win-overlay.show { display: flex; }

.win-card {
  background: var(--card-panel);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}

.win-card h2 {
  margin: 0 0 6px;
  font-size: 26px;
  background: linear-gradient(90deg, var(--primary-dark), var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.win-card p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.win-stats { display: flex; justify-content: center; gap: 18px; margin-bottom: 18px; }
.win-stats div { font-size: 13px; color: var(--muted); }
.win-stats strong { display: block; font-size: 20px; color: var(--text); }

.confetti-piece {
  position: fixed;
  top: -20px;
  z-index: 2001;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: 0.4; }
}

/* Info / FAQ sections */
.info-section {
  max-width: 860px;
  width: 100%;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
}

.info-section h2 {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 800;
}

.info-section h3 {
  font-size: 15px;
  margin: 16px 0 6px;
  font-weight: 700;
  color: var(--primary-dark);
}

.info-section p, .info-section li {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
}

.info-section ul, .info-section ol { padding-left: 20px; margin: 8px 0; }

.faq details {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.faq details:first-of-type { border-top: none; padding-top: 0; }

.faq summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 18px; color: var(--primary); font-weight: 800; }
.faq details[open] summary::after { content: "\2212"; }

.faq details p { margin: 8px 0 0; color: var(--muted); }

/* Footer */
.site-footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--muted);
}

.site-footer p { margin: 0 0 4px; }
.site-footer a { color: var(--primary-dark); font-weight: 600; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 900px) {
  .game-grid { grid-template-columns: 1fr; }
  .game-layout { flex-direction: column; }
  .side-panel { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .side-panel .new-game-btn { flex: 1 1 100%; }
  .side-panel .control-group { flex: 1 1 140px; }
}

@media (max-width: 720px) {
  .site-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 560px) {
  .board-area { padding: 14px; }
  .board-inner { gap: 14px; }
  .spider-board .board-inner { gap: 24px; }
}

.tab-btn.home-link {
  margin-left: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
  opacity: 0.75;
}
.tab-btn.home-link:hover { opacity: 1; }
