:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --felt: #2f6b4f;
  --felt-edge: #24553e;
  --text: #1f2321;
  --muted: #6b716d;
  --line: #ddd8cc;
  --accent: #b5462f;
  --accent-text: #ffffff;
  --gold: #e2b23c;
  --red-suit: #c0392b;
  --black-suit: #1f2321;
  --card: #fffdf8;
  --card-edge: #cfc8b8;
  --danger: #a12a1a;
  --ok: #2f7a4f;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161a18;
    --surface: #202623;
    --felt: #1f4a37;
    --felt-edge: #173a2b;
    --text: #ece9e2;
    --muted: #9aa19c;
    --line: #34403a;
    --accent: #d8644a;
    --card: #f6f2e8;
    --card-edge: #a9a291;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161a18;
  --surface: #202623;
  --felt: #1f4a37;
  --felt-edge: #173a2b;
  --text: #ece9e2;
  --muted: #9aa19c;
  --line: #34403a;
  --accent: #d8644a;
  --card: #f6f2e8;
  --card-edge: #a9a291;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input { font: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar h1 { margin: 0; font-size: 1.25rem; letter-spacing: .02em; }
.who { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .95rem; }

.app { max-width: 1100px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input[type=text] {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); min-width: 0; flex: 1 1 180px;
}
.btn {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; }

.code { font: 700 2rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .15em; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

/* ---- game layout */
.game { display: grid; grid-template-columns: 1fr 260px; gap: 16px; }
@media (max-width: 860px) { .game { grid-template-columns: 1fr; } }

.status {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
  padding: 10px 14px; margin-bottom: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.status .msg { font-weight: 600; flex: 1 1 260px; }
.stake { font-weight: 700; }
.stake b { font-size: 1.2rem; color: var(--accent); }

.felt {
  background: var(--felt); border: 6px solid var(--felt-edge); border-radius: 18px;
  padding: 14px; display: grid; gap: 12px;
  grid-template-columns: 1fr 1fr; grid-template-areas: "top top" "left right" "me me";
}
.seat-top { grid-area: top; } .seat-left { grid-area: left; }
.seat-right { grid-area: right; } .seat-me { grid-area: me; }

.seat {
  background: rgba(255,255,255,.08); border: 2px solid transparent; border-radius: 12px;
  padding: 10px; color: #f3efe4;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(226,178,60,.25); }
.seat.out { opacity: .55; }
.seat-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.seat-name { font-weight: 700; }
.badge {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px; background: rgba(0,0,0,.28);
}
.badge.gold { background: var(--gold); color: #2a2000; }
.badge.red { background: var(--danger); color: #fff; }
.tallies { margin-left: auto; font-family: ui-monospace, Menlo, monospace; letter-spacing: .05em; }
.tallies .n { opacity: .8; margin-left: 4px; }

.played { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; max-width: 320px; }
.slot {
  aspect-ratio: 5 / 7; border: 1px dashed rgba(255,255,255,.25); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; font-size: .7rem; color: rgba(255,255,255,.45);
}
.slot.current { border-color: var(--gold); }
.backs { display: flex; gap: 3px; margin-top: 8px; min-height: 22px; }
.back { width: 15px; height: 21px; border-radius: 3px; background: repeating-linear-gradient(45deg, #8c2f22 0 3px, #a7402f 3px 6px); border: 1px solid rgba(255,255,255,.4); }

/* ---- cards */
.card {
  aspect-ratio: 5 / 7; width: 100%; border-radius: 7px; background: var(--card);
  border: 1px solid var(--card-edge); display: flex; flex-direction: column;
  align-items: center; justify-content: center; line-height: 1; font-weight: 700; user-select: none;
}
.card .r { font-size: 1.05rem; }
.card .s { font-size: 1.2rem; margin-top: 2px; }
.card.red { color: var(--red-suit); } .card.black { color: var(--black-suit); }
.card.won { box-shadow: 0 0 0 3px var(--gold); }

.hand { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.hand .card { width: 70px; font-size: 1.15rem; cursor: default; transition: transform .1s; }
.hand .card .r { font-size: 1.4rem; } .hand .card .s { font-size: 1.6rem; }
.hand .card.playable { cursor: pointer; }
.hand .card.playable:hover, .hand .card.playable:focus-visible { transform: translateY(-6px); outline: none; box-shadow: 0 0 0 3px var(--gold); }
.hand .card.dim { opacity: .45; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.decision {
  margin-top: 12px; padding: 12px; border-radius: 10px; background: rgba(0,0,0,.25);
}
.decision p { margin: 0 0 8px; }

.log { font-size: .88rem; max-height: 520px; overflow: auto; }
.log li { padding: 4px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }

@media (max-width: 560px) {
  .felt { grid-template-columns: 1fr; grid-template-areas: "top" "left" "right" "me"; }
  .hand .card { width: 58px; }
}
