:root {
  --bg: #14101f;
  --panel: #1f1930;
  --panel-2: #2a2240;
  --line: #3a3056;
  --text: #f1edfa;
  --muted: #a79dc0;
  --accent: #8f63f0;
  --accent-2: #b596ff;
  --good: #49c98b;
  --bad: #ef6a6a;
  --gold: #f2c14e;
  --card: #fbf9ff;
  --card-ink: #221a36;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html { color-scheme: dark; }
#app {
  max-width: 980px; margin: 0 auto; padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 2.2rem; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, input { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
}
button:hover:not(:disabled) { border-color: var(--accent-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button.ghost { background: transparent; }
button.tiny { padding: 4px 10px; font-size: 0.85rem; font-weight: 500; }

input[type="text"], input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
select {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px; font-size: 0.9rem;
}
.divider { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 2px 0; }
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* ---------- home ---------- */

.home { max-width: 460px; margin: 8vh auto 0; }
.home .tag { color: var(--accent-2); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }
.rules li { margin-bottom: 4px; }

/* ---------- lobby ---------- */

.code {
  font-size: 2rem; font-weight: 800; letter-spacing: 0.25em;
  color: var(--gold); font-variant-numeric: tabular-nums;
}
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.members li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--panel-2); border-radius: 10px; padding: 10px 12px;
}
.members li.empty { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--line); color: var(--text); margin-left: 6px;
  text-transform: uppercase; letter-spacing: 0.04em; vertical-align: middle;
}
.badge.ai { background: #3d2f6b; color: var(--accent-2); }
.badge.gold { background: var(--gold); color: #2a2000; }
.badge.bad { background: var(--bad); color: #2a0808; }
.badge.good { background: var(--good); color: #062a18; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.settings label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.settings input:disabled { opacity: 0.7; }

/* ---------- table ---------- */

.topbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; min-width: 0; }
.stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat .v { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat.limit { border-color: var(--gold); }
.stat.limit .v { color: var(--gold); }

.seats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.seat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: grid; gap: 8px; align-content: start; position: relative; min-width: 0;
}
.seat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-width: 0; }
.lvl { font-weight: 500; font-size: 0.78em; color: var(--muted); margin-left: 6px; }
.badge.first { background: transparent; border: 1px solid var(--gold); color: var(--gold); padding: 0 6px; }
.mine.turn { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(143, 99, 240, 0.35); }
.mine.winner { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.35); }
.mine .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mine .chips { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 700; }
.mine-chips { white-space: nowrap; color: var(--muted); font-size: 0.9rem; }
.mine-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mine-row .cards { flex: 1; min-width: 0; }
.seat.turn { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(143, 99, 240, 0.35); }
.seat.winner { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.35); }
.seat.folded, .seat.out { opacity: 0.5; }
.seat .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.seat .chips { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 700; white-space: nowrap; }
.seat .meta { font-size: 0.85rem; color: var(--muted); min-height: 1.3em; }

.cards { display: flex; gap: 6px; flex-wrap: wrap; min-height: 56px; }
.card {
  width: 40px; height: 56px; border-radius: 7px; display: grid; place-items: center;
  font-weight: 800; font-size: 1.25rem; background: var(--card); color: var(--card-ink);
  border: 2px solid transparent; font-variant-numeric: tabular-nums; position: relative;
}
.card.neg { color: #c62f2f; }
.card.back {
  background: repeating-linear-gradient(45deg, #5a3fb0, #5a3fb0 5px, #6b4dcc 5px, #6b4dcc 10px);
  border-color: #7a5ce0;
}
.card.hidden-mine { border-color: var(--accent); background: #e4dcfa; }
.card.hidden-mine::after {
  content: "hidden"; position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%);
  font-size: 0.6rem; font-weight: 600; color: var(--muted); letter-spacing: 0.04em;
}
.mine .cards { gap: 10px; min-height: 96px; padding-bottom: 16px; }
.mine .card { width: 58px; height: 80px; font-size: 1.8rem; border-radius: 10px; }
button.card { padding: 0; cursor: pointer; }
button.card.pick:hover { transform: translateY(-4px); border-color: var(--gold); }
button.card.pick { transition: transform 0.12s; }

.mine { display: grid; gap: 12px; background: var(--panel-2); }
.mine .total { display: grid; justify-items: center; gap: 0; text-align: center; line-height: 1.15; flex: none; }
.mine .total .k { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.mine .total b { font-size: 2rem; font-variant-numeric: tabular-nums; }
.mine .total .muted { font-size: 0.85rem; }
.mine .total .badge { margin: 2px 0 0; }
.over-limit { color: var(--bad); }
.on-limit { color: var(--good); }

.actions { display: grid; gap: 10px; }
.actions .buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.actions .buttons button { flex: 1 1 110px; padding: 14px 10px; font-size: 1.05rem; }
.raise { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: stretch; }
.amount { display: grid; grid-template-columns: 44px 68px 44px; gap: 4px; }
.amount button { padding: 0; font-size: 1.4rem; line-height: 1; }
.amount input { text-align: center; font-weight: 700; font-size: 1.1rem; padding: 8px 4px; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.amount input::-webkit-outer-spin-button, .amount input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.raise > button { white-space: nowrap; font-size: 1.05rem; }
.quick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.quick button { padding: 8px 2px; font-weight: 600; white-space: nowrap; }

.timer { height: 5px; background: var(--line); border-radius: 999px; overflow: hidden; }
.timer > i { display: block; height: 100%; width: 100%; background: var(--accent-2); transform-origin: left; }
.timer.low > i { background: var(--bad); }

.banner {
  border-radius: var(--radius); padding: 12px 16px; text-align: center; font-weight: 700;
  background: rgba(242, 193, 78, 0.14); border: 1px solid var(--gold); color: var(--gold);
}
.prompt { text-align: center; font-weight: 600; }

.log { max-height: 180px; overflow-y: auto; font-size: 0.88rem; color: var(--muted); display: grid; gap: 3px; }
.log .r { color: var(--text); font-weight: 600; margin-top: 4px; }

.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.standings li { display: flex; gap: 12px; align-items: center; background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.standings .place { font-size: 1.4rem; font-weight: 800; width: 2ch; color: var(--muted); }
.standings li:first-child { border: 1px solid var(--gold); }
.standings li:first-child .place { color: var(--gold); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--bad); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }
#toast.info { background: var(--accent); }

/* Phones: the limit, every hand and your own cards and buttons all fit on one screen. */
@media (max-width: 560px) {
  #app { padding-block: 8px; }
  #app > .stack { gap: 8px; }
  .panel { padding: 10px; }
  .topbar { gap: 6px; }
  .stat { padding: 4px 2px; border-radius: 10px; }
  .stat .k { font-size: 0.62rem; }
  .stat .v { font-size: 1.25rem; }
  .seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .seats.n1 { grid-template-columns: minmax(0, 1fr); }
  .seat { padding: 8px; gap: 5px; border-radius: 10px; }
  .seat .name, .seat .chips { font-size: 0.92rem; }
  .seat .meta { font-size: 0.75rem; min-height: 1.2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .seat .cards { gap: 4px; min-height: 40px; }
  .seat .card { width: 28px; height: 40px; font-size: 1rem; border-radius: 5px; border-width: 1px; }
  .mine { gap: 8px; }
  .mine .cards { gap: 6px; min-height: 0; padding-bottom: 13px; }
  .mine .card { width: 44px; height: 60px; font-size: 1.45rem; border-radius: 8px; }
  .card.hidden-mine::after { bottom: -13px; font-size: 0.55rem; }
  .mine .total b { font-size: 1.7rem; }
  .actions { gap: 8px; }
  .actions .buttons { gap: 8px; }
  .actions .buttons button { padding: 11px 8px; font-size: 1rem; }
  .raise { gap: 8px; }
  .amount { grid-template-columns: 42px 60px 42px; }
  .quick { gap: 5px; }
  .quick button { padding: 9px 0; font-size: 0.85rem; }
  .banner { padding: 9px 12px; font-size: 0.95rem; }
  .prompt { font-size: 0.95rem; }
}
