/* ==========================================================================
   Spades — game shell styles
   Scoped with .spd-* 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/glyph characters.
   ========================================================================== */

:root {
  /* Card-room palette: deep navy felt, cool gold accents. */
  --spd-bg-0:        #0c1220;
  --spd-bg-1:        #141d33;
  --spd-bg-2:        #1c2a49;
  --spd-gold:        #e2b23c;
  --spd-gold-soft:   #f0cf7c;
  --spd-blue:        #5aa9e6;
  --spd-ink:         #eef2fb;
  --spd-ink-dim:     #a9b6d6;
  --spd-panel:       rgba(12, 18, 32, 0.92);
  --spd-panel-line:  rgba(226, 178, 60, 0.22);
  --spd-chip:        rgba(6, 9, 18, 0.6);

  /* Playing-card faces are always cream/white, independent of the felt
     theme above — the one deliberately "unthemed" part, same as a real
     deck. */
  --spd-card-bg:     #fbf8ef;
  --spd-card-black:  #1c2420;
  --spd-card-red:    #b91c3a;

  /* Card geometry — one source of truth, everything else derives from
     these via calc(), never a %-of-self trick. */
  --spd-card-w:      clamp(38px, 10.5vw, 62px);
  --spd-card-h:      calc(var(--spd-card-w) * 1.4);
  --spd-card-w-sm:   clamp(15px, 4vw, 24px);
  --spd-card-h-sm:   calc(var(--spd-card-w-sm) * 1.4);
  --spd-overlap:     calc(var(--spd-card-w) * 0.58);
  --spd-overlap-sm:  calc(var(--spd-card-w-sm) * 0.62);

  --spd-radius:      16px;
  --spd-font:        'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --spd-safe-t:      env(safe-area-inset-top, 0px);
  --spd-safe-b:      env(safe-area-inset-bottom, 0px);
  --spd-safe-l:      env(safe-area-inset-left, 0px);
  --spd-safe-r:      env(safe-area-inset-right, 0px);
}

html, body.spd-body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--spd-bg-0);
  color: var(--spd-ink);
  font-family: var(--spd-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* --------------------------------------------------------------------------
   Shared site header — visible on the menu/help, hidden during play.
   -------------------------------------------------------------------------- */
.spd-site-header {
  position: relative;
  z-index: 40;
  font-size: 13px;
}
.spd-site-header header {
  padding: 10px calc(16px + var(--spd-safe-r)) 10px calc(16px + var(--spd-safe-l));
  padding-top: calc(10px + var(--spd-safe-t));
  background: rgba(6, 9, 18, .78);
  border-bottom: 1px solid var(--spd-panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.spd-site-header a { color: var(--spd-ink-dim); text-decoration: none; padding: 5px 9px; border-radius: 8px; }
.spd-site-header a:hover { color: var(--spd-ink); background: rgba(255,255,255,.07); }
.spd-site-header a.active { color: var(--spd-gold); background: rgba(226,178,60,.14); }

body:has(.spd-root.is-playing) .spd-site-header,
body:has(.spd-root.is-playing) #footer { display: none; }

.spd-root {
  position: relative;
  min-height: 100vh;
  background:
    radial-gradient(60vw 60vw at 15% -10%, rgba(90, 169, 230, .12), transparent 60%),
    radial-gradient(70vw 70vw at 110% 10%, rgba(226, 178, 60, .1), transparent 60%),
    linear-gradient(180deg, var(--spd-bg-1), var(--spd-bg-0) 60%);
}
.spd-root.is-playing { height: 100vh; overflow: hidden; }

/* --------------------------------------------------------------------------
   Generic dialog-style screens (loading / menu / help / hand-over / game-over)
   -------------------------------------------------------------------------- */
.spd-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--spd-safe-t)) calc(16px + var(--spd-safe-r)) calc(20px + var(--spd-safe-b)) calc(16px + var(--spd-safe-l));
  opacity: 0;
  transform: scale(.98);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 20;
  overflow-y: auto;
}
.spd-screen.is-open { opacity: 1; transform: none; pointer-events: auto; z-index: 30; }
#screen-handover.spd-screen.is-open { z-index: 35; }

.spd-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--spd-panel);
  border: 1px solid var(--spd-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;
}
.spd-panel-narrow { max-width: 340px; }
.spd-panel-wide { max-width: 760px; text-align: left; }

.spd-logo {
  margin: 6px 0 4px;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: .3px;
  background: linear-gradient(135deg, var(--spd-gold), var(--spd-blue) 65%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.spd-menu-glyphs { font-size: 26px; letter-spacing: 10px; margin-bottom: 4px; color: var(--spd-ink); filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)); }
.spd-tagline { color: var(--spd-ink-dim); margin: 0 0 18px; font-size: 14px; }
.spd-muted { color: var(--spd-ink-dim); }

.spd-progress { width: 100%; height: 8px; border-radius: 8px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 18px; }
.spd-progress-bar { height: 100%; width: 40%; background: linear-gradient(90deg, var(--spd-blue), var(--spd-gold)); border-radius: 8px; animation: spd-load 1.1s ease-in-out infinite; }
@keyframes spd-load { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

.spd-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.spd-actions-secondary { margin-top: 4px; }
.spd-btn {
  appearance: none; border: none; cursor: pointer;
  padding: 14px 20px; border-radius: 14px; font-size: 16px; font-weight: 700;
  font-family: inherit; color: var(--spd-ink);
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.spd-btn[hidden] { display: none; }
.spd-btn:active { transform: scale(.97); }
.spd-btn-primary { background: linear-gradient(135deg, var(--spd-gold), #b9821c); box-shadow: 0 10px 24px rgba(226,178,60,.28); color: #2a1c00; }
.spd-btn-primary:hover { filter: brightness(1.08); }
.spd-btn-primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; filter: none; }
.spd-btn-cash { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: var(--spd-ink-dim); }
.spd-btn-cash.is-disabled, .spd-btn-cash:disabled { opacity: .55; cursor: not-allowed; }
.spd-btn-ghost { background: rgba(255,255,255,.05); border: 1px solid var(--spd-panel-line); color: var(--spd-ink); }
.spd-btn-ghost:hover { background: rgba(255,255,255,.09); }
.spd-btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.spd-btn-small { padding: 9px 16px; font-size: 13px; border-radius: 10px; flex: 0 0 auto; }

.spd-bid-nil-btn.is-active { background: rgba(226,178,60,.22); border-color: var(--spd-gold); color: var(--spd-gold-soft); }

.spd-record-strip {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 14px 0 6px;
}
.spd-record-item {
  padding: 10px 8px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(90,169,230,.1), rgba(226,178,60,.06));
  border: 1px solid rgba(90,169,230,.2);
  display: flex; flex-direction: column; gap: 2px;
}
.spd-record-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--spd-gold-soft); }
.spd-record-value { font-size: 16px; font-weight: 800; color: var(--spd-ink); font-variant-numeric: tabular-nums; }

.spd-fineprint { margin-top: 14px; font-size: 11px; color: var(--spd-ink-dim); opacity: .8; line-height: 1.5; }
.spd-version::before { content: 'v' attr(data-v); }

.spd-close {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid var(--spd-panel-line); background: rgba(255,255,255,.06);
  color: var(--spd-ink); font-size: 20px; line-height: 1; cursor: pointer;
}

.spd-h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; color: var(--spd-ink); }
.spd-h3 { margin: 18px 0 8px; font-size: 15px; color: var(--spd-gold-soft); text-transform: uppercase; letter-spacing: .06em; }
.spd-h3:first-child { margin-top: 0; }
.spd-body { font-size: 14px; line-height: 1.6; color: var(--spd-ink-dim); margin: 0 0 10px; }
.spd-list { margin: 0; padding-left: 18px; color: var(--spd-ink-dim); font-size: 14px; line-height: 1.7; }
.spd-list b, .spd-body b { color: var(--spd-ink); }

.spd-help-cols { display: grid; grid-template-columns: 1fr; gap: 22px; }
@media (min-width: 720px) {
  .spd-help-cols { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   Play screen
   -------------------------------------------------------------------------- */
#screen-play.spd-screen {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  display: none;
  background: transparent;
}
#screen-play.spd-screen.is-open { display: flex; opacity: 1; transform: none; }

.spd-play {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(10px + var(--spd-safe-t)) calc(10px + var(--spd-safe-r)) calc(14px + var(--spd-safe-b)) calc(10px + var(--spd-safe-l));
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.spd-topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spd-chip {
  display: flex; align-items: baseline; gap: 6px; padding: 7px 11px;
  border-radius: 12px; background: var(--spd-chip); border: 1px solid var(--spd-panel-line);
}
.spd-chip-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--spd-ink-dim); }
.spd-chip-value { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

.spd-topbar-right { display: flex; gap: 6px; margin-left: auto; }
.spd-icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--spd-panel-line);
  background: var(--spd-chip); color: var(--spd-ink); font-size: 15px; cursor: pointer;
}
.spd-icon-btn:active { transform: scale(.94); }

.spd-status {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--spd-gold-soft);
  min-height: 18px;
  padding: 2px 4px;
}

/* Seats row — all 4 table positions (You first, then the other 3), each
   showing name, a compact fanned card-back count (skipped for your own
   seat since your hand is shown in full below), bid and tricks taken. */
.spd-seats {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 2.5vw, 12px);
  flex-wrap: wrap;
  padding: 2px 0;
}
.spd-seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--spd-chip);
  border: 1px solid var(--spd-panel-line);
  min-width: 74px;
  flex: 1 1 0;
  max-width: 150px;
}
.spd-seat.is-active {
  border-color: var(--spd-gold);
  box-shadow: 0 0 0 1px rgba(226,178,60,.4), 0 0 14px rgba(226,178,60,.25);
}
.spd-seat.is-you { border-color: rgba(90,169,230,.5); background: rgba(90,169,230,.08); }
.spd-seat.is-partner .spd-seat-name::after { content: ' (P)'; color: var(--spd-blue); font-weight: 700; }
.spd-seat-name { font-size: 12px; font-weight: 700; color: var(--spd-ink); white-space: nowrap; }
.spd-seat-hand {
  display: flex;
  min-height: var(--spd-card-h-sm);
  padding-left: var(--spd-overlap-sm);
}
.spd-seat-hand:empty { min-height: 0; }
.spd-card-back-sm {
  width: var(--spd-card-w-sm);
  height: var(--spd-card-h-sm);
  margin-left: calc(-1 * var(--spd-overlap-sm));
  border-radius: 4px;
  background: repeating-linear-gradient(135deg, #16305a, #16305a 4px, #0a1830 4px, #0a1830 8px);
  border: 1px solid rgba(226,178,60,.35);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.spd-seat-meta { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--spd-ink-dim); font-variant-numeric: tabular-nums; }
.spd-seat-bid { font-weight: 800; color: var(--spd-gold-soft); }
.spd-seat-bid.is-nil { color: var(--spd-blue); }
.spd-seat-tricks { font-weight: 700; color: var(--spd-ink); }

/* Trick area — 4 fixed seat slots (You, then each other seat in turn
   order) showing whatever that seat has played this trick. */
.spd-trick {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 3.5vw, 22px);
  padding: 6px 0;
  min-height: calc(var(--spd-card-h) + 34px);
}
.spd-trick-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: var(--spd-card-w);
}
.spd-trick-slot-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--spd-ink-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.spd-trick-slot.is-winner .spd-trick-slot-label { color: var(--spd-gold); }
.spd-trick-slot-card {
  width: var(--spd-card-w);
  height: var(--spd-card-h);
  border-radius: 8px;
  border: 1.5px dashed rgba(255,255,255,.14);
  background: rgba(255,255,255,.03);
  display: flex;
  align-items: center;
  justify-content: center;
}
.spd-trick-slot.is-winner .spd-trick-slot-card { box-shadow: 0 0 0 2px var(--spd-gold), 0 6px 16px rgba(0,0,0,.4); }

/* Bidding action bar. */
.spd-bid-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--spd-chip);
  border: 1px solid var(--spd-panel-line);
}
.spd-bid-bar[hidden] { display: none; }
.spd-bid-hint { font-size: 12px; color: var(--spd-ink-dim); text-align: center; }
.spd-bid-controls { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }

.spd-hand-wrap {
  flex: 0 0 auto;
  overflow-x: auto;
  overflow-y: visible;
  padding: 14px 4px 6px;
}
.spd-hand {
  display: flex;
  justify-content: center;
  width: max-content;
  min-width: 100%;
  padding-left: var(--spd-overlap);
}

/* --------------------------------------------------------------------------
   Stepper (bid amount)
   -------------------------------------------------------------------------- */
.spd-stepper { display: flex; align-items: center; gap: 10px; }
.spd-stepper-btn {
  width: 30px; height: 30px; border-radius: 8px; border: none; cursor: pointer;
  background: rgba(255,255,255,.1); color: var(--spd-ink); font-size: 18px; line-height: 1;
}
.spd-stepper-btn:active { transform: scale(.92); }
.spd-stepper-btn:disabled { opacity: .35; cursor: not-allowed; }
.spd-stepper-value { min-width: 32px; text-align: center; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.spd-card {
  position: relative;
  width: var(--spd-card-w);
  height: var(--spd-card-h);
  margin-left: calc(-1 * var(--spd-overlap));
  border-radius: 7px;
  cursor: default;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
  flex: 0 0 auto;
}
.spd-card:first-child { margin-left: 0; }
.spd-card-face {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 7px;
  background: var(--spd-card-bg);
  border: 1px solid rgba(0,0,0,.15);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.spd-card[data-color="red"] .spd-card-rank,
.spd-card[data-color="red"] .spd-card-suit,
.spd-card[data-color="red"] .spd-card-pip { color: var(--spd-card-red); }
.spd-card[data-color="black"] .spd-card-rank,
.spd-card[data-color="black"] .spd-card-suit,
.spd-card[data-color="black"] .spd-card-pip { color: var(--spd-card-black); }

.spd-card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
}
.spd-card-corner-tl { top: 3%; left: 8%; }
.spd-card-corner-br { bottom: 3%; right: 8%; transform: rotate(180deg); }
.spd-card-rank { font-size: calc(var(--spd-card-w) * 0.24); }
.spd-card-suit { font-size: calc(var(--spd-card-w) * 0.2); }
.spd-card-pip { font-size: calc(var(--spd-card-w) * 0.46); opacity: .9; }

.spd-card.is-legal { cursor: pointer; }
.spd-card.is-legal:hover { transform: translateY(calc(var(--spd-card-h) * -0.12)); }
.spd-card.is-legal .spd-card-face { box-shadow: 0 0 0 2px var(--spd-gold), 0 6px 14px rgba(0,0,0,.35); }
.spd-card.is-dim { opacity: .5; }

/* --------------------------------------------------------------------------
   Hand-over / game-over tables
   -------------------------------------------------------------------------- */
.spd-ho-table, .spd-go-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}
.spd-ho-row, .spd-go-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--spd-panel-line);
  font-size: 13px;
}
.spd-ho-row.is-you-team, .spd-go-row.is-you-team { border-color: rgba(226,178,60,.4); background: rgba(226,178,60,.07); }
.spd-go-row.is-winner { border-color: var(--spd-gold); box-shadow: 0 0 0 1px rgba(226,178,60,.35) inset; }
.spd-ho-name, .spd-go-name { flex: 1 1 auto; font-weight: 700; color: var(--spd-ink); }
.spd-ho-detail { color: var(--spd-ink-dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.spd-ho-added { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.spd-ho-added.is-negative { color: #ff6b6b; }
.spd-ho-added.is-positive { color: var(--spd-gold-soft); }
.spd-go-score { font-weight: 800; color: var(--spd-gold-soft); font-variant-numeric: tabular-nums; }
.spd-ho-nils { margin: 4px 0 0; font-size: 12px; color: var(--spd-ink-dim); }

/* --------------------------------------------------------------------------
   Game-over celebration
   -------------------------------------------------------------------------- */
#screen-gameover.spd-screen {
  background: radial-gradient(circle at 50% 40%, rgba(226,178,60,.18), rgba(12,18,32,.96) 65%);
}
.spd-win-celebrate { text-align: center; max-width: 420px; width: 100%; }
.spd-win-glyphs { font-size: 36px; letter-spacing: 10px; margin-bottom: 6px; color: var(--spd-ink); animation: spd-glyph-bounce 1s ease-in-out infinite; }
@keyframes spd-glyph-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.spd-win-title {
  font-size: clamp(24px, 6.6vw, 40px); font-weight: 900; margin: 0;
  background: linear-gradient(135deg, var(--spd-gold), #fff 50%, var(--spd-blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: spd-shimmer 1.4s linear infinite;
  background-size: 200% auto;
}
@keyframes spd-shimmer { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }

.spd-win-best {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--spd-gold-soft);
}
.spd-win-best[hidden] { display: none; }

@media (min-width: 480px) {
  .spd-record-strip { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
  .spd-record-strip { grid-template-columns: repeat(5, 1fr); }
}
