/* Algo Quest – ruhiges Design: Dunkelblau #1F4E79, Gold #B8860B als Akzent */
:root {
  --blue: #1f4e79;
  --blue-dark: #163a5c;
  --blue-soft: #dbe7f5;
  --gold: #b8860b;
  --gold-soft: #f6ecd2;
  --green: #548235;
  --red: #c00000;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #5b6b7c;
  --line: #d9dfe7;
  --grey: #f0f0f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 40, 70, 0.08), 0 1px 2px rgba(20, 40, 70, 0.05);
  --mono: Consolas, 'DejaVu Sans Mono', 'Liberation Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', Calibri, system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.25; color: var(--blue-dark); }
h1 { font-size: 1.6rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.25rem; margin: 0 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
p { margin: 0 0 0.75rem; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  background: var(--blue);
  color: #fff;
  border-bottom: 3px solid var(--gold);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  letter-spacing: 0.02em;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 6px;
  background: var(--gold);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
}
.topnav { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-left: auto; align-items: center; }
.topnav a, .topnav button {
  color: #e6eef7;
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.topnav a:hover, .topnav button:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.topnav a.active { background: rgba(255, 255, 255, 0.18); color: #fff; box-shadow: inset 0 -2px 0 var(--gold); }
.who { color: #cfe0f1; font-size: 0.9rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
main.narrow { max-width: 460px; }

/* ---------- Karten / Layout ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  min-width: 0;
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { min-width: 0; }
.grow { flex: 1 1 200px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.right { margin-left: auto; }
.center { text-align: center; }
.spacer { height: 0.5rem; }

/* ---------- Formulare ---------- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.25rem; color: var(--blue-dark); }
.field { margin-bottom: 0.8rem; }
input[type='text'], input[type='password'], input[type='number'], input[type='date'], select, textarea {
  width: 100%;
  font: inherit;
  padding: 0.5rem 0.65rem;
  border: 1px solid #b9c4d1;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}
input[type='color'] { width: 3rem; height: 2.4rem; padding: 0.15rem; border: 1px solid #b9c4d1; border-radius: 7px; background: #fff; }
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(184, 134, 11, 0.45);
  outline-offset: 1px;
}
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.callout {
  background: var(--blue-soft);
  border-left: 4px solid var(--blue);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.92rem;
  margin-bottom: 0.9rem;
}
.callout.warn { background: #fbeaea; border-left-color: var(--red); }
.callout.gold { background: var(--gold-soft); border-left-color: var(--gold); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--blue-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--blue); }
.btn.secondary:hover { background: var(--blue-soft); }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.btn.gold:hover { background: #9a7009; }
.btn.danger { background: #fff; color: var(--red); border-color: #e3b3b3; }
.btn.danger:hover { background: #fbeaea; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn.big { padding: 0.75rem 1.4rem; font-size: 1.05rem; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid #b9c4d1; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  font: inherit;
  border: 0;
  background: #fff;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  color: var(--text);
}
.seg button + button { border-left: 1px solid #b9c4d1; }
.seg button.on { background: var(--blue); color: #fff; }

/* ---------- Tabs (Admin) ---------- */
.tabs { display: flex; gap: 0.25rem; overflow-x: auto; border-bottom: 2px solid var(--line); margin-bottom: 1rem; scrollbar-width: thin; }
.tabs button {
  font: inherit;
  background: none;
  border: 0;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  font-weight: 600;
}
.tabs button.on { color: var(--blue); border-bottom-color: var(--gold); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 0.45rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--blue-dark); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; background: #f7f9fb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbfd; }

/* ---------- Kleine Elemente ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--grey);
  color: var(--text);
  white-space: nowrap;
}
.dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; display: inline-block; flex: none; border: 1px solid rgba(0, 0, 0, 0.15); }
.xp { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.xp.neg { color: var(--red); }
.pin { font-family: var(--mono); font-weight: 700; letter-spacing: 0.08em; }
.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid #e4cf98;
  background: var(--gold-soft);
  color: #6b4e06;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.8rem;
  margin: 0.1rem 0.15rem 0.1rem 0;
}
.code {
  font-family: var(--mono);
  background: var(--grey);
  border: 1px solid #e0e0e0;
  border-radius: 7px;
  padding: 0.75rem 0.9rem;
  white-space: pre;
  overflow-x: auto;
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0.5rem 0 0.9rem;
  tab-size: 4;
}
.kbd { font-family: var(--mono); background: var(--grey); padding: 0 0.3rem; border-radius: 4px; }

.progress { height: 0.9rem; background: #e7ecf2; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #2d6aa3); border-radius: 999px; }
.progress.gold > span { background: linear-gradient(90deg, #a77a0a, var(--gold), #d6a52a); }

.stat { display: flex; flex-direction: column; }
.stat .val { font-size: 2rem; font-weight: 800; color: var(--blue-dark); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 0.85rem; }

.empty { color: var(--muted); font-style: italic; padding: 0.5rem 0; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--blue-dark);
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  z-index: 50;
  max-width: calc(100% - 2rem);
  font-weight: 600;
}
#toast.err { background: var(--red); }

/* ---------- Dialog ---------- */
dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  width: min(520px, calc(100% - 2rem));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(15, 30, 50, 0.45); }

/* ---------- Startseite ---------- */
.hero { text-align: center; margin: 1.5rem 0 1.25rem; }
.hero .brand-mark { width: 3.4rem; height: 3.4rem; font-size: 1.7rem; border-radius: 12px; margin-bottom: 0.5rem; }
.hero h1 { font-size: 2rem; margin-bottom: 0.25rem; }

/* ---------- Mein Stand ---------- */
.rank-card { display: grid; grid-template-columns: auto 1fr; gap: 1rem 1.25rem; align-items: center; }
.rank-emblem {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #2d6aa3, var(--blue-dark));
  color: #fff;
  border: 4px solid var(--gold);
  font-weight: 800;
  font-size: 1.6rem;
  text-align: center;
}
.rank-name { font-size: 1.5rem; font-weight: 800; color: var(--blue-dark); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem; }
.badge-tile {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.6rem;
  text-align: center;
  background: #fafbfc;
}
.badge-tile .ic { font-size: 1.8rem; line-height: 1.2; filter: grayscale(1); opacity: 0.35; }
.badge-tile .nm { font-weight: 700; font-size: 0.9rem; color: var(--muted); }
.badge-tile .ds { font-size: 0.75rem; color: var(--muted); }
.badge-tile.earned { background: var(--gold-soft); border-color: #e4cf98; }
.badge-tile.earned .ic { filter: none; opacity: 1; }
.badge-tile.earned .nm { color: #6b4e06; }

.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { padding: 0.55rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.member-list li:last-child { border-bottom: 0; }
.member-list .nm { font-weight: 700; margin-right: 0.4rem; }

/* ---------- Kata-Trainer ---------- */
.kata-card { border-top: 5px solid var(--blue); }
.kata-head { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.5rem; }
.kata-title { font-size: 1.3rem; margin: 0.25rem 0 0.6rem; }
.kata-text { white-space: pre-wrap; }
.solution { border-top: 2px dashed var(--line); margin-top: 1rem; padding-top: 0.9rem; }
.solution h3 { color: var(--green); margin-top: 0; }
.answer-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-top: 1rem; }
.answer-row .btn { white-space: normal; text-align: center; }
.btn.ok { background: var(--green); border-color: var(--green); }
.btn.ok:hover { background: #456b2b; }
.btn.mid { background: #fff; color: #7a5a06; border-color: var(--gold); }
.btn.mid:hover { background: var(--gold-soft); }
.btn.bad { background: #fff; color: var(--red); border-color: var(--red); }
.btn.bad:hover { background: #fbeaea; }
.boxes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.4rem; }
.box { text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 0.4rem 0.2rem; background: #fafbfc; }
.box .n { font-size: 1.35rem; font-weight: 800; color: var(--blue-dark); }
.box .l { font-size: 0.72rem; color: var(--muted); }
.box.cur { border-color: var(--gold); box-shadow: inset 0 0 0 2px var(--gold); }

/* ---------- Board (Beamer) ---------- */
body.board { background: #eef2f7; font-size: 20px; }
.board-head {
  background: var(--blue);
  color: #fff;
  border-bottom: 5px solid var(--gold);
  padding: 0.9rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.board-head h1 { color: #fff; margin: 0; font-size: 2.1rem; }
.board-head .sub { color: #cfe0f1; font-size: 1.1rem; }
.board-head .right { text-align: right; color: #cfe0f1; font-size: 0.95rem; }
.board-main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; padding: 1.5rem 2rem; max-width: 1800px; margin: 0 auto; }
.board-main h2 { font-size: 1.5rem; margin-bottom: 1rem; }
.g-row { display: grid; grid-template-columns: 3rem minmax(0, 1fr) auto; gap: 0.25rem 1rem; align-items: center; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.g-row:last-child { border-bottom: 0; }
.g-pos { font-size: 2rem; font-weight: 800; color: var(--muted); text-align: center; }
.g-row.first .g-pos { color: var(--gold); }
.g-name { font-size: 1.55rem; font-weight: 800; color: var(--blue-dark); display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.g-name span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-name .dot { width: 1.1rem; height: 1.1rem; }
.g-xp { font-size: 1.8rem; font-weight: 800; color: var(--gold); text-align: right; font-variant-numeric: tabular-nums; }
.g-xp small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.g-bar { grid-column: 2 / 4; height: 1.4rem; background: #e3e9f0; border-radius: 999px; overflow: hidden; }
.g-bar > span { display: block; height: 100%; border-radius: 999px; min-width: 0.5rem; }
.g-meta { grid-column: 2 / 4; color: var(--muted); font-size: 1rem; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li { display: grid; grid-template-columns: 1.1rem minmax(0, 1fr) auto; gap: 0.75rem; align-items: baseline; padding: 0.6rem 0; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
.ev-list li:last-child { border-bottom: 0; }
.ev-list .dot { width: 0.95rem; height: 0.95rem; transform: translateY(0.1rem); }
.ev-list .g { font-weight: 700; color: var(--blue-dark); }
.ev-list .when { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.board-foot { text-align: center; color: var(--muted); font-size: 0.9rem; padding: 0 1rem 1.5rem; }

/* ---------- Wettbewerbe (Board) ---------- */
.board-side { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.board-side > .card { margin-bottom: 0; }
.card.comp { border-top: 5px solid var(--gold); }
.card.comp h2 { margin-bottom: 0.15rem; }
.comp-sub { color: var(--muted); font-size: 0.95rem; margin-bottom: 0.6rem; }
.comp-list { list-style: none; margin: 0; padding: 0; }
.comp-row { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr) auto; gap: 0.75rem; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.comp-row:last-child { border-bottom: 0; }
.c-pos { font-size: 1.5rem; font-weight: 800; color: var(--muted); text-align: center; }
.c-name { font-size: 1.25rem; font-weight: 700; color: var(--blue-dark); display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.c-name .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-val { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-val .v { font-size: 1.4rem; font-weight: 800; color: var(--blue-dark); }
.c-val small { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.c-val .tb { display: block; color: var(--muted); font-size: 0.8rem; }
.c-val .pill { margin-right: 0.5rem; vertical-align: 0.2rem; }
.comp-row.first .c-val .v { color: var(--gold); }
.comp-row.invalid .c-name, .comp-row.invalid .c-val .v { color: var(--muted); }
.comp-row.invalid .c-val .v { text-decoration: line-through; font-weight: 600; }
.comp-open { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0; }
.pill.ok { background: #e6f0de; color: #3d6125; }
.pill.bad { background: #fbeaea; color: var(--red); font-weight: 700; }

/* ---------- Wettbewerbe (Admin) ---------- */
.comp-admin { border-top: 4px solid var(--gold); }
.comp-admin.closed { border-top-color: var(--line); }
.comp-table td { padding: 0.35rem 0.45rem; }
.comp-table input.num-in { width: 7.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.comp-table tr.invalid td { background: #fdf6f6; }
.comp-table tr.muted strong { color: var(--muted); }
.g-cell { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.comp-foot { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; justify-content: space-between; margin-top: 0.8rem; padding-top: 0.7rem; border-top: 1px dashed var(--line); }

/* ---------- Druckliste ---------- */
.print-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.6rem; }
.print-card { border: 1.5px dashed #8b98a8; border-radius: 8px; padding: 0.7rem 0.9rem; background: #fff; break-inside: avoid; }
.print-card .ps { font-size: 1.15rem; font-weight: 800; color: var(--blue-dark); }
.print-card dl { display: grid; grid-template-columns: auto 1fr; gap: 0.1rem 0.6rem; margin: 0.4rem 0 0; font-size: 0.95rem; }
.print-card dt { color: var(--muted); }
.print-card dd { margin: 0; font-weight: 600; }
@media print {
  .no-print, .topbar { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
}

/* ---------- Responsiv ---------- */
@media (max-width: 900px) {
  .board-main { grid-template-columns: 1fr; padding: 1rem; }
  body.board { font-size: 17px; }
  .board-head { padding: 0.8rem 1rem; }
  .board-head h1 { font-size: 1.6rem; }
  .board-head .right { text-align: left; margin-left: 0; }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  main { padding: 1rem 0.75rem 2.5rem; }
  .card { padding: 0.9rem; }
  .topbar-inner { padding: 0.5rem 0.75rem; gap: 0.4rem; }
  .topnav { margin-left: 0; width: 100%; }
  .topnav a, .topnav button { padding: 0.3rem 0.55rem; }
  .rank-card { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .rank-card > div:not(.rank-emblem) { width: 100%; }
  .rank-card .row { justify-content: center; }
  .answer-row { grid-template-columns: 1fr; }
  .boxes { grid-template-columns: repeat(3, 1fr); }
  .g-row { grid-template-columns: 2.2rem minmax(0, 1fr) auto; gap: 0.2rem 0.6rem; }
  .g-pos { font-size: 1.4rem; }
  .g-name { font-size: 1.15rem; }
  .g-xp { font-size: 1.3rem; }
  .code { font-size: 0.82rem; padding: 0.6rem; }
  .comp-row { grid-template-columns: 1.8rem minmax(0, 1fr) auto; gap: 0.5rem; }
  .c-pos { font-size: 1.15rem; }
  .c-name { font-size: 1.05rem; }
  .c-val .v { font-size: 1.1rem; }
  .c-val .pill { display: table; margin: 0 0 0.2rem auto; vertical-align: baseline; }
  .hide-sm { display: none; }
}

/* Admin-Tabellen: auf schmalen Bildschirmen horizontal scrollen statt Zeilen zu stauchen */
body.admin .table-wrap > table { min-width: 680px; }
body.admin td .btn-row { flex-wrap: nowrap; }
.solution .kata-text + .small, .solution .code + .small { margin-top: 0.9rem; }
