:root {
  --bg: #0e1017;
  --panel: rgba(24, 28, 40, 0.85);
  --panel-solid: #181c28;
  --panel2: #212738;
  --line: #2c3347;
  --text: #eaedf6;
  --muted: #8f97ad;
  --gold: #f2c14e;
  --gold-dim: rgba(242, 193, 78, 0.18);
  --red: #e2566a;
  --green: #4fd18b;
  --blue: #6aa8ff;
  --cw: 72px;
  --ch: 100px;
  --cws: 46px;
  --chs: 64px;
  --radius: 16px;
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 50% -15%, #2a3148 0%, transparent 60%),
    radial-gradient(900px 500px at 50% 115%, #1a2a24 0%, transparent 60%),
    var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
}

button { font: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 23, 0.6);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.status { display: flex; gap: 14px; }
.stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 12px; border-radius: 10px; background: var(--panel2); min-width: 64px;
}
.stat .label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat span:last-child { font-weight: 700; font-size: 16px; }
.quickref { display: flex; gap: 12px; margin-left: auto; color: var(--muted); font-size: 13px; }
.quickref span { white-space: nowrap; }
.quickref em { font-style: normal; color: var(--text); font-weight: 600; }
.quickref .guard-txt em { color: var(--red); }
.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  color: #1a1c22;
  background: linear-gradient(180deg, #ffd978, var(--gold));
  box-shadow: 0 4px 14px rgba(242, 193, 78, 0.25);
  transition: transform .15s, box-shadow .15s, opacity .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(242, 193, 78, 0.35); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: var(--panel2); box-shadow: none; }

/* ---------- Table layout ---------- */
.table {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 12px 20px 14px;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 600;
}

/* Opponents */
.opponents { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: box-shadow .3s, border-color .3s;
}
.panel.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 28px rgba(242,193,78,.25); }
.phead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel2); font-size: 18px; flex: none;
}
.pname { font-weight: 700; font-size: 15px; }
.pscore { margin-left: auto; font-weight: 800; font-size: 18px; color: var(--gold); }
.pscore small { font-weight: 500; font-size: 11px; color: var(--muted); }
.ptotal { font-size: 12px; color: var(--muted); }
.bag { display: flex; gap: 6px; min-height: var(--chs); align-items: center; flex-wrap: wrap; }
.empty-hint { color: var(--muted); font-size: 12px; font-style: italic; }
.tag {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; background: var(--gold-dim); color: var(--gold); margin-left: 6px;
  vertical-align: middle;
}
.phead .tag { margin-left: 0; }

/* Center */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; min-height: 0; }
.bids-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.bids { display: flex; gap: 26px; }
.bid-slot { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.slot-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.bid-slot.active .slot-label { color: var(--gold); }
.badge {
  position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; letter-spacing: .5px;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1) both;
  white-space: nowrap; z-index: 2;
}
.badge.ord { background: var(--gold); color: #1a1c22; }
.badge.bad { background: var(--red); color: white; }
.bid-slot.collided .card { animation: shake .55s ease-in-out both; }
.bid-slot.collided .card .front { filter: saturate(.3) brightness(.85); }

.loot {
  display: flex; align-items: center; gap: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 22px;
}
.loot-head { writing-mode: vertical-rl; transform: rotate(180deg); }
.row { display: flex; gap: 14px; }
.vault { display: flex; align-items: center; gap: 12px; padding-left: 16px; border-left: 1px solid var(--line); }
.vault .card { box-shadow: 2px 2px 0 #1b2440, 4px 4px 0 #161d33; }
.vault-count { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.vault-count span { font-weight: 800; font-size: 22px; }
.vault-count small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

/* You */
.you {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 18px;
  transition: box-shadow .3s, border-color .3s;
}
.you.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 28px rgba(242,193,78,.25); }
.your-bag { display: flex; flex-direction: column; gap: 8px; }
.your-bag .bag { min-height: var(--chs); }
.your-center { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.message {
  min-height: 24px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  max-width: 560px;
  transition: color .3s;
}
.message.hint { color: var(--gold); }
.message.warn { color: var(--red); }
.hand { display: flex; gap: 10px; min-height: var(--ch); align-items: flex-end; }
.hand .card { transition: transform .18s, filter .18s; }
.hand .card.selectable:hover { transform: translateY(-12px) scale(1.05); }
.controls { display: flex; gap: 10px; }
.log-wrap { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.log {
  list-style: none; margin: 0; padding: 0;
  font-size: 12.5px; color: var(--muted); line-height: 1.45;
  max-height: 120px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.log li { animation: slideIn .3s ease both; }
.log li:last-child { color: var(--text); }
.log b { color: var(--text); }

/* ---------- Cards ---------- */
.card {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  border-radius: 10px;
  perspective: 800px;
  flex: none;
  --pip: 34px;
  --corner: 15px;
}
.card.small { width: var(--cws); height: var(--chs); border-radius: 7px; --pip: 20px; --corner: 11px; }
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.4, 0, .2, 1), box-shadow .2s;
  border-radius: inherit;
}
.card.down .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: inherit;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.front {
  background: linear-gradient(160deg, #fffdf7, #f2eee2);
  color: #1c1e26;
  box-shadow: 0 3px 8px rgba(0,0,0,.45), inset 0 0 0 1px rgba(0,0,0,.06);
}
.card.red .front { color: #cf3244; }
.back {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0 4px, transparent 4px 8px),
    linear-gradient(160deg, #35467e, #1f2a4f);
  border: 3px solid #d9def0;
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.corner {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  line-height: 1; font-size: var(--corner); font-weight: 800;
}
.corner i { font-style: normal; font-size: calc(var(--corner) * 0.9); }
.corner.tl { top: 6px; left: 6px; }
.corner.br { bottom: 6px; right: 6px; transform: rotate(180deg); }
.card.small .corner.tl { top: 3px; left: 4px; }
.card.small .corner.br { bottom: 3px; right: 4px; }
.pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--pip); }

.card.guard .front {
  background: linear-gradient(160deg, #343a4b, #161922);
  color: var(--gold);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 3px 8px rgba(0,0,0,.6), inset 0 0 0 2px rgba(242,193,78,.35);
}
.guard-icon { font-size: calc(var(--pip) * 0.8); line-height: 1; }
.guard-label { font-size: calc(var(--corner) * 0.75); letter-spacing: 1.5px; font-weight: 800; }
.guard-val { font-size: calc(var(--corner) * 0.95); font-weight: 800; color: var(--red); }

.card.placeholder { border: 2px dashed var(--line); background: rgba(255,255,255,.02); }

.card.selectable { cursor: pointer; }
.card.selectable .card-inner {
  box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(242,193,78,.55);
  animation: glow 1.4s ease-in-out infinite;
}
.card.selectable.steal .card-inner {
  box-shadow: 0 0 0 3px var(--red), 0 0 22px rgba(226,86,106,.6);
  animation: glowRed 1.4s ease-in-out infinite;
}
.card.selectable:hover { transform: translateY(-6px) scale(1.04); }
.card .mini-tag {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  font-size: 9px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  padding: 2px 6px; border-radius: 999px; background: var(--red); color: white; z-index: 2;
  white-space: nowrap;
}
.card.locked .front { filter: brightness(.7); }
.card .lock {
  position: absolute; right: -4px; top: -6px; z-index: 2;
  width: 18px; height: 18px; border-radius: 50%; background: var(--panel-solid);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 10px;
}

/* ---------- Modal / overlay ---------- */
.hidden { display: none !important; }
.modal, .overlay {
  position: fixed; inset: 0; z-index: 100;
}
.modal { z-index: 120; }
.modal, .overlay {
  display: grid; place-items: center;
  background: rgba(8, 9, 14, 0.7);
  backdrop-filter: blur(6px);
  animation: fadeIn .25s ease both;
}
.modal-card, .overlay-card {
  position: relative;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 680px;
  width: min(92vw, 680px);
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: rise .35s cubic-bezier(.2,.9,.3,1.2) both;
}
.modal-card h2, .overlay-card h2 { margin: 0 0 8px; font-size: 26px; }
.modal-card h3 { margin: 22px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--gold); }
.modal-card p, .modal-card li { line-height: 1.5; color: #d5d9e6; }
.modal-card .lead { font-size: 16px; color: var(--text); }
.modal-card ol, .modal-card ul { padding-left: 22px; margin: 6px 0; }
.modal-card li { margin: 4px 0; }
.close {
  position: absolute; top: 12px; right: 14px;
  border: none; background: var(--panel2); color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; font-size: 20px; cursor: pointer;
}
.values { border-collapse: collapse; width: 100%; }
.values th, .values td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.values th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.bad { color: var(--red); }

.overlay-card { text-align: center; }
.overlay-card .sub { color: var(--muted); margin: 0 0 18px; }
.overlay-card .btn { margin-top: 20px; padding: 12px 26px; font-size: 16px; }
.intro-steps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; text-align: left; margin-top: 14px; }
.intro-steps div {
  background: var(--panel2); border-radius: 12px; padding: 12px 14px; line-height: 1.45; font-size: 14px;
}
.intro-steps b { color: var(--gold); display: block; margin-bottom: 2px; }
.results { width: 100%; border-collapse: collapse; margin-top: 12px; }
.results td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; }
.results tr.winner td { background: var(--gold-dim); }
.results .rname { font-weight: 700; white-space: nowrap; }
.results .rcards { display: flex; gap: 4px; flex-wrap: wrap; }
.results .rscore { font-weight: 800; font-size: 20px; white-space: nowrap; text-align: right; }
.results .rscore small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.results .rtotal { font-weight: 800; font-size: 20px; color: var(--gold); text-align: right; white-space: nowrap; }
.results .rtotal small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.trophy { font-size: 56px; animation: bounce 1s ease infinite; display: inline-block; }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetto {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall linear both;
}

/* ---------- Multiplayer: header, lobby, toasts ---------- */
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-right: 6px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.conn[data-state="online"] i { background: var(--green); box-shadow: 0 0 8px rgba(79,209,139,.7); }
.conn[data-state="connecting"] i { background: var(--gold); animation: blink 1s ease-in-out infinite; }
.conn[data-state="offline"] i { background: var(--red); animation: blink 1s ease-in-out infinite; }
.room-chip {
  border: 1px solid var(--line); background: var(--panel2); color: var(--muted);
  border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.room-chip b { color: var(--gold); letter-spacing: 3px; margin-left: 4px; font-weight: 800; }
.room-chip:hover { border-color: var(--gold); }

.tag.muted { background: rgba(143,151,173,.18); color: var(--muted); }
.tag.ok { background: rgba(79,209,139,.18); color: var(--green); }
.panel.away { opacity: .7; }

.notice { background: rgba(226,86,106,.15); color: #ffb3bd; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.notice.soft { background: var(--gold-dim); color: var(--gold); margin-top: 10px; }
.lobby-form { display: flex; flex-direction: column; gap: 12px; align-items: stretch; max-width: 360px; margin: 14px auto 6px; text-align: left; }
.lobby-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.lobby-form input {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); outline: none;
}
.lobby-form input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
.lobby-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; align-items: center; }
.lobby-actions .btn { margin-top: 0; }
.waiting { color: var(--muted); font-size: 14px; padding: 8px 4px; animation: blink 2s ease-in-out infinite; }
.code { color: var(--gold); letter-spacing: 6px; font-weight: 800; }

.seats { list-style: none; padding: 0; margin: 0 auto 18px; max-width: 420px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.seat {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--panel2); border: 1px solid var(--line); min-height: 54px;
}
.seat.empty { border-style: dashed; background: transparent; }
.seat-name { font-weight: 700; flex: 1; }
.seat-name small { color: var(--muted); font-weight: 500; }
.seat-empty { color: var(--muted); font-size: 13px; font-style: italic; }
.mini-btn {
  border: none; background: rgba(226,86,106,.15); color: var(--red); width: 26px; height: 26px;
  border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1;
}
.mini-btn:hover { background: rgba(226,86,106,.3); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--panel-solid); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 300;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: rise .25s ease both;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Animations ---------- */
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(242,193,78,.35); }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 28px rgba(242,193,78,.75); }
}
@keyframes glowRed {
  0%, 100% { box-shadow: 0 0 0 3px var(--red), 0 0 14px rgba(226,86,106,.4); }
  50% { box-shadow: 0 0 0 3px var(--red), 0 0 28px rgba(226,86,106,.8); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-7px) rotate(-4deg); }
  40% { transform: translateX(7px) rotate(4deg); }
  60% { transform: translateX(-5px) rotate(-2deg); }
  80% { transform: translateX(5px) rotate(2deg); }
}
@keyframes pop {
  from { transform: translateX(-50%) scale(0.3); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(24px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideIn { from { transform: translateX(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: .9; }
}
@keyframes scorePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); color: #fff; }
  100% { transform: scale(1); }
}
.pscore.bump, #your-bag-score.bump { display: inline-block; animation: scorePop .5s ease; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .quickref { display: none; }
  :root { --cw: 62px; --ch: 86px; --cws: 40px; --chs: 56px; }
  .you { grid-template-columns: 1fr auto; }
  .log-wrap { display: none; }
}
@media (max-height: 760px) {
  :root { --cw: 60px; --ch: 84px; --cws: 38px; --chs: 54px; }
  .center { gap: 12px; }
  .log { max-height: 80px; }
}
