:root {
  --bg: #15171c;           /* page */
  --panel: #1f232b;        /* top bar, cheatsheet, modal */
  --panel-2: #272c35;      /* buttons, inputs, chips */
  --panel-hover: #313742;
  --line: #333945;
  --line-strong: #4a515f;
  --ink: #d9dce2;          /* primary UI text (on dark) */
  --muted: #8a919e;
  --accent: #43b17f;

  /* cards stay white regardless of theme */
  --card-face: #ffffff;
  --red: #c0392b;          /* red suits on white cards */
  --black: #1a1b1f;        /* black suits on white cards */

  --card-w: 78px;
  --card-h: 106px;
  --peek: 30px;            /* visible strip of an overlapped card */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; color: var(--ink); }
.brand { display: flex; align-items: baseline; gap: 8px; }
.game-version { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.game-version:empty { display: none; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls button {
  font: inherit; font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}
.controls button:hover { background: var(--panel-hover); }
.controls button:active { transform: translateY(1px); }
.seed-field { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seed-field input {
  width: 84px; font: inherit; font-size: 13px;
  padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--panel-2); color: var(--ink);
}
.status { font-size: 13px; color: var(--muted); margin-left: 4px; }

/* HUD chips (score, coins, chain) */
.hud { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; white-space: nowrap;
}
.chip b { color: var(--accent); font-size: 15px; font-weight: 600; margin-left: 4px; }
.chip .of { color: var(--muted); font-weight: 400; font-size: 13px; }
.chip.coins b { color: #e0b341; }
.chip.chain b { color: var(--muted); }
.chip.chain.active { border-color: var(--accent); background: rgba(67,177,127,0.14); }
.chip.chain.active b { color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 152px 268px;
  gap: 20px;
  padding: 22px 20px 60px;
  max-width: 1260px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .pace-panel { max-width: 260px; }
}

.board { min-width: 0; }
.upper {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}
.cells { display: flex; gap: 10px; }

/* ---------- slots ---------- */
.slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 1.5px dashed var(--line-strong);
  background: rgba(255,255,255,0.03);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.slot .slot-mark {
  font-size: 30px;
  color: var(--line-strong);
  user-select: none;
}
.slot.drop-ok { border-color: var(--accent); background: rgba(67,177,127,0.15); }
/* QoL: matching foundation highlighted while a foundation-playable card is held */
.slot.playable { border-style: solid; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(67,177,127,0.35); }

/* ---------- tableau ---------- */
.tableau {
  display: grid;
  grid-template-columns: repeat(8, var(--card-w));
  gap: 12px;
  justify-content: center;
}
.col {
  min-height: var(--card-h);
  border-radius: 8px;
  padding-bottom: 8px;
}
.col.drop-ok { outline: 2px solid var(--accent); outline-offset: 2px; }
.col.empty { border: 1.5px dashed var(--line); }

/* ---------- cards (white in both themes) ---------- */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 1px solid #c9ccd2;
  background: var(--card-face);
  box-shadow: 0 1px 3px rgba(0,0,0,0.45);
  position: relative;
  cursor: grab;
  user-select: none;
  touch-action: none;   /* let pointer-drag work on touch without the page scrolling */
}
/* floating copy that follows the pointer/finger during a drag */
.drag-ghost {
  position: fixed;
  left: 0; top: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.92;
  min-height: 0;
  padding: 0;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5));
}
.col .card { margin-top: calc(var(--peek) - var(--card-h)); }
.col .card:first-child { margin-top: 0; }
.card:active { cursor: grabbing; }
.card.red   { color: var(--red); }
.card.black { color: var(--black); }
.card.dragging { opacity: 0.4; }
/* QoL: brief start-of-round cue on the Aces */
.card.pulse-ace { outline: 3px solid transparent; outline-offset: 1px; animation: acePulse 0.85s ease-in-out 3; }
@keyframes acePulse {
  0%, 100% { outline-color: rgba(67,177,127,0); }
  50%      { outline-color: rgba(67,177,127,0.9); }
}
.card .corner {
  position: absolute;
  left: 6px; top: 5px;
  line-height: 1;
  text-align: center;
}
.card .corner .r { font-size: 17px; font-weight: 700; display: block; }
.card .corner .s { font-size: 14px; display: block; }
.card .pip {
  position: absolute;
  right: 8px; bottom: 6px;
  font-size: 26px;
  line-height: 1;
}

/* cards sitting alone in a cell/foundation shouldn't overlap */
.slot .card { margin: 0; position: absolute; top: -1px; left: -1px; }

/* enhancement borders (one per card) */
.card.enh-red  { border: 2px solid #e0483b; }
.card.enh-blue { border: 2px solid #3d8be0; }
.card.enh-gold { border: 2px solid #e0b341; }

/* enhancement stamps — one center badge per card, coexists with a border */
.stamp {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; line-height: 1; color: #fff;
  border: 1.5px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.stamp-green     { background: #2fae66; }
.stamp-retrigger { background: #7b6cf0; font-size: 11px; }
.stamp-wild      { background: #17a2b8; }
.stamp-suited    { background: #e0663a; }

/* sticker placement mode */
body.placing .card:not(.eligible) { opacity: 0.4; }
.card.eligible { outline: 3px dashed var(--accent); outline-offset: 2px; cursor: pointer; }
.card.eligible:hover { outline-style: solid; }

.placement-bar {
  padding: 9px 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #10131a;
}
.placement-bar.hidden { display: none; }
.placement-bar.red  { background: #e0483b; }
.placement-bar.blue { background: #3d8be0; }
.placement-bar.gold { background: #e0b341; }

/* ---------- pace bar (score gates on a commit-move axis) ---------- */
.pace-panel { position: sticky; top: 16px; }
.pace-title { font-size: 13px; color: var(--muted); margin: 0 0 10px; text-align: center; }
.pace-foot { font-size: 11px; color: var(--muted); margin-top: 8px; text-align: center; }
.pace-track {
  position: relative;
  height: 420px;
  width: 30px;
  margin: 0 0 0 30px;   /* left-aligned: leaves room for the move label at left, gate labels at right */
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pace-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(67,177,127,0.22);
  border-top: 2px solid var(--accent);
  border-radius: 0 0 7px 7px;
}
/* current commit-move position (left of the track) */
.pace-now {
  position: absolute; right: calc(100% + 7px); transform: translateY(50%);
  font-size: 12px; font-weight: 600; color: var(--accent); white-space: nowrap;
}
.pace-now::after {   /* little pointer into the track */
  content: ""; position: absolute; left: calc(100% + 1px); top: 50%;
  border: 4px solid transparent; border-left-color: var(--accent); transform: translateY(-50%);
}
/* score-gate marks (right of the track) */
.pace-mark {
  position: absolute; left: -5px; right: -5px;
  border-top: 1px dashed var(--line-strong);
}
.pace-lab {
  position: absolute; left: calc(100% + 8px); transform: translateY(-50%);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 2px 7px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--ink);
}
.pace-mark.met { border-top-color: var(--accent); }
.pace-mark.met .pace-lab { border-color: var(--accent); color: var(--accent); }
.pace-mark.pending .pace-lab { color: var(--muted); }
.pace-mark.final { border-top: 2px solid var(--line-strong); }
.pace-mark.final .pace-lab { background: var(--panel); font-weight: 600; }
.pace-mark.final.met { border-top-color: var(--accent); }

/* ---------- sidebar (shop + cheatsheet) ---------- */
.sidebar {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.shop {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.shop-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.shop-head h2 { margin: 0; font-size: 16px; color: var(--ink); }
.shop-note { font-size: 11px; color: var(--muted); }
.shop-slots { display: flex; flex-direction: column; gap: 8px; }

.offer {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left-width: 3px;
}
.offer.red  { border-left-color: #e0483b; }
.offer.blue { border-left-color: #3d8be0; }
.offer.gold { border-left-color: #e0b341; }
.offer-info { flex: 1; min-width: 0; }
.offer-name { font-size: 13px; color: var(--ink); }
.offer-effect { font-size: 12px; color: var(--muted); }
.offer-buy {
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #0f1a14; border: 1px solid var(--accent);
}
.offer-buy:hover { filter: brightness(1.08); }
.offer.cant-afford { opacity: 0.55; }
.offer.cant-afford .offer-buy {
  background: var(--panel-2); color: var(--muted);
  border-color: var(--line-strong); cursor: default;
}
.offer.empty { min-height: 44px; border-style: dashed; }

/* ---------- cheatsheet ---------- */
.cheatsheet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}
.cheatsheet h2 { margin: 0 0 8px; font-size: 16px; color: var(--ink); }
.cheatsheet .goal { margin: 0 0 12px; font-weight: 600; }
.cheatsheet ul { margin: 0 0 14px; padding-left: 18px; }
.cheatsheet li { margin-bottom: 7px; }
.cheatsheet b { color: #eceef2; }
.cheatsheet .tips {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
}
.cheatsheet .tips p { margin: 0 0 6px; }

/* ---------- win banner ---------- */
.win-banner {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.win-banner.hidden { display: none; }
.win-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 30px 40px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
}
.win-title { margin: 0 0 6px; font-size: 30px; color: var(--accent); }
.win-banner.fail .win-title { color: #e0483b; }
.win-sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.win-inner button {
  font: inherit; font-size: 14px;
  padding: 8px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #0f1a14;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- mobile / touch ---------- */
@media (max-width: 700px) {
  :root { --card-w: 38px; --card-h: 54px; --peek: 17px; }
  .layout { padding: 12px 6px 40px; gap: 14px; }
  .topbar { padding: 10px 12px; gap: 8px 12px; }
  .topbar h1 { font-size: 18px; }
  .hud { margin-left: 0; }
  .tableau { gap: 4px; }
  .upper { gap: 10px; margin-bottom: 18px; }
  .cells { gap: 5px; }
  .slot .slot-mark { font-size: 22px; }
  .card .corner { left: 4px; top: 3px; }
  .card .corner .r { font-size: 13px; }
  .card .corner .s { font-size: 11px; }
  .card .pip { font-size: 16px; right: 5px; bottom: 4px; }
  .pace-panel { position: static; }
  .pace-track { height: 300px; margin-left: 34px; }
}
