:root {
  --felt: #14523a;
  --felt-deep: #0c3a29;
  --oxblood: #7a1f2b;
  --oxblood-deep: #5d1620;
  --gold: #c9a24b;
  --cream: #faf6ec;
  --ink: #2b2621;
  --card-red: #b03434;
  --card-w: 62px;
  --card-h: 88px;
  --mini-w: 34px;
  --mini-h: 48px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, 'Segoe UI', sans-serif;
  background: radial-gradient(ellipse 130% 90% at 50% 30%, var(--felt) 0%, var(--felt-deep) 100%);
  color: #f2ede2;
  min-height: 100vh;
}
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ── Lobby ───────────────────────────────────────────────── */
#lobby { align-items: center; justify-content: center; }
.lobby-box {
  background: rgba(0,0,0,0.42); border: 1px solid rgba(201,162,75,0.35);
  padding: 2.2rem 2.5rem; border-radius: 14px; width: 330px; text-align: center;
  box-shadow: 0 14px 50px rgba(0,0,0,0.5);
}
.lobby-cardart { display: flex; justify-content: center; margin-bottom: 0.4rem; }
.mini-card { width: var(--mini-w); height: var(--mini-h); border-radius: 5px; box-shadow: 0 3px 8px rgba(0,0,0,0.5); }
.mini-card.back { transform: rotate(-8deg) translateX(4px); z-index: 1; }
.mini-card.face {
  background: var(--cream); color: var(--card-red);
  transform: rotate(7deg) translateX(-4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; font-family: Georgia, serif; font-size: 0.95rem;
}
.lobby-box h1 { margin: 0.2rem 0; color: var(--gold); font-family: Georgia,serif; font-weight: 600; }
.subtitle { color: #cfe3d6; font-size: 0.82rem; margin: 0 0 1.4rem; }
.lobby-box label { display: block; text-align: left; font-size: 0.8rem; margin: 0.8rem 0 0.3rem; color: #d9d2c2; }
.lobby-box input, .lobby-box select {
  width: 100%; padding: 0.6rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.15);
  font-size: 1rem; background: #f5f1e6; color: var(--ink);
}
#startBtn {
  margin-top: 1.6rem; width: 100%; padding: 0.8rem; border: none; border-radius: 8px;
  background: var(--gold); color: #241c0d; font-weight: 700; font-size: 1rem; cursor: pointer;
}
#startBtn:hover { filter: brightness(1.08); }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.45rem 1rem; background: rgba(0,0,0,0.3);
  border-bottom: 1px solid rgba(201,162,75,0.25);
}
#scoreboard { display: flex; gap: 0.5rem; flex-wrap: wrap; font-size: 0.78rem; }
.score-chip { background: rgba(255,255,255,0.08); padding: 0.22rem 0.6rem; border-radius: 20px; border: 1px solid transparent; }
.score-chip.active { border-color: var(--gold); color: var(--gold); font-weight: 600; }
.hand-info { font-size: 0.82rem; color: var(--gold); }

/* ── Gegner-Sitzplätze ───────────────────────────────────── */
.opponents { display: flex; justify-content: space-around; padding: 0.6rem 0.5rem 0.1rem; }
.seat { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 90px; }
.seat-name { font-size: 0.76rem; color: #d9d2c2; }
.seat.active .seat-name { color: var(--gold); font-weight: 600; }
.seat.active .seat-fan  { filter: drop-shadow(0 0 8px rgba(201,162,75,0.5)); }
.seat-fan { display: flex; height: calc(var(--mini-h) + 14px); align-items: flex-end; }
.fan-card {
  width: var(--mini-w); height: var(--mini-h);
  margin-left: calc(var(--mini-w) * -0.62);
  border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.45);
  transform-origin: bottom center;
}
.fan-card:first-child { margin-left: 0; }
.seat-count { font-size: 0.68rem; color: #a9bfae; }

/* ── Karten-Rückseite (Signature-Element) ────────────────── */
.card.back, .fan-card, .mini-card.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(201,162,75,0.3) 0 16%, transparent 17%),
    repeating-linear-gradient(45deg, var(--oxblood) 0 7px, var(--oxblood-deep) 7px 14px),
    var(--oxblood);
  border: 2px solid var(--gold);
  outline: 2px solid var(--oxblood-deep);
  outline-offset: -5px;
}

/* ── Karten-Front ────────────────────────────────────────── */
.card {
  width: var(--card-w); height: var(--card-h);
  background: linear-gradient(158deg, #fffdf6 0%, var(--cream) 65%, #ece4d2 100%);
  color: var(--ink); border-radius: 7px; position: relative; overflow: hidden;
  box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(0,0,0,0.07);
  cursor: pointer; user-select: none;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  font-family: Georgia, 'Times New Roman', serif;
}
.card.red { color: var(--card-red); }
.card.joker { color: #8a5a12; }
.card .corner {
  position: absolute; top: 4px; left: 5px;
  font-size: 0.8rem; font-weight: 700; line-height: 1;
  display: flex; flex-direction: column; align-items: center; z-index: 2;
}
.card .corner .c-suit { font-size: 0.72rem; }
.card .corner.br { top: auto; left: auto; bottom: 4px; right: 5px; transform: rotate(180deg); }
.card .center-pip {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; z-index: 1;
}
/* SVG-Figurenkarten füllen die Karte komplett, corner-Elemente kommen aus dem SVG selbst */
.card svg { position: absolute; inset: 0; width: 100%; height: 100%; }

.card.selected {
  transform: translateY(-16px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.5), 0 0 0 2px var(--gold);
  z-index: 5;
}
.hand .card:hover:not(.selected) { transform: translateY(-8px); }

/* kleine Karten im Meld */
.card.small {
  --card-w: 46px; --card-h: 66px;
  width: 46px; height: 66px; border-radius: 5px; cursor: pointer;
}
.card.small .center-pip { font-size: 1.5rem; }
.card.small .corner { font-size: 0.66rem; }
.card.small .corner .c-suit { font-size: 0.6rem; }

/* ── Tisch ───────────────────────────────────────────────── */
.table-area {
  flex: 1; padding: 0.5rem 1rem; display: flex; flex-direction: column;
  gap: 0.5rem; overflow-y: auto; min-height: 110px;
}
.player-melds { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.owner-label { font-size: 0.7rem; color: #a9bfae; width: 100%; letter-spacing: 0.03em; }
.meld-group {
  display: flex; background: rgba(0,0,0,0.2); border-radius: 8px;
  padding: 4px; gap: 0; cursor: pointer; border: 2px solid transparent;
}
.meld-group .card { margin-left: -18px; }
.meld-group .card:first-child { margin-left: 2px; }
.meld-group.targetable { border-color: var(--gold); }
.meld-group.targetable:hover { background: rgba(201,162,75,0.2); }
@keyframes popIn { from { transform: scale(0.45); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card.pop { animation: popIn 0.32s cubic-bezier(.2,.8,.4,1); }

/* ── Mitte: Stapel ───────────────────────────────────────── */
.center-piles { display: flex; justify-content: center; gap: 2.5rem; padding: 0.3rem 0 0.3rem; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.pile-label { font-size: 0.7rem; color: #cfc6b0; letter-spacing: 0.04em; }
.card-slot {
  width: var(--card-w); height: var(--card-h);
  border: 2px dashed rgba(255,255,255,0.25); border-radius: 7px;
}
.card-slot .card { margin: -2px; }
.pile.clickable .card, .pile.clickable .card-slot {
  box-shadow: 0 0 0 2.5px var(--gold), 0 4px 14px rgba(0,0,0,0.5);
}

/* ── Banner ──────────────────────────────────────────────── */
.turn-banner {
  text-align: center; padding: 0.3rem; font-size: 0.88rem; color: var(--gold);
  font-family: Georgia, serif; min-height: 1.5rem;
}

/* ── Eigene Hand ─────────────────────────────────────────── */
.hand-area { padding: 0.4rem 1rem 0.6rem; }
.hand {
  display: flex; justify-content: center; flex-wrap: wrap;
  min-height: calc(var(--card-h) + 18px); padding-top: 18px;
}
.hand .card { margin-left: -16px; }
.hand .card:first-child { margin-left: 0; }

/* ── Aktionsbar ──────────────────────────────────────────── */
.action-bar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;
  padding: 0.55rem; background: rgba(0,0,0,0.28);
  border-top: 1px solid rgba(201,162,75,0.22);
}
.action-bar button {
  padding: 0.52rem 1rem; border-radius: 8px;
  border: 1px solid rgba(201,162,75,0.4); background: transparent;
  color: #e9e2d0; cursor: pointer; font-size: 0.84rem;
}
.action-bar button:disabled { opacity: 0.28; cursor: not-allowed; }
.action-bar button:not(:disabled):hover { background: rgba(201,162,75,0.18); }

.mode-hint { text-align: center; font-size: 0.76rem; color: var(--gold); min-height: 1rem; }
.log {
  font-size: 0.67rem; color: #a9bfae; max-height: 80px; overflow-y: auto;
  padding: 0.35rem 1rem; background: rgba(0,0,0,0.22);
}
.log div { padding: 1px 0; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  background: #a3352c; color: #fff; padding: 0.6rem 1.2rem; border-radius: 8px;
  z-index: 300; display: none; box-shadow: 0 4px 15px rgba(0,0,0,0.4); font-size: 0.84rem;
}

/* ── Fliegende Karten ────────────────────────────────────── */
.flying-card {
  position: fixed; z-index: 250; pointer-events: none; margin: 0 !important;
  width: var(--card-w); height: var(--card-h);
  transition: transform 0.46s cubic-bezier(0.3,0.8,0.35,1), opacity 0.46s ease;
  will-change: transform;
}

/* ── Modal / Zusammenfassung ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #0e3d29; border: 1px solid rgba(201,162,75,0.5);
  border-radius: 14px; padding: 1.6rem 1.8rem; max-width: 540px; width: 94%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6); max-height: 85vh; overflow-y: auto;
}
.modal-box h2 { margin: 0 0 1rem; color: var(--gold); font-family: Georgia,serif; font-size: 1.1rem; }
.summary-table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-bottom: 1rem;
}
.summary-table th, .summary-table td {
  padding: 0.45rem 0.6rem; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.summary-table th { color: var(--gold); font-weight: 600; }
.summary-table .total-row td { font-weight: 700; color: var(--gold); border-top: 2px solid rgba(201,162,75,0.4); }
.pts-gained { color: #a8e0b2; font-weight: 600; }
.round-winner {
  text-align: center; font-size: 1rem; color: var(--gold); font-family: Georgia,serif;
  padding: 0.8rem 0 0.2rem;
}
.modal-actions { display: flex; gap: 0.8rem; justify-content: center; margin-top: 1.2rem; }
.modal-actions button {
  padding: 0.6rem 1.4rem; border-radius: 8px; border: none;
  background: var(--gold); color: #241c0d; font-weight: 700; cursor: pointer;
}
.modal-actions button:hover { filter: brightness(1.08); }
#closeSummaryBtn { background: rgba(255,255,255,0.12); color: #f2ede2; border: 1px solid rgba(255,255,255,0.2); }

/* ── Reduced Motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .flying-card { transition: none; }
  .card, .card.pop { transition: none; animation: none; }
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --card-w: 46px; --card-h: 66px; --mini-w: 26px; --mini-h: 38px; }
  .card .center-pip { font-size: 1.5rem; }
  .card.small { width: 36px; height: 52px; }
  .meld-group .card { margin-left: -14px; }
  .action-bar button { font-size: 0.75rem; padding: 0.48rem 0.7rem; }
  .seat { min-width: 70px; }
  .modal-box { padding: 1.2rem; }
}
