:root {
  color-scheme: light;
  --bg: #e6edf2;
  --surface: #ffffff;
  --ink: #10283c;
  --muted: #4f6a80;
  --line: #c6d3dd;
  --sign: #f2c230;
  --sign-ink: #10283c;
  --ok: #23875a;
  --bad: #c2453a;
  --bar: #2c6a9a;
  --focus: #1d6fd6;
  --display: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --body: 'Barlow', 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #10283c;
    --surface: #163650;
    --ink: #eaf0f5;
    --muted: #9bb3c7;
    --line: #2a4e6e;
    --ok: #45b97c;
    --bad: #e8665a;
    --bar: #5b9fd4;
    --focus: #8cc4ff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--body);
}

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 600;
  line-height: 1.1;
  margin: 0 0 0.75rem;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.0625rem; color: var(--muted); margin-top: 1.5rem; }

button, .button, input, select, textarea {
  font: inherit;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0 1rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.0625rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
}
button.primary {
  background: var(--sign);
  color: var(--sign-ink);
  border-color: var(--sign);
}
button.ghost { border-color: var(--line); }
button.link {
  border: 0;
  min-height: auto;
  padding: 0;
  font-family: var(--body);
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--muted);
  text-decoration: underline;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

input[type='text'], input:not([type]), input[list], select, textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; }
.status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.875rem;
  color: var(--muted);
}
.chip::before {
  content: '';
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--line);
}
.chip.ok { color: var(--ink); }
.chip.ok::before { background: var(--ok); }
.chip.bad { color: var(--bad); }
.chip.bad::before { background: var(--bad); }
.chip.live { color: var(--ink); border-color: var(--bad); }
.chip.live::before { background: var(--bad); }
.who { margin-left: auto; display: flex; gap: 0.75rem; align-items: center; color: var(--muted); font-size: 0.9375rem; }

/* ---------- Layout ---------- */

main {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
  grid-template-areas:
    "round   guesses"
    "vote    score"
    "board   setup"
    "stats   stats"
    "cmds    cmds";
  align-items: start;
  gap: 2.5rem clamp(1.5rem, 3vw, 3rem);
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem clamp(1rem, 3vw, 2rem) 4rem;
}
main > section { min-width: 0; }
.round { grid-area: round; }
.live-guesses { grid-area: guesses; }
.vote { grid-area: vote; }
.score { grid-area: score; }
.leaderboard { grid-area: board; }
.setup { grid-area: setup; }
.stats { grid-area: stats; }
.commands { grid-area: cmds; }

@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    grid-template-areas: "round" "guesses" "vote" "score" "board" "stats" "setup" "cmds";
  }
}

.banner {
  max-width: 1200px;
  margin: 1rem auto 0;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  border-left: 4px solid var(--sign);
  background: var(--surface);
}

/* ---------- Runde: das Verkehrsschild ---------- */

.sign {
  position: relative;
  padding: 1.5rem 1.75rem 1.25rem;
  border-radius: 14px;
  background: var(--sign);
  color: var(--sign-ink);
  box-shadow: inset 0 0 0 4px var(--sign), inset 0 0 0 7px var(--sign-ink);
}
.sign h2 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
.sign .count {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(3.5rem, 9vw, 5.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.sign .count-label { font-size: 1.5rem; font-weight: 600; }
.sign .hint { margin: 0.5rem 0 0; max-width: 46ch; }
.sign.idle {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
}
.sign.idle .count { color: var(--muted); }
.sign.locked {
  background: repeating-linear-gradient(135deg, var(--sign) 0 18px, #e4b31f 18px 36px);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem;
}

.resolve {
  display: grid;
  gap: 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.field-label { margin: 0 0 0.4rem; font-family: var(--display); font-weight: 600; font-size: 1.125rem; }
.resolve-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; }

/* Ein-Klick-Auflösen */
.quick-picks { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pick {
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 0.85rem 0 0.6rem;
  border: 2px solid var(--sign);
  font-size: 1.125rem;
}
.pick img { width: 1.6rem; border-radius: 2px; }
.pick .cnt { font-family: var(--body); font-size: 0.875rem; font-weight: 500; color: var(--muted); }
.pick:hover:not(:disabled) { background: var(--sign); color: var(--sign-ink); }
.pick:hover:not(:disabled) .cnt { color: var(--sign-ink); }

/* Korrektur */
.correction {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--sign);
  background: var(--surface);
}
.correction p { margin: 0; }
.correction .pick { border-color: var(--line); }
.segmented.small label { padding: 0.25rem 0.7rem; font-size: 0.9375rem; }
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.segmented legend { padding: 0; margin-bottom: 0.4rem; color: var(--muted); font-size: 0.9375rem; }
.segmented label {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--line);
  margin-left: -1px;
  cursor: pointer;
}
.segmented label:first-of-type { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type { border-radius: 0 6px 6px 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }


/* ---------- Tipps ---------- */

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.bars li {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
}
.bars img { width: 1.75rem; height: auto; border-radius: 2px; }
.bar-track { position: relative; height: 1.9rem; border-radius: 4px; background: var(--surface); overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--bar); opacity: 0.35; transition: width 0.3s ease; }
.bar-name { position: relative; padding: 0 0.6rem; line-height: 1.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars .num { font-family: var(--display); font-weight: 600; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.empty, .meta { color: var(--muted); font-size: 0.9375rem; }

.recent { list-style: none; margin: 0; padding: 0; font-size: 0.9375rem; max-height: 16rem; overflow-y: auto; }
.recent li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; border-bottom: 1px solid var(--line); }
.recent li span:last-child { color: var(--muted); }

/* ---------- Score ---------- */

.versus { display: flex; gap: 2rem; margin: 0 0 0.25rem; font-family: var(--display); font-size: 1.25rem; }
.versus b { font-size: 3rem; font-weight: 700; display: block; line-height: 1; font-variant-numeric: tabular-nums; }

/* ---------- Leaderboard ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.875rem; padding: 0.4rem 0.5rem; border-bottom: 2px solid var(--line); }
td { padding: 0.5rem; border-bottom: 1px solid var(--line); }
td:first-child { font-family: var(--display); font-weight: 700; font-size: 1.125rem; width: 3.5rem; }
td:nth-child(3) { font-weight: 600; }

/* ---------- Commands ---------- */

.cmd-form {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(0, 3fr) auto auto;
  gap: 0.5rem;
  align-items: center;
}
@media (max-width: 640px) { .cmd-form { grid-template-columns: 1fr; } }
.check { display: inline-flex; gap: 0.4rem; align-items: center; white-space: nowrap; }
.cmd-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.cmd-list li {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(0, 3fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.cmd-list code { font-weight: 600; }
.cmd-list .resp { overflow-wrap: anywhere; }

/* ---------- Einrichtung ---------- */

.setup dl { margin: 0; }
.setup dt { font-family: var(--display); font-weight: 600; font-size: 1.125rem; margin-top: 1rem; }
.setup dt:first-child { margin-top: 0; }
.setup dd { margin: 0.35rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.setup dd .meta { flex-basis: 100%; margin: 0; }
.setup code { overflow-wrap: anywhere; padding: 0.2rem 0.4rem; background: var(--surface); border-radius: 4px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90vw, 36rem);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  z-index: 10;
}
#toast.error { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}

/* ---------- Login-Problem ---------- */

.login-problem {
  grid-column: 1 / -1;
  max-width: 40rem;
}
.login-problem .button { margin-top: 0.5rem; }

textarea { padding: 0.5rem 0.75rem; resize: vertical; line-height: 1.4; }
select { padding: 0 0.5rem; }

/* ---------- Abstimmung ---------- */

.vote-form { display: grid; gap: 0.4rem; }
.vote-form label { color: var(--muted); font-size: 0.9375rem; margin-top: 0.4rem; }
.vote-form .controls { margin: 0.75rem 0 0; }
.vote-question { font-family: var(--display); font-size: 1.25rem; font-weight: 600; margin: 0 0 0.75rem; }
.bars .idx { font-family: var(--display); font-weight: 700; font-size: 1.125rem; text-align: center; }

/* ---------- Statistiken ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem 1.5rem;
  margin: 0 0 1.5rem;
}
.stat-row div { border-top: 2px solid var(--line); padding-top: 0.5rem; }
.stat-row dt { color: var(--muted); font-size: 0.875rem; }
.stat-row dd { margin: 0; font-family: var(--display); font-weight: 700; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-row dd small { font-size: 1rem; font-weight: 600; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 2rem; }
@media (max-width: 860px) { .stats-grid { grid-template-columns: 1fr; } }
.stats h3 { margin-top: 0; }
.stats-grid > div > h3 + ol + h3 { margin-top: 1.5rem; }
.plain-list { margin: 0; padding-left: 1.4rem; }
.plain-list li { padding: 0.25rem 0; }
.plain-list .muted { color: var(--muted); }

/* ---------- Token ---------- */

.token-reveal { flex-basis: 100%; padding: 0.75rem 1rem; border-left: 4px solid var(--sign); background: var(--surface); }
.token-reveal p { margin: 0 0 0.35rem; }
.token-reveal code { display: block; margin-bottom: 0.5rem; }
.button.ghost { border-color: var(--line); }
