/* ── VARIABLES & RESET ─────────────────────────────────────── */
:root {
  --felt: #1b3d2a;
  --felt-light: #234d38;
  --felt-dark: #0f2218;
  --felt-stripe: rgba(255,255,255,0.018);
  --gold: #c9a84c;
  --gold-light: #e8c97a;
  --cream: #f5eedc;
  --card-bg: #faf7f0;
  --card-shadow: rgba(0,0,0,0.5);
  --red: #c0392b;
  --black: #1a1a1a;
  --valid-glow: #4ecb71;
  --radius: 7px;
  --cw: 54px;   /* ← was 62px */
  --ch: 76px;   /* ← was 88px */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── BODY ──────────────────────────────────────────────────── */
body {
  background-color: var(--felt);
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 3px, var(--felt-stripe) 3px, var(--felt-stripe) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 3px, var(--felt-stripe) 3px, var(--felt-stripe) 4px),
    radial-gradient(ellipse at 15% 15%, rgba(255,255,255,0.04) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 85%, rgba(0,0,0,0.25) 0%, transparent 55%);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;  /* ← key */
  font-family: 'DM Mono', monospace;
  color: var(--cream);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ── HEADER ────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(201,168,76,0.15);
  background: rgba(0,0,0,0.15);
  flex-shrink: 0;
}
header h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.3rem, 4vw, 1.8rem);  /* ← bigger */
  color: var(--gold);
  letter-spacing: 0.08em;
  text-shadow: 0 2px 12px rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  gap: 10px;
}
header h1::before {
  content: '♦';  /* ← simple logo mark for now */
  font-size: 0.75em;
  color: var(--gold-light);
  opacity: 0.7;
}
header .sub {
  font-size: 0.58rem;
  color: rgba(245,238,220,0.35);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* ── STATUS BAR ────────────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px;
  min-height: 26px;
}
#status-msg {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-size: 0.72rem;
  color: var(--gold-light);
  opacity: 0.85;
}
#score-info {
  font-size: 0.6rem;
  color: rgba(245,238,220,0.4);
  letter-spacing: 0.1em;
}

/* ── MAIN TABLE GRID ───────────────────────────────────────── */
#table {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  padding: 8px 10px 10px;
  gap: 0;
  overflow: hidden;
  flex: 1;  /* ← fills all available space between header and footer */
}

/* ── COLUMN A ──────────────────────────────────────────────── */
#col-a {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 12px;
  padding-top: 2px;
}
.stack-row {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  height: calc(var(--ch) + 16px);
  flex-shrink: 0;
}
.stack-num {
  font-size: 0.5rem;
  color: rgba(201,168,76,0.3);
  padding-top: 8px;
  width: 10px;
  text-align: center;
  flex-shrink: 0;
}
.stack-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.stack-visual {
  position: relative;
  width: var(--cw);
  height: var(--ch);
}
.stack-cnt {
  font-size: 0.5rem;
  color: rgba(245,238,220,0.25);
  letter-spacing: 0.04em;
  text-align: center;
}

/* ── BOARD ─────────────────────────────────────────────────── */
#board {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 2px;
  overflow-y: auto; /* ← lets board rows scroll internally if needed */
  overflow-x: hidden;
}
.board-row-wrap {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  height: calc(var(--ch) + 16px);
  flex-shrink: 0;
}
.row-pip {
  font-size: 1.05rem;
  width: 24px;
  flex-shrink: 0;
  padding-top: 5px;
  text-align: center;
  line-height: 1;
}
.fan {
  position: relative;
  flex-shrink: 0;
}
.fan-card {
  position: absolute !important;
  top: 0 !important;
  display: grid;
}
.row-count {
  font-size: 0.54rem;
  color: rgba(245,238,220,0.25);
  padding: 6px 0 0 6px;
  align-self: flex-start;
  white-space: nowrap;
  letter-spacing: 0.06em;
}

/* ── BOTTOM ROW ────────────────────────────────────────────── */
#bottom-row {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid rgba(201,168,76,0.1);
  margin-top: 4px;
  gap: 8px;
  flex-wrap: nowrap;
}
#hand-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.hand-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.hand-lbl {
  font-size: 0.52rem;
  color: rgba(201,168,76,0.4);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.hand-cnt {
  font-size: 0.5rem;
  color: rgba(245,238,220,0.28);
  letter-spacing: 0.04em;
  text-align: center;
  height: 13px;
}
#waste-fan {
  position: relative;
  height: var(--ch);
}

/* ── CONTROLS ──────────────────────────────────────────────── */
#controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;  /* ← was 5px, tiny tighten */
}
#anchor-badge {
  font-size: 0.55rem;  /* ← slightly smaller */
  padding: 2px 8px;    /* ← less padding */
}
#anchor-badge b {
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 400;
}
.btn-row {
  display: flex;
  gap: 7px;
}
.btn {
  background: transparent;
  border: 1px solid rgba(201,168,76,0.35);
  color: var(--gold);
  font-family: 'DM Mono', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.btn:hover  { background: rgba(201,168,76,0.1); border-color: var(--gold); }
.btn:active { background: rgba(201,168,76,0.2); transform: scale(0.97); }
.btn.primary { background: rgba(201,168,76,0.15); border-color: var(--gold); }

/* ── CARDS ─────────────────────────────────────────────────── */
.card {
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid rgba(200,190,170,0.6);
  box-shadow: 2px 3px 10px var(--card-shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 3px 4px;
  position: relative;
  overflow: hidden;
}
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
  pointer-events: none;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { transform: scale(0.95) !important; }
.card.valid-target {
  box-shadow: 0 0 0 2.5px var(--valid-glow), 2px 3px 14px var(--card-shadow);
}
.pip-top {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
}
.pip-bot {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  transform: rotate(180deg);
  align-self: end;
  line-height: 1;
}
.pip-r {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1;
}
.pip-s {
  font-size: 0.58rem;
  line-height: 1.15;
}
.card-mid {
  font-size: 1.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.red { color: var(--red); }
.blk { color: var(--black); }

/* ── CARD BACK ─────────────────────────────────────────────── */
.card-back {
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--radius);
  background: linear-gradient(160deg, #1a5c3a 0%, #0d3321 100%);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 2px 3px 10px var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}
.card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(201,168,76,0.25);
  border-radius: 4px;
}
.card-back::after {
  content: '◆';
  font-size: 1.25rem;
  color: rgba(201,168,76,0.18);
}
.card-back:active { transform: scale(0.95); }

/* ── EMPTY SLOT ────────────────────────────────────────────── */
.empty-slot {
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--radius);
  border: 1px dashed rgba(201,168,76,0.18);
  background: rgba(0,0,0,0.08);
  flex-shrink: 0;
}

/* ── MODALS ────────────────────────────────────────────────── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
#modal-overlay.show { display: flex; }
#modal {
  background: var(--felt-dark);
  border: 1px solid rgba(201,168,76,0.4);
  border-radius: 14px;
  padding: 32px 28px;
  max-width: 310px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,0.8);
}
#modal h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.7rem;
  color: var(--gold);
  margin-bottom: 10px;
}
#modal p {
  font-size: 0.73rem;
  color: rgba(245,238,220,0.7);
  line-height: 1.65;
  margin-bottom: 22px;
}

/* ── RULES PANEL ───────────────────────────────────────────── */
#rules-panel {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#rules-panel.show { display: flex; }
#rules-content {
  background: var(--felt-dark);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 14px;
  padding: 24px 20px;
  max-width: 380px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
}
#rules-content h3 {
  font-family: 'Playfair Display', serif;
  color: var(--gold);
  font-size: 1.15rem;
  margin-bottom: 12px;
}
#rules-content h4 {
  color: var(--gold-light);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 14px 0 5px;
}
#rules-content p {
  font-size: 0.72rem;
  color: rgba(245,238,220,0.72);
  line-height: 1.68;
  margin-bottom: 5px;
}
.rule-eg {
  background: rgba(201,168,76,0.07);
  border-left: 2px solid rgba(201,168,76,0.45);
  padding: 8px 12px;
  border-radius: 0 5px 5px 0;
  font-size: 0.68rem;
  color: rgba(245,238,220,0.55);
  margin: 7px 0;
  font-style: italic;
  line-height: 1.6;
}

/* ── WIN CONFETTI ──────────────────────────────────────────── */
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(-80px) rotate(35deg) scale(1.5); }
}
.confetti {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  animation: floatUp 1.4s ease-out forwards;
  font-size: 1.8rem;
}

/* ── AD BANNER ─────────────────────────────────────────────────── */
#ad-banner {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  min-height: 50px;  /* ← was 60px */
  background: rgba(0,0,0,0.25);
  border-top: 1px solid rgba(201,168,76,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;  /* ← add this, stops it from getting crushed */
}
.ad-banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 16px;
}
.ad-label {
  font-size: 0.55rem;
  color: rgba(245,238,220,0.25);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.ad-remove {
  font-size: 0.58rem;
  color: rgba(201,168,76,0.5);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ad-remove:hover { color: var(--gold); }

/* Hide remove-ads button in modal if user already purchased */
body.no-ads #remove-ads-btn { display: none; }

/* ── UNDO CIRCLE BUTTON ────────────────────────────────────── */
.undo-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(201,168,76,0.35);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s;
  flex-shrink: 0;
  align-self: center;
  margin-bottom: 13px; /* nudge up to align with card midpoint */
}
.undo-btn svg {
  width: 18px;
  height: 18px;
}
.undo-btn:hover  { background: rgba(201,168,76,0.1); border-color: var(--gold); }
.undo-btn:active { background: rgba(201,168,76,0.2); transform: scale(0.94) rotate(-20deg); }

/* ── FOOTER  ─────────────────────────────────────────────────── */
#game-footer {
  display: flex;
  justify-content: space-between;
  padding: 6px 16px;
  font-size: 0.5rem;
  color: rgba(245,238,220,0.2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-top: 1px solid rgba(201,168,76,0.06);
  margin-top: auto;  /* ← pushes footer down if content is short */
}

/* ── STATS  ─────────────────────────────────────────────────── */
#stats-panel {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#stats-panel.show { display: flex; }
#stats-content {
  background: var(--felt-dark);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 14px;
  padding: 28px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}
#stats-content h3 {
  font-family: 'Playfair Display', serif;
  color: var(--gold);
  font-size: 1.15rem;
  margin-bottom: 20px;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.stat-block {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(201,168,76,0.1);
  border-radius: 10px;
  padding: 16px 8px;
}
.stat-num {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--gold);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-lbl {
  font-size: 0.58rem;
  color: rgba(245,238,220,0.4);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}