:root {
  --gap: clamp(3px, 1.1vw, 9px);
  --pad: clamp(4px, 1.5vw, 12px);
  --card-w: min(calc((100vw - 2 * var(--pad) - 6 * var(--gap)) / 7), 96px);
  --card-h: calc(var(--card-w) * 1.4);
  --radius: clamp(4px, 1.4vw, 9px);
  --fan-down: calc(var(--card-h) * 0.16);
  --fan-up: calc(var(--card-h) * 0.30);
  --felt-1: #0c7a44;
  --felt-2: #075a31;
  --ink: #1a1a1a;
  --red: #d31f2b;
  --gold: #ffd24d;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(circle at 50% 0%, var(--felt-1), var(--felt-2) 70%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  background: rgba(0, 0, 0, 0.18);
}
.topbar-left, .topbar-right { display: flex; gap: 8px; }
.btn {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.95); background: rgba(255, 255, 255, 0.26); }
.btn:disabled { opacity: 0.4; }
#btn-menu { font-size: 18px; padding: 8px 12px; }

.stats { display: flex; gap: 18px; font-variant-numeric: tabular-nums; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.65; }
.stat span:last-child { font-size: 16px; font-weight: 700; }

/* ---------- Board ---------- */
.board {
  padding: var(--pad);
  height: calc(100% - 52px);
  /* Let the game handle all touch gestures itself so drags aren't
     intercepted by the browser as scroll/pan (which cancels the drag). */
  touch-action: none;
}
.board .card { touch-action: none; -webkit-user-drag: none; }
.row { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--gap); }
.top-row { margin-bottom: calc(var(--gap) * 1.5); }
.spacer { visibility: hidden; }

.pile {
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--radius);
  position: relative;
}
.foundation, .stock, .waste {
  border: 1.5px dashed rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.12);
}
.foundation::after {
  content: attr(data-suit);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.5);
  color: rgba(255, 255, 255, 0.16);
}
.stock.empty-recycle::after {
  content: "\21BB";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.55);
  color: rgba(255, 255, 255, 0.4);
}

.tableau-row { align-items: start; }
.column {
  position: relative;
  width: 100%;
  min-height: var(--card-h);
}
.column .placeholder {
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--radius);
  border: 1.5px dashed rgba(255, 255, 255, 0.18);
}

/* ---------- Cards ---------- */
.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  background: #fdfdfb;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  will-change: transform;
}
.top-row .card, .waste .card, .stock .card { position: absolute; }

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  font-weight: 800;
  font-size: calc(var(--card-w) * 0.30);
  padding: 3px;
}
.card .corner.tl { top: 1px; left: 2px; }
.card .corner.br { bottom: 1px; right: 2px; transform: rotate(180deg); }
.card .corner .pip { font-size: calc(var(--card-w) * 0.26); }
.card .center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.62);
}
.card.red { color: var(--red); }
.card.black { color: var(--ink); }

.card.face-down {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 6px, transparent 6px 12px),
    linear-gradient(135deg, #1d4ed8, #0b2f8a);
  border: 2px solid #fff;
}
.card.face-down .corner, .card.face-down .center { display: none; }

.card.dragging { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45); }
.card.hint { animation: pulse 0.6s ease 2; }
@keyframes pulse {
  50% { box-shadow: 0 0 0 3px var(--gold), 0 8px 18px rgba(0,0,0,0.4); }
}

.drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}
.drag-layer .card { box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5); }

/* ---------- Overlays ---------- */
.overlay, .win {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 20px;
}
.hidden { display: none !important; }

.sheet, .win-card {
  width: min(360px, 90vw);
  background: #14532d;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.sheet h2, .win-card h2 { margin: 0 0 6px; text-align: center; }
.sheet-btn {
  appearance: none;
  border: 0;
  background: var(--gold);
  color: #3a2c00;
  font-size: 16px;
  font-weight: 800;
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.sheet-btn:active { transform: scale(0.98); }
.sheet-btn.ghost { background: rgba(255, 255, 255, 0.12); color: #fff; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg { display: flex; background: rgba(0,0,0,0.25); border-radius: 10px; overflow: hidden; }
.seg-btn {
  appearance: none; border: 0; background: transparent; color: #fff;
  padding: 9px 14px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.seg-btn.active { background: var(--gold); color: #3a2c00; }

.win-card { text-align: center; align-items: center; }
.win-card p { margin: 0; opacity: 0.85; }
