:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --felt: #1c4532;
  --felt-edge: #2f6b4f;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --gold: #d4a017;
  --red: #ef5350;
  --green: #4caf7d;
  --card-bg: #f5f2ea;
  --card-red: #c62828;
  --card-black: #1a1a1a;
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header { text-align: center; padding: 1.2rem 1rem 0.4rem; }
header h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.02em; }
.subtitle { color: var(--muted); margin: 0.3rem auto 0; max-width: 42rem; font-size: 0.85rem; }
.model-info { color: var(--accent); }

main { flex: 1; width: 100%; max-width: 60rem; margin: 0 auto; padding: 0.8rem 1rem; }
.hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: var(--radius);
  padding: 1.5rem;
}

.loading { text-align: center; }
.spinner {
  width: 2.2rem; height: 2.2rem;
  border: 3px solid #30363d;
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 0.8rem;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.topbar {
  display: grid;
  grid-template-columns: minmax(22rem, 1fr) auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.5rem 0.2rem;
}
.score { font-weight: 600; white-space: nowrap; overflow: hidden; }
.score span#score.positive { color: var(--green); }
.score span#score.negative { color: var(--red); }
.controls { display: flex; gap: 0.9rem; align-items: center; color: var(--muted); font-size: 0.85rem; }
.controls select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid #30363d; border-radius: 6px; padding: 0.25rem 0.4rem;
  margin-left: 0.3rem;
}
.advice-toggle { cursor: pointer; user-select: none; }
.new-game {
  background: var(--panel-2); color: var(--text);
  border: 1px solid #3d444d; border-radius: 6px;
  padding: 0.3rem 0.8rem; font-size: 0.85rem; cursor: pointer;
}
.new-game:hover { border-color: var(--accent); }
.tracking-stats {
  display: grid;
  grid-template-rows: 2.4rem 2.4rem;
  padding: 0 0.2rem 0.25rem;
}
.stats {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.stats .winrate { color: var(--accent); }
.stats-content, .all-in-stats-content { line-height: 1.25; }
.all-in-stats {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.all-in-stats.lucky strong { color: var(--green); }
.all-in-stats.unlucky strong { color: var(--red); }
.all-in-stats.even strong { color: var(--accent); }

.table-wrap { padding: 0.4rem 0; }
.table {
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at center, var(--felt) 0%, #143726 100%);
  border: 10px solid #3a2b18;
  outline: 2px solid var(--felt-edge);
  outline-offset: -12px;
  border-radius: 45% / 38%;
  min-height: 29.5rem;
  display: grid;
  grid-template-rows: minmax(9.1rem, 1fr) 9.5rem minmax(9.1rem, 1fr);
  padding: 1rem;
}

.seat {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  justify-self: center; align-self: center;
  min-width: 9rem;
  height: 9.1rem;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  background: rgba(13, 17, 23, 0.55);
  border: 1px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s, filter 0.2s;
}
.seat.acting {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(212, 160, 23, 0.35);
  animation: acting-pulse 1.25s ease-in-out infinite;
}
.seat.folded { opacity: 0.45; }
.seat-top { grid-row: 1; }
.seat-right { grid-row: 1; position: absolute; right: 6%; top: 34%; }
.seat-bottom { grid-row: 3; }

.seat .name { font-weight: 600; font-size: 0.9rem; display: flex; gap: 0.4rem; align-items: center; white-space: nowrap; }
.position-name {
  font-size: 0.65rem; font-weight: 700;
  color: var(--muted);
  border: 1px solid rgba(139, 148, 158, 0.38);
  border-radius: 999px; padding: 0.02rem 0.35rem;
}
.seat .stack { color: var(--muted); font-size: 0.8rem; }
.seat .last-action {
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1.05em;
  height: 2.2em;
  flex-shrink: 0;
  max-width: 9rem;
  text-align: center;
  overflow: hidden;
}

.markers {
  position: absolute;
  right: -0.58rem;
  bottom: 1.45rem;
  display: flex;
  gap: 0.2rem;
  z-index: 4;
}
.table-marker {
  width: 1.72rem;
  height: 1.72rem;
  border-radius: 50%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  color: #17130a;
  background: linear-gradient(145deg, #fff4bc, #d7a823);
  border: 2px dashed rgba(63, 43, 5, 0.48);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.48), inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  will-change: transform;
}
.marker-small-blind { background: linear-gradient(145deg, #f4f7fa, #9aa6b2); }
.marker-big-blind { background: linear-gradient(145deg, #bce1ff, #508ac0); }
.marker-arrive { animation: marker-pop 0.38s cubic-bezier(.2, .9, .25, 1) both; }

/* Wagered chips sit on the felt in front of each seat; app.js positions each
   spot between its seat and the table center. */
.bet-spot {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.34rem;
  z-index: 6;
  pointer-events: none;
  color: #ffe081;
  font-size: 0.74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.bet-spot.bet-incoming .chip-pile,
.bet-spot.bet-incoming .bet-value { opacity: 0; }
.bet-spot.bet-landed .chip-pile { animation: pile-pop 0.28s cubic-bezier(.2, .9, .25, 1) both; }

/* Chip piles grow with the bet: taller columns and higher-value chip colors. */
.chip-pile {
  display: inline-flex;
  align-items: flex-end;
  gap: 0.14rem;
  transform-origin: center bottom;
  --chip-a: #f4d75d;
  --chip-b: #8d6512;
}
.chip-pile.tier-micro { --chip-a: #a9cdf5; --chip-b: #2f5c93; }
.chip-pile.tier-mid { --chip-a: #63d492; --chip-b: #1c5a37; }
.chip-pile.tier-high { --chip-a: #f07a7a; --chip-b: #7c1d1d; }
.pile-col {
  position: relative;
  width: 1.32rem;
  height: calc(0.52rem + (var(--n) - 1) * 0.3rem);
  flex: 0 0 auto;
}
.pile-col i {
  position: absolute;
  left: 0;
  bottom: calc(var(--i) * 0.3rem);
  width: 1.32rem;
  height: 0.5rem;
  border-radius: 50%;
  background: repeating-conic-gradient(var(--chip-a) 0deg 34deg, var(--chip-b) 34deg 50deg);
  border: 1px solid rgba(18, 11, 0, 0.6);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.pile-col i:nth-child(even) { filter: brightness(0.92); }
.bet-value { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); }

.cards { display: flex; gap: 0.3rem; min-height: 3.4rem; }
.card {
  width: 2.4rem; height: 3.4rem;
  background: var(--card-bg);
  border-radius: 6px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  font-weight: 700; font-size: 1.05rem; line-height: 1;
  box-shadow: 0 2px 5px rgba(0,0,0,0.45);
  transform-origin: center;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
.card .suit { font-size: 1.1rem; }
.card.red { color: var(--card-red); }
.card.black { color: var(--card-black); }
.card.back {
  background: repeating-linear-gradient(45deg, #2a4d8f, #2a4d8f 4px, #23407a 4px, #23407a 8px);
  border: 2px solid #d7dce3;
}
.seat-top { --deal-x: 0px; --deal-y: 8rem; --deal-rotate: -8deg; }
.seat-right { --deal-x: -11rem; --deal-y: 1rem; --deal-rotate: 10deg; }
.seat-bottom { --deal-x: 0px; --deal-y: -8rem; --deal-rotate: 7deg; }
.hole-card-deal { animation: deal-hole 0.32s cubic-bezier(.16, .84, .3, 1.05) both; }
.board-card-deal { animation: deal-board 0.34s cubic-bezier(.2, .9, .25, 1) both; }
.card-reveal { animation: reveal-card 0.4s cubic-bezier(.2, .8, .25, 1) both; }
.card-deal { animation-delay: var(--card-delay, 0ms); }
.seat.folding .cards { animation: muck-cards 0.32s cubic-bezier(.4, 0, .7, .2) both; }
.seat.folding { animation: fold-seat 0.34s ease-out both; }
.seat.winner { animation: winner-glow 0.7s ease-out both; }

.board-area { grid-row: 2; text-align: center; padding: 0.4rem 0; }
.pot {
  color: #ffe17b;
  font-weight: 700;
  margin-bottom: 0.4rem;
  min-height: 1.2em;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.pot-chip {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: repeating-conic-gradient(#f4d75d 0deg 34deg, #8d6512 34deg 50deg);
  border: 2px dashed rgba(50, 32, 2, 0.55);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
  animation: pot-pop 0.25s cubic-bezier(.2, .9, .25, 1) both;
}
.board { display: flex; gap: 0.35rem; justify-content: center; min-height: 3.4rem; }
.banner {
  margin-top: 0.5rem;
  font-weight: 600;
  height: 3.2rem;
  overflow: hidden;
}
.banner .win { color: var(--green); animation: banner-pop 0.42s cubic-bezier(.2, .9, .25, 1) both; display: inline-block; }
.banner .lose { color: var(--red); animation: banner-pop 0.42s cubic-bezier(.2, .9, .25, 1) both; display: inline-block; }
.banner .all-in-equity {
  display: block;
  margin-top: 0.25rem;
  color: #b8d8ff;
  font-size: 0.72rem;
  font-weight: 500;
}

.wager-flight {
  position: absolute;
  left: -1.5rem;
  top: -1.1rem;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  pointer-events: none;
  white-space: nowrap;
  color: #fff0a8;
  font-size: 0.72rem;
  text-shadow: 0 2px 3px #000;
  will-change: transform, opacity;
}
.wager-flight.pot-award strong { color: #8cf0b5; }

.action-area { min-height: 8.6rem; padding: 0.6rem 0.2rem; }

.action-bar {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1.4fr;
  gap: 0.6rem;
  max-width: 34rem;
  margin: 0 auto;
}
.action-btn {
  border-radius: 10px;
  padding: 0.85rem 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid #3d444d;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.12s, border-color 0.12s, opacity 0.12s, transform 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.action-btn:hover:not(:disabled) { filter: brightness(1.2); }
.action-btn:active:not(:disabled) { transform: translateY(2px) scale(0.985); filter: brightness(1.35); }
.action-btn:disabled { opacity: 0.35; cursor: default; }
.fold-btn { border-color: #7a3b3b; color: #ff9b9b; }
.call-btn { border-color: #2f5e8f; color: #9ecbff; background: #17293c; }
.raise-btn { border-color: #7a6420; color: #ffd766; background: #2c2410; }

.raise-controls { max-width: 34rem; margin: 0 auto 0.55rem; }
.raise-controls input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
  height: 1.4rem;
}
.raise-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 0.15rem;
}
.raise-ticks span { cursor: pointer; user-select: none; padding: 0.1rem 0.15rem; }
.raise-ticks span:hover { color: var(--gold); }
.raise-ticks span.active { color: var(--gold); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.actions button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid #3d444d; border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.actions button:hover { background: #263041; border-color: var(--accent); }
.actions button.fold { border-color: #6e3b3b; }
.actions button.fold:hover { border-color: var(--red); }
.actions button.allin { border-color: #6e5b1e; color: var(--gold); }
.actions button.primary { border-color: var(--accent); }
.actions button.deal {
  background: var(--accent); color: #0d1117; border-color: var(--accent);
  font-size: 1rem; padding: 0.6rem 1.6rem;
}
.actions button.deal { animation: deal-button-in 0.3s cubic-bezier(.2, .9, .25, 1) both; }
.actions .hint { width: 100%; text-align: center; color: var(--muted); font-size: 0.85rem; }

.advice {
  max-width: 30rem; margin: 0 auto 0.7rem;
  background: var(--panel);
  border: 1px solid #30363d; border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  font-size: 0.8rem;
}
.advice h3 { margin: 0 0 0.4rem; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.advice .row { display: flex; align-items: center; gap: 0.5rem; margin: 0.15rem 0; }
.advice .label { width: 7.5rem; color: var(--text); }
.advice .bar-track { flex: 1; height: 0.55rem; background: #21262d; border-radius: 999px; overflow: hidden; }
.advice .bar { height: 100%; background: var(--accent); border-radius: 999px; }
.advice .pct { width: 3.2rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.advice .value-line { margin-top: 0.4rem; color: var(--muted); }

.log-wrap { margin: 0.4rem 0.2rem; color: var(--muted); font-size: 0.85rem; }
.copy-log {
  margin-left: 0.6rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid #3d444d; border-radius: 6px;
  padding: 0.1rem 0.6rem; font-size: 0.75rem; cursor: pointer;
}
.copy-log:hover { border-color: var(--accent); }
.log {
  max-height: 14rem; overflow-y: auto;
  background: var(--panel);
  border: 1px solid #30363d; border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
}

footer { text-align: center; color: var(--muted); font-size: 0.72rem; padding: 0.6rem 1rem 1.2rem; }
footer p { max-width: 46rem; margin: 0 auto; }

@keyframes acting-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(212, 160, 23, 0.26); }
  50% { box-shadow: 0 0 20px rgba(212, 160, 23, 0.46); }
}
@keyframes marker-pop {
  0% { opacity: 0; transform: scale(0.35) rotate(-35deg); }
  72% { opacity: 1; transform: scale(1.18) rotate(4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes deal-hole {
  0% { opacity: 0; transform: translate(var(--deal-x), var(--deal-y)) rotate(var(--deal-rotate)) scale(0.82); }
  70% { opacity: 1; transform: translate(0, -2px) rotate(-1deg) scale(1.035); }
  100% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}
@keyframes deal-board {
  0% { opacity: 0; transform: translate(-4.5rem, -3rem) rotate(-14deg) scale(0.82); }
  72% { opacity: 1; transform: translate(2px, 0) rotate(1deg) scale(1.04); }
  100% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}
@keyframes reveal-card {
  0% { opacity: 0.4; transform: perspective(200px) rotateY(90deg) scale(0.92); }
  70% { opacity: 1; transform: perspective(200px) rotateY(-7deg) scale(1.04); }
  100% { opacity: 1; transform: perspective(200px) rotateY(0) scale(1); }
}
@keyframes muck-cards {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0.2; transform: translate(0, 2.7rem) rotate(-13deg) scale(0.78); }
}
@keyframes fold-seat {
  0% { filter: grayscale(0); }
  100% { filter: grayscale(0.75); }
}
@keyframes winner-glow {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(76, 175, 125, 0); }
  45% { transform: scale(1.035); box-shadow: 0 0 25px rgba(76, 175, 125, 0.7); }
  100% { transform: scale(1); box-shadow: 0 0 12px rgba(76, 175, 125, 0.35); }
}
@keyframes pile-pop {
  0% { transform: scale(0.55) translateY(0.3rem); }
  70% { transform: scale(1.12) translateY(-1px); }
  100% { transform: scale(1) translateY(0); }
}
@keyframes pot-pop {
  0% { opacity: 0.2; transform: scale(0.6) rotate(-18deg); }
  75% { opacity: 1; transform: scale(1.18) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes banner-pop {
  0% { opacity: 0; transform: translateY(6px) scale(0.92); }
  70% { opacity: 1; transform: translateY(-1px) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes deal-button-in {
  0% { opacity: 0; transform: translateY(6px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .tracking-stats { grid-template-rows: 3.5rem 3.5rem; }
  .table {
    min-height: 32rem;
    grid-template-rows: minmax(9.1rem, 1fr) 10.5rem minmax(9.1rem, 1fr);
  }
  .banner { height: 4.2rem; }
  .seat-right { position: relative; right: auto; top: auto; grid-row: 1; }
  .table { grid-template-columns: 1fr 1fr; }
  .seat-top { grid-column: 1; }
  .seat-right { grid-column: 2; align-self: center; justify-self: center; }
  .board-area { grid-column: 1 / -1; }
  .seat-bottom { grid-column: 1 / -1; }
  .card { width: 2rem; height: 2.9rem; font-size: 0.9rem; }
  .seat { min-width: 8rem; padding-inline: 0.55rem; }
  .seat-right { --deal-x: -5rem; --deal-y: 7rem; }
  .markers { right: -0.35rem; }
  .table-marker { width: 1.55rem; height: 1.55rem; font-size: 0.5rem; }
}

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr; grid-template-rows: 2.5rem 4.5rem; }
  .score {
    height: 2.5rem;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }
  .controls { flex-wrap: wrap; justify-content: center; align-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
