:root {
  --felt: #0f5132;
  --felt-dark: #0a3d26;
  --felt-light: #157347;
  --gold: #e9c46a;
  --gold-bright: #f4d27a;
  --ink: #11241b;
  --cream: #f5f0e1;
  --black-suit: #1c1c1c;
  --red-suit: #c0392b;
  --danger: #e74c3c;
  --safe: #2ecc71;
  --panel: rgba(0, 0, 0, 0.25);
  --panel-line: rgba(233, 196, 106, 0.35);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 0%, var(--felt-light), var(--felt) 45%, var(--felt-dark) 100%);
  background-attachment: fixed;
  overflow-x: hidden; /* never scroll sideways on small screens */
}

#app { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }

.screen { animation: fade 0.25s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---- typography & brand ---- */
.brand { text-align: center; margin: 24px 0 18px; }
.brand h1 {
  font-size: clamp(2.4rem, 8vw, 4rem);
  letter-spacing: 0.12em;
  margin: 0;
  color: var(--gold-bright);
  text-shadow: 0 2px 0 #6b4e16, 0 4px 14px rgba(0,0,0,0.5);
}
.tagline { margin: 4px 0 0; color: var(--cream); opacity: 0.85; font-style: italic; }

h2 { margin-top: 0; color: var(--gold-bright); }
.muted { opacity: 0.75; font-size: 0.9rem; }
.black { color: #cfd8dc; }
.red { color: #ff8a80; }

/* ---- cards / panels ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin: 14px auto;
  max-width: 480px;
}
.landing-card { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
input {
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--panel-line);
  background: rgba(255,255,255,0.95);
  color: var(--ink);
  font-size: 1rem;
}
#code-input { text-transform: uppercase; letter-spacing: 0.25em; text-align: center; font-weight: 700; }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; }

.divider { display: flex; align-items: center; gap: 10px; opacity: 0.6; font-size: 0.8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--panel-line); }

/* ---- buttons ---- */
.btn {
  cursor: pointer;
  border: 1px solid var(--gold);
  background: rgba(0,0,0,0.18);
  color: var(--gold-bright);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(233,196,106,0.18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: var(--ink); border-color: var(--gold-bright); }
.btn.primary:hover:not(:disabled) { background: var(--gold-bright); }
.btn.big { padding: 13px; font-size: 1.05rem; }
.btn.small { padding: 6px 12px; font-size: 0.82rem; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,0.3); color: var(--cream); }
.btn.danger { border-color: var(--danger); color: #ffb3aa; }

.error-text { color: #ffb3aa; min-height: 1.1em; margin: 0; font-size: 0.88rem; }

/* ---- rules peek ---- */
.rules-peek summary { cursor: pointer; color: var(--gold-bright); font-weight: 600; }
.rules-peek ul { margin: 12px 0 0; padding-left: 18px; line-height: 1.7; }

/* ---- lobby ---- */
.code-pill {
  background: var(--gold); color: var(--ink);
  padding: 3px 12px; border-radius: 8px; letter-spacing: 0.25em; font-weight: 800;
}
.player-list { list-style: none; padding: 0; margin: 14px 0; }
.player-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border-radius: 9px; margin-bottom: 6px;
  background: rgba(0,0,0,0.2); border: 1px solid var(--panel-line);
}
.badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 20px; background: var(--gold); color: var(--ink); font-weight: 700; }
.badge.off { background: #555; color: #ccc; }

/* ---- status bar ---- */
#status-bar {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 14px;
}
.stat { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.stat-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; }
.stat-val { font-size: 1.25rem; font-weight: 800; color: var(--gold-bright); }
.stat.deck .stat-val { font-size: 0.95rem; }

/* ---- players grid ---- */
#players-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.player {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 12px; padding: 12px; position: relative;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.player.you { border-color: var(--gold); }
.player.to-act { box-shadow: 0 0 0 2px var(--gold-bright), var(--shadow); border-color: var(--gold-bright); }
.player.folded { opacity: 0.5; }
.player.eliminated { opacity: 0.6; filter: grayscale(0.5); }
.player.winner { box-shadow: 0 0 0 3px var(--safe); }

.player-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.player-name { font-weight: 700; font-size: 1.05rem; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 0.62rem; padding: 1px 7px; border-radius: 12px; font-weight: 700; text-transform: uppercase; }
.tag.host { background: var(--gold); color: var(--ink); }
.tag.turn { background: var(--gold-bright); color: var(--ink); }
.tag.fold { background: #607d8b; color: #fff; }
.tag.bust { background: var(--danger); color: #fff; }
.tag.audit { background: #9b59b6; color: #fff; }
.tag.win { background: var(--safe); color: #07331c; }
.tag.off { background: #555; color: #ccc; }

/* balance bar */
.bal-row { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 4px; }
.bal-num { font-size: 1.5rem; font-weight: 800; }
.bal-num.warn { color: #ffd28a; }
.bal-num.crit { color: var(--danger); }
.bar {
  height: 9px; border-radius: 6px; background: rgba(255,255,255,0.12); position: relative; overflow: hidden;
  border: 1px solid rgba(0,0,0,0.3);
}
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--safe), var(--gold)); transition: width 0.4s; }
.bar-mid { position: absolute; top: -2px; bottom: -2px; width: 2px; background: rgba(255,255,255,0.5); }

.chips-row { display: flex; justify-content: space-between; font-size: 0.85rem; margin-top: 8px; opacity: 0.95; }
.committed { color: var(--gold-bright); font-weight: 700; }

/* current roll */
.roll-now { display: flex; align-items: center; gap: 12px; margin-top: 10px; min-height: 56px; }
.die-svg { display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45)); }
.rolled-die { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.die-cap { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; opacity: 0.85; }
.die-label { font-size: 0.78rem; opacity: 0.8; }

/* dice roll buttons */
.die-btn {
  cursor: pointer; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 8px 6px; border-radius: 14px;
  transition: transform 0.1s ease, background 0.15s;
}
.die-btn:hover { background: rgba(255,255,255,0.08); transform: translateY(-4px); }
.die-btn:hover .die-svg { filter: drop-shadow(0 5px 7px rgba(0,0,0,0.5)); }
.die-btn:active { transform: translateY(-1px); }
.die-btn .die-cap { color: var(--cream); }

/* roll-in animation, played once per new roll */
@keyframes tumble {
  0% { transform: rotate(-200deg) scale(0.3); opacity: 0; }
  60% { transform: rotate(18deg) scale(1.15); opacity: 1; }
  100% { transform: rotate(0) scale(1); }
}
.just-rolled { animation: tumble 0.55s cubic-bezier(0.2, 0.8, 0.3, 1.25); transform-origin: center; }
.facedown {
  width: 26px; height: 36px; border-radius: 5px;
  background: repeating-linear-gradient(45deg, #7a1f1f, #7a1f1f 4px, #5e1717 4px, #5e1717 8px);
  border: 1px solid rgba(255,255,255,0.4);
}

/* store row */
.store { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; min-height: 20px; }
.store-item {
  display: flex; align-items: center; gap: 3px;
  font-size: 0.72rem; padding: 2px 6px; border-radius: 7px; background: rgba(0,0,0,0.25);
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.black { background: #cfd8dc; }
.dot.red { background: var(--red-suit); }
.delta-up { color: var(--safe); }
.delta-down { color: #ff8a80; }

/* ---- action area ---- */
#action-area {
  position: sticky; bottom: 0; margin-top: 16px;
  background: linear-gradient(180deg, transparent, var(--felt-dark) 30%);
  padding-top: 14px;
}
.prompt { text-align: center; font-size: 1.05rem; margin-bottom: 10px; min-height: 1.4em; color: var(--gold-bright); font-weight: 600; }
#controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.dice-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.bet-amount { width: 90px; }
.amount-group { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.2); padding: 6px; border-radius: 10px; }

/* ---- results banner ---- */
#results-banner {
  margin: 14px auto; max-width: 760px; text-align: center;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; padding: 12px;
}
.flip-list { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.flip {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 12px; border-radius: 10px; min-width: 92px;
}
.flip.black { background: rgba(207,216,220,0.16); }
.flip.red { background: rgba(192,57,43,0.2); }
.flip .who { font-weight: 700; font-size: 0.85rem; }
.flip .amt { font-size: 1.25rem; font-weight: 800; }

/* ---- log ---- */
#log-box { max-width: 760px; }
#log-box summary { cursor: pointer; color: var(--gold-bright); font-weight: 600; }
#log { font-size: 0.82rem; line-height: 1.55; max-height: 220px; overflow-y: auto; margin-top: 8px; }
#log div { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }

#leave-game-btn { display: block; margin: 18px auto 0; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1c1c1c; color: #fff; padding: 12px 18px; border-radius: 10px;
  border: 1px solid var(--danger); box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.ok { border-color: var(--safe); }

/* ============ phones ============ */
@media (max-width: 640px) {
  #app { padding: 12px 10px 92px; }

  .brand { margin: 14px 0 12px; }
  .brand h1 { font-size: clamp(2rem, 12vw, 3.2rem); letter-spacing: 0.05em; line-height: 1.05; }
  .tagline { font-size: 0.9rem; }
  .card { padding: 14px; }

  /* status bar: compact, wraps into tidy equal cells */
  #status-bar { gap: 6px 8px; padding: 8px 10px; justify-content: space-between; }
  .stat { flex: 1 1 28%; min-width: 0; }
  .stat-label { font-size: 0.58rem; }
  .stat-val { font-size: 1.05rem; }
  .stat.deck .stat-val { font-size: 0.78rem; }

  /* players: one per row, a touch tighter */
  #players-grid { grid-template-columns: 1fr; gap: 10px; }
  .player { padding: 11px; }
  .player-name { font-size: 1rem; }
  .bal-num { font-size: 1.35rem; }
  .roll-now { gap: 10px; min-height: 52px; }
  .roll-now .die-svg { width: 50px; height: 50px; }

  /* dice picker: smaller dice so a full set fits in two neat rows */
  #controls > .dice-grid { flex: 1 1 100%; gap: 6px; }
  .die-btn { padding: 6px 4px; }
  .die-btn .die-svg { width: 50px; height: 50px; }

  /* betting controls: large tap targets; amount input gets its own row */
  .prompt { font-size: 0.98rem; }
  #controls { gap: 8px; }
  #controls > .btn { flex: 1 1 42%; padding: 13px 10px; font-size: 1rem; }
  #controls > .btn.big { flex-basis: 100%; }
  .amount-group { flex: 1 1 100%; justify-content: center; }
  .bet-amount { width: 120px; font-size: 1rem; padding: 12px; }

  /* keep the toast clear of the sticky controls */
  .toast { bottom: 96px; }
  #log { max-height: 150px; }
  #log-box, #results-banner { max-width: 100%; }
}

/* very narrow phones */
@media (max-width: 380px) {
  .stat { flex-basis: 30%; }
  .die-btn .die-svg, .roll-now .die-svg { width: 46px; height: 46px; }
}
