/* ========== Grundlagen ========== */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;
  --ja: #16a34a;
  --ja-soft: #dcfce7;
  --nein: #dc2626;
  --nein-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #162236;
    --text: #e5edf7;
    --muted: #94a3b8;
    --border: #22314a;
    --primary: #14b8a6;
    --primary-hover: #2dd4bf;
    --primary-soft: #0f3b39;
    --ja: #22c55e;
    --ja-soft: #0f3320;
    --nein: #f87171;
    --nein-soft: #3b1515;
    --warn: #fbbf24;
    --warn-soft: #3a2a0a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
img, svg { max-width: 100%; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.narrow { max-width: 720px; margin: 0 auto; }
.narrow-sm { max-width: 440px; }
.narrow-card { max-width: 520px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ja); font-weight: 600; }
.neg { color: var(--nein); font-weight: 600; }
.side-ja { color: var(--ja); }
.side-nein { color: var(--nein); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; border-radius: 8px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent); outline-offset: 2px; }

/* ========== Kopfzeile ========== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; color: var(--primary); flex: none; }

.nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav > a { padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.nav > a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav > a.active { color: var(--text); background: var(--surface-2); }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.nav-user form { margin: 0; }
.balance-chip {
  display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15;
  padding: 6px 12px; border-radius: 10px; background: var(--primary-soft); color: var(--text);
}
.balance-chip:hover { text-decoration: none; filter: brightness(.97); }
.balance-name { font-size: .75rem; color: var(--muted); }

.nav-toggle {
  display: none; margin-left: auto; width: 44px; height: 44px; border: 0; background: transparent;
  border-radius: 10px; cursor: pointer; padding: 10px; flex-direction: column; justify-content: center; gap: 5px;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; transition: transform .2s, opacity .2s; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 860px) {
  .nav-toggle { display: flex; }
  .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: 2px; padding: 8px 16px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav > a { padding: 12px; }
  .nav-user { margin: 8px 0 0; padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
  .balance-chip { flex: 1; align-items: flex-start; }
}

/* ========== Buttons & Formulare ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-lg { min-height: 50px; padding: 10px 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ja { background: var(--ja); color: #fff; }
.btn-nein { background: var(--nein); color: #fff; }
.btn-danger { background: transparent; color: var(--nein); border-color: var(--nein); }
.btn-danger:hover { background: var(--nein-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: 6px; }
.field > span em, .field > legend em { font-weight: 400; font-style: normal; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="datetime-local"], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; min-height: 46px;
  font-size: 16px; /* verhindert Zoom auf iOS */
}
textarea { resize: vertical; min-height: 100px; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--primary); }
.form-errors { background: var(--nein-soft); color: var(--nein); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.form-errors ul { margin: 0; padding-left: 18px; }

/* Seitenwahl Ja/Nein */
.side-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border: 0; padding: 0; margin: 0 0 14px; }
.side-option {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 14px;
  border: 2px solid var(--border); border-radius: 12px; cursor: pointer; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.side-option input { position: absolute; opacity: 0; pointer-events: none; }
.side-option-title { font-weight: 800; font-size: 1.15rem; }
.side-option-sub { font-size: .85rem; color: var(--muted); }
.side-option-quote { font-weight: 700; margin-top: 4px; }
.side-option-ja .side-option-title, .side-option-ja .side-option-quote { color: var(--ja); }
.side-option-nein .side-option-title, .side-option-nein .side-option-quote { color: var(--nein); }
.side-option-ja:has(input:checked) { border-color: var(--ja); background: var(--ja-soft); }
.side-option-nein:has(input:checked) { border-color: var(--nein); background: var(--nein-soft); }
.side-option:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--primary) 50%, transparent); outline-offset: 2px; }
.side-option.locked { opacity: .45; cursor: not-allowed; }

.quick-amounts { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.chip {
  font: inherit; font-size: .9rem; font-weight: 600; padding: 6px 12px; min-height: 36px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.estimate { font-size: .95rem; min-height: 1.5em; margin-bottom: 12px; }

/* ========== Karten & Layout ========== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card-accent { border-color: var(--primary); }
.card-manage { background: var(--surface-2); }
@media (min-width: 640px) { .card { padding: 24px; } }

.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.breadcrumb { margin-bottom: 12px; font-size: .95rem; }

.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #0e7490 100%);
  color: #fff; border-radius: 20px; padding: clamp(24px, 5vw, 48px); margin-bottom: 32px;
}
.hero h1 { font-size: clamp(1.7rem, 1.2rem + 2.5vw, 2.75rem); max-width: 18ch; }
.hero .lead { font-size: 1.1rem; max-width: 60ch; opacity: .95; }
.hero .muted { color: rgba(255, 255, 255, .8); }
.hero .btn-primary { background: #fff; color: var(--primary); }
.hero .btn-primary:hover { background: #f0fdfa; }
@media (prefers-color-scheme: dark) { .hero .btn-primary { color: #0f766e; } }
.hero .btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .5); }
.hero .btn-ghost:hover { background: rgba(255, 255, 255, .12); }

/* Tabs & Suche */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 14px; border-radius: 999px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); white-space: nowrap; font-weight: 500; font-size: .95rem;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.search { display: flex; gap: 8px; margin-bottom: 20px; }
.search input { flex: 1; min-width: 0; }

/* Wett-Karten */
.bet-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.bet-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); transition: transform .15s, border-color .15s;
}
.bet-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--primary); }
.bet-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.bet-card-title { font-size: 1.08rem; margin: 0; overflow-wrap: anywhere; }
.bet-card .muted.small { margin: 0; }
.bet-card-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); flex-wrap: wrap; }

.split { height: 8px; border-radius: 999px; background: var(--nein); overflow: hidden; margin-top: 8px; }
.split-lg { height: 12px; margin-top: 16px; }
.split-ja { height: 100%; background: var(--ja); border-right: 2px solid var(--surface); }
.split-legend { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; gap: 8px; }

.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; letter-spacing: .01em; }
.badge-offen { background: var(--primary-soft); color: var(--primary); }
.badge-wartend { background: var(--warn-soft); color: var(--warn); }
.badge-entschieden { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.badge-annulliert { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill { display: inline-block; font-size: .8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.pill-ja { background: var(--ja-soft); color: var(--ja); }
.pill-nein { background: var(--nein-soft); color: var(--nein); }
.tag { font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* Detailseite */
.bet-layout { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .bet-layout { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .bet-side { position: sticky; top: 80px; }
}
@media (max-width: 959px) {
  /* Auf dem Handy: Einsatzformular direkt unter dem Wettkopf */
  .bet-layout { display: flex; flex-direction: column; }
  .bet-main { display: contents; }
  .bet-main > .card:first-child { order: 1; }
  .bet-side { order: 2; }
  .bet-main > .card:nth-child(2) { order: 3; }
}
.bet-title { overflow-wrap: anywhere; margin-top: 8px; }
.bet-desc { white-space: pre-line; overflow-wrap: anywhere; }
.big { font-size: 1.25rem; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 0; }
.stats-4 .card { margin: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-value { font-size: 1.35rem; font-weight: 800; overflow-wrap: anywhere; }
.stat-value-sm { font-size: 1rem; }
@media (max-width: 860px) { .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats > .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stats-4 .stat-value { font-size: 1.1rem; }
}

.pool { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.pool-side { border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 2px; border: 2px solid transparent; }
.pool-ja { background: var(--ja-soft); }
.pool-nein { background: var(--nein-soft); }
.pool-side.winner { border-color: currentColor; }
.pool-ja.winner { color: var(--ja); }
.pool-nein.winner { color: var(--nein); }
.pool-label { font-weight: 800; }
.pool-ja .pool-label { color: var(--ja); }
.pool-nein .pool-label { color: var(--nein); }
.pool-amount { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.pool-quote { font-size: .9rem; color: var(--muted); }

.result { margin-top: 20px; padding: 14px 16px; border-radius: 12px; display: flex; flex-direction: column; gap: 2px; font-size: .95rem; }
.result-ja { background: var(--ja-soft); }
.result-ja strong { color: var(--ja); }
.result-nein { background: var(--nein-soft); }
.result-nein strong { color: var(--nein); }
.result-void, .result-wait { background: var(--warn-soft); }
.result-void strong, .result-wait strong { color: var(--warn); }

.resolve-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.resolve-buttons form { margin: 0; }
.card-manage > form { margin-bottom: 8px; }
.void-box { margin-top: 8px; }
.void-box summary { cursor: pointer; color: var(--nein); font-weight: 600; padding: 6px 0; }
.void-box form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* Tabellen */
.table-wrap { overflow-x: auto; margin: 0 -4px; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table tr.me { background: var(--primary-soft); }
.leaderboard .rank { font-weight: 800; width: 40px; }
.rank-1 { color: #ca8a04; }
.rank-2 { color: #64748b; }
.rank-3 { color: #b45309; }
@media (max-width: 520px) { .hide-sm { display: none; } .table { font-size: .9rem; } }

/* Hinweise */
.flash {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-radius: 12px; margin-bottom: 20px; font-weight: 500;
}
.flash-success { background: var(--ja-soft); color: var(--ja); }
.flash-error { background: var(--nein-soft); color: var(--nein); }
.flash-info { background: var(--primary-soft); color: var(--primary); }
.flash-close { background: none; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: inherit; padding: 0 4px; }

.empty { text-align: center; padding: 48px 16px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty .btn { margin-top: 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 8px; }

.prose .card ul { padding-left: 20px; }
.prose .card li { margin-bottom: 6px; }
.formula { background: var(--surface-2); border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 8px; }
.error-code { font-size: 4rem; font-weight: 900; color: var(--primary); margin: 0; line-height: 1; }

/* Fußzeile */
.footer { border-top: 1px solid var(--border); background: var(--surface); }
.footer-inner {
  max-width: 1180px; margin: 0 auto; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: .9rem; color: var(--muted);
}
.footer-inner p { margin: 0; max-width: 60ch; }
.footer nav { display: flex; gap: 16px; }
