:root {
  --bg: #0e2219;
  --bg2: #143326;
  --felt: #1f6d48;
  --felt-dark: #154d33;
  --rail: #4a2d1a;
  --panel: #fbf7ee;
  --ink: #1d1d1b;
  --muted: #6b6b63;
  --accent: #e8b23a;
  --accent-ink: #3a2700;
  --red: #c8232c;
  --good: #1f8a4c;
  --bad: #b3261e;
  --cw: 62px;
  --ch: 88px;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, var(--bg2), var(--bg) 70%);
  color: #f2efe6;
}

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  background: #e9e4d6;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
}
button:hover:not(:disabled) { filter: brightness(1.06); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.big { font-size: 1.15rem; padding: 14px 40px; }
button.small { padding: 5px 11px; font-size: .85rem; }
button.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1px currentColor; opacity: .8; }

input, select {
  font: inherit;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid #cfc8b6;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
select:disabled, input:disabled { background: #f0ece2; color: #555; }

.muted { color: var(--muted); font-weight: 400; }
.red { color: var(--red); }
.black { color: #1d1d1b; }
.eyebrow { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }

.panel {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.panel h2 { margin: 0 0 14px; font-size: 1.15rem; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #2a2a28;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  z-index: 100;
  max-width: calc(100vw - 32px);
}
#banner {
  position: sticky;
  top: 0;
  background: var(--bad);
  color: #fff;
  text-align: center;
  padding: 6px;
  z-index: 50;
}
.connecting { text-align: center; padding: 80px 0; opacity: .7; }

/* ---- Home ---- */
.home { max-width: 420px; margin: 6vh auto 0; }
.home h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3.4rem;
  text-align: center;
  margin: 0;
  letter-spacing: -.02em;
}
.home h1 span { color: var(--accent); }
.tagline { text-align: center; opacity: .8; margin: 6px 0 24px; }
.home form { display: grid; gap: 14px; }
.home label { display: grid; gap: 6px; font-weight: 600; }
.home .row { display: flex; gap: 8px; }
.home .row input { text-transform: uppercase; letter-spacing: .15em; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #ddd5c3; }
.msg { margin: 0; color: var(--bad); }
.rules { margin-top: 16px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules p { line-height: 1.5; }

/* ---- Lobby ---- */
.lobby-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.lobby .code { font-size: 2.6rem; font-weight: 800; letter-spacing: .2em; color: var(--accent); }
.share { display: flex; gap: 8px; flex: 1; max-width: 460px; min-width: 260px; }
.cols { display: grid; grid-template-columns: 1fr 1.4fr; gap: 18px; }
.players { list-style: none; padding: 0; margin: 0 0 16px; }
.players li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 4px;
  border-bottom: 1px solid #e7e0cf;
  font-weight: 600;
}
.players li.offline { opacity: .55; }
.players button.ghost { color: var(--bad); }
.settings { display: grid; gap: 14px; }
.settings label { display: grid; gap: 5px; font-weight: 600; }
.settings small { font-weight: 400; color: var(--muted); }
.toggle { display: flex !important; gap: 10px; align-items: flex-start; cursor: pointer; }
.toggle input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--felt); }
.toggle span { display: grid; gap: 2px; }
.preview { background: #f1ecdf; border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.preview span { color: var(--muted); word-spacing: 2px; }
.start { text-align: center; margin: 24px 0; }

/* ---- Game ---- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 22px;
  background: rgba(0, 0, 0, .25);
  padding: 10px 14px;
  border-radius: var(--radius);
}
.topbar .spacer { flex: 1; }
.topbar .red { color: #ff7a7f; }
.topbar .black { color: #f2efe6; }

.table-wrap { padding: 12px 0; }
.table {
  position: relative;
  height: clamp(360px, 58vh, 540px);
  margin: 0 auto;
}
.felt {
  position: absolute;
  inset: 12% 10%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, var(--felt), var(--felt-dark));
  border: 14px solid var(--rail);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .45), 0 18px 40px rgba(0, 0, 0, .5);
}

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(10, 25, 18, .88);
  border: 2px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 112px;
  text-align: center;
  z-index: 3;
  transition: border-color .2s, box-shadow .2s;
}
.seat.me { background: rgba(40, 32, 8, .92); }
.seat.turn { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(232, 178, 58, .3), 0 0 22px rgba(232, 178, 58, .5); }
.seat.won { border-color: #7be3a5; }
.seat.offline { opacity: .5; }
.seat-name { font-weight: 700; white-space: nowrap; display: flex; gap: 5px; justify-content: center; align-items: center; }
.seat-bid { font-size: .85rem; white-space: nowrap; }
.seat-bid.exact { color: #7be3a5; font-weight: 700; }
.seat-bid.over { color: #ff8f8f; font-weight: 700; }
.seat-sub { font-size: .75rem; opacity: .7; white-space: nowrap; }
.offline-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff6b6b; display: inline-block; }
.table.crowded .seat { min-width: 0; padding: 4px 7px; font-size: .85rem; }
.chip {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .65rem;
  font-weight: 800;
}

.trump-box, .last-trick {
  position: absolute;
  z-index: 2;
  text-align: center;
  background: rgba(0, 0, 0, .25);
  padding: 6px 8px 8px;
  border-radius: 10px;
}
.trump-box { left: 0; top: 0; }
.last-trick { right: 0; top: 0; }
.trump-suit {
  width: calc(var(--cw) * .7);
  height: calc(var(--ch) * .7);
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 4px;
}
.mini-row { display: flex; gap: 3px; margin-top: 4px; justify-content: center; }

/* ---- Cards ---- */
.card {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  flex: none;
  background: #fff;
  border-radius: 7px;
  border: 1px solid #c9c3b4;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  padding: 0;
  font-weight: 700;
  user-select: none;
}
.card.red { color: var(--red); }
.card.black { color: #1d1d1b; }
.card .corner {
  position: absolute;
  top: 4px;
  left: 5px;
  font-size: .82rem;
  line-height: 1;
  text-align: center;
}
.card .corner.br { top: auto; left: auto; bottom: 4px; right: 5px; transform: rotate(180deg); }
.card .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.9rem;
}
.card.mini { --cw: 36px; --ch: 50px; margin-top: 4px; }
.card.mini .corner.br { display: none; }
.card.mini .pip { font-size: 1.1rem; padding-top: 10px; }
.card.mini .corner { font-size: .65rem; top: 3px; left: 3px; }

.trick-card {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
}
.trick-card.fresh { animation: drop .25s ease-out; }
.trick-card.winning { box-shadow: 0 0 0 3px #7be3a5, 0 0 22px rgba(123, 227, 165, .8); }
@keyframes drop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.status { text-align: center; font-size: 1.1rem; margin: 6px 0 10px; min-height: 1.5em; }
.status.your-turn { color: var(--accent); font-weight: 700; }

.bidbar, .offline-note {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.bidbar .bid { min-width: 44px; font-size: 1.1rem; background: var(--accent); color: var(--accent-ink); }
.bidbar .bid:disabled { background: #6b6b63; color: #ddd; text-decoration: line-through; }
.bidbar small { width: 100%; text-align: center; opacity: .8; }

.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  padding: 18px 8px 8px 26px;
  row-gap: 10px;
  min-height: calc(var(--ch) + 30px);
}
.hand .card { margin-left: -12px; transition: transform .12s, filter .12s; }
.hand .card.trump { box-shadow: 0 2px 6px rgba(0, 0, 0, .35), inset 0 -4px 0 var(--accent); }
.hand .card.playable { cursor: pointer; }
.hand .card.playable:hover { transform: translateY(-14px); }
.hand .card.unplayable { filter: brightness(.6) saturate(.5); cursor: not-allowed; }
.hand .card:disabled { cursor: default; }
.hand.active .card.playable { box-shadow: 0 0 0 2px var(--accent), 0 4px 10px rgba(0, 0, 0, .4); }

.log { margin-top: 18px; background: rgba(0, 0, 0, .2); border-radius: 10px; padding: 8px 14px; }
.log summary { cursor: pointer; opacity: .8; }
.log ol { list-style: none; padding: 0; margin: 8px 0; max-height: 220px; overflow-y: auto; font-size: .9rem; }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }

/* ---- Modals ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}
.modal {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px;
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  display: grid;
  gap: 14px;
  justify-items: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal.wide { width: min(900px, 100%); }
.modal h2 { margin: 0; text-align: center; }
.modal table { border-collapse: collapse; width: 100%; }
.modal th, .modal td { padding: 6px 8px; text-align: center; border-bottom: 1px solid #e7e0cf; white-space: nowrap; }
.modal th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.results tr.made td:first-child::before { content: "✓ "; color: var(--good); }
.results tr.missed td:first-child::before { content: "✗ "; color: var(--bad); }
.made { color: var(--good); }
.missed { color: var(--bad); }
.sheet-wrap { width: 100%; overflow-x: auto; }
.sheet td.made, .sheet td.missed { font-weight: 700; }
.sheet .bt { font-weight: 400; font-size: .8rem; color: var(--muted); margin-right: 4px; }
.sheet tr.current { background: #fff3cf; }
.sheet tr.future { color: #b5ae9c; }
.sheet tfoot td { border-top: 2px solid var(--ink); }
.small-print { font-size: .8rem; margin: 6px 0 0; text-align: center; }
.standings { margin: 0; padding: 0; list-style: none; width: min(320px, 100%); counter-reset: rank; }
.standings li {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px;
  border-bottom: 1px solid #e7e0cf;
  counter-increment: rank;
}
.standings li span::before { content: counter(rank) ". "; color: var(--muted); }
.standings li:first-child { font-size: 1.15rem; font-weight: 700; }

@media (max-width: 760px) {
  :root { --cw: 48px; --ch: 68px; }
  main { padding: 10px; }
  .cols { grid-template-columns: 1fr; }
  .card .pip { font-size: 1.4rem; }
  .card .corner { font-size: .7rem; }
  .seat { min-width: 0; padding: 4px 7px; font-size: .8rem; }
  .seat-sub { font-size: .68rem; }
  .table { height: clamp(340px, 56vh, 460px); }
  .last-trick, .trump-box { display: none; }
  .table.crowded .seat { font-size: .72rem; padding: 3px 5px; }
  .table.crowded .seat-sub { display: none; }
  .hand .card { margin-left: -14px; }
}
