/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  touch-action: none;
  background: #0d1117;
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  color: #e6edf3;
  user-select: none; -webkit-user-select: none;
  padding: 12px 8px 20px;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  width: min(96vw, 640px); margin-bottom: 10px;
}
h1 {
  font-size: clamp(1.1rem, 4.5vw, 1.6rem);
  color: #f0c040; letter-spacing: 3px; text-transform: uppercase;
}
.round-badge {
  font-size: .75rem; font-weight: 700; color: #7dd3fc;
  background: #161b22; border-radius: 8px; padding: 4px 10px;
}

/* ── HUD stats ──────────────────────────────────────────────────────────────── */
.hud-row {
  display: flex; gap: 8px; width: min(96vw, 640px); margin-bottom: 8px;
  flex-wrap: wrap; justify-content: center;
}
.hud-box {
  flex: 1; min-width: 80px;
  background: #161b22; border-radius: 10px; padding: 6px 10px; text-align: center;
}
.hud-box .lbl {
  font-size: .58rem; text-transform: uppercase; color: #8b949e;
  letter-spacing: 1px; margin-bottom: 1px;
}
.hud-box .val {
  font-size: 1.15rem; font-weight: 800; color: #f0c040;
}
.hud-box.score  .val { color: #f0c040; }
.hud-box.target .val { color: #7dd3fc; }
.hud-box.turns  .val { color: #f97316; }
.hud-box.high   .val { color: #a8b3c4; font-size: .95rem; }

/* ── Score progress bar ─────────────────────────────────────────────────────── */
.progress-wrap {
  width: min(96vw, 640px); height: 8px;
  background: #21262d; border-radius: 4px; margin-bottom: 10px; overflow: hidden;
}
#score-progress-bar {
  height: 100%; border-radius: 4px; width: 0;
  background: #7dd3fc; transition: width .4s ease, background .3s;
}

/* ── Board ──────────────────────────────────────────────────────────────────── */
.game-area {
  display: grid; grid-template-columns: minmax(0, 432px) 180px;
  align-items: start; gap: 12px; width: min(96vw, 640px);
}
.board-column { min-width: 0; }
.board-wrap {
  background: #21262d; padding: 6px; border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  margin-bottom: 10px;
}
#board {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  width: min(96vw, 432px); aspect-ratio: 1;
}

/* ── Card cell ──────────────────────────────────────────────────────────────── */
.card-cell {
  position: relative; border-radius: 6px;
  transition: transform .1s;
}

.card {
  width: 100%; height: 100%;
  background: #faf7f0; border-radius: 6px;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 3px 4px; position: relative; overflow: hidden;
  box-shadow: 0 2px 5px rgba(0,0,0,.3);
}
.card.red   { color: #cc2020; }
.card.black { color: #1a1a2e; }
.card.empty { background: #161b22; box-shadow: none; }

.card-corner {
  display: flex; flex-direction: column; align-items: center; line-height: 1;
}
.card-corner.bot { transform: rotate(180deg); align-self: flex-end; }
.card-rank    { font-size: clamp(9px, 2.4vw, 13px); font-weight: 800; line-height: 1; }
.card-suit-sm { font-size: clamp(7px, 1.8vw, 10px); line-height: 1; }
.card-suit-center {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(14px, 4.2vw, 22px); line-height: 1; opacity: .85;
  pointer-events: none;
}

/* ── Path selection ─────────────────────────────────────────────────────────── */
.card-cell.selected .card {
  box-shadow: 0 0 0 2.5px #f0c040, 0 4px 14px rgba(0,0,0,.5);
  transform: scale(1.06);
  z-index: 1;
}
.path-badge {
  position: absolute; top: 2px; right: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #f0c040; color: #1a1a2e;
  font-size: 9px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  z-index: 2; pointer-events: none;
}
.card-cell.path-1 .card { box-shadow: 0 0 0 2.5px #4ade80, 0 4px 14px rgba(0,0,0,.5); }
.card-cell.path-2 .card { box-shadow: 0 0 0 2.5px #facc15, 0 4px 14px rgba(0,0,0,.5); }
.card-cell.path-3 .card { box-shadow: 0 0 0 2.5px #fb923c, 0 4px 14px rgba(0,0,0,.5); }
.card-cell.path-4 .card { box-shadow: 0 0 0 2.5px #f87171, 0 4px 14px rgba(0,0,0,.5); }
.card-cell.non-contributing .card {
  filter: grayscale(1); opacity: .35;
  box-shadow: 0 0 0 2px #59636e, 0 2px 5px rgba(0,0,0,.3);
  transform: scale(.96);
}
.card-cell.non-contributing .path-badge { background: #59636e; color: #d0d7de; }

/* ── Card animations ────────────────────────────────────────────────────────── */
.card-cell.lifting .card {
  transform: translateY(-10px) scale(1.1);
  transition: transform .15s ease;
  z-index: 10;
}
.card-cell.flipping { animation: cardFlip .3s ease; }
@keyframes cardFlip {
  0%   { transform: scaleY(1); }
  40%  { transform: scaleY(0) scaleX(1.05); }
  100% { transform: scaleY(1); }
}

/* ── Hand preview ───────────────────────────────────────────────────────────── */
#hand-preview {
  width: 100%; min-height: 88px;
  background: #161b22; border-radius: 10px;
  padding: 8px 14px; margin-bottom: 10px;
  display: flex; align-items: center;
}
.preview-hint { font-size: .8rem; color: #8b949e; }
.preview-hand { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.preview-hand.idle { align-items: center; }
.preview-cards {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.preview-card-group {
  display: grid; grid-template-columns: repeat(4, 32px); gap: 4px;
}
.preview-card {
  position: relative; width: 32px; height: 44px;
  background: #faf7f0; border-radius: 5px;
  border: 2px solid #30363d;
  display: grid; grid-template-rows: 1fr auto;
  align-content: center; justify-items: center;
  padding: 5px 3px 3px;
  font-weight: 900; line-height: 1;
}
.preview-card.red { color: #cc2020; }
.preview-card.black { color: #1a1a2e; }
.preview-card.active { border-color: #f0c040; box-shadow: 0 0 0 1px rgba(240,192,64,.35); }
.preview-card.muted {
  filter: grayscale(1); opacity: .38;
  background: #d0d7de; border-color: #59636e;
}
.preview-card.river {
  border-color: #7dd3fc;
  box-shadow: 0 0 0 1px rgba(125,211,252,.25);
}
.preview-card.river.active {
  border-color: #f0c040;
  box-shadow: 0 0 0 1px rgba(240,192,64,.35), 0 0 14px rgba(125,211,252,.2);
}
.preview-card.empty {
  background: #21262d; color: #59636e;
}
.preview-slot {
  width: 32px; height: 44px; border: 2px dashed #30363d;
  border-radius: 5px; display: flex; align-items: center; justify-content: center;
  color: #59636e; font-size: .68rem; font-weight: 900;
}
.preview-card-label {
  position: absolute; top: 2px; left: 3px;
  font-size: .5rem; color: #59636e;
}
.preview-card-rank { font-size: .78rem; }
.preview-card-suit { font-size: .95rem; }
.river-plus {
  color: #59636e; font-weight: 900; font-size: .8rem;
}
.preview-copy {
  min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.preview-name {
  font-size: 1rem; font-weight: 800; letter-spacing: 1px;
}
.preview-hand.low  .preview-name { color: #8b949e; }
.preview-hand.mid  .preview-name { color: #7dd3fc; }
.preview-hand.high .preview-name { color: #f0c040; }
.preview-hand.top  .preview-name { color: #f87171; text-shadow: 0 0 8px #f87171; }
.preview-score   { font-size: .95rem; font-weight: 700; color: #f0c040; }
.preview-formula { font-size: .7rem; color: #8b949e; }
.preview-note { width: 100%; font-size: .7rem; color: #8b949e; }

/* ── Controls row ───────────────────────────────────────────────────────────── */
.controls {
  display: flex; gap: 8px; width: 100%;
  margin-bottom: 10px; flex-wrap: wrap;
}
#play-hand-btn {
  flex: 2; background: #21262d; color: #8b949e; border: 2px solid #30363d;
  border-radius: 10px; padding: 11px 20px; font-size: .95rem; font-weight: 800;
  cursor: not-allowed; letter-spacing: 1px; text-transform: uppercase;
  transition: all .15s;
}
#play-hand-btn.active {
  background: #f0c040; color: #1a1a2e; border-color: #f0c040; cursor: pointer;
  box-shadow: 0 4px 16px rgba(240,192,64,.4);
}
#play-hand-btn.active:hover { background: #fbbf24; }
#play-hand-btn.active:active { transform: scale(.97); }

#deck-tracker-btn {
  flex: 1; background: #161b22; color: #7dd3fc; border: 2px solid #30363d;
  border-radius: 10px; padding: 11px 14px; font-size: .82rem; font-weight: 700;
  cursor: pointer; letter-spacing: .5px; transition: background .15s;
}
#deck-tracker-btn:hover { background: #21262d; }

#restart-btn {
  flex: 1; background: #161b22; color: #8b949e; border: 2px solid #30363d;
  border-radius: 10px; padding: 11px 14px; font-size: .82rem; font-weight: 700;
  cursor: pointer; transition: all .15s;
}
#restart-btn:hover { color: #f87171; border-color: #f87171; }

/* ── Hand ladder ────────────────────────────────────────────────────────────── */
#hand-ladder {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px;
  padding: 11px 9px; min-height: 100%;
}
#hand-ladder h2 {
  color: #f0c040; font-size: .85rem; letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 3px;
}
#hand-ladder > p { color: #8b949e; font-size: .62rem; line-height: 1.3; margin-bottom: 8px; }
#hand-ladder ol { list-style: none; display: grid; gap: 3px; }
.hand-level {
  display: flex; align-items: baseline; justify-content: space-between; gap: 4px;
  border-radius: 6px; color: #8b949e; font-size: .7rem; padding: 5px 6px;
}
.hand-level small { color: #59636e; font-size: .58rem; white-space: nowrap; }
.hand-level.active {
  color: #161b22; background: #f0c040; font-weight: 800;
  box-shadow: 0 0 0 1px rgba(240,192,64,.35);
}
.hand-level.active small { color: #3b3320; font-weight: 700; }

/* ── Deck tracker panel ─────────────────────────────────────────────────────── */
#deck-panel {
  width: min(96vw, 640px); background: #161b22;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
#deck-panel.hidden { display: none; }
.deck-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .8rem; color: #8b949e; margin-bottom: 8px;
}
.close-btn {
  background: none; border: none; color: #8b949e; font-size: 1.1rem;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.deck-suits {
  display: flex; gap: 12px; margin-bottom: 10px;
  font-size: .9rem; font-weight: 700;
}
.suit-count.hearts, .suit-count.diamonds { color: #cc2020; }
.suit-count.clubs,  .suit-count.spades   { color: #e6edf3; }
.deck-ranks { display: flex; flex-direction: column; gap: 4px; }
.rank-row {
  display: flex; align-items: center; gap: 8px;
}
.rank-label {
  font-size: .78rem; font-weight: 700; color: #8b949e;
  width: 22px; text-align: right; flex-shrink: 0;
}
.rank-pips { display: flex; gap: 3px; }
.pip {
  width: 10px; height: 10px; border-radius: 50%;
  transition: background .2s;
}
.pip.filled  { background: #7dd3fc; }
.pip.empty   { background: #21262d; }
.rank-count  { font-size: .72rem; color: #8b949e; width: 14px; }
.reshuffle-info {
  margin-top: 8px; font-size: .72rem; color: #8b949e; text-align: center;
}

/* ── Score animation overlay ────────────────────────────────────────────────── */
#score-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.75);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; pointer-events: none;
  opacity: 0; transition: opacity .2s;
}
#score-overlay.visible { opacity: 1; }
#score-overlay.hidden  { display: none; }

.anim-hand-title {
  font-size: clamp(1.4rem, 6vw, 2.6rem); font-weight: 900;
  letter-spacing: 3px; text-transform: uppercase;
}
.anim-hand-title.tier-common { color: #8b949e; }
.anim-hand-title.tier-good   { color: #7dd3fc; }
.anim-hand-title.tier-great  { color: #f0c040; }
.anim-hand-title.tier-epic   {
  color: #f87171;
  text-shadow: 0 0 20px #f87171, 0 0 40px rgba(248,113,113,.5);
}

#anim-chips { font-size: 1rem; color: #7dd3fc; font-weight: 700; }
#anim-mult  { font-size: 1.4rem; color: #f0c040; font-weight: 900; }
#anim-total { font-size: 2rem; color: #4ade80; font-weight: 900; }

.pop-in  { animation: popIn .25s ease; }
.slam-in { animation: slamIn .2s cubic-bezier(.36,.07,.19,.97); }
.burst   { animation: burst .3s ease; }

@keyframes popIn  { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slamIn { 0% { transform: scale(2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes burst  { 0% { transform: scale(.5); opacity: 0; } 60% { transform: scale(1.2); } 100% { transform: scale(1); opacity: 1; } }

/* ── Overlays (victory / defeat / gameover) ─────────────────────────────────── */
.game-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 20px; animation: fadeIn .3s ease;
}
.game-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-title {
  font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 900;
  text-align: center; letter-spacing: 2px;
}
.overlay-sub {
  font-size: .95rem; color: #8b949e; text-align: center;
}
#victory-overlay  .overlay-title { color: #4ade80; }
#defeat-overlay   .overlay-title { color: #f87171; }
#gameover-overlay .overlay-title { color: #f97316; }
#runwin-overlay   .overlay-title { color: #f0c040; text-shadow: 0 0 20px rgba(240,192,64,.6); }

.overlay-btn {
  background: #f0c040; color: #1a1a2e; border: none;
  border-radius: 10px; padding: 12px 36px; font-size: 1rem; font-weight: 800;
  cursor: pointer; letter-spacing: 1.5px; text-transform: uppercase;
  transition: background .15s, transform .1s;
}
.overlay-btn:hover  { background: #fbbf24; }
.overlay-btn:active { transform: scale(.97); }
.overlay-btn.secondary {
  background: #21262d; color: #8b949e; border: 2px solid #30363d;
  margin-top: -6px;
}
.overlay-btn.secondary:hover { color: #e6edf3; border-color: #8b949e; }

@media (max-width: 620px) {
  .game-area { grid-template-columns: 1fr; gap: 8px; width: min(96vw, 440px); }
  #hand-ladder { min-height: auto; }
  #hand-ladder ol { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
  .hand-level { font-size: .66rem; }
  .preview-hand { grid-template-columns: 1fr; gap: 8px; }
  .preview-card-group { grid-template-columns: repeat(4, minmax(26px, 32px)); }
}
