/* ==========================================================================
   Hearts — game shell styles
   Scoped with .hrt-* 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-room palette: deep wine felt, warm gold accents. */
  --hrt-bg-0:        #1a0810;
  --hrt-bg-1:         #24101a;
  --hrt-bg-2:        #331526;
  --hrt-gold:        #e8b84b;
  --hrt-gold-soft:   #f3d488;
  --hrt-rose:        #ff6b81;
  --hrt-red:         #ff4d6d;
  --hrt-ink:         #f8ecec;
  --hrt-ink-dim:     #d9b6c2;
  --hrt-panel:       rgba(26, 8, 16, 0.92);
  --hrt-panel-line:  rgba(232, 184, 75, 0.22);
  --hrt-chip:        rgba(10, 4, 8, 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. */
  --hrt-card-bg:     #fbf8ef;
  --hrt-card-black:  #1c2420;
  --hrt-card-red:    #b91c3a;

  /* Card geometry — one source of truth, everything else derives from
     these via calc(), never a %-of-self trick. */
  --hrt-card-w:      clamp(38px, 10.5vw, 62px);
  --hrt-card-h:      calc(var(--hrt-card-w) * 1.4);
  --hrt-card-w-sm:   clamp(15px, 4vw, 24px);
  --hrt-card-h-sm:   calc(var(--hrt-card-w-sm) * 1.4);
  --hrt-overlap:     calc(var(--hrt-card-w) * 0.58);
  --hrt-overlap-sm:  calc(var(--hrt-card-w-sm) * 0.62);

  --hrt-radius:      16px;
  --hrt-font:        'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --hrt-safe-t:      env(safe-area-inset-top, 0px);
  --hrt-safe-b:      env(safe-area-inset-bottom, 0px);
  --hrt-safe-l:      env(safe-area-inset-left, 0px);
  --hrt-safe-r:      env(safe-area-inset-right, 0px);
}

html, body.hrt-body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--hrt-bg-0);
  color: var(--hrt-ink);
  font-family: var(--hrt-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* --------------------------------------------------------------------------
   Shared site header — visible on the menu/help, hidden during play.
   -------------------------------------------------------------------------- */
.hrt-site-header {
  position: relative;
  z-index: 40;
  font-size: 13px;
}
.hrt-site-header header {
  padding: 10px calc(16px + var(--hrt-safe-r)) 10px calc(16px + var(--hrt-safe-l));
  padding-top: calc(10px + var(--hrt-safe-t));
  background: rgba(10, 3, 6, .78);
  border-bottom: 1px solid var(--hrt-panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hrt-site-header a { color: var(--hrt-ink-dim); text-decoration: none; padding: 5px 9px; border-radius: 8px; }
.hrt-site-header a:hover { color: var(--hrt-ink); background: rgba(255,255,255,.07); }
.hrt-site-header a.active { color: var(--hrt-gold); background: rgba(232,184,75,.14); }

body:has(.hrt-root.is-playing) .hrt-site-header,
body:has(.hrt-root.is-playing) #footer { display: none; }

.hrt-root {
  position: relative;
  min-height: 100vh;
  background:
    radial-gradient(60vw 60vw at 15% -10%, rgba(255, 107, 129, .1), transparent 60%),
    radial-gradient(70vw 70vw at 110% 10%, rgba(232, 184, 75, .1), transparent 60%),
    linear-gradient(180deg, var(--hrt-bg-1), var(--hrt-bg-0) 60%);
}
.hrt-root.is-playing { height: 100vh; overflow: hidden; }

/* --------------------------------------------------------------------------
   Generic dialog-style screens (loading / menu / help / hand-over / game-over)
   -------------------------------------------------------------------------- */
.hrt-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--hrt-safe-t)) calc(16px + var(--hrt-safe-r)) calc(20px + var(--hrt-safe-b)) calc(16px + var(--hrt-safe-l));
  opacity: 0;
  transform: scale(.98);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 20;
  overflow-y: auto;
}
.hrt-screen.is-open { opacity: 1; transform: none; pointer-events: auto; z-index: 30; }
#screen-handover.hrt-screen.is-open { z-index: 35; }

.hrt-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--hrt-panel);
  border: 1px solid var(--hrt-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;
}
.hrt-panel-narrow { max-width: 340px; }
.hrt-panel-wide { max-width: 760px; text-align: left; }

.hrt-logo {
  margin: 6px 0 4px;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: .3px;
  background: linear-gradient(135deg, var(--hrt-gold), var(--hrt-rose) 60%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hrt-menu-glyphs { font-size: 26px; letter-spacing: 10px; margin-bottom: 4px; filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)); }
.hrt-menu-glyphs .hrt-red { color: var(--hrt-red); }
.hrt-tagline { color: var(--hrt-ink-dim); margin: 0 0 18px; font-size: 14px; }
.hrt-muted { color: var(--hrt-ink-dim); }

.hrt-progress { width: 100%; height: 8px; border-radius: 8px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 18px; }
.hrt-progress-bar { height: 100%; width: 40%; background: linear-gradient(90deg, var(--hrt-rose), var(--hrt-gold)); border-radius: 8px; animation: hrt-load 1.1s ease-in-out infinite; }
@keyframes hrt-load { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

.hrt-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.hrt-actions-secondary { margin-top: 4px; }
.hrt-btn {
  appearance: none; border: none; cursor: pointer;
  padding: 14px 20px; border-radius: 14px; font-size: 16px; font-weight: 700;
  font-family: inherit; color: var(--hrt-ink);
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.hrt-btn[hidden] { display: none; }
.hrt-btn:active { transform: scale(.97); }
.hrt-btn-primary { background: linear-gradient(135deg, var(--hrt-gold), #d18a1f); box-shadow: 0 10px 24px rgba(232,184,75,.28); color: #2a1400; }
.hrt-btn-primary:hover { filter: brightness(1.08); }
.hrt-btn-primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; filter: none; }
.hrt-btn-cash { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: var(--hrt-ink-dim); }
.hrt-btn-cash.is-disabled, .hrt-btn-cash:disabled { opacity: .55; cursor: not-allowed; }
.hrt-btn-ghost { background: rgba(255,255,255,.05); border: 1px solid var(--hrt-panel-line); color: var(--hrt-ink); }
.hrt-btn-ghost:hover { background: rgba(255,255,255,.09); }
.hrt-btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.hrt-btn-small { padding: 9px 16px; font-size: 13px; border-radius: 10px; flex: 0 0 auto; }

.hrt-record-strip {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 14px 0 6px;
}
.hrt-record-item {
  padding: 10px 8px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(255,107,129,.1), rgba(232,184,75,.06));
  border: 1px solid rgba(255,107,129,.2);
  display: flex; flex-direction: column; gap: 2px;
}
.hrt-record-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--hrt-gold-soft); }
.hrt-record-value { font-size: 16px; font-weight: 800; color: var(--hrt-ink); font-variant-numeric: tabular-nums; }

.hrt-fineprint { margin-top: 14px; font-size: 11px; color: var(--hrt-ink-dim); opacity: .8; line-height: 1.5; }
.hrt-version::before { content: 'v' attr(data-v); }

.hrt-close {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid var(--hrt-panel-line); background: rgba(255,255,255,.06);
  color: var(--hrt-ink); font-size: 20px; line-height: 1; cursor: pointer;
}

.hrt-h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; color: var(--hrt-ink); }
.hrt-h3 { margin: 18px 0 8px; font-size: 15px; color: var(--hrt-gold-soft); text-transform: uppercase; letter-spacing: .06em; }
.hrt-h3:first-child { margin-top: 0; }
.hrt-body { font-size: 14px; line-height: 1.6; color: var(--hrt-ink-dim); margin: 0 0 10px; }
.hrt-list { margin: 0; padding-left: 18px; color: var(--hrt-ink-dim); font-size: 14px; line-height: 1.7; }
.hrt-list b, .hrt-body b { color: var(--hrt-ink); }

.hrt-help-cols { display: grid; grid-template-columns: 1fr; gap: 22px; }
@media (min-width: 720px) {
  .hrt-help-cols { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   Play screen
   -------------------------------------------------------------------------- */
#screen-play.hrt-screen {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  display: none;
  background: transparent;
}
#screen-play.hrt-screen.is-open { display: flex; opacity: 1; transform: none; }

.hrt-play {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(10px + var(--hrt-safe-t)) calc(10px + var(--hrt-safe-r)) calc(14px + var(--hrt-safe-b)) calc(10px + var(--hrt-safe-l));
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.hrt-topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hrt-chip {
  display: flex; align-items: baseline; gap: 6px; padding: 7px 11px;
  border-radius: 12px; background: var(--hrt-chip); border: 1px solid var(--hrt-panel-line);
}
.hrt-chip-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--hrt-ink-dim); }
.hrt-chip-value { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

.hrt-topbar-right { display: flex; gap: 6px; margin-left: auto; }
.hrt-icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--hrt-panel-line);
  background: var(--hrt-chip); color: var(--hrt-ink); font-size: 15px; cursor: pointer;
}
.hrt-icon-btn:active { transform: scale(.94); }

.hrt-status {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--hrt-gold-soft);
  min-height: 18px;
  padding: 2px 4px;
}

/* Opponents row — 3 boxes, each a compact fanned card-back count, name and
   running score. */
.hrt-opponents {
  display: flex;
  justify-content: center;
  gap: clamp(6px, 3vw, 18px);
  flex-wrap: wrap;
  padding: 2px 0;
}
.hrt-opponent {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hrt-chip);
  border: 1px solid var(--hrt-panel-line);
  min-width: 78px;
  flex: 1 1 0;
  max-width: 140px;
}
.hrt-opponent.is-active {
  border-color: var(--hrt-gold);
  box-shadow: 0 0 0 1px rgba(232,184,75,.4), 0 0 14px rgba(232,184,75,.25);
}
.hrt-opponent-name { font-size: 12px; font-weight: 700; color: var(--hrt-ink); }
.hrt-opponent-hand {
  display: flex;
  min-height: var(--hrt-card-h-sm);
  padding-left: var(--hrt-overlap-sm);
}
.hrt-card-back-sm {
  width: var(--hrt-card-w-sm);
  height: var(--hrt-card-h-sm);
  margin-left: calc(-1 * var(--hrt-overlap-sm));
  border-radius: 4px;
  background: repeating-linear-gradient(135deg, #6a1330, #6a1330 4px, #3a0a1a 4px, #3a0a1a 8px);
  border: 1px solid rgba(232,184,75,.35);
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.hrt-opponent-meta { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--hrt-ink-dim); font-variant-numeric: tabular-nums; }
.hrt-opponent-score { font-weight: 800; color: var(--hrt-gold-soft); }

/* Trick area — 4 fixed seat slots (You, then each bot) showing whatever
   that seat has played this trick. */
.hrt-trick {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 3.5vw, 22px);
  padding: 6px 0;
  min-height: calc(var(--hrt-card-h) + 34px);
}
.hrt-trick-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: var(--hrt-card-w);
}
.hrt-trick-slot-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--hrt-ink-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.hrt-trick-slot.is-winner .hrt-trick-slot-label { color: var(--hrt-gold); }
.hrt-trick-slot-card {
  width: var(--hrt-card-w);
  height: var(--hrt-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;
}
.hrt-trick-slot-card:empty { }
.hrt-trick-slot.is-winner .hrt-trick-slot-card { box-shadow: 0 0 0 2px var(--hrt-gold), 0 6px 16px rgba(0,0,0,.4); }

/* Passing action bar. */
.hrt-pass-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--hrt-chip);
  border: 1px solid var(--hrt-panel-line);
  font-size: 12px;
  color: var(--hrt-ink-dim);
}
.hrt-pass-bar[hidden] { display: none; }

.hrt-hand-wrap {
  flex: 0 0 auto;
  overflow-x: auto;
  overflow-y: visible;
  padding: 14px 4px 6px;
}
.hrt-hand {
  display: flex;
  justify-content: center;
  width: max-content;
  min-width: 100%;
  padding-left: var(--hrt-overlap);
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.hrt-card {
  position: relative;
  width: var(--hrt-card-w);
  height: var(--hrt-card-h);
  margin-left: calc(-1 * var(--hrt-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;
}
.hrt-card:first-child { margin-left: 0; }
.hrt-card-face {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 7px;
  background: var(--hrt-card-bg);
  border: 1px solid rgba(0,0,0,.15);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.hrt-card[data-color="red"] .hrt-card-rank,
.hrt-card[data-color="red"] .hrt-card-suit,
.hrt-card[data-color="red"] .hrt-card-pip { color: var(--hrt-card-red); }
.hrt-card[data-color="black"] .hrt-card-rank,
.hrt-card[data-color="black"] .hrt-card-suit,
.hrt-card[data-color="black"] .hrt-card-pip { color: var(--hrt-card-black); }

.hrt-card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
}
.hrt-card-corner-tl { top: 3%; left: 8%; }
.hrt-card-corner-br { bottom: 3%; right: 8%; transform: rotate(180deg); }
.hrt-card-rank { font-size: calc(var(--hrt-card-w) * 0.24); }
.hrt-card-suit { font-size: calc(var(--hrt-card-w) * 0.2); }
.hrt-card-pip { font-size: calc(var(--hrt-card-w) * 0.46); opacity: .9; }

.hrt-card.is-legal { cursor: pointer; }
.hrt-card.is-legal:hover { transform: translateY(calc(var(--hrt-card-h) * -0.12)); }
.hrt-card.is-legal .hrt-card-face { box-shadow: 0 0 0 2px var(--hrt-gold), 0 6px 14px rgba(0,0,0,.35); }
.hrt-card.is-dim { opacity: .5; }

.hrt-card.is-selectable { cursor: pointer; }
.hrt-card.is-selectable:hover { transform: translateY(calc(var(--hrt-card-h) * -0.1)); }
.hrt-card.is-selected { transform: translateY(calc(var(--hrt-card-h) * -0.22)); }
.hrt-card.is-selected .hrt-card-face { box-shadow: 0 0 0 2px var(--hrt-rose), 0 6px 14px rgba(0,0,0,.4); }

/* --------------------------------------------------------------------------
   Hand-over overlay table
   -------------------------------------------------------------------------- */
.hrt-ho-table, .hrt-go-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}
.hrt-ho-row, .hrt-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(--hrt-panel-line);
  font-size: 13px;
}
.hrt-ho-row.is-you, .hrt-go-row.is-you { border-color: rgba(232,184,75,.4); background: rgba(232,184,75,.07); }
.hrt-ho-row.is-moon, .hrt-go-row.is-winner { border-color: var(--hrt-gold); box-shadow: 0 0 0 1px rgba(232,184,75,.35) inset; }
.hrt-ho-name, .hrt-go-name { flex: 1 1 auto; font-weight: 700; color: var(--hrt-ink); }
.hrt-ho-detail { color: var(--hrt-ink-dim); font-variant-numeric: tabular-nums; }
.hrt-ho-added { font-weight: 800; color: var(--hrt-rose); font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }
.hrt-go-score { font-weight: 800; color: var(--hrt-gold-soft); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Game-over celebration
   -------------------------------------------------------------------------- */
#screen-gameover.hrt-screen {
  background: radial-gradient(circle at 50% 40%, rgba(232,184,75,.18), rgba(26,8,16,.96) 65%);
}
.hrt-win-celebrate { text-align: center; max-width: 420px; width: 100%; }
.hrt-win-glyphs { font-size: 36px; letter-spacing: 10px; margin-bottom: 6px; animation: hrt-glyph-bounce 1s ease-in-out infinite; }
.hrt-win-glyphs .hrt-red { color: var(--hrt-red); }
@keyframes hrt-glyph-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.hrt-win-title {
  font-size: clamp(24px, 6.6vw, 40px); font-weight: 900; margin: 0;
  background: linear-gradient(135deg, var(--hrt-gold), #fff 50%, var(--hrt-rose));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: hrt-shimmer 1.4s linear infinite;
  background-size: 200% auto;
}
@keyframes hrt-shimmer { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }

.hrt-win-best {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--hrt-rose);
}
.hrt-win-best[hidden] { display: none; }

@media (min-width: 480px) {
  .hrt-record-strip { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
  .hrt-record-strip { grid-template-columns: repeat(5, 1fr); }
}
