/* Solitaire Classic — system theme + layout. Follows prefers-color-scheme live. */
:root {
  color-scheme: light dark;
  --banner-h: 0px;
  --cw: 43px;   /* card width, set by fitLayout() */
  --ch: 60px;   /* card height, set by fitLayout() */
  --ov: 24px;   /* face-up tableau step, set by fitLayout() */
  --ovd: 9px;   /* face-down tableau step */
  --pgap: 4px;  /* gap between the 7 columns */
  --bg: #e6f2e4;
  --surface: #ffffff;
  --ink: #14261a;
  --ink-dim: #57705c;
  --accent: #1b7a3d;
  --accent-ink: #ffffff;
  --line: #c4dcc4;
  --felt: #2f7d46;
  --felt-dark: #256b3a;
  --slot: rgba(255, 255, 255, 0.14);
  --shadow: 0 8px 32px rgba(20, 38, 26, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1f12;
    --surface: #1a2f1f;
    --ink: #eef7ea;
    --ink-dim: #a8c2ab;
    --accent: #4ade80;
    --accent-ink: #0d1f12;
    --line: #2c4a33;
    --felt: #1d5c31;
    --felt-dark: #174a28;
    --slot: rgba(255, 255, 255, 0.10);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--banner-h);
  -webkit-touch-callout: none; /* no long-press callout anywhere in the app */
  user-select: none;
  -webkit-user-select: none;
}
button { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
body.sc_banner { padding-bottom: var(--banner-h); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 2px;
  max-width: 480px; width: 100%; margin: 0 auto;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #1b7a3d, #4ade80);
  color: #ffffff; font-size: 20px;
}
.icon-btn {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}
.top-actions { display: flex; gap: 8px; }

main {
  max-width: 480px; width: 100%; margin: 0 auto;
  padding: 6px 16px 6px; /* 6px bottom = tight 6px gap above the banner zone */
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
}

/* ---- HUD ---- */
.hud {
  display: flex; gap: 8px; margin-top: 4px;
  flex: 0 0 auto;
}
.hud-item {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 4px 5px; text-align: center;
}
.hud-label { display: block; font-size: 11px; color: var(--ink-dim); font-weight: 600; }
.hud-value { display: block; font-size: 17px; font-weight: 800; }

/* ---- board ---- */
.board-wrap {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 8px;
}
.board {
  /* border-box: this width INCLUDES the 8px padding + 1px border each side,
   * so the pile row (7 cards + 6 gaps) needs the extra 18px of chrome —
   * without it the 7th column overflows the felt on the right by ~9px. */
  width: calc(var(--cw) * 7 + var(--pgap) * 6 + 18px);
  max-width: 100%;
  background: linear-gradient(160deg, var(--felt), var(--felt-dark));
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 8px;
}
.top-row, .tableau-row {
  display: flex; gap: var(--pgap);
}
.tableau-row { margin-top: 8px; }
.top-gap { flex: 0 0 var(--cw); }
.pile {
  position: relative;
  width: var(--cw); height: var(--ch);
  flex: 0 0 var(--cw);
  border-radius: 6px;
}
.pile:empty::before {
  content: "";
  position: absolute; inset: 0;
  border: 1px dashed var(--slot);
  border-radius: 6px;
}
.foundation:empty::after {
  content: "A";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--slot); font-size: 20px; font-weight: 700;
}
.stock:empty::after {
  content: "↻";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--slot); font-size: 20px; font-weight: 700;
}
.pile.tableau { height: calc(var(--ch) + var(--ov) * 12); }
.pile.drop-hint { outline: 2px solid #ffd54a; outline-offset: 1px; }

/* ---- cards: first-party CSS/text faces, zero bundled images ---- */
.card {
  position: absolute; left: 0; top: 0;
  width: var(--cw); height: var(--ch);
  border-radius: 6px;
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #b9c4bb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  font-weight: 700;
  touch-action: none;
  cursor: pointer;
}
.card.red { color: #c81e3a; }
.card.black { color: #1a1a1a; }
.card .rank {
  position: absolute; top: 2px; left: 3px;
  font-size: calc(var(--cw) * 0.30);
  line-height: 1;
}
.card .suit {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cw) * 0.52);
  line-height: 1;
  padding-top: calc(var(--cw) * 0.10);
}
.card .rank-br {
  position: absolute; bottom: 2px; right: 3px;
  font-size: calc(var(--cw) * 0.30);
  line-height: 1;
  transform: rotate(180deg);
}
.card.back .rank, .card.back .suit, .card.back .rank-br { display: none; }
.card.back {
  background:
    repeating-linear-gradient(45deg, #1b5e8a 0 4px, #2a7ab0 4px 8px);
  border-color: #ffffff;
  box-shadow: inset 0 0 0 3px #ffffff, inset 0 0 0 4px #1b5e8a, 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: default;
}
.card.back::after {
  content: "♠";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: calc(var(--cw) * 0.44);
}
/* The card being dragged (or flown) hides at its source so only the clone
   under the finger is visible. !important is required: placePile() sets an
   INLINE visibility:visible on every card at render time, and an inline
   style beats a plain class rule — without it the source card stayed visible
   under the drag (Michelle 2026-11-16: "card on deck still visible"). */
.card.drag-src { visibility: hidden !important; }
.card.lifted { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45); }

/* drag layer follows the pointer; clones of the moving stack */
.drag-layer {
  position: fixed; left: 0; top: 0; z-index: 30;
  pointer-events: none;
  transition: none; /* during a drag the layer tracks the finger with no lag */
}
/* .fly: after release, the layer glides to its destination (or back home)
   instead of the card teleporting — every card movement animates. */
.drag-layer.fly { transition: left 0.18s ease, top 0.18s ease; }
.drag-layer .card { position: absolute; transition: none; }

/* ---- controls ---- */
.controls {
  flex: 0 0 auto;
  display: flex; gap: 8px;
  margin-top: 8px;
}
.controls .control-btn { flex: 1 1 0; width: auto; min-width: 0; margin-top: 0; white-space: nowrap; font-size: 16px; padding: 13px 4px; }

.primary-btn, .ghost-btn {
  display: block; width: 100%; border-radius: 12px; font-size: 17px;
  font-weight: 700; padding: 13px; margin-top: 10px; cursor: pointer;
  flex: 0 0 auto;
}
.primary-btn { background: var(--accent); color: var(--accent-ink); border: none; }
.ghost-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---- sheets / toast ---- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  bottom: var(--banner-h);
}
.sheet-card {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 480px; max-height: calc(100dvh - var(--banner-h) - 16px);
  overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + var(--banner-h));
  box-shadow: var(--shadow);
}
body.sc_banner .sheet-card { padding-bottom: calc(18px + var(--banner-h)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-card p { line-height: 1.55; font-size: 15px; }
.sheet-note { color: var(--ink-dim); font-size: 13px; }
.sheet-label { font-weight: 700; margin: 14px 0 6px; }
.result-line { font-size: 18px; font-weight: 700; text-align: center; }
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; border-radius: 10px; padding: 11px; font-size: 16px; font-weight: 700;
  background: transparent; color: var(--ink); border: 1px solid var(--line); cursor: pointer;
}
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(65px + var(--banner-h));
  /* 65px = 6px main bottom padding + 47px controls row + 12px gap: the toast
     sits ABOVE the controls, never covering the Draw / Undo / New Deal buttons
     (Michelle 2026-11-16: the toast half-covered the Draw button). */
  z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--bg);
  border-radius: 10px; padding: 12px 14px; text-align: center;
  font-size: 14px; font-weight: 600;
}
