:root {
  --bg: #100e0c;
  --panel: #171410;
  --ink: #e6ddd0;
  --muted: #8a8076;
  --line: rgba(198, 168, 110, 0.28);
  --line-soft: rgba(230, 221, 208, 0.1);
  --brass: #c6a86e;
  --felt: #1c2924;
  --felt-deep: #14201c;
  --blood: #7a2a2a;
  --blood-deep: #4e1818;
  --warn: #6a5424;
  --shadow: rgba(0, 0, 0, 0.5);
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-ui: "Manrope", "Segoe UI", sans-serif;
  --r: 2px;
  --card-w: 70px;
  --card-h: 102px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  max-width: 100vw;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow-x: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    radial-gradient(ellipse 90% 60% at 50% 0%, #1a1612 0%, transparent 55%),
    linear-gradient(180deg, #14110e, var(--bg));
}

.grain, .vignette { display: none; }

.screen {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: 14px;
}
.hidden { display: none !important; }

/* —— Lobby —— */
.lobby {
  display: grid;
  place-content: center;
  gap: 36px;
}
.brand {
  text-align: center;
}
.brand-mark {
  font-size: 28px;
  color: var(--brass);
  line-height: 1;
  margin-bottom: 6px;
}
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(52px, 13vw, 84px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 0.92;
}
.brand p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.lobby-panel {
  width: min(380px, 92vw);
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
}
.field {
  display: grid;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
input {
  width: 100%;
  border: 1px solid var(--line-soft);
  background: #0c0a09;
  color: var(--ink);
  border-radius: var(--r);
  padding: 11px 12px;
  font: 500 15px/1.2 var(--font-ui);
  outline: none;
}
input:focus { border-color: var(--line); }
.lobby-actions { display: grid; gap: 8px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.status-line {
  min-height: 1.2em;
  margin: 4px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* —— Controls —— */
.btn {
  border: 1px solid var(--line-soft);
  background: #1c1814;
  color: var(--ink);
  border-radius: var(--r);
  padding: 11px 14px;
  font: 600 13px/1 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover:not(:disabled) {
  border-color: var(--line);
  background: #241f1a;
}
.btn:disabled { opacity: .32; cursor: default; }
.btn.primary {
  background: var(--blood);
  border-color: #933636;
}
.btn.primary:hover:not(:disabled) { background: #8f3232; }
.btn.danger {
  background: var(--blood-deep);
  border-color: #6a2828;
}
.btn.warn {
  background: var(--warn);
  border-color: #8a6e30;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--muted);
}
.btn.ghost:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--line-soft);
}

/* —— Table —— */
.table {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  width: 100%;
  max-width: min(920px, 100%);
  margin: 0 auto;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  overflow-x: hidden;
  box-sizing: border-box;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.room-chip {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.room-chip span {
  color: var(--brass);
  font-weight: 700;
  letter-spacing: 0.14em;
}
.trump-badge {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--brass);
  min-width: 1.5ch;
  text-align: center;
  line-height: 1;
}

.opponent-zone, .self-zone {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.player-meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: center;
}
.self-meta { justify-content: space-between; padding: 0 2px; }
.pname {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}
.prole {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mid {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 10px;
  align-items: center;
  min-height: 220px;
}
.felt {
  position: relative;
  min-height: 210px;
  border-radius: var(--r);
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent 30%),
    var(--felt);
  border: 1px solid rgba(198, 168, 110, 0.22);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35), inset 0 20px 50px rgba(0,0,0,.25);
  overflow: hidden;
}
.felt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0 3px,
    rgba(0,0,0,.03) 3px 4px
  );
  pointer-events: none;
}
.table-cards {
  position: absolute;
  inset: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-content: center;
  justify-content: center;
  z-index: 1;
}
.banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: rgba(230, 221, 208, 0.42);
  font-family: var(--font-display);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 0.06em;
  text-align: center;
  z-index: 0;
  transition: opacity .2s ease;
}
.banner.busy { opacity: 0; }

.pair {
  position: relative;
  width: 64px;
  height: 92px;
  flex: 0 0 auto;
}
.pair .card.defend {
  position: absolute;
  left: 14px;
  top: 16px;
  transform: rotate(16deg);
}

.deck-pile, .discard-pile {
  position: relative;
  height: 110px;
  display: grid;
  place-items: center;
}
.deck-stack, .discard-stack {
  width: 52px;
  height: 78px;
  border-radius: 6px;
  background:
    repeating-linear-gradient(45deg, #2a2430 0 5px, #221d28 5px 10px);
  border: 1px solid rgba(198, 168, 110, 0.35);
  box-shadow: 0 6px 14px var(--shadow);
}
.deck-stack { position: relative; }
.deck-stack::before,
.deck-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  border: 1px solid rgba(198, 168, 110, 0.2);
  background: inherit;
}
.deck-stack::before { transform: translate(2px, -2px); z-index: -1; }
.deck-stack::after { transform: translate(4px, -4px); z-index: -2; }
.deck-count {
  position: absolute;
  bottom: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.trump-mini {
  position: absolute;
  width: 52px;
  height: 78px;
  transform: rotate(90deg) translate(16px, 6px);
  z-index: 0;
}

.hand {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 96px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
.hand-spacer {
  height: 1px;
  pointer-events: none;
  visibility: hidden;
}
.hand .card {
  position: absolute;
  bottom: 4px;
  margin: 0 !important;
  transform-origin: bottom center;
  transition: transform .15s ease, bottom .15s ease;
}
.self-hand {
  height: 132px;
  padding-top: 18px;
  box-sizing: border-box;
}
.opp-hand {
  height: 86px;
}
.opp-hand .card {
  transform: scale(0.72);
}
.self-hand .card.legal {
  box-shadow: 0 0 0 1px var(--brass), 0 8px 16px var(--shadow);
  cursor: pointer;
}
.self-hand .card.legal:hover,
.self-hand .card.legal:active,
.self-hand .card.legal.raised {
  transform: translateY(-16px);
}
.self-hand .card.dim { opacity: .4; }

/* —— Cards (keep) —— */
.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: linear-gradient(180deg, #f7ecdc, #e7d5bc);
  color: #1b1410;
  border: 1px solid rgba(40, 24, 16, .35);
  box-shadow: 0 8px 14px rgba(0,0,0,.35);
  flex: 0 0 auto;
  font-family: var(--font-display);
  overflow: hidden;
}
.card.red { color: #8f1e1e; }
.card .corner {
  position: absolute;
  top: 5px;
  left: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1;
  font-weight: 700;
  font-size: 14px;
  width: 1.15em;
  text-align: center;
  z-index: 2;
}
.card .corner .rank {
  display: block;
  font-size: 15px;
  line-height: 1;
}
.card .corner .g {
  display: block;
  font-size: 11px;
  line-height: 1;
  margin-top: 1px;
}
.card .corner.bl {
  top: auto;
  left: auto;
  right: 6px;
  bottom: 5px;
  transform: rotate(180deg);
}
.card .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 34px;
  opacity: .92;
}
.card.hidden-card,
.card.back {
  background:
    repeating-linear-gradient(45deg, #2a2430 0 5px, #221d28 5px 10px);
  color: transparent;
  border-color: rgba(198, 168, 110, 0.35);
}

.card.fly {
  position: fixed !important;
  z-index: 80;
  pointer-events: none;
  margin: 0 !important;
  flex: none !important;
  box-sizing: border-box;
  will-change: left, top, transform;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
  position: relative;
  z-index: 20;
}
.actions .btn {
  min-height: 52px;
  padding: 16px 10px;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.toast {
  position: fixed;
  left: 50%;
  top: max(12px, env(safe-area-inset-top));
  bottom: auto;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: var(--r);
  z-index: 40;
  font-size: 13px;
  letter-spacing: 0.02em;
  max-width: min(92vw, 420px);
  text-align: center;
  white-space: normal;
  pointer-events: none;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: grid;
  place-items: center;
  z-index: 100;
}
.overlay-card {
  width: min(340px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 28px 22px;
  text-align: center;
}
.overlay-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
}
.overlay-card p {
  color: var(--muted);
  margin: 10px 0 18px;
}

.fx-flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(36px, 9vw, 64px);
  letter-spacing: 0.14em;
  color: var(--brass);
  text-shadow: 0 4px 18px rgba(0,0,0,.75);
  animation: bannerPop .85s ease forwards;
  pointer-events: none;
  z-index: 5;
}
.fx-flash.take { color: #c87878; }
.fx-flash.transfer { color: #d2c08a; }

@keyframes bannerPop {
  0% { opacity: 0; transform: translateY(6px); }
  20% { opacity: 1; transform: none; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 640px) {
  .mid { grid-template-columns: 48px 1fr 48px; min-height: 190px; gap: 6px; }
  .felt { min-height: 176px; }
  .card { width: 58px; height: 86px; }
  .pair { width: 52px; height: 78px; }
  .pair .card.defend { left: 10px; top: 12px; }
  .deck-stack, .discard-stack, .trump-mini { width: 44px; height: 66px; }
  .self-hand { height: 120px; }
  .opp-hand { height: 78px; }
  .actions .btn {
    min-height: 50px;
    padding: 14px 6px;
    font-size: 13px;
    letter-spacing: 0.04em;
  }
  .card .corner .rank { font-size: 13px; }
  .card .corner .g { font-size: 10px; }
}
