/* Spades — Playnesta original (MIT, see LICENSE.txt). */
:root {
  --felt-1: #17203e;
  --felt-2: #0c1226;
  --gold: #e8c469;
  --ink: #12121c;
  --paper: #f7f3e8;
  --red: #cf3a3a;
  --text: #eaeef7;
  --dim: #9da9c4;
  --warn: #ffb4a1;
  --card-w: clamp(24px, min(8vw, 10vh), 58px);
  --seat-w: clamp(60px, 15vw, 96px);
  --pn-vh: 1vh;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #233157 0%, var(--felt-1) 45%, var(--felt-2) 100%);
  color: var(--text);
  font: 500 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

#app {
  height: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
  gap: 4px;
}

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 26px;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: clamp(13px, 2.4vw, 17px);
  color: var(--gold);
}
.brand small {
  font-weight: 600;
  font-size: 0.66em;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-left: 4px;
}
.meta {
  font-size: clamp(10px, 1.9vw, 12px);
  color: var(--dim);
  display: flex;
  gap: 5px;
  align-items: center;
  white-space: nowrap;
}

.scoreboard {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(232, 196, 105, 0.16);
  font-size: clamp(9px, 1.7vw, 11.5px);
  color: var(--dim);
}
.chip.me { border-color: rgba(232, 196, 105, 0.55); color: var(--text); }
.chip b { color: var(--gold); font-size: 1.12em; }
.chip .who { white-space: nowrap; }
.chip .bag { color: var(--warn); }
.chip .bid { color: #7fd4a8; font-weight: 700; }

/* ── bidding bar ─────────────────────────────────────────── */
.bidbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 3px 4px;
  border-radius: 10px;
  background: rgba(4, 10, 24, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.bidbar.hidden { display: none; }
.bid-prompt { font-size: clamp(11px, 2vw, 13px); color: var(--text); font-weight: 700; }
.bid-buttons { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.bid-btn {
  min-height: 44px;
  min-width: 40px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(232, 196, 105, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: clamp(12px, 2.1vw, 14px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bid-btn.nil { border-color: var(--warn); color: var(--warn); }
.bid-btn:active { transform: scale(0.94); }

/* ── table ───────────────────────────────────────────────── */
.table {
  position: relative;
  min-height: 0;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255, 255, 255, 0.06), transparent 62%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.3));
  box-shadow: inset 0 0 0 1px rgba(232, 196, 105, 0.14), inset 0 10px 40px rgba(0, 0, 0, 0.28);
}
.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: var(--seat-w);
  padding: 3px 4px;
  border-radius: 9px;
  background: rgba(4, 10, 24, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: clamp(9px, 1.6vw, 11px);
  color: var(--dim);
  transition: border-color 120ms ease, background 120ms ease;
}
.seat .who { font-weight: 700; color: var(--text); white-space: nowrap; }
.seat .badge {
  font-size: 0.82em;
  color: #7fd4a8;
  font-weight: 700;
}
.seat.active { border-color: var(--gold); background: rgba(232, 196, 105, 0.14); }
.seat-n { top: 6px; left: 50%; transform: translateX(-50%); }
.seat-w { left: 6px; top: 46%; transform: translateY(-50%); }
.seat-e { right: 6px; top: 46%; transform: translateY(-50%); }

.center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}
.trick-area {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-areas:
    ". n ."
    "w c e"
    ". s .";
  align-items: center;
  justify-items: center;
  padding: clamp(26px, 8vh, 52px) calc(var(--seat-w) + 10px) clamp(18px, 5vh, 30px);
}
.play-slot { display: flex; align-items: center; justify-content: center; min-width: 0; }
.slot-n { grid-area: n; }
.slot-w { grid-area: w; }
.slot-e { grid-area: e; }
.slot-s { grid-area: s; }

.msg {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 16px);
  text-align: center;
  font-size: clamp(10px, 1.8vw, 12px);
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg.warn { color: var(--warn); }

/* ── cards ───────────────────────────────────────────────── */
.card {
  position: relative;
  width: var(--card-w);
  height: calc(var(--card-w) * 1.42);
  border-radius: calc(var(--card-w) * 0.12);
  background: linear-gradient(180deg, #fffdf7, var(--paper));
  color: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 110ms ease, box-shadow 110ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.card .r { font-size: calc(var(--card-w) * 0.42); line-height: 1; }
.card .s { font-size: calc(var(--card-w) * 0.4); line-height: 1; }
.card.red { color: var(--red); }
.card:disabled { opacity: 0.42; cursor: default; }
.played-card {
  width: 100%;
  height: 100%;
  max-width: calc(var(--card-w) * 0.94);
  max-height: calc(var(--card-w) * 1.34);
  border-radius: 6px;
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.45);
  animation: drop 160ms ease-out;
  cursor: default;
}
@keyframes drop {
  from { transform: translateY(-8px) scale(0.94); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

/* ── hand bar ────────────────────────────────────────────── */
.hand {
  display: flex;
  gap: clamp(1px, 0.4vw, 4px);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 1px 4px;
  scrollbar-width: thin;
  justify-content: center;
  min-height: calc(var(--card-w) * 1.42 + 8px);
}
.hand .card:not(:disabled):hover { transform: translateY(-5px); }
.hand .card.trump-card { border-color: rgba(232, 196, 105, 0.55); }

.controls { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }
.btn {
  min-height: 44px;
  min-width: 60px;
  padding: 5px 11px;
  border-radius: 9px;
  border: 1px solid rgba(232, 196, 105, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  font-size: clamp(11px, 1.9vw, 12.5px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: rgba(232, 196, 105, 0.16); }
.btn.primary {
  background: linear-gradient(180deg, #f0d083, var(--gold));
  color: #2a1f05;
  border-color: #b8933f;
}

/* ── overlays ────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(3, 8, 18, 0.78);
  backdrop-filter: blur(2px);
  z-index: 20;
}
.overlay.hidden { display: none; }
.panel {
  width: min(420px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, #131b38, #0b1128);
  border: 1px solid rgba(232, 196, 105, 0.32);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.panel-wide { width: min(520px, 100%); }
.panel h2 { margin: 0 0 8px; font-size: clamp(15px, 3vw, 19px); color: var(--gold); }
.panel p { margin: 0 0 12px; white-space: pre-line; color: var(--text); font-size: clamp(12px, 2.2vw, 13.5px); line-height: 1.5; }
.panel .btn { margin-top: 4px; }
.rules-list {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: clamp(11.5px, 2.1vw, 13px);
  line-height: 1.5;
  color: var(--text);
}
.rules-list li { margin-bottom: 6px; }
.rules-list b { color: var(--gold); }

@media (max-height: 320px) {
  .seat { padding: 2px 3px; }
  .meta { display: none; }
  .msg { display: none; }
  .bidbar { min-height: 34px; }
}
