:root {
  --felt: #0f3d2e;
  --felt-2: #13513c;
  --felt-edge: #0a2a20;
  --ink: #f4f1e8;
  --muted: #a9c2b6;
  --gold: #e6b84a;
  --gold-ink: #2a1f05;
  --red: #c8322f;
  --card: #fffdf7;
  --card-ink: #1b1b1b;
  --panel: rgba(6, 26, 20, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --us: #4fd1a1;
  --them: #f08a6a;
  --cw: 58px;
  --ch: 84px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 35%, var(--felt-2), var(--felt) 55%, var(--felt-edge));
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; color: var(--ink); background: rgba(255,255,255,.1); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-gold { background: var(--gold); color: var(--gold-ink); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-small { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn-lg { padding: 14px 26px; font-size: 18px; border-radius: 12px; }
.link-btn { background: none; border: 0; color: var(--gold); font-weight: 600; padding: 6px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: rgba(0,0,0,.28); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; }
.brand-mark { font-size: 26px; line-height: 1; color: var(--gold); }
.brand-name { font-family: Oswald, Impact, sans-serif; font-weight: 700; letter-spacing: .12em; font-size: 20px; }
.room-info { display: flex; align-items: center; gap: 8px; }
.code-pill { font-family: Oswald, sans-serif; letter-spacing: .18em; background: rgba(255,255,255,.08); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; font-size: 14px; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; position: relative; }
.user-chip { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; color: var(--ink); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--gold); color: var(--gold-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.menu { position: absolute; right: 0; top: 44px; background: #0c2a20; border: 1px solid var(--line); border-radius: 12px; padding: 6px; min-width: 180px; box-shadow: 0 12px 30px rgba(0,0,0,.4); }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--ink); padding: 9px 12px; border-radius: 8px; }
.menu button:hover { background: rgba(255,255,255,.08); }

/* ---------- home ---------- */
.screen { min-height: calc(100vh - 56px); }
.hero { max-width: 560px; margin: 0 auto; padding: 56px 20px; text-align: center; }
.hero h1 { font-family: Oswald, Impact, sans-serif; font-size: clamp(36px, 8vw, 56px); line-height: 1.05; margin: 18px 0 10px; text-transform: uppercase; letter-spacing: .02em; }
.lead { color: var(--muted); font-size: 18px; line-height: 1.5; margin: 0 0 28px; }
.hero-cards { display: flex; justify-content: center; gap: 0; height: 130px; }
.hero-cards .card { margin: 0 -10px; }
.hero-cards .tilt { transform: rotate(10deg) translateY(6px); }
.hero-cards .card:first-child { transform: rotate(-8deg); }
.home-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 18px; }
.join-form { display: flex; gap: 8px; }
.join-form input { width: 140px; text-transform: uppercase; letter-spacing: .2em; text-align: center; }
input[type], .join-form input, .chat-form input, .modal input {
  background: rgba(0,0,0,.3); border: 1px solid var(--line); color: var(--ink); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus { border-color: var(--gold); }

/* ---------- cards ---------- */
.card { width: var(--cw); height: var(--ch); background: var(--card); color: var(--card-ink); border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.35); position: relative; display: inline-block; user-select: none; flex: 0 0 auto; }
.card .r { position: absolute; top: 4px; left: 6px; font-weight: 700; font-size: 17px; line-height: 1; }
.card .s { position: absolute; bottom: 4px; right: 6px; font-size: 26px; line-height: 1; }
.card .s2 { position: absolute; top: 22px; left: 6px; font-size: 13px; line-height: 1; }
.card.red { color: var(--red); }
.card.big { --cw: 84px; --ch: 120px; width: var(--cw); height: var(--ch); }
.card.big .r { font-size: 26px; }
.card.big .s { font-size: 40px; }
.card.back { background: repeating-linear-gradient(45deg, #1f6b52 0 6px, #185a45 6px 12px); border: 3px solid var(--card); }

/* ---------- room ---------- */
.scorebar { display: flex; justify-content: center; gap: 10px; padding: 10px 12px 0; flex-wrap: wrap; }
.team { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; }
.team .label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.team .pts { font-family: Oswald, sans-serif; font-size: 24px; }
.team .bags { font-size: 12px; color: var(--muted); }
.team.us .pts { color: var(--us); }
.team.them .pts { color: var(--them); }
.target { font-size: 12px; color: var(--muted); align-self: center; }

.table {
  display: grid;
  grid-template-columns: 1fr minmax(240px, 380px) 1fr;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  grid-template-areas: ". top ." "left center right" ". bottom .";
  gap: 10px; max-width: 900px; margin: 10px auto 0; padding: 0 12px;
}
.pos2 { grid-area: top; justify-self: center; }
.pos1 { grid-area: left; align-self: center; justify-self: end; }
.pos3 { grid-area: right; align-self: center; justify-self: start; }
.pos0 { grid-area: bottom; justify-self: center; }
.center { grid-area: center; position: relative; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.06), rgba(0,0,0,.08) 70%); border: 1px solid rgba(255,255,255,.06); min-height: 240px; }

.seat { min-width: 132px; max-width: 170px; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px; text-align: center; transition: border-color .2s, box-shadow .2s; }
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(230,184,74,.18), 0 0 24px rgba(230,184,74,.25); }
.seat.away { opacity: .6; }
.seat .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.seat .chips { display: flex; justify-content: center; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.1); }
.chip.gold { background: var(--gold); color: var(--gold-ink); }
.chip.dealer { background: #fff; color: #111; }
.chip.us { background: rgba(79,209,161,.2); color: var(--us); }
.chip.them { background: rgba(240,138,106,.2); color: var(--them); }
.seat .stats { font-family: Oswald, sans-serif; font-size: 18px; margin-top: 4px; }
.seat .stats small { font-family: Inter, sans-serif; font-size: 11px; color: var(--muted); }
.seat.empty { border-style: dashed; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; min-height: 74px; }

.trick { position: absolute; inset: 0; }
.trick .card { position: absolute; left: 50%; top: 50%; transition: transform .25s ease; }
.trick .t0 { transform: translate(-50%, -8%); }
.trick .t1 { transform: translate(-125%, -50%) rotate(-6deg); }
.trick .t2 { transform: translate(-50%, -92%); }
.trick .t3 { transform: translate(25%, -50%) rotate(6deg); }
.trick .win { box-shadow: 0 0 0 3px var(--gold), 0 4px 14px rgba(0,0,0,.4); }
.status { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: rgba(0,0,0,.55); border: 1px solid var(--line); padding: 5px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.status.mine { background: var(--gold); color: var(--gold-ink); font-weight: 700; }
.center-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); font-size: 14px; }

.panel { max-width: 720px; margin: 22px auto 0; padding: 0 12px; text-align: center; }
.panel h3 { margin: 0 0 10px; font-family: Oswald, sans-serif; letter-spacing: .06em; text-transform: uppercase; font-size: 18px; }
.bid-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; max-width: 460px; margin: 0 auto; }
.bid-grid button { padding: 10px 0; border-radius: 8px; border: 1px solid var(--line); background: rgba(0,0,0,.3); color: var(--ink); font-weight: 700; font-size: 16px; }
.bid-grid button:hover { border-color: var(--gold); }
.bid-grid .nil { grid-column: span 2; background: rgba(230,184,74,.15); color: var(--gold); }
.lobby-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.lobby-row input { width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--ink); padding: 6px 12px; }
.seg button.on { background: var(--gold); color: var(--gold-ink); font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

.hand { display: flex; justify-content: center; padding: 18px 12px 8px; min-height: calc(var(--ch) + 40px); }
.hand .card { margin-left: calc(var(--cw) * -0.38); transition: transform .12s; }
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { box-shadow: 0 0 0 2px var(--gold), 0 4px 10px rgba(0,0,0,.35); }

.hand .card.dim { filter: brightness(.62); }
.hand .card.tappable { cursor: pointer; }
.hand .card.tappable:hover { transform: translateY(-14px); }
.btn-red { background: var(--red); color: #fff; }
.chat-log .sys { background: rgba(230,184,74,.1); border-radius: 8px; padding: 4px 8px; }

.toolbar { display: flex; justify-content: center; gap: 8px; padding: 8px 12px 24px; }
.badge { background: var(--red); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

.chat { position: fixed; right: 12px; bottom: 12px; width: min(340px, calc(100vw - 24px)); height: 360px; background: #0b271e; border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; z-index: 30; box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.x { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.chat-log b { color: var(--gold); margin-right: 6px; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #0c2a20; border: 1px solid var(--line); border-radius: 16px; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; position: relative; }
.modal h2 { font-family: Oswald, sans-serif; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 14px; }
.modal .x { position: absolute; top: 12px; right: 14px; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal input { width: 100%; }
.tabs { display: flex; gap: 4px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; font-weight: 600; }
.tabs button.on { background: rgba(255,255,255,.1); color: var(--ink); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.form-err { color: #ff9a8a; font-size: 14px; min-height: 18px; }
#gbtn { display: flex; justify-content: center; min-height: 44px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.stat .v { font-family: Oswald, sans-serif; font-size: 26px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat.hl .v { color: var(--gold); }
table.lb, table.sum { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lb th, table.lb td, table.sum th, table.sum td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.lb th:nth-child(-n+2), table.lb td:nth-child(-n+2), table.sum th:first-child, table.sum td:first-child { text-align: left; }
table.lb th, table.sum th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr.me td { color: var(--gold); }
.big-result { text-align: center; font-family: Oswald, sans-serif; font-size: 34px; text-transform: uppercase; margin: 4px 0 12px; }
.big-result.win { color: var(--us); }
.big-result.loss { color: var(--them); }
.modal-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.mini-trick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.mini-trick .who { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; max-width: var(--cw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; transition: all .25s; z-index: 60; pointer-events: none; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  :root { --cw: 46px; --ch: 66px; }
  .brand-name { display: none; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .user-chip .nm { display: none; }
  .user-chip { padding: 4px; }
  .table { grid-template-columns: 1fr 1.5fr 1fr; gap: 6px; padding: 0 6px; }
  .center { min-height: 200px; border-radius: 24px; }
  .seat { min-width: 0; max-width: 112px; padding: 6px; border-radius: 10px; }
  .seat .nm { font-size: 13px; }
  .seat .stats { font-size: 15px; }
  .card .r { font-size: 14px; top: 3px; left: 4px; }
  .card .s { font-size: 20px; }
  .card .s2 { top: 18px; left: 4px; font-size: 11px; }
  .hand .card { margin-left: calc(var(--cw) * -0.45); }
  
  .bid-grid { grid-template-columns: repeat(5, 1fr); }
  .bid-grid .nil { grid-column: span 1; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* password show/hide */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--gold); font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 8px; }
.pw-toggle:hover { background: rgba(255,255,255,.14); }
