/* ==========================================================================
   FreeCell — game shell styles
   Scoped with .fcl-* so the shared site stylesheet can't leak in and we
   can't leak out. Mobile-first, single file, no image assets — every visual
   is CSS (gradients, shadows, borders) plus text/emoji glyphs.
   ========================================================================== */

:root {
  /* Card-table palette on a dark blue felt ground — distinct from the
     site's green Klondike table. */
  --fcl-bg-0:        #081524;
  --fcl-bg-1:         #0d2338;
  --fcl-bg-2:         #123351;
  --fcl-felt:         #164468;
  --fcl-gold:         #ffd23f;
  --fcl-gold-soft:    #ffe9a3;
  --fcl-ice:          #59d1ff;
  --fcl-red:          #ff5d6c;
  --fcl-ink:          #f2f8fb;
  --fcl-ink-dim:      #b6cee1;
  --fcl-panel:        rgba(8, 21, 36, 0.92);
  --fcl-panel-line:   rgba(89, 209, 255, 0.22);
  --fcl-chip:         rgba(4, 13, 22, 0.6);

  /* Playing-card faces are always cream/white, independent of the felt
     theme above — that's the one deliberately "unthemed" part, same as a
     real deck. */
  --fcl-card-bg:      #fbf8ef;
  --fcl-card-black:   #1c2420;
  --fcl-card-red:     #c81e3a;

  /* Card geometry — one source of truth, everything else (stacking offset,
     column height) derives from these via calc(), never a %-of-self trick.
     8 tableau columns need a narrower card than a 7-column Klondike board. */
  --fcl-card-w:       clamp(28px, 10.2vw, 58px);
  --fcl-card-h:       calc(var(--fcl-card-w) * 1.4);
  --fcl-offset:       calc(var(--fcl-card-h) * 0.26);
  --fcl-gap:          clamp(3px, 1.2vw, 8px);

  --fcl-radius:       16px;
  --fcl-font:         'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --fcl-safe-t:       env(safe-area-inset-top, 0px);
  --fcl-safe-b:       env(safe-area-inset-bottom, 0px);
  --fcl-safe-l:       env(safe-area-inset-left, 0px);
  --fcl-safe-r:       env(safe-area-inset-right, 0px);
}

html, body.fcl-body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--fcl-bg-0);
  color: var(--fcl-ink);
  font-family: var(--fcl-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* --------------------------------------------------------------------------
   Shared site header — visible on the menu/help, hidden during play.
   -------------------------------------------------------------------------- */
.fcl-site-header {
  position: relative;
  z-index: 40;
  font-size: 13px;
}
.fcl-site-header header {
  padding: 10px calc(16px + var(--fcl-safe-r)) 10px calc(16px + var(--fcl-safe-l));
  padding-top: calc(10px + var(--fcl-safe-t));
  background: rgba(6, 18, 30, .78);
  border-bottom: 1px solid var(--fcl-panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.fcl-site-header a { color: var(--fcl-ink-dim); text-decoration: none; padding: 5px 9px; border-radius: 8px; }
.fcl-site-header a:hover { color: var(--fcl-ink); background: rgba(255,255,255,.07); }
.fcl-site-header a.active { color: var(--fcl-gold); background: rgba(255,210,63,.14); }

body:has(.fcl-root.is-playing) .fcl-site-header,
body:has(.fcl-root.is-playing) #footer { display: none; }

.fcl-root {
  position: relative;
  min-height: 100vh;
  background:
    radial-gradient(60vw 60vw at 15% -10%, rgba(89, 209, 255, .12), transparent 60%),
    radial-gradient(70vw 70vw at 110% 10%, rgba(255, 210, 63, .08), transparent 60%),
    linear-gradient(180deg, var(--fcl-bg-1), var(--fcl-bg-0) 60%);
}
.fcl-root.is-playing { height: 100vh; overflow: hidden; }

/* --------------------------------------------------------------------------
   Generic dialog-style screens (loading / menu / help / win)
   -------------------------------------------------------------------------- */
.fcl-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--fcl-safe-t)) calc(16px + var(--fcl-safe-r)) calc(20px + var(--fcl-safe-b)) calc(16px + var(--fcl-safe-l));
  opacity: 0;
  transform: scale(.98);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 20;
  overflow-y: auto;
}
.fcl-screen.is-open { opacity: 1; transform: none; pointer-events: auto; z-index: 30; }

.fcl-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--fcl-panel);
  border: 1px solid var(--fcl-panel-line);
  border-radius: 22px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.02) inset;
}
.fcl-panel-narrow { max-width: 340px; }
.fcl-panel-wide { max-width: 720px; text-align: left; }

.fcl-logo {
  margin: 6px 0 4px;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: .3px;
  background: linear-gradient(135deg, var(--fcl-ice), var(--fcl-gold) 60%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.fcl-menu-glyphs { font-size: 26px; letter-spacing: 10px; margin-bottom: 4px; filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)); }
.fcl-menu-glyphs .fcl-red { color: var(--fcl-red); }
.fcl-tagline { color: var(--fcl-ink-dim); margin: 0 0 18px; font-size: 14px; }
.fcl-muted { color: var(--fcl-ink-dim); }

.fcl-progress { width: 100%; height: 8px; border-radius: 8px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 18px; }
.fcl-progress-bar { height: 100%; width: 40%; background: linear-gradient(90deg, var(--fcl-ice), var(--fcl-gold)); border-radius: 8px; animation: fcl-load 1.1s ease-in-out infinite; }
@keyframes fcl-load { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

.fcl-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.fcl-actions-secondary { margin-top: 4px; }
.fcl-btn {
  appearance: none; border: none; cursor: pointer;
  padding: 14px 20px; border-radius: 14px; font-size: 16px; font-weight: 700;
  font-family: inherit; color: var(--fcl-ink);
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.fcl-btn:active { transform: scale(.97); }
.fcl-btn-primary { background: linear-gradient(135deg, var(--fcl-ice), #2e8fc7); box-shadow: 0 10px 24px rgba(89,209,255,.3); color: #06202f; }
.fcl-btn-primary:hover { filter: brightness(1.08); }
.fcl-btn-cash { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: var(--fcl-ink-dim); }
.fcl-btn-cash.is-disabled, .fcl-btn-cash:disabled { opacity: .55; cursor: not-allowed; }
.fcl-btn-ghost { background: rgba(255,255,255,.05); border: 1px solid var(--fcl-panel-line); color: var(--fcl-ink); }
.fcl-btn-ghost:hover { background: rgba(255,255,255,.09); }

.fcl-record-strip {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 14px 0 6px;
}
.fcl-record-item {
  padding: 10px 8px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(89,209,255,.12), rgba(255,210,63,.06));
  border: 1px solid rgba(89,209,255,.22);
  display: flex; flex-direction: column; gap: 2px;
}
.fcl-record-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--fcl-gold-soft); }
.fcl-record-value { font-size: 17px; font-weight: 800; color: var(--fcl-ink); font-variant-numeric: tabular-nums; }

.fcl-fineprint { margin-top: 14px; font-size: 11px; color: var(--fcl-ink-dim); opacity: .8; line-height: 1.5; }
.fcl-version::before { content: 'v' attr(data-v); }

.fcl-close {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid var(--fcl-panel-line); background: rgba(255,255,255,.06);
  color: var(--fcl-ink); font-size: 20px; line-height: 1; cursor: pointer;
}

.fcl-h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; color: var(--fcl-ink); }
.fcl-h3 { margin: 18px 0 8px; font-size: 15px; color: var(--fcl-gold-soft); text-transform: uppercase; letter-spacing: .06em; }
.fcl-h3:first-child { margin-top: 0; }
.fcl-body { font-size: 14px; line-height: 1.6; color: var(--fcl-ink-dim); margin: 0 0 10px; }
.fcl-list { margin: 0; padding-left: 18px; color: var(--fcl-ink-dim); font-size: 14px; line-height: 1.7; }
.fcl-list b { color: var(--fcl-ink); }

.fcl-help-cols { display: grid; grid-template-columns: 1fr; gap: 22px; }
@media (min-width: 720px) {
  .fcl-help-cols { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   Play screen
   -------------------------------------------------------------------------- */
#screen-play.fcl-screen {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  display: none;
  background: transparent;
}
#screen-play.fcl-screen.is-open { display: flex; opacity: 1; transform: none; }

.fcl-play {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(10px + var(--fcl-safe-t)) calc(12px + var(--fcl-safe-r)) calc(14px + var(--fcl-safe-b)) calc(12px + var(--fcl-safe-l));
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.fcl-topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fcl-chip {
  display: flex; align-items: baseline; gap: 6px; padding: 7px 11px;
  border-radius: 12px; background: var(--fcl-chip); border: 1px solid var(--fcl-panel-line);
}
.fcl-chip-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--fcl-ink-dim); }
.fcl-chip-value { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

.fcl-topbar-right { display: flex; gap: 6px; margin-left: auto; }
.fcl-icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--fcl-panel-line);
  background: var(--fcl-chip); color: var(--fcl-ink); font-size: 15px; cursor: pointer;
}
.fcl-icon-btn:active { transform: scale(.94); }
.fcl-icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.fcl-autofinish-btn {
  appearance: none; border: none; cursor: pointer;
  padding: 10px; border-radius: 12px; font-size: 14px; font-weight: 800; letter-spacing: .04em;
  color: #06202f;
  background: linear-gradient(135deg, var(--fcl-gold), var(--fcl-ice));
  box-shadow: 0 8px 18px rgba(255,210,63,.3);
  animation: fcl-pulse-glow 1.6s ease-in-out infinite;
}
.fcl-autofinish-btn[hidden] { display: none; }
@keyframes fcl-pulse-glow { 0%, 100% { box-shadow: 0 0 0 rgba(255,210,63,0); } 50% { box-shadow: 0 0 16px rgba(255,210,63,.5); } }

.fcl-board {
  position: relative;
  border-radius: 18px;
  padding: 10px 6px 16px;
  background: radial-gradient(120% 100% at 50% 0%, var(--fcl-felt), var(--fcl-bg-2) 70%);
  border: 1px solid var(--fcl-panel-line);
  box-shadow: inset 0 0 40px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fcl-top-row, .fcl-tableau {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  justify-items: center;
  gap: var(--fcl-gap);
  padding: 0 4px;
}

/* Every slot/pile shares one geometry + an "empty outline" drawn via ::before
   so a truly empty spot still reads as a droppable slot. */
.fcl-cell, .fcl-foundation, .fcl-tableau-pile {
  position: relative;
  width: var(--fcl-card-w);
}
.fcl-cell, .fcl-foundation {
  height: var(--fcl-card-h);
}
.fcl-tableau-pile {
  height: max(var(--fcl-card-h), calc(var(--fcl-card-h) + (var(--count, 0) - 1) * var(--fcl-offset)));
}

.fcl-cell::before, .fcl-foundation::before, .fcl-tableau-pile::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: var(--fcl-card-w);
  height: var(--fcl-card-h);
  border-radius: 8px;
  border: 1.5px dashed rgba(255,255,255,.18);
  background: rgba(255,255,255,.03);
}
.fcl-foundation::before {
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--fcl-card-w) * 0.42);
  color: rgba(255,255,255,.14);
}
.fcl-foundation[data-suit="S"]::before { content: '♠'; }
.fcl-foundation[data-suit="C"]::before { content: '♣'; }
.fcl-foundation[data-suit="H"]::before { content: '♥'; color: rgba(255,93,108,.22); }
.fcl-foundation[data-suit="D"]::before { content: '♦'; color: rgba(255,93,108,.22); }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.fcl-card {
  position: absolute;
  left: 0; right: 0;
  top: calc(var(--fcl-offset) * var(--i, 0));
  width: var(--fcl-card-w);
  height: var(--fcl-card-h);
  border-radius: 7px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
}

.fcl-card-face {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 7px;
  background: var(--fcl-card-bg);
  border: 1px solid rgba(0,0,0,.15);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.fcl-card[data-color="red"] .fcl-card-rank,
.fcl-card[data-color="red"] .fcl-card-suit,
.fcl-card[data-color="red"] .fcl-card-pip { color: var(--fcl-card-red); }
.fcl-card[data-color="black"] .fcl-card-rank,
.fcl-card[data-color="black"] .fcl-card-suit,
.fcl-card[data-color="black"] .fcl-card-pip { color: var(--fcl-card-black); }

.fcl-card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
}
.fcl-card-corner-tl { top: 3%; left: 8%; }
.fcl-card-corner-br { bottom: 3%; right: 8%; transform: rotate(180deg); }
.fcl-card-rank { font-size: calc(var(--fcl-card-w) * 0.24); }
.fcl-card-suit { font-size: calc(var(--fcl-card-w) * 0.2); }
.fcl-card-pip { font-size: calc(var(--fcl-card-w) * 0.46); opacity: .9; }

.fcl-card.is-selected { transform: translateY(calc(var(--fcl-card-h) * -0.12)); z-index: 50; }
.fcl-card.is-selected .fcl-card-face { box-shadow: 0 0 0 3px var(--fcl-gold), 0 8px 18px rgba(0,0,0,.4); }

.fcl-card.is-hint .fcl-card-face { animation: fcl-hint-pulse 1s ease-in-out infinite; }
@keyframes fcl-hint-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--fcl-ice), 0 0 6px rgba(89,209,255,.5); }
  50% { box-shadow: 0 0 0 4px var(--fcl-ice), 0 0 18px rgba(89,209,255,.85); }
}

.fcl-board.fcl-shake { animation: fcl-shake .35s ease; }
@keyframes fcl-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.fcl-toast {
  align-self: center;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(0,0,0,.55);
  color: var(--fcl-ink);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--fcl-panel-line);
}
.fcl-toast[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Win celebration
   -------------------------------------------------------------------------- */
#screen-win.fcl-screen {
  background: radial-gradient(circle at 50% 40%, rgba(89,209,255,.2), rgba(8,21,36,.96) 65%);
}
.fcl-win-celebrate { text-align: center; max-width: 380px; }
.fcl-win-glyphs { font-size: 36px; letter-spacing: 10px; margin-bottom: 6px; animation: fcl-glyph-bounce 1s ease-in-out infinite; }
.fcl-win-glyphs .fcl-red { color: var(--fcl-red); }
@keyframes fcl-glyph-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.fcl-win-title {
  font-size: clamp(34px, 10vw, 56px); font-weight: 900; margin: 0;
  background: linear-gradient(135deg, var(--fcl-gold), #fff 50%, var(--fcl-ice));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: fcl-shimmer 1.4s linear infinite;
  background-size: 200% auto;
}
@keyframes fcl-shimmer { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }

.fcl-win-stats { display: flex; justify-content: center; gap: 20px; margin: 18px 0 6px; }
.fcl-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.fcl-stat-label { font-size: 11px; color: var(--fcl-ink-dim); text-transform: uppercase; letter-spacing: .05em; }
.fcl-stat-value { font-size: 20px; font-weight: 800; color: var(--fcl-gold-soft); font-variant-numeric: tabular-nums; }

.fcl-win-best {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--fcl-ice);
}
.fcl-win-best[hidden] { display: none; }

@media (min-width: 480px) {
  .fcl-record-strip { grid-template-columns: repeat(4, 1fr); }
}
