:root {
  --bg: #0e1a15;
  --bg-2: #12231c;
  --panel: #172c23;
  --panel-2: #1e3a2e;
  --line: #2b4b3c;
  --text: #eaf3ee;
  --muted: #93ad9f;
  --accent: #57c98b;
  --accent-dark: #2f7d55;
  --warn: #e0b040;
  --danger: #d9534f;
  --card-red: #c0392b;
  --card-black: #1c2833;
  --radius: 14px;
  --hand-card-w: 62px;
  --mini-card-w: 34px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }

/* --- Grundelemente --- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-dark); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
@media (hover: hover) {
  .btn:hover:not(:disabled) { background: var(--line); }
  .btn.primary:hover:not(:disabled) { background: var(--accent); color: #08150f; }
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 17px;
  width: 100%;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#input-code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row input { flex: 1; }

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.bar-title { font-weight: 700; }
.round-info { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.round-info strong { font-size: 16px; }
.round-info span { font-size: 12px; }

.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 4px 0 0; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0; }

/* --- Startseite --- */

.home-inner {
  margin: auto;
  width: min(420px, 100%);
  padding: 24px 20px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.logo { font-size: 40px; margin: 0; text-align: center; letter-spacing: -.02em; }
.tagline { margin: -8px 0 8px; text-align: center; color: var(--muted); font-size: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.rules-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.rules-box summary { cursor: pointer; font-weight: 600; }
.rules-box ol { margin: 10px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.5; }
.rules-box b { color: var(--text); }

/* --- Lobby --- */

.lobby-inner {
  padding: 18px 16px calc(18px + var(--safe-bottom));
  width: min(480px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.code-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.code-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.code { font-size: 44px; letter-spacing: .18em; font-weight: 800; color: var(--accent); }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.host { background: var(--accent-dark); color: #eafff2; border-color: var(--accent); }
.badge.off { color: var(--warn); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.dot.off { background: var(--muted); }

/* --- Spiel --- */

.opponents {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 0;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  align-content: start;
  align-content: safe center;
}
/* Auf breiten Schirmen nebeneinander, aber mittig statt am linken Rand geklebt. */
@media (min-width: 620px) {
  .opponents {
    grid-template-columns: repeat(auto-fit, minmax(280px, 360px));
    justify-content: center;
  }
}

.player-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.player-panel.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(87,201,139,.25); }
.player-panel.won { border-color: var(--warn); }
.player-panel.offline { opacity: .55; }
.panel-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.panel-name { font-weight: 700; font-size: 15px; }
.stats { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin-left: auto; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.panel-cards { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; min-height: 50px; }
.panel-cards:empty { min-height: 0; }
.panel-cards .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.bj-total { font-size: 12px; color: var(--warn); font-weight: 700; margin-left: 4px; }

.status {
  flex: 0 0 auto;
  padding: 8px 14px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.status.active { color: var(--accent); font-weight: 600; }

.self { flex: 0 0 auto; padding: 8px 12px 0; }
.self .player-panel { background: var(--panel-2); }

.hand {
  flex: 0 0 auto;
  display: flex;
  gap: 0;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
}
/* Zentriert bei wenigen Karten, laesst bei vielen aber nach links scrollen,
   statt die erste Karte abzuschneiden. */
.hand::before,
.hand::after {
  content: "";
  margin: auto;
}
/* Reichen 6px Abstand nicht, ruecken die Karten zusammen und ueberlappen sich,
   damit auch sieben Karten auf ein Handy passen. --count setzt der Client. */
.hand .card + .card {
  margin-left: min(
    6px,
    calc((100% - var(--count, 7) * var(--w)) / max(var(--count, 7) - 1, 1))
  );
}
.hand .card { position: relative; }
.hand .card.selected { z-index: 3; }
.hand.tight .card .pip { display: none; }
.actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 0 12px calc(12px + var(--safe-bottom));
  justify-content: center;
  flex-wrap: wrap;
}
.actions .btn { flex: 1 1 140px; max-width: 240px; }

/* --- Karten --- */

.card {
  --w: var(--hand-card-w);
  position: relative;
  width: var(--w);
  aspect-ratio: 5 / 7;
  border-radius: 7px;
  background: #fdfdf8;
  color: var(--card-black);
  border: 1px solid #d8d8cd;
  font-weight: 800;
  line-height: 1;
  flex: 0 0 auto;
  user-select: none;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0,0,0,.35);
}
.card .corner {
  position: absolute;
  top: 6%;
  left: 9%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--w) * .04);
}
.card .r { font-size: calc(var(--w) * .34); }
.card .s { font-size: calc(var(--w) * .28); }
.card .pip {
  position: absolute;
  right: 8%;
  bottom: 5%;
  font-size: calc(var(--w) * .42);
}
.card.red { color: var(--card-red); }
.card.mini { --w: var(--mini-card-w); border-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.card.back {
  background: repeating-linear-gradient(45deg, #2a4d8f 0 5px, #1d3663 5px 10px);
  border-color: #14264a;
}
.card.selectable { cursor: pointer; transition: transform .12s ease; }
.card.selectable:active { transform: translateY(-4px); }
@media (hover: hover) { .card.selectable:hover { transform: translateY(-8px); } }
.card.selected { outline: 3px solid var(--accent); outline-offset: 2px; transform: translateY(-10px); }
.card.dim { opacity: .45; }

/* --- Overlay --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 8, .82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  width: min(460px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.overlay-card h2 { margin: 0; font-size: 22px; text-align: center; }
.overlay-card h3 { margin: 0; font-size: 15px; color: var(--muted); text-align: center; font-weight: 600; }
.bid-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.bid-grid .btn { padding: 18px 0; font-size: 20px; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid transparent;
}
.result-row.win { border-color: var(--accent); }
.result-row .who { font-weight: 700; font-size: 14px; min-width: 72px; }
.result-row .cards { display: flex; gap: 3px; flex: 1; flex-wrap: wrap; }
.result-row .val { font-size: 13px; color: var(--muted); text-align: right; }
.big-result { text-align: center; font-size: 52px; line-height: 1; }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.score-table th, .score-table td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table thead th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.score-table tr.me td { color: var(--accent); font-weight: 700; }
.waiting { font-size: 13px; color: var(--muted); text-align: center; }

.log-panel {
  position: absolute;
  z-index: 15;
  top: 52px;
  left: 10px;
  right: 10px;
  max-height: 45dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  box-shadow: 0 12px 30px rgba(0,0,0,.5);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 30;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  max-width: 90vw;
  text-align: center;
}

@media (min-width: 700px) {
  :root { --hand-card-w: 78px; --mini-card-w: 42px; }
  .opponents, .self, .hand, .actions, .status { max-width: 1100px; margin-inline: auto; width: 100%; }
}
