:root {
  --bg: #0e3b2a;
  --bg2: #0a2a1e;
  --fg: #f3f3f3;
  --muted: #a0c0b0;
  --accent: #f5c518;
  --red: #d94a4a;
  --black: #1a1a1a;
  --card-bg: #fff;
  --border: rgba(255,255,255,0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  color: var(--fg);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.landing { display: grid; place-items: center; min-height: 100vh; padding: 24px; text-align: center; }

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 10px 12px; background: rgba(0,0,0,0.25); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
#me { font-weight: 600; font-size: 16px; flex-shrink: 0; }
#phase {
  font-size: 13px; color: var(--muted); flex: 1; min-width: 0;
  text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
button {
  background: var(--accent); color: #1a1a1a; border: 0; padding: 10px 16px;
  border-radius: 8px; font-weight: 600; font-size: 15px; cursor: pointer;
  min-height: 44px;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: rgba(255,255,255,0.15); color: var(--fg); }
.header-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.header-actions button {
  padding: 7px 10px; min-height: 36px; font-size: 13px;
  border-radius: 7px;
}
#notify-btn { background: rgba(255,255,255,0.15); color: var(--fg); padding: 6px 10px; }
@media (max-width: 420px) {
  #me { font-size: 15px; }
  #phase { font-size: 12px; }
  .header-actions button { padding: 6px 8px; font-size: 12px; min-height: 32px; }
  .trump-badge { padding: 1px 6px; font-size: 11px; }
}

section { padding: 12px 16px; }

#teams { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.team {
  background: rgba(255,255,255,0.06); padding: 10px; border-radius: 10px;
  border: 1px solid var(--border);
}
.team.me { border-color: var(--accent); }
.team-name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.team-score { font-size: 28px; font-weight: 700; }
.team-target { font-size: 12px; color: var(--muted); }

#status {
  font-size: 14px; line-height: 1.5; background: rgba(0,0,0,0.2);
  border-radius: 10px; margin: 12px 16px; padding: 12px;
}
#status .row { display: flex; justify-content: space-between; gap: 8px; }
#status .turn { color: var(--accent); font-weight: 600; }

#others { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.other {
  background: rgba(255,255,255,0.05); padding: 6px 4px; border-radius: 8px;
  text-align: center; border: 1px solid var(--border);
}
.other.turn { border-color: var(--accent); background: rgba(245,197,24,0.12); }
.other.is-me { border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.08); }
.other.is-me.turn { border-color: var(--accent); }
.other-name { font-weight: 600; font-size: 12px; line-height: 1.2; }
.other-cards { font-size: 10px; color: var(--muted); margin-top: 2px; }
.other-bid { font-size: 11px; color: var(--accent); margin-top: 2px; min-height: 14px; }
.dealer-badge {
  display: inline-block; margin-left: 3px; padding: 0 4px;
  border-radius: 8px; font-size: 9px; font-weight: 700;
  background: rgba(255,255,255,0.2); color: var(--fg);
  vertical-align: middle;
}

#progress {
  background: rgba(0,0,0,0.2); border-radius: 10px;
  margin: 0 16px; padding: 10px 12px;
}
#progress:empty { display: none; }
.progress-header { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.progress-header strong { color: var(--fg); }
.progress-points { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.point {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 4px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.point.bidder { border-color: #4ade80; background: rgba(74,222,128,0.12); }
.point.opp { border-color: var(--red); background: rgba(217,74,74,0.12); }
.point-label { font-size: 10px; color: var(--muted); letter-spacing: 0.5px; font-weight: 600; }
.card-val {
  background: var(--card-bg); border-radius: 4px;
  padding: 2px 6px; font-weight: 700; font-size: 14px; min-width: 30px;
}
.card-val.red { color: var(--red); }
.card-val.black { color: var(--black); }
.num-val { font-weight: 700; font-size: 14px; color: var(--fg); }
.point-team { font-size: 10px; color: var(--muted); }
.point.bidder .point-team { color: #4ade80; font-weight: 600; }
.point.opp .point-team { color: var(--red); font-weight: 600; }
.point.pending .card-val { opacity: 0.6; }

#trick {
  min-height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 16px 12px;
  background: rgba(0,0,0,0.2); border-radius: 12px;
  margin: 0 16px;
}
.trick-empty { color: var(--muted); font-style: italic; padding: 60px 0; }
.trick-earlier {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  min-height: 70px;
}
.mini-card {
  background: var(--card-bg); border-radius: 6px;
  width: 44px; height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.mini-card.red { color: var(--red); }
.mini-card.black { color: var(--black); }
.mini-card.winner { box-shadow: 0 0 0 2px var(--accent), 0 1px 3px rgba(0,0,0,0.4); }
.mini-card.lead::before {
  content: 'Anspiel';
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.85); color: #0e3b2a;
  font-size: 9px; font-weight: 700; letter-spacing: 0.4px;
  padding: 1px 5px; border-radius: 4px; white-space: nowrap;
  pointer-events: none;
}
.mini-rank { font-size: 16px; line-height: 1; }
.mini-suit { font-size: 14px; line-height: 1; }
.mini-player {
  position: absolute; bottom: -16px;
  font-size: 10px; color: var(--muted); white-space: nowrap;
}
.trick-center {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.big-card {
  background: var(--card-bg); border-radius: 12px;
  width: 110px; height: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  animation: cardLand 0.25s ease-out;
}
.big-card.red { color: var(--red); }
.big-card.black { color: var(--black); }
.big-card.winner { box-shadow: 0 0 0 3px var(--accent), 0 6px 20px rgba(0,0,0,0.5); }
.trick-center { position: relative; }
.big-card.lead::before {
  content: 'ANSPIEL';
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.9); color: #0e3b2a;
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  padding: 2px 10px; border-radius: 6px; white-space: nowrap;
  pointer-events: none;
}
.big-rank { font-size: 64px; line-height: 1; }
.big-suit { font-size: 40px; line-height: 1; margin-top: 4px; }
.latest-player {
  font-size: 14px; color: var(--accent); font-weight: 600;
}
.trick-result {
  font-size: 13px; color: var(--accent); font-weight: 600;
  background: rgba(245,197,24,0.12); padding: 4px 12px; border-radius: 8px;
}
@keyframes cardLand {
  0% { transform: scale(0.6) translateY(-20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

#hand {
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  padding: 10px 6px; background: rgba(0,0,0,0.15); border-radius: 10px;
  margin: 10px 8px;
}
.card {
  background: var(--card-bg); border-radius: 8px;
  width: 48px; height: 70px; display: grid; place-items: center;
  font-size: 20px; font-weight: 700; cursor: pointer;
  user-select: none; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  transition: transform .1s;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.playable:hover { transform: translateY(-4px); }
.card.disabled { opacity: 0.5; cursor: not-allowed; }
.card .corner { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.card .suit { font-size: 16px; }

#actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#actions button { flex: 1 1 80px; max-width: 140px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: white; padding: 10px 16px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; }

dialog {
  background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  border-radius: 12px; max-width: 90vw; padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h2 { margin-top: 0; }
dialog button { margin-top: 12px; }

#leaderboard table { width: 100%; border-collapse: collapse; }
#leaderboard td, #leaderboard th { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
#leaderboard th { color: var(--muted); font-weight: 500; font-size: 12px; }

.history-teams { font-size: 12px; color: var(--muted); margin: 0 0 8px 0; }
.history-list { display: flex; flex-direction: column; gap: 4px; }
.history-hand {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.history-hand.set-back { background: rgba(217,74,74,0.08); border-color: rgba(217,74,74,0.4); }
.hand-summary {
  display: grid; grid-template-columns: 28px 1fr 18px 40px 56px;
  gap: 6px; padding: 7px 10px; cursor: pointer;
  font-size: 13px; align-items: center;
  list-style: none;
}
.hand-summary::-webkit-details-marker { display: none; }
.hand-summary::marker { display: none; content: ''; }
.hand-summary::before {
  content: '▸'; color: var(--muted); font-size: 11px;
  transition: transform 0.15s; display: inline-block;
  position: absolute; right: 10px; margin-top: -1px;
}
.history-hand { position: relative; }
.history-hand[open] .hand-summary::before { transform: rotate(90deg); }
.h-num { color: var(--muted); font-size: 11px; }
.h-bidder { font-weight: 600; }
.h-bid { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 2px; }
.h-status { font-weight: 700; font-size: 14px; text-align: center; }
.history-hand.made .h-status { color: #4ade80; }
.history-hand.set-back .h-status { color: var(--red); }
.h-pts { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; text-align: right; }
.h-score { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; padding-right: 14px; }
.hand-tricks {
  background: rgba(0,0,0,0.25); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.trick-line {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 12px; padding: 3px 0;
}
.trick-num { color: var(--muted); font-weight: 600; min-width: 18px; }
.play-entry {
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px;
}
.play-player { font-size: 11px; color: var(--muted); }
.play-card {
  font-weight: 700; font-size: 12px;
  background: var(--card-bg); padding: 1px 4px; border-radius: 3px;
}
.play-card.red { color: var(--red); }
.play-card.black { color: var(--black); }
.play-sep { color: var(--muted); font-size: 11px; }
.trick-winner { margin-left: auto; font-size: 11px; color: var(--accent); font-weight: 600; }

.trump-badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  background: var(--accent); color: #1a1a1a; font-weight: 600; font-size: 12px;
}

@media (min-width: 600px) {
  .card { width: 64px; height: 90px; font-size: 24px; }
  .card .suit { font-size: 18px; }
  #hand { gap: 6px; padding: 12px; margin: 12px 16px; }
}
