:root {
  --bg: #0c1424;
  --bg-2: #142038;
  --bg-3: #1d2c4c;
  --ink: #f1f3fb;
  --muted: #9ba6c6;
  --gold: #f2c14e;
  --felt: #0f6b3e;
  --felt-2: #0a5130;
  --red: #c8102e;
  --team0: #3aa0ff;
  --team1: #ff6b6b;
  --line: rgba(255, 255, 255, 0.12);
  --cw: clamp(48px, 11vw, 76px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; background: radial-gradient(900px 500px at 50% -15%, rgba(200, 16, 46, 0.25), transparent 70%), var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.muted { color: var(--muted); }
.err { color: var(--team1); }

.hub-tabs { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: rgba(12, 20, 36, 0.92); overflow-x: auto; }
.hub-tabs[hidden] { display: none; }
.hub-brand { font-weight: 900; text-decoration: none; color: var(--ink); margin-right: 8px; white-space: nowrap; }
.hub-brand span { color: var(--gold); }
.hub-tab { text-decoration: none; color: var(--muted); font-weight: 700; font-size: 13px; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.hub-tab[aria-current="page"] { background: var(--gold); color: #1a1400; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; max-width: 1100px; margin: 0 auto; }
.logo { background: none; border: 0; font-size: 21px; font-weight: 900; padding: 0; letter-spacing: 0.02em; }
.logo span { color: var(--gold); font-weight: 800; }
.top-actions { display: flex; gap: 6px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); font-weight: 800; }
.sound-toggle[aria-pressed="false"] { opacity: 0.4; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }

.btn { border: 1px solid var(--line); background: var(--bg-2); border-radius: 12px; padding: 10px 16px; font-weight: 800; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1a1400; border-color: var(--gold); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.input { font: 600 16px system-ui, sans-serif; color: var(--ink); background: var(--bg); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 10px; padding: 10px 12px; width: 100%; }
.row { display: flex; gap: 8px; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 900; }

/* home */
.home { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; align-items: start; padding-top: 10px; }
.intro h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.05; margin: 0 0 10px; }
.intro h1 span { color: var(--gold); }
.intro h2 { font-size: 18px; margin: 18px 0 6px; }
.intro p, .intro li { color: #cfd5ec; }
.intro ul { padding-left: 18px; margin: 6px 0; }
.intro .tagline { font-weight: 800; color: var(--gold); }
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: grid; gap: 12px; position: sticky; top: 12px; }
.field { display: grid; gap: 6px; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.toggle { display: flex; gap: 10px; align-items: center; font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--gold); }
.divider { text-align: center; color: var(--muted); font-size: 12px; letter-spacing: 0.12em; }
@media (max-width: 820px) { .home { grid-template-columns: 1fr; } .panel { position: static; } }

/* lobby */
.lobby { text-align: center; padding-top: 10px; }
.lobby .code { font: 900 46px/1 ui-monospace, monospace; letter-spacing: 0.25em; color: var(--gold); margin: 6px 0; }
.seat-table { position: relative; width: min(420px, 100%); aspect-ratio: 1; margin: 18px auto; }
.seat-table .felt { position: absolute; inset: 22%; border-radius: 50%; background: radial-gradient(circle, var(--felt), var(--felt-2)); box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5), 0 0 0 8px #3b2414; }
.seat-btn { position: absolute; width: 156px; transform: translate(-50%, -50%); background: var(--bg-2); border: 2px dashed var(--line); border-radius: 14px; padding: 10px 8px; display: grid; gap: 2px; }
.seat-btn.taken { border-style: solid; }
.seat-btn.t0 { border-color: var(--team0); }
.seat-btn.t1 { border-color: var(--team1); }
.seat-btn.me { box-shadow: 0 0 0 3px var(--gold); }
.seat-btn .team { font-size: 11px; font-weight: 900; letter-spacing: 0.08em; }
.seat-btn.t0 .team { color: var(--team0); } .seat-btn.t1 .team { color: var(--team1); }
.pos-bottom { left: 50%; top: 90%; } .pos-right { left: 88%; top: 50%; } .pos-top { left: 50%; top: 10%; } .pos-left { left: 12%; top: 50%; }

/* game layout */
.game { display: grid; grid-template-columns: 1fr 260px; gap: 14px; }
@media (max-width: 900px) { .game { grid-template-columns: 1fr; } }
.scorebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; margin-bottom: 10px; }
.score { display: flex; gap: 10px; align-items: center; font-weight: 900; }
.score .t { padding: 4px 10px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.score .t0 { background: rgba(58, 160, 255, 0.18); color: var(--team0); }
.score .t1 { background: rgba(255, 107, 107, 0.18); color: var(--team1); }
.contract-chip { font-weight: 900; background: var(--bg); border-radius: 999px; padding: 4px 12px; border: 1px solid var(--line); }
.contract-chip .suit-r { color: #ff5a6a; }

.table {
  position: relative; border-radius: 26px; background: radial-gradient(ellipse at center, #13804a, var(--felt) 45%, var(--felt-2));
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5), 0 0 0 10px #3b2414, 0 20px 50px rgba(0, 0, 0, 0.5);
  height: clamp(420px, 62vh, 620px); margin: 10px 4px;
}
.player { position: absolute; display: grid; justify-items: center; gap: 4px; z-index: 2; }
.player.top { top: 12px; left: 50%; transform: translateX(-50%); }
.player.left { left: 14px; top: 50%; transform: translateY(-50%); }
.player.right { right: 14px; top: 50%; transform: translateY(-50%); }
.player.bottom { bottom: 10px; left: 50%; transform: translateX(-50%); width: 96%; }
.nameplate { display: flex; gap: 6px; align-items: center; background: rgba(0, 0, 0, 0.45); border-radius: 999px; padding: 4px 10px; font-weight: 800; font-size: 13px; border: 2px solid transparent; white-space: nowrap; }
.nameplate.t0 { border-color: rgba(58, 160, 255, 0.7); } .nameplate.t1 { border-color: rgba(255, 107, 107, 0.7); }
.nameplate.turn { box-shadow: 0 0 0 3px var(--gold), 0 0 16px rgba(242, 193, 78, 0.8); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #fff3b0, 0 0 26px rgba(242, 193, 78, 1); } }
.chip { font-size: 10px; font-weight: 900; border-radius: 999px; padding: 1px 6px; background: var(--gold); color: #1a1400; }
.chip.off { background: rgba(255, 255, 255, 0.2); color: #fff; }
.backs { display: flex; }
.backs .card { margin-left: calc(var(--cw) * -0.72); --cw: clamp(30px, 6vw, 44px); }
.backs .card:first-child { margin-left: 0; }
.player.left .backs, .player.right .backs { flex-direction: column; }
.player.left .backs .card, .player.right .backs .card { margin-left: 0; margin-top: calc(var(--cw) * -1.1); }
.player.left .backs .card:first-child, .player.right .backs .card:first-child { margin-top: 0; }
.bubble { background: #fff; color: #111; font-weight: 900; font-size: 13px; border-radius: 12px; padding: 4px 10px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); animation: pop 0.25s ease-out; white-space: nowrap; }
.bubble.coinche { background: var(--red); color: #fff; }
.bubble.ann { background: var(--gold); }

/* cards */
.card {
  width: var(--cw); height: calc(var(--cw) * 1.42); border-radius: calc(var(--cw) * 0.1); background: #fffdf8; color: #151515;
  border: 1px solid rgba(0, 0, 0, 0.25); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35); position: relative; flex: none; padding: 0;
  display: block; user-select: none;
}
.card.red { color: var(--red); }
.card .c-tl { position: absolute; top: 4%; left: 8%; font-weight: 900; font-size: calc(var(--cw) * 0.26); line-height: 0.9; text-align: center; }
.card .c-tl small { display: block; font-size: 0.85em; }
.card .c-mid { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cw) * 0.62); padding-top: 12%; }
.card .c-face { position: absolute; inset: 22% 14% 10%; border-radius: 6px; display: grid; place-items: center; font-weight: 900; font-size: calc(var(--cw) * 0.34); background: linear-gradient(160deg, #fff3d6, #f2c14e); color: inherit; border: 1px solid rgba(0, 0, 0, 0.15); }
.card.back {
  background:
    radial-gradient(circle at 50% 50%, #f2c14e 0 9%, transparent 10%),
    conic-gradient(from 22.5deg, #b8141c 0 12.5%, #7d0d13 0 25%, #b8141c 0 37.5%, #7d0d13 0 50%, #b8141c 0 62.5%, #7d0d13 0 75%, #b8141c 0 87.5%, #7d0d13 0);
  border: 3px solid #fffdf8;
}
.hand { display: flex; justify-content: center; padding-top: 6px; min-height: calc(var(--cw) * 1.5); }
.hand .card { margin-left: calc(var(--cw) * -0.28); transition: transform 0.15s; }
.hand .card:first-child { margin-left: 0; }
.hand .card.legal { cursor: pointer; }
.hand .card.legal:hover, .hand .card.legal:focus-visible { transform: translateY(-14px); z-index: 3; }
.hand.my-turn .card.legal { box-shadow: 0 0 0 2px var(--gold), 0 6px 14px rgba(0, 0, 0, 0.4); }
.hand.my-turn .card:not(.legal) { filter: brightness(0.55); cursor: not-allowed; }
.hand .card.trump::after { content: "★"; position: absolute; right: 6%; bottom: 3%; font-size: calc(var(--cw) * 0.18); color: #b88400; }

.trick { position: absolute; inset: 0; pointer-events: none; }
.trick .card { position: absolute; left: 50%; top: 50%; transition: transform 0.3s; }
.trick .slot-bottom { transform: translate(-50%, -12%); }
.trick .slot-top { transform: translate(-50%, -88%); }
.trick .slot-left { transform: translate(-125%, -50%) rotate(-8deg); }
.trick .slot-right { transform: translate(25%, -50%) rotate(8deg); }
.trick .card.win { box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(242, 193, 78, 0.9); }
.center-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; font-weight: 900; color: rgba(255, 255, 255, 0.85); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }

/* bidding */
.bidbox { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; background: rgba(12, 20, 36, 0.96); border: 2px solid var(--gold); border-radius: 18px; padding: 14px; width: min(400px, 92%); display: grid; gap: 10px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6); }
.bidbox h3 { margin: 0; font-size: 16px; }
.values, .suits { display: grid; gap: 6px; }
.values { grid-template-columns: repeat(5, 1fr); }
.suits { grid-template-columns: repeat(4, 1fr); }
.vbtn, .sbtn { border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; padding: 8px 4px; font-weight: 900; }
.vbtn[aria-pressed="true"], .sbtn[aria-pressed="true"] { background: var(--gold); color: #1a1400; border-color: var(--gold); }
.sbtn { font-size: 22px; padding: 4px; }
.sbtn.red { color: #ff5a6a; }
.sbtn.red[aria-pressed="true"] { color: var(--red); }
.bidrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bidlog { font-size: 12px; color: var(--muted); max-height: 60px; overflow: auto; }

/* side */
.side { display: grid; gap: 10px; align-content: start; }
.box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.box h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 0; font-size: 13px; display: grid; gap: 3px; max-height: 260px; overflow: auto; }
.feed li .t0 { color: var(--team0); font-weight: 800; } .feed li .t1 { color: var(--team1); font-weight: 800; }
.hist { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist td, .hist th { padding: 3px 4px; text-align: right; }
.hist th { color: var(--muted); font-weight: 700; }
.hist td:first-child, .hist th:first-child { text-align: left; }
.status { text-align: center; font-weight: 800; margin: 6px 0; min-height: 22px; }
.status.mine { color: var(--gold); }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(4, 8, 20, 0.75); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.breakdown { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.breakdown td, .breakdown th { padding: 6px; border-bottom: 1px solid var(--line); text-align: right; }
.breakdown td:first-child, .breakdown th:first-child { text-align: left; color: var(--muted); }
.breakdown tr.total td { font-weight: 900; font-size: 17px; color: var(--gold); }
.made { font-size: 22px; font-weight: 900; text-align: center; margin-bottom: 8px; }
.made.yes { color: #52d98a; } .made.no { color: var(--team1); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-weight: 800; padding: 10px 16px; border-radius: 999px; z-index: 60; }
.toast[hidden] { display: none; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } }
@media (max-width: 560px) {
  .table { height: 520px; }
  .player.left { left: 4px; } .player.right { right: 4px; }
  .nameplate { font-size: 11px; padding: 3px 7px; }
}
@media (prefers-reduced-motion: reduce) { .nameplate.turn { animation: none; } }
.vbtn:disabled { opacity: 0.28; cursor: not-allowed; text-decoration: line-through; }

/* AI seats + game length */
.seat-actions { display: flex; gap: 6px; justify-content: center; }
.mini { white-space: nowrap; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 800; }
.mini:hover { border-color: var(--gold); }
.mini.ai { background: rgba(242, 193, 78, 0.15); border-color: rgba(242, 193, 78, 0.6); }
.target-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tp { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; text-transform: none; letter-spacing: normal; font-size: 14px; color: var(--ink); font-weight: 500; }
.tp input { accent-color: var(--gold); }
.tp:has(input:checked) { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
