:root {
  /* ── Apple-inspirierte Farbpalette ───────────── */
  --bg: #0d111b;
  --bg-2: #121827;
  --panel: #171f31;
  --panel-2: #1f2a40;
  --panel-3: #263451;
  --text: #f4f7fb;
  --muted: #aeb8ca;
  --line: rgba(255, 255, 255, .1);
  --accent: #f4b942;
  --accent-2: #7ee787;
  --danger: #ff6b6b;
  --ok: #7ee787;

  /* Apple: ein weicher, diffuser Schatten statt mehrerer */
  --shadow: 0 4px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, .3);

  /* ── Apple-Radien (8px Basis, 12px gross, 9999px Pill) ── */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  /* ── Apple-Spacing (8er-Skala) ───────────────── */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:   12px;
  --space-lg:   16px;
  --space-xl:   24px;
  --space-2xl:  32px;

  /* ── Apple-Typografie ────────────────────────── */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-lg: 18px;
  --fs-xl: 22px;

  --lh-tight: 1.15;
  --lh-body: 1.47;

  /* ── Komponenten-Tokens ──────────────────────── */
  --panel-pad: var(--space-xl);
  --panel-gap: var(--space-lg);
  --shell-pad: var(--space-md);
  --btn-pad: 10px 16px;
  --btn-pad-sm: 7px 12px;
  --btn-radius: var(--radius-md);
  --btn-weight: 600;
  --card-radius: var(--radius-lg);
  --fixed-bottom-gap: var(--space-sm);
  --fixed-bottom-pad: var(--space-sm) var(--space-lg);
  --transition-fast: .15s ease;
  --transition-normal: .25s ease;

  /* ── Apple-Farb-Tokens ───────────────────────── */
  --error-text: #ffd7d7;
  --error-bg: rgba(255, 107, 107, .12);
  --error-border: rgba(255, 107, 107, .5);
  --warn-text: #ffe4a3;
  --warn-bg: rgba(244, 185, 66, .1);
  --warn-border: rgba(244, 185, 66, .55);
  --danger-bg: rgba(255, 107, 107, .12);
  --danger-border: rgba(255, 107, 107, .4);
  --good-text: #06200e;
  --good-bg-start: #93f2a9;
  --good-bg-end: #4ccf73;
  --primary-text: #231705;
  --primary-bg-start: #ffd66b;
  --primary-bg-end: #e7a72f;
  --leave-text: #ffb8b8;
  --leave-bg: rgba(255, 107, 107, .1);
  --leave-border: rgba(255, 107, 107, .3);
  --ready-bg: rgba(126, 231, 135, .1);
  --ready-border: rgba(126, 231, 135, .3);
  --won-bg: rgba(126, 231, 135, .18);
  --won-border: rgba(126, 231, 135, .45);
  --replacement-bg: rgba(244, 185, 66, .12);
  --replacement-border: rgba(244, 185, 66, .35);

  /* Apple-Glass-Effekt für die Topbar */
  --glass-bg: rgba(13, 17, 27, .78);
  --glass-blur: 24px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(244,185,66,.18), transparent 30rem),
    radial-gradient(circle at bottom right, rgba(126,231,135,.12), transparent 24rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }

/* ── Shell ──────────────────────────────────── */
.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: var(--shell-pad) var(--shell-pad) calc(80px + var(--safe-bottom));
}

/* ── Fixed bottom overlays ──────────────────── */
.toast,
.update-banner {
  position: fixed;
  z-index: 20;
  left: var(--shell-pad);
  right: var(--shell-pad);
  bottom: calc(var(--shell-pad) + var(--safe-bottom));
  padding: var(--fixed-bottom-pad);
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.toast.error { border-color: var(--error-border); }
.toast.ok { border-color: rgba(126, 231, 135, .55); }

/* ── Topbar (Apple-Glass) ────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: calc(-1 * var(--shell-pad)) calc(-1 * var(--shell-pad)) var(--panel-gap);
  padding: var(--space-sm) var(--shell-pad);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  background: var(--glass-bg);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}
.brand { min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -.3px;
}
.brand small {
  display: block;
  color: var(--muted);
  margin-top: 1px;
  font-size: clamp(10px, 2.8vw, var(--fs-sm));
}
.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px var(--space-md);
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: var(--text);
  white-space: nowrap;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.room-pill:hover { background: rgba(255,255,255,.12); }

/* ── Panel (Apple: kein Border, kein Gradient) ─ */
.panel {
  background: var(--panel);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--panel-pad);
  margin-bottom: var(--panel-gap);
}
.center-panel { margin-top: 14vh; }
.compact-panel { box-shadow: none; }
.panel h1, .panel h2, .panel h3 {
  margin: 0 0 var(--space-md);
  line-height: var(--lh-tight);
}
.panel h2 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.3px; }
.panel h3 { font-size: var(--fs-lg); font-weight: 600; }
.panel p {
  color: var(--muted);
  line-height: var(--lh-body);
  margin: var(--space-sm) 0;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin: 0 0 var(--space-md);
}
.section-title h2, .section-title h3 { margin: 0; }

/* ── Form ────────────────────────────────────── */
.form-row {
  display: grid;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 500;
}
input {
  width: 100%;
  color: var(--text);
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius-md);
  padding: var(--space-md) 14px;
  outline: none;
  transition: border-color var(--transition-fast);
}
input:focus { border-color: var(--accent); }

/* ── Buttons (Apple: schlank, weicher) ────────── */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}
.btn {
  border: 0;
  border-radius: var(--btn-radius);
  padding: var(--btn-pad);
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  font-weight: var(--btn-weight);
  border: 1px solid rgba(255,255,255,.1);
  transition: transform var(--transition-fast), filter var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary {
  background: linear-gradient(180deg, var(--primary-bg-start), var(--primary-bg-end));
  color: var(--primary-text);
  border-color: rgba(255,255,255,.2);
  font-weight: 700;
}
.btn.good {
  background: linear-gradient(180deg, var(--good-bg-start), var(--good-bg-end));
  color: var(--good-text);
  font-weight: 700;
}
.btn.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--error-text);
}
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(255,255,255,.06); }
.btn.small {
  padding: var(--btn-pad-sm);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}

/* Leave button */
.btn.leave {
  background: var(--leave-bg);
  border-color: var(--leave-border);
  color: var(--leave-text);
  font-size: var(--fs-xs);
  padding: 6px var(--space-sm);
  font-weight: 500;
}

/* ── Notice (Apple: dezenter) ─────────────────── */
.notice {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: none;
  background: rgba(255,255,255,.05);
  color: var(--muted);
  line-height: var(--lh-body);
  font-size: var(--fs-sm);
}
.notice.warn {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-border);
  color: var(--warn-text);
}
.notice.error {
  background: var(--error-bg);
  border-left: 3px solid var(--error-border);
  color: var(--error-text);
}

/* ── Stats ──────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin: var(--space-md) 0 0;
}
.stat-box {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: rgba(0,0,0,.22);
  border: 1px solid var(--line);
  text-align: center;
}
.stat-box strong { display: block; font-size: var(--fs-lg); font-weight: 700; }
.stat-box span { color: var(--muted); font-size: var(--fs-xs); }

/* ── Player list ─────────────────────────────── */
.player-list, .deck-list, .history-list {
  display: grid;
  gap: var(--space-sm);
}
.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.18);
  transition: background var(--transition-fast);
}
.player-main { min-width: 0; }
.player-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-sub {
  color: var(--muted);
  font-size: var(--fs-xs);
  margin-top: 2px;
}
.status-chip {
  flex: 0 0 auto;
  padding: 4px var(--space-sm);
  border-radius: var(--radius-pill);
  color: var(--muted);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.status-chip.ok {
  color: #baffc7;
  border-color: rgba(126,231,135,.45);
  background: rgba(126,231,135,.1);
}
.status-chip.host {
  color: #ffe09a;
  border-color: rgba(244,185,66,.4);
  background: rgba(244,185,66,.08);
}

/* Player states */
.player-item.ready { background: var(--ready-bg); }
.player-item.not-ready { background: rgba(0,0,0,.12); }
.player-item.won { background: var(--won-bg); }
.player-item.replacement { background: var(--replacement-bg); }

/* Combined player + reveal layout */
.player-item.with-reveal {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
}
.player-item.with-reveal .reveal-thumb {
  width: 52px;
}
@media (max-width: 520px) {
  .player-item.with-reveal { grid-template-columns: 48px 1fr; }
  .player-item.with-reveal .reveal-thumb { width: 48px; }
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  flex: 0 0 auto;
}
.status-dot.ready {
  background: var(--accent-2);
  box-shadow: 0 0 6px rgba(126,231,135,.6);
}
.status-dot.not-ready {
  background: var(--muted);
  opacity: .35;
}

/* ── Progress ────────────────────────────────── */
.progress-line {
  height: 6px;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: var(--radius-pill);
  transition: width var(--transition-normal);
}

/* ── Card grid ───────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(var(--option-count, 3), minmax(0, 1fr));
  gap: var(--space-sm);
  align-items: stretch;
}
.card-choice {
  width: 100%;
  position: relative;
  border: none;
  border-radius: var(--card-radius);
  overflow: hidden;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  min-height: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.card-choice:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
}
.card-choice.selected {
  outline: 2.5px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(244,185,66,.2), 0 8px 28px rgba(0,0,0,.28);
}
.card-choice:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.card-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: rgba(0,0,0,.22);
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px var(--space-xs);
  text-align: center;
  font-weight: 700;
  font-size: clamp(10px, 2.7vw, var(--fs-sm));
  line-height: var(--lh-tight);
  letter-spacing: -.2px;
}
.pick-badge {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  display: none;
  min-width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: rgba(0,0,0,.72);
  color: var(--accent);
  font-weight: 700;
  font-size: var(--fs-sm);
  border: 1.5px solid var(--accent);
}
.card-choice.selected .pick-badge { display: inline-flex; }

/* ── Value buttons ──────────────────────────── */
.value-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  margin-top: var(--space-md);
}
.value-btn {
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.06);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 0;
  font-weight: 800;
  font-size: var(--fs-lg);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.value-btn:hover { background: rgba(255,255,255,.1); }
.value-btn:active { transform: scale(.96); }
.value-btn.selected {
  background: linear-gradient(180deg, var(--primary-bg-start), var(--primary-bg-end));
  color: var(--primary-text);
  border-color: rgba(255,255,255,.2);
  font-weight: 900;
}
.value-btn.used, .value-btn:disabled {
  opacity: .25;
  text-decoration: line-through;
  cursor: not-allowed;
  transform: none;
}
.value-btn.used:hover { background: rgba(255,255,255,.06); }

/* ── Submit bar ──────────────────────────────── */
.submit-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  padding: var(--space-md) var(--shell-pad) calc(var(--space-md) + var(--safe-bottom));
  background: rgba(13,17,27,.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.submit-inner {
  width: min(980px, 100%);
  margin: 0 auto;
  display: grid;
  gap: var(--space-sm);
}
.submit-summary {
  color: var(--muted);
  font-size: var(--fs-sm);
  text-align: center;
  font-weight: 500;
}
.submit-inner .btn {
  width: 100%;
  padding: 14px;
}

/* ── Reveal / Deck / History cards ──────────── */
.reveal-card, .deck-card, .history-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(0,0,0,.18);
  padding: var(--space-md);
}
.reveal-card.win { border-color: rgba(126,231,135,.42); }
.reveal-card.fallback { border-color: rgba(244,185,66,.4); }
.reveal-card .line, .deck-card .line, .player-item.with-reveal .line {
  display: flex;
  justify-content: space-between;
  gap: var(--space-sm);
  align-items: baseline;
}
.reveal-card strong, .deck-card strong { min-width: 0; font-weight: 700; }
.reveal-card span, .deck-card span {
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: right;
}

/* ── Deck mini-grid ──────────────────────────── */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}
.deck-mini {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
}
.deck-mini img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.deck-mini small {
  display: block;
  padding: var(--space-xs) 3px;
  font-size: 10px;
  line-height: 1.1;
  text-align: center;
  color: var(--muted);
}

/* ── Copy box ────────────────────────────────── */
.copy-box {
  width: 100%;
  white-space: pre-wrap;
  user-select: all;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: rgba(0,0,0,.2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  overflow-wrap: anywhere;
}

/* ── Layout ──────────────────────────────────── */
.two-col {
  display: grid;
  gap: var(--space-lg);
}
.footer-actions {
  display: grid;
  gap: var(--space-sm);
}
.hidden { display: none !important; }

/* ── Separator (Apple: dünn) ─────────────────── */
.separator {
  border: none;
  height: 1px;
  background: var(--line);
  margin: var(--space-md) 0;
}

/* ── Utility ─────────────────────────────────── */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.row-tight {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sr-only {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* ── Collapsible sections ────────────────────── */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
  padding: var(--space-xs) 0;
}
.collapsible-header::after {
  content: '▸';
  font-size: var(--space-lg);
  color: var(--muted);
  transition: transform var(--transition-normal);
}
.collapsible-header.open::after { transform: rotate(90deg); }
.collapsible-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .35s ease;
}
.collapsible-content {
  min-height: 0;
  overflow: hidden;
  display: grid;
  gap: var(--space-sm);
}
.collapsible-body.open { grid-template-rows: 1fr; }

/* ── Reveal panel ─────────────────────────────── */
.reveal-list {
  display: grid;
  gap: var(--space-sm);
}
.reveal-panel {
  border: 1px solid rgba(244,185,66,.28);
}
.reveal-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
}
.reveal-thumb {
  width: 58px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(0,0,0,.26);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  font-size: var(--fs-lg);
}
.reveal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.reveal-main { min-width: 0; }
.reveal-card-name {
  font-weight: 700;
  margin-top: var(--space-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reveal-meta {
  color: var(--muted);
  font-size: var(--fs-xs);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Final deck ───────────────────────────────── */
.deck-card.self {
  border-color: rgba(126,231,135,.45);
}
.deck-actions {
  margin-top: var(--space-md);
}
.deck-actions .btn.primary { flex: 1 1 100%; }
.copy-box.compact {
  margin-top: var(--space-sm);
  font-size: var(--fs-xs);
  max-height: 150px;
  overflow: auto;
}

/* ── Pinned own deck ──────────────────────────── */
.deck-own-pin {
  position: sticky;
  bottom: 70px;
  z-index: 5;
}

/* ── Update banner ────────────────────────────── */
.update-banner { z-index: 50; }
.update-banner strong,
.update-banner span { display: block; }
.update-banner span {
  color: var(--muted);
  font-size: var(--fs-xs);
  margin-top: 2px;
}

/* ── Responsive ───────────────────────────────── */
@media (min-width: 680px) {
  .app-shell { padding-left: var(--space-xl); padding-right: var(--space-xl); }
  .topbar { margin-left: calc(-1 * var(--space-xl)); margin-right: calc(-1 * var(--space-xl)); padding-left: var(--space-xl); padding-right: var(--space-xl); }
  .two-col { grid-template-columns: 1fr 1fr; align-items: start; }
  .card-title { font-size: var(--fs-base); }
  .value-grid { grid-template-columns: repeat(8, 1fr); }
  .submit-inner { grid-template-columns: 1fr 220px; align-items: center; }
  .submit-summary { text-align: left; }
}

@media (max-width: 520px) {
  .deck-grid { grid-template-columns: repeat(4, 1fr); }
  .reveal-card { grid-template-columns: 52px 1fr; }
  .reveal-thumb { width: 52px; }
}

@media (max-width: 380px) {
  .card-grid { gap: 6px; }
  .card-choice { border-radius: var(--radius-md); }
  .card-title { font-size: 10px; min-height: 32px; }
  .btn { padding-left: var(--space-sm); padding-right: var(--space-sm); }
}
