:root {
  --bg: #0b1120;
  --panel: #111a2e;
  --panel-2: #16223b;
  --border: #22314f;
  --text: #e5ecf6;
  --muted: #8c9ab3;
  --accent: #14b8a6;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --up: #22c55e;
  --down: #ef4444;
  --gold: #f5b942;
  --blue: #60a5fa;
  --warn: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --border: #e1e6ef;
  --text: #0f172a;
  --muted: #5b6b85;
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, 0.1);
  --up: #16a34a;
  --down: #dc2626;
  --gold: #c98a0b;
  --blue: #2563eb;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: 0.2px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #111827 0 18%, transparent 19%),
              radial-gradient(circle at 65% 30%, #111827 0 18%, transparent 19%),
              radial-gradient(circle at 50% 62%, #f9fafb 0 30%, transparent 31%), var(--accent);
}
.badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); text-transform: uppercase; letter-spacing: 0.6px;
}
.status {
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.status::before { content: "●"; margin-right: 6px; }
.status.ok { color: var(--up); }
.status.paused { color: var(--warn); }
.status.halt, .status.offline { color: var(--down); }

.icon-btn, .select, .btn {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px;
}
.icon-btn { width: 34px; height: 34px; cursor: pointer; }
.select { padding: 6px 10px; }
.btn { padding: 8px 16px; cursor: pointer; font-weight: 600; }
.btn:hover, .icon-btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04211e; border-color: var(--accent); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 50%, var(--border)); }
.btn:disabled { opacity: 0.5; cursor: wait; }

/* Layout */
.container { max-width: 1320px; margin: 0 auto; padding: 18px 20px 40px; display: grid; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card h2 { font-size: 16px; margin: 0; font-weight: 650; }
.card h3 { font-size: 12.5px; margin: 0 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.sub-head { margin-top: 16px !important; }
.row-gap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.banner { padding: 12px 16px; border-radius: var(--radius); font-weight: 600; }
.banner.danger { background: color-mix(in srgb, var(--down) 14%, var(--panel)); border: 1px solid var(--down); color: var(--text); }
.banner.warn { background: color-mix(in srgb, var(--gold) 14%, var(--panel)); border: 1px solid var(--gold); color: var(--text); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi-value { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.3px; }
.kpi-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.hint {
  display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--border); font-size: 10px; cursor: help; text-transform: none; vertical-align: 1px;
}
.progress { height: 6px; background: var(--panel-2); border-radius: 999px; margin: 8px 0 4px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 999px; transition: width 0.6s; }

/* Segmente */
.seg { display: inline-flex; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button {
  font: inherit; font-size: 13px; color: var(--muted); background: none; border: 0;
  padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* Charts */
.chart { width: 100%; height: 300px; }
.chart.tall { height: 440px; }
.chart.small { height: 150px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.accent { background: var(--accent); }
.dot.gray { background: var(--muted); }
.dot.gold { background: var(--gold); }
.tri { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; display: inline-block; }
.tri.up { border-bottom: 10px solid var(--up); }
.tri.down { border-top: 10px solid var(--down); }
.tri.stop { border-top: 10px solid var(--warn); }
.line { width: 16px; height: 0; border-top: 2px dashed; display: inline-block; }
.line.blue { border-color: var(--blue); }
.line.red { border-color: var(--down); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.r, .table th.r { text-align: right; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--panel-2); }
.table tr.detail td { background: var(--panel-2); color: var(--muted); font-size: 13px; }
.table tr.selected td { background: var(--accent-soft); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; background: var(--panel-2); padding: 1px 5px; border-radius: 6px; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap; }
.pill.buy { color: var(--up); }
.pill.sell { color: var(--down); }
.pill.champ { color: var(--gold); border-color: var(--gold); }

/* Feed */
.feed { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.feed li:last-child { border-bottom: 0; }
.feed .ic { text-align: center; }
.feed .t { color: var(--muted); font-size: 12px; white-space: nowrap; }
.feed .rej { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 12px 2px; margin: 0; }
.note { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 13.5px; }

/* Regeln */
.rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-bottom: 14px; }
.rule { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.rule b { display: block; font-size: 16px; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.footer { text-align: center; padding-top: 6px; }

/* Anmeldung */
.login { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); }
.login-card { width: min(360px, 90vw); display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; text-align: center; }
.login-card input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); }
.error { color: var(--down); min-height: 1em; margin: 0; font-size: 13px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart.tall { height: 360px; }
  .container { padding: 14px 12px 30px; gap: 14px; }
  .topbar { padding: 10px 12px; }
  #heartbeat { display: none; }
}
@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 20px; }
}

.grid-2.inner { gap: 24px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.bars li { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.bars .bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bars .bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.pill.ok { color: var(--up); border-color: color-mix(in srgb, var(--up) 50%, var(--border)); }
.pill.no { color: var(--muted); }

/* Turnier – Farben je Versuch (feste Reihenfolge, folgen dem Versuch, nicht dem Rang) */
/* geprüft mit validate_palette.js (hell gegen #ffffff, dunkel gegen #111a2e): Farbsehschwäche ok,
   hell 3 Farben unter 3:1 Kontrast – daher immer mit Namen beschriftet und als Tabelle verfügbar */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --bench: #898781; }
:root:not([data-theme="light"]) { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --bench: #898781; }
:root[data-theme="light"] { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --bench: #898781; }

.headline { display: grid; gap: 10px; }
.winner { display: flex; gap: 14px; align-items: flex-start; font-size: 16.5px; }
.winner .trophy { font-size: 28px; line-height: 1.1; }
.winner-title { line-height: 1.4; margin-bottom: 4px; }
.explain { margin: 0; line-height: 1.55; }
.tiny { font-size: 11.5px; }
.participants { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.pcard {
  background: var(--panel); border: 1px solid var(--border); border-top: 4px solid var(--slot, var(--accent));
  border-radius: var(--radius); padding: 14px 16px 16px; display: grid; gap: 6px; align-content: start;
  box-shadow: var(--shadow); min-width: 0;
}
.pcard h2 { font-size: 16px; margin: 0; font-weight: 650; }
.pcard h3 {
  font-size: 12px; margin: 8px 0 0; color: var(--muted); font-weight: 650; text-transform: uppercase;
  letter-spacing: 0.5px; border-top: 1px solid var(--border); padding-top: 8px;
}
.pcard p { margin: 0; }
.pcard-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pcard-head .rank { color: var(--muted); font-weight: 600; }
.pcard-desc { line-height: 1.45; }
.pcard-money { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.pcard-money .big { font-size: 24px; font-weight: 700; letter-spacing: -0.3px; }
.pcard-money .r { text-align: right; }
.pcard-warn { background: color-mix(in srgb, var(--warn) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 50%, var(--border)); border-radius: 8px; padding: 6px 10px; }
.pcard-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.pcard-actions .btn { padding: 6px 12px; font-size: 13.5px; }
.spark { width: 100%; height: 48px; display: block; }
.spark-zero { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-empty { height: 48px; display: grid; place-items: center; }
.dot { vertical-align: middle; margin-right: 2px; }

/* Stand je Coin */
.coins summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-top: 4px; }
.coins ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.coins li { display: grid; grid-template-columns: 58px 1fr; gap: 8px; font-size: 13px; line-height: 1.45; }
.state { font-weight: 650; font-size: 12px; text-align: center; border-radius: 6px; padding: 1px 4px; align-self: start;
  border: 1px solid var(--border); background: var(--panel-2); }
.state.hold { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.state.near { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 50%, var(--border)); }
.state.wait { color: var(--muted); }

/* Reiter */
.tabs {
  position: sticky; top: 55px; z-index: 9; display: flex; gap: 4px; overflow-x: auto;
  padding: 6px 20px 0; background: var(--bg); border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14.5px; padding: 8px 14px 10px;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: grid; gap: 18px; min-width: 0; }

/* Auswahl eines Versuchs */
.picker { display: flex; gap: 6px; flex-wrap: wrap; }
.picker button {
  font: inherit; font-size: 13.5px; color: var(--muted); background: var(--panel-2); cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; display: inline-flex; align-items: center; gap: 4px;
}
.picker button.active { color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.story { display: grid; gap: 6px; line-height: 1.55; }
.story p { margin: 0; }
.story h3 { margin-top: 10px !important; }

/* Fachwörter mit Erklärung */
.term { text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--accent); cursor: help; }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.term-sample { text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--accent); }
.card h3 .term, .kpi h3 .term { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.pop {
  position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px;
  padding: 12px 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); font-size: 14px; line-height: 1.55;
}
.pop p { margin: 6px 0 0; }
.pop-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.icon-btn.small { width: 26px; height: 26px; font-size: 12px; }
.glossary h3 { margin-top: 18px !important; }
.gloss { margin: 0; display: grid; gap: 4px 18px; grid-template-columns: minmax(150px, 220px) 1fr; }
.gloss dt { font-weight: 650; padding-top: 8px; }
.gloss dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--border); line-height: 1.55; color: var(--text); }
.gloss dt { border-bottom: 1px solid var(--border); }

.chart-wrap { position: relative; }
.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 210px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; box-shadow: var(--shadow); display: grid; gap: 3px;
}
.tip .dot { margin-right: 6px; }
.tip b { float: right; margin-left: 12px; }
.table-view summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }
.section-title { font-size: 18px; margin: 10px 2px -4px; font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Handy: nichts darf breiter werden als der Bildschirm */
.container { grid-template-columns: minmax(0, 1fr); }
.pcard, .headline, .winner > div { min-width: 0; }
.winner-title, .pcard-desc, .story, .coins li span { overflow-wrap: anywhere; }
@media (max-width: 820px) {
  .tabs { top: 55px; padding: 4px 8px 0; }
  .tabs a { padding: 8px 10px 9px; font-size: 14px; }
  .gloss { grid-template-columns: 1fr; }
  .gloss dt { border-bottom: 0; padding-top: 10px; }
}

/* Trefferquote: grün = mit Gewinn verkauft, rot = mit Verlust (immer mit Text daneben) */
.hitbar { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; margin: 4px 0 2px; background: var(--panel-2); }
.hitbar .win { background: var(--up); }
.hitbar .loss { background: var(--down); }
