/* ----------------------------------------------------------------
   Five Hundred — card-room styling
   Palette: baize #1c4b38 → #0d2b1f · walnut #4a2f1c/#2c1a0e
            card cream #faf6ec · ink #24211b · suit red #b0252b
            brass #c9a35c · parchment pad #f2ead8
---------------------------------------------------------------- */

:root {
  --baize-hi: #205a43;
  --baize-lo: #0d2b1f;
  --walnut-hi: #5a3a22;
  --walnut-lo: #2c1a0e;
  --card-face: #fbf7ee;
  --card-edge: #d8d0bd;
  --ink: #24211b;
  --suit-red: #b0252b;
  --brass: #c9a35c;
  --brass-dark: #8f6f35;
  --pad: #f2ead8;
  --pad-line: #d9cdb2;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  --display: "Fraunces", serif;
  --body: "Karla", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--body);
  background: #17130e;
  color: var(--ink);
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: var(--body); cursor: pointer; }

/* ---------------- landing page ---------------- */
#landing {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, var(--baize-hi), var(--baize-lo) 75%);
}
.landing-card { text-align: center; color: #efe8d8; }
.landing-title {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(3rem, 8vw, 5.5rem);
  letter-spacing: 0.02em;
  color: var(--brass);
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
}
.landing-sub { margin: 0.5rem 0 2rem; opacity: 0.75; font-size: 1.05rem; }
.landing-links { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }
.landing-links a {
  font-family: var(--display); font-weight: 600; font-size: 1.1rem;
  color: var(--ink); text-decoration: none;
  background: var(--card-face);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  padding: 1rem 1.6rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.landing-links a:hover { transform: translateY(-4px) rotate(-1deg); }

/* ---------------- room layout ---------------- */
.room {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 300px;
}
.table-wrap {
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
  min-width: 0;
}

/* walnut rail around the felt */
.rail {
  width: 100%; height: 100%;
  border-radius: 46px;
  padding: 16px;
  background:
    linear-gradient(135deg, var(--walnut-hi), var(--walnut-lo) 60%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.03) 0 2px, transparent 2px 7px);
  box-shadow:
    inset 0 2px 3px rgba(255, 235, 200, 0.25),
    inset 0 -3px 6px rgba(0,0,0,0.6),
    0 12px 40px rgba(0,0,0,0.7);
}
.felt {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 34px;
  background:
    radial-gradient(ellipse at 50% 38%, var(--baize-hi), var(--baize-lo) 80%);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.55),
    inset 0 2px 2px rgba(255,255,255,0.08);
  overflow: hidden;
}
/* subtle baize weave */
.felt::before {
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,0.02) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

/* ---------------- brass contract plaque (signature) ---------------- */
.plaque {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 6;
  padding: 3px;
  border-radius: 8px;
  background: linear-gradient(160deg, #e8cf95, var(--brass) 40%, var(--brass-dark));
  box-shadow: 0 3px 10px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.6);
}
.plaque-inner {
  font-family: var(--display); font-weight: 700;
  font-size: 0.95rem; letter-spacing: 0.06em;
  color: #3a2b10;
  background: linear-gradient(180deg, #dfc383, #c5a057);
  border-radius: 5px;
  padding: 6px 22px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
  white-space: nowrap;
}
.plaque-inner .suit-red { color: #8c1418; }

/* ---------------- seats ---------------- */
.seat {
  position: absolute; z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.seat-top   { top: 58px; left: 50%; transform: translateX(-50%); }
.seat-left  { left: 26px; top: 50%; transform: translateY(-50%); }
.seat-right { right: 26px; top: 50%; transform: translateY(-50%); }

.nameplate {
  font-family: var(--display); font-weight: 600; font-size: 0.9rem;
  color: #f0e8d4;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(201,163,92,0.4);
  border-radius: 999px;
  padding: 4px 14px;
  letter-spacing: 0.04em;
  display: flex; align-items: center; gap: 7px;
  white-space: nowrap;
}
.nameplate .tricks {
  font-family: var(--body); font-size: 0.72rem; font-weight: 700;
  background: var(--brass); color: #2f2308;
  border-radius: 999px; padding: 1px 7px;
}
.nameplate.turn {
  border-color: var(--brass);
  box-shadow: 0 0 12px rgba(201,163,92,0.55);
}
.nameplate.dealer::after {
  content: "dealer";
  font-family: var(--body); font-size: 0.62rem; letter-spacing: 0.1em;
  text-transform: uppercase; opacity: 0.7;
}
.nameplate.out { opacity: 0.45; }

/* fanned card backs for opponents */
.back-fan { display: flex; height: 54px; }
.back-fan .card-back {
  width: 36px; height: 52px;
  margin-left: -22px;
  border-radius: 5px;
  border: 2px solid #f4efe2;
  background:
    radial-gradient(circle at 50% 50%, #7b1f24 0 25%, transparent 26%),
    repeating-linear-gradient(45deg, #5e161b 0 4px, #6f1b20 4px 8px);
  background-color: #5e161b;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.back-fan .card-back:first-child { margin-left: 0; }
.seat-left .back-fan, .seat-right .back-fan { height: 46px; }
.seat-left .card-back, .seat-right .card-back { width: 32px; height: 46px; }

/* ---------------- playing cards ---------------- */
.card {
  position: relative;
  width: var(--cw, 74px);
  height: calc(var(--cw, 74px) * 1.42);
  background: linear-gradient(160deg, #fffdf6, var(--card-face) 55%, #f1ead9);
  border: 1px solid var(--card-edge);
  border-radius: calc(var(--cw, 74px) * 0.09);
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
  color: var(--ink);
  user-select: none;
  flex-shrink: 0;
}
.card.red { color: var(--suit-red); }
.card .idx {
  position: absolute;
  top: 4%; left: 6%;
  text-align: center; line-height: 1;
  font-family: var(--display); font-weight: 700;
  font-size: calc(var(--cw, 74px) * 0.21);
}
.card .idx .s { display: block; font-size: calc(var(--cw, 74px) * 0.18); }
.card .idx.b {
  top: auto; left: auto; bottom: 4%; right: 6%;
  transform: rotate(180deg);
}
.card .pips {
  position: absolute; inset: 18% 22%;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: repeat(7, 1fr);
  align-items: center; justify-items: center;
  font-size: calc(var(--cw, 74px) * 0.19);
}
.card .pips .p { grid-column: var(--c); grid-row: var(--r); }
.card .pips .p.flip { transform: rotate(180deg); }
.card .court {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 2%;
}
.card .court .letter {
  font-family: var(--display); font-weight: 900;
  font-size: calc(var(--cw, 74px) * 0.52);
  line-height: 1;
}
.card .court .cs { font-size: calc(var(--cw, 74px) * 0.26); }
.card.joker .court .letter { font-size: calc(var(--cw, 74px) * 0.4); color: var(--brass-dark); }
.card.joker .idx { color: var(--brass-dark); }
.card.joker .court .cs { font-size: calc(var(--cw, 74px) * 0.34); }

/* ---------------- my hand ---------------- */
.my-area {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
  padding-bottom: 10px; z-index: 5;
}
.my-nameplate { margin-bottom: 6px; }
.my-hand {
  display: flex; justify-content: center;
  height: calc(var(--cw, 74px) * 1.42 + 26px);
  align-items: flex-end;
}
.my-hand .card {
  margin-left: calc(var(--cw, 74px) * -0.42);
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.2s;
  transform: translateY(var(--lift, 0)) rotate(var(--rot, 0deg));
  transform-origin: 50% 120%;
}
.my-hand .card:first-child { margin-left: 0; }
.my-hand .card.playable { cursor: pointer; }
.my-hand .card.playable:hover {
  transform: translateY(calc(var(--lift, 0px) - 16px)) rotate(var(--rot, 0deg));
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  z-index: 4;
}
.my-hand .card.dim { opacity: 0.45; }
.my-hand .card.selected {
  transform: translateY(calc(var(--lift, 0px) - 22px)) rotate(var(--rot, 0deg));
  box-shadow: 0 0 0 3px var(--brass), 0 8px 16px rgba(0,0,0,0.5);
}

/* ---------------- trick area ---------------- */
.trick-area {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 2;
}
.trick-card {
  position: absolute; left: 50%; top: 46%;
  --cw: 64px;
  transition: transform 0.25s ease;
}
.trick-card.rel-0 { transform: translate(-50%, -14%) rotate(2deg); }
.trick-card.rel-1 { transform: translate(-108%, -58%) rotate(-7deg); }
.trick-card.rel-2 { transform: translate(-50%, -104%) rotate(4deg); }
.trick-card.rel-3 { transform: translate(8%, -58%) rotate(8deg); }
.trick-note {
  position: absolute; left: 50%; top: 66%;
  transform: translateX(-50%);
  font-size: 0.78rem; color: #d8cfae; opacity: 0.9;
  background: rgba(0,0,0,0.3); border-radius: 999px; padding: 3px 12px;
}

.table-message {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 4;
  font-size: 0.86rem; color: #e9e1c8;
  background: rgba(0,0,0,0.32);
  border-radius: 999px;
  padding: 5px 16px;
  max-width: 70%;
  text-align: center;
  pointer-events: none;
}

/* ---------------- lobby ---------------- */
.lobby-overlay {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 24, 17, 0.55);
}
.lobby-card {
  background: var(--pad);
  border-radius: 14px;
  padding: 26px 30px;
  width: min(480px, 92%);
  box-shadow: var(--shadow);
  text-align: center;
}
.lobby-card h2 {
  font-family: var(--display); font-weight: 700; font-size: 1.5rem;
  margin-bottom: 4px;
}
.lobby-card .sub { font-size: 0.85rem; opacity: 0.7; margin-bottom: 18px; }
.team-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.team-col {
  border: 1px dashed var(--pad-line);
  border-radius: 10px; padding: 12px;
}
.team-col h4 {
  font-family: var(--display); font-size: 0.95rem; margin-bottom: 10px;
  color: var(--brass-dark);
}
.seat-btn {
  display: block; width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--pad-line);
  background: #fbf6ea;
  font-size: 0.95rem; font-weight: 700;
}
.seat-btn:last-child { margin-bottom: 0; }
.seat-btn.taken { background: var(--baize-hi); color: #f4eeda; border-color: transparent; cursor: default; }
.seat-btn.mine { outline: 3px solid var(--brass); }
.seat-btn:not(.taken):hover { background: #f3ebd6; }

/* ---------------- bidding panel ---------------- */
.bid-panel {
  position: absolute; z-index: 8;
  left: 50%; bottom: calc(var(--cw, 74px) * 1.42 + 62px);
  transform: translateX(-50%);
  background: var(--pad);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  width: min(430px, 92%);
}
.bid-panel h3 {
  font-family: var(--display); font-size: 1.05rem; text-align: center;
  margin-bottom: 10px;
}
.bid-grid {
  display: grid; grid-template-columns: 56px repeat(5, 1fr);
  gap: 5px; align-items: center;
  margin-bottom: 8px;
}
.bid-grid .rowlab {
  font-size: 1.05rem; text-align: center; font-weight: 700;
}
.bid-grid .rowlab.nt { font-size: 0.72rem; letter-spacing: 0.04em; }
.bid-btn {
  padding: 7px 0;
  border-radius: 7px;
  border: 1px solid var(--pad-line);
  background: #fbf6ea;
  font-weight: 700; font-size: 0.85rem;
}
.bid-btn small { display: block; font-weight: 400; font-size: 0.62rem; opacity: 0.6; }
.bid-btn:disabled { opacity: 0.3; cursor: default; }
.bid-btn:not(:disabled):hover { background: var(--brass); }
.bid-specials { display: flex; gap: 6px; }
.bid-specials .bid-btn { flex: 1; }
.bid-specials .pass-btn { background: #4a2f1c; color: #f0e6d2; border: none; }
.bid-specials .pass-btn:hover { background: #5f3d24; }

/* ---------------- kitty bar ---------------- */
.kitty-bar {
  position: absolute; z-index: 8;
  left: 50%; bottom: calc(var(--cw, 74px) * 1.42 + 62px);
  transform: translateX(-50%);
  background: var(--pad);
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.kitty-bar p { font-size: 0.9rem; margin-bottom: 8px; }

/* ---------------- hand end / game over ---------------- */
.handend-overlay {
  position: absolute; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 24, 17, 0.5);
}
.handend-card {
  background: var(--pad);
  border-radius: 14px;
  padding: 26px 34px;
  text-align: center;
  box-shadow: var(--shadow);
  width: min(440px, 92%);
}
.handend-card h2 { font-family: var(--display); font-size: 1.5rem; margin-bottom: 6px; }
.handend-card .result-line { font-size: 0.95rem; margin-bottom: 4px; }
.handend-card .made { color: #1d6b42; font-weight: 700; }
.handend-card .down { color: var(--suit-red); font-weight: 700; }
.handend-card .scores-line {
  font-family: var(--display); font-size: 1.1rem; margin: 12px 0 16px;
}
.handend-card .btn { margin: 0 4px; }

/* ---------------- buttons ---------------- */
.btn {
  font-weight: 700; font-size: 0.9rem;
  border: none; border-radius: 8px;
  padding: 10px 22px;
  background: linear-gradient(180deg, #dfc383, var(--brass));
  color: #33260c;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.5);
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-ghost {
  background: transparent; color: inherit;
  border: 1px solid var(--pad-line); box-shadow: none;
}
.btn-small { padding: 6px 14px; font-size: 0.78rem; }

/* ---------------- score pad ---------------- */
.scorepad {
  background:
    repeating-linear-gradient(180deg, transparent 0 27px, var(--pad-line) 27px 28px),
    var(--pad);
  border-left: 6px solid var(--walnut-lo);
  overflow-y: auto;
  padding: 0;
}
.pad-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--walnut-lo); color: var(--brass);
  padding: 10px 16px;
}
.pad-title { font-family: var(--display); font-weight: 700; letter-spacing: 0.05em; }
.pad-toggle { display: none; background: none; border: none; color: var(--brass); font-size: 1rem; }
.pad-body { padding: 14px 16px; }
.pad-section { margin-bottom: 18px; }
.pad-h {
  font-family: var(--display); font-size: 0.95rem;
  border-bottom: 2px solid var(--brass);
  display: inline-block; margin-bottom: 8px;
}
.pad-quiet { font-size: 0.8rem; opacity: 0.75; }
.team-score {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0;
}
.team-score .names { font-size: 0.85rem; font-weight: 700; }
.team-score .pts { font-family: var(--display); font-size: 1.4rem; font-weight: 700; }
.team-score .pts.neg { color: var(--suit-red); }
.bid-line { font-size: 0.8rem; padding: 2px 0; }
.lb-row {
  display: flex; justify-content: space-between;
  font-size: 0.88rem; padding: 3px 0;
}
.lb-row .lb-wins { font-family: var(--display); font-weight: 700; }
.lb-row.top .lb-name::after { content: " 🏆"; }

/* ---------------- joker modal / toast ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--pad); border-radius: 12px;
  padding: 22px 26px; text-align: center;
  box-shadow: var(--shadow);
}
.modal h3 { font-family: var(--display); margin-bottom: 4px; }
.modal p { font-size: 0.85rem; opacity: 0.8; margin-bottom: 14px; }
.joker-suits { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.joker-suits button {
  font-size: 1.7rem; width: 54px; height: 54px;
  border-radius: 10px; border: 1px solid var(--pad-line); background: #fbf6ea;
}
.joker-suits button:hover { background: var(--brass); }
.joker-suits .red { color: var(--suit-red); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 30;
  background: #3a2416; color: #f2e8d2;
  border-radius: 999px; padding: 9px 20px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .room { grid-template-columns: 1fr; grid-template-rows: 78vh auto; height: auto; }
  .table-wrap { height: 78vh; padding: 8px; }
  .rail { border-radius: 30px; padding: 10px; }
  .felt { border-radius: 22px; --cw: 56px; }
  .felt .my-hand .card, .felt .card { --cw: 56px; }
  .trick-card { --cw: 50px; }
  .seat-left { left: 8px; }
  .seat-right { right: 8px; }
  .seat-left .nameplate, .seat-right .nameplate { font-size: 0.72rem; padding: 3px 9px; }
  .back-fan .card-back { width: 26px; height: 38px; margin-left: -17px; }
  .plaque-inner { font-size: 0.78rem; padding: 4px 12px; }
  .table-message { top: 48px; font-size: 0.74rem; }
  .bid-panel, .kitty-bar { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
  .scorepad { border-left: none; border-top: 6px solid var(--walnut-lo); }
  .pad-toggle { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
