:root {
  --bg: #0e1410;
  --bg-alt: #16201a;
  --panel: #1c2a20;
  --panel-alt: #223526;
  --border: #35503f;
  --text: #e9f3ec;
  --text-dim: #9fb8a9;
  --gold: #f4c95d;
  --gold-bright: #ffdd88;
  --felt: #1f6b45;
  --felt-dark: #123b27;
  --danger: #e35d6a;
  --success: #3ecf8e;
  --radius: 14px;
  --hand-bar-height: 288px;
  --header-h: 64px;
  /* Verfügbare Höhe für den Tisch zwischen Kopfzeile und der fixierten
     Handkarten-Leiste – so wird nie etwas dahinter verdeckt/abgeschnitten. */
  --table-max-h: calc(100vh - var(--header-h) - var(--hand-bar-height) - 44px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1a2a1f 0%, var(--bg) 62%);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { margin: 0 0 0.4em 0; }

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 14px;
}

#screen-home, #screen-lobby { align-items: center; min-height: 100vh; }
#screen-home { flex-direction: column; gap: 14px; }

#screen-game { display: block; padding: 0; min-height: 100vh; position: relative; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}

.home-card { text-align: center; }
.home-card h1 { font-size: 2.1rem; text-shadow: 0 0 18px rgba(62,207,142,0.5); }
.subtle-title { font-size: 1.1rem; color: var(--text-dim); font-weight: 500; }
.subtitle { color: var(--text-dim); margin-bottom: 20px; }
.hint { color: var(--text-dim); font-size: 0.85rem; margin-top: 14px; }
.eyebrow { color: var(--text-dim); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 600;
}
.tab-btn.active { background: var(--felt); color: white; border-color: var(--felt); }
.tab-panel label { display: block; font-size: 0.8rem; color: var(--text-dim); margin: 12px 0 4px; }

input, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--gold); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--felt), #0f4a2e); border-color: var(--felt); color: white; width: 100%; margin-top: 16px; }
.btn.secondary { background: linear-gradient(135deg, var(--gold), #d9a53a); border-color: var(--gold); color: #241a05; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn.wide { width: 100%; }

.rules-btn { width: 100%; margin-top: 10px; }

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-alt);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 999;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  max-width: 90vw;
  text-align: center;
}

/* ---------------- Lobby ---------------- */

.lobby-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }

.room-code { font-size: 1.8rem; font-weight: 700; letter-spacing: 0.12em; color: var(--gold-bright); }
.room-code.small { font-size: 1rem; }

.player-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
}
.player-list li.disconnected { opacity: 0.5; }
.player-name { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.tag { font-size: 0.68rem; padding: 2px 6px; border-radius: 6px; background: var(--panel-alt); color: var(--text-dim); }
.tag.host { background: var(--gold); color: #241a05; }
.remove-bot-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
}
.remove-bot-btn.confirm {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  width: auto;
  padding: 0 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.bot-controls { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }

.deck-settings { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.deck-settings-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.deck-settings-row label { color: var(--text-dim); font-size: 0.85rem; flex-shrink: 0; }
.deck-settings-row select { width: auto; min-width: 190px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper span { min-width: 22px; text-align: center; font-weight: 700; font-size: 1.1rem; color: var(--gold-bright); }
.checkbox-label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 0.9rem; cursor: pointer; }
.checkbox-label input { width: auto; }
.afk-toggle-row { margin-top: 10px; }
.deck-settings-readonly { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------------- Spiel: Kopfzeile ---------------- */

.game-header {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: relative;
  z-index: 5;
}
.game-header-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.game-header-left, .game-header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.round-badge { font-weight: 700; color: var(--gold-bright); }

/* ---------------- Der Tisch ---------------- */

.table-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(var(--hand-bar-height) + 24px);
  min-height: calc(100vh - var(--header-h));
}

.table-oval {
  position: relative;
  width: min(97vw, 1240px);
  height: min(82vw, 780px, var(--table-max-h));
  border-radius: 50%;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 72%, #0a2417 100%);
  border: 10px solid #4a3018;
  box-shadow: inset 0 4px 30px rgba(0,0,0,0.5), 0 14px 50px rgba(0,0,0,0.45);
}

/* ---------------- Spieler-Panel (Übersicht mit Kartenanzahl) ---------------- */

.player-panel {
  position: fixed;
  top: 76px;
  left: 16px;
  width: 210px;
  max-width: 34vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  max-height: calc(100vh - 110px - var(--hand-bar-height));
  overflow-y: auto;
}
.player-panel h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 8px;
}
.player-panel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--bg-alt);
  border: 1px solid transparent;
  font-size: 0.85rem;
}
.player-panel-row.me { border-color: var(--gold); }
.player-panel-row.active { border-color: var(--success); box-shadow: 0 0 10px rgba(62,207,142,0.4); }
.player-panel-row.disconnected { opacity: 0.45; }
.player-panel-row.finished { opacity: 0.75; }
.player-panel-name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-panel-count {
  color: var(--gold-bright);
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.pile-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 2;
}
.pile-stack {
  position: relative;
  width: 128px;
  height: 183px;
}
.pile-stack .pcard-back {
  position: absolute;
  top: 0; left: 0;
  width: 128px;
  height: 183px;
}
.pile-count {
  position: absolute;
  top: 0; left: 50%;
  transform: translate(-50%, calc(-100% - 10px));
  background: rgba(0,0,0,0.6);
  color: white;
  font-weight: 800;
  font-size: 1.05rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--gold);
}
.claim-line {
  background: rgba(0,0,0,0.72);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  max-width: 92vw;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.claim-line:empty { display: none; }
.pile-claim {
  margin-top: 8px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  text-align: center;
  max-width: 240px;
  min-height: 1.2em;
}

.seats-layer { position: absolute; inset: 0; }

.seat {
  position: absolute;
  top: 0; left: 0;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 116px;
  text-align: center;
  z-index: 3;
}
.seat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--panel-alt);
  border: 3px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.seat.me .seat-avatar { border-color: var(--gold); }
.seat.active-turn .seat-avatar {
  border-color: var(--success);
  box-shadow: 0 0 0 4px rgba(62,207,142,0.35), 0 0 18px rgba(62,207,142,0.6);
  animation: seat-pulse 1.4s ease-in-out infinite;
}
.seat.finished .seat-avatar { border-color: var(--gold); opacity: 0.75; }
.seat.disconnected .seat-avatar { opacity: 0.4; }
@keyframes seat-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(62,207,142,0.35), 0 0 18px rgba(62,207,142,0.6); }
  50% { box-shadow: 0 0 0 7px rgba(62,207,142,0.2), 0 0 26px rgba(62,207,142,0.85); }
}

.seat-name { font-size: 0.82rem; font-weight: 700; max-width: 116px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.seat-hand-count {
  font-size: 0.72rem;
  color: var(--text-dim);
  background: rgba(0,0,0,0.35);
  border-radius: 999px;
  padding: 2px 8px;
}
.seat-place {
  font-size: 0.72rem;
  color: var(--gold-bright);
  font-weight: 700;
}

/* ---------------- Spielkarten (echte Kartenmotive als Bild) ---------------- */

.pcard {
  width: 84px;
  height: 120px;
  border-radius: 9px;
  overflow: hidden;
  background: #fdfdfb;
  border: 1px solid #c9c9c0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  flex-shrink: 0;
  user-select: none;
}

.pcard-back {
  width: 84px;
  height: 120px;
  border-radius: 9px;
  overflow: hidden;
  background: #0a2417;
  border: 2px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.pcard-img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

/* ---------------- Aktionsleiste + Hand ---------------- */

.action-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--hand-bar-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 40;
  padding: 0 14px;
}
#action-bar-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
  text-align: center;
}
.action-bar-note { color: var(--text-dim); font-size: 0.88rem; margin: 0 0 8px; }
.rank-choice { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 10px; }
.rank-btn {
  min-width: 42px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
  flex: 0 0 auto;
  cursor: pointer;
}
.rank-btn.selected { background: var(--felt); border-color: var(--felt); color: white; }
.action-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.action-buttons .btn { margin-top: 0; width: auto; min-width: 140px; }

.hand-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--hand-bar-height);
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
  padding: 14px 14px 20px;
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.hand-bar-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.hand-bar-label { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; text-align: center; }
.auto-sort-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.auto-sort-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-switch {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}
.auto-sort-toggle input:checked + .toggle-switch { background: var(--felt); border-color: var(--felt); }
.auto-sort-toggle input:checked + .toggle-switch::after { transform: translateX(14px); background: white; }
@media (max-width: 640px) {
  .auto-sort-toggle { right: 8px; }
  .toggle-label-text { display: none; }
}
.hand-list {
  list-style: none;
  margin: 0;
  flex: 1;
  padding: 30px 22px 4px;
  display: flex;
  align-items: flex-end;
  overflow-x: auto;
  overflow-y: hidden;
  justify-content: safe center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.hand-list::-webkit-scrollbar { display: none; height: 0; }
.hand-list .pcard {
  width: 132px;
  height: 189px;
  cursor: grab;
  transform-origin: bottom center;
  transition: transform 0.12s ease-out, box-shadow 0.12s ease;
}
.hand-list .pcard.auto-sorted { cursor: pointer; }
.hand-list .pcard.auto-sorted.disabled { cursor: not-allowed; }
.hand-list .pcard.selected { box-shadow: 0 0 0 3px var(--gold), 0 6px 16px rgba(0,0,0,0.5); }
.hand-list .pcard.disabled { cursor: not-allowed; }
.hand-list .pcard.limit-reached { cursor: not-allowed; filter: grayscale(0.35) brightness(0.85); }
.hand-list .pcard.dragging {
  cursor: grabbing;
  opacity: 1;
  outline: 3px dashed var(--gold);
  transform: scale(0.94) !important;
  z-index: 500 !important;
}

/* ---------------- Würfel-Overlay ---------------- */

.dice-modal-content { text-align: center; max-width: 420px; }
.dice-emoji { font-size: 3rem; }
.dice-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dice-list li { display: flex; justify-content: space-between; padding: 7px 12px; background: var(--bg-alt); border-radius: 8px; }
.dice-list li.winner { border: 1px solid var(--gold); color: var(--gold-bright); font-weight: 700; }

/* ---------------- Bluff-Aufdeckung ---------------- */

.reveal-modal-content { text-align: center; max-width: 480px; }
.reveal-cards { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.reveal-hidden-note { color: var(--text-dim); font-size: 0.85rem; font-style: italic; margin: 0 0 10px; }
.reveal-text { font-size: 1.05rem; font-weight: 600; }
.reveal-text.lie { color: var(--danger); }
.reveal-text.truth { color: var(--success); }

/* ---------------- Rundenende ---------------- */

.roundend-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 9, 0.72);
  z-index: 60;
  padding: 16px;
}
.roundend-card { max-width: 460px; text-align: center; }
.roundend-order { text-align: left; margin: 14px 0; padding-left: 26px; }
.roundend-order li { padding: 4px 0; }
.roundend-order li.loser { color: var(--danger); font-weight: 700; }
.roundend-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.roundend-actions .btn { margin-top: 0; }

/* ---------------- Modals ---------------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(8, 12, 9, 0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  max-width: 560px;
  width: 100%;
  position: relative;
  max-height: 86vh;
  overflow: auto;
}
.modal-close { position: absolute; top: 14px; right: 14px; }
.rules-text h3 { color: var(--gold-bright); margin-top: 16px; }
.rules-text p { color: var(--text); line-height: 1.5; }

.history-round { border-bottom: 1px solid var(--border); padding: 10px 0; }
.history-round:last-child { border-bottom: none; }
.history-round-title { color: var(--gold-bright); font-weight: 700; margin-bottom: 4px; }
.history-round ol { margin: 0; padding-left: 20px; }

@media (max-width: 640px) {
  :root { --hand-bar-height: 208px; }
  .table-wrap { align-items: flex-start; min-height: 0; padding: 8px 8px calc(var(--hand-bar-height) + 8px); }
  .table-oval { width: 96vw; height: clamp(300px, calc(100vh - 150px - var(--hand-bar-height) - 60px), 118vw); border-width: 6px; }
  /* Am Zug erscheint die Aktionsleiste über der Handleiste - Tisch schrumpft entsprechend. */
  body.turn-bar-open .table-oval { height: clamp(280px, calc(100vh - 150px - var(--hand-bar-height) - 60px - 128px), 118vw); }
  .table-wrap { padding-bottom: calc(var(--hand-bar-height) + 8px); }
  .seat { width: 88px; }
  .seat-avatar { width: 42px; height: 42px; font-size: 1.05rem; }
  .seat-name { font-size: 0.72rem; max-width: 88px; }
  .pcard { width: 56px; height: 80px; }
  .pile-stack, .pile-stack .pcard-back { width: 92px; height: 132px; }
  .pile-count { width: 30px; height: 30px; font-size: 0.85rem; }
  .hand-list { padding: 20px 14px 4px; }
  .hand-list .pcard { width: 84px; height: 120px; }

  .player-panel {
    position: static;
    width: auto;
    max-width: none;
    max-height: none;
    margin: 10px 12px 0;
    overflow-y: visible;
  }
  .player-panel-list { flex-direction: row; overflow-x: auto; padding-bottom: 2px; }
  .player-panel-row { flex-shrink: 0; }
}

/* --- Warte-Hinweis (Host kann überspringen) --- */
.wait-banner{display:flex;align-items:center;justify-content:center;gap:10px;flex-wrap:wrap;margin:6px auto;padding:8px 12px;max-width:640px;border-radius:10px;background:rgba(255,190,60,.16);border:1px solid rgba(255,190,60,.5);color:inherit;font-size:.92rem;text-align:center}
.wait-banner.hidden{display:none}
#btn-share-link{margin-top:6px}
