:root {
  --color-ink: #1f2933;
  --color-muted: #627184;
  --color-line: #d8dee6;
  --color-paper: #ffffff;
  --color-soft: #f3f6f9;
  --color-page-bg: #edf1f5;
  --color-nav-bg: #17212b;
  --color-nav-text: #dce6ee;
  --color-nav-hover: rgba(255, 255, 255, 0.08);
  --color-teal: #0f766e;
  --color-teal-dark: #0b5751;
  --color-teal-soft: #e2f5f2;
  --color-orange: #c2410c;
  --color-orange-soft: #fff0e6;
  --color-win: #e5f7ec;
  --color-win-text: #075c33;
  --color-draw: #fff7db;
  --color-draw-text: #744210;
  --color-loss: #fff1f1;
  --color-loss-text: #7f1d1d;
  --shadow-lg: 0 16px 36px rgba(20, 33, 43, 0.12);
  --shadow-sm: 0 8px 18px rgba(31, 41, 51, 0.05);
  --radius: 8px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-ink: #e7e8ee;
    --color-muted: #97a1b0;
    --color-line: #313846;
    --color-paper: #1b1f2a;
    --color-soft: #232836;
    --color-page-bg: #12141c;
    --color-nav-bg: #0d1218;
    --color-teal: #14b8a6;
    --color-teal-dark: #0d9488;
    --color-teal-soft: rgba(20, 184, 166, 0.16);
    --color-orange: #fb923c;
    --color-orange-soft: rgba(251, 146, 60, 0.14);
    --color-win: rgba(16, 185, 129, 0.16);
    --color-win-text: #6ee7b7;
    --color-draw: rgba(217, 119, 6, 0.16);
    --color-draw-text: #fcd34d;
    --color-loss: rgba(220, 38, 38, 0.16);
    --color-loss-text: #fca5a5;
    --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 8px 18px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  background: var(--color-page-bg);
  color: var(--color-ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

#root {
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.35rem;
  margin-top: 0;
}

.anchor-link {
  margin-left: 8px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--color-muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

h2:hover .anchor-link {
  opacity: 1;
}

.anchor-link:hover {
  color: var(--color-teal-dark);
}

h3 {
  font-size: 0.8rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-top: 22px;
}

a {
  color: var(--color-teal-dark);
}

/* ---------- App shell: sidebar + content ---------- */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 18px 12px;
  color: var(--color-nav-text);
  background: var(--color-nav-bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-ball {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 58% 32%, #fff 0 7%, transparent 8%),
    radial-gradient(circle at 39% 51%, #fff 0 6%, transparent 7%),
    radial-gradient(circle at 61% 64%, #fff 0 6%, transparent 7%),
    linear-gradient(135deg, var(--color-orange), var(--color-teal));
}

.brand h1 {
  margin: 0;
  color: #fff;
  font-size: 18px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: #97a5b3;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 3px;
}

.nav button {
  width: 100%;
  text-align: left;
  color: var(--color-nav-text);
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 500;
}

.nav button:hover:not(:disabled) {
  background: var(--color-nav-hover);
}

.nav button.active {
  color: #fff;
  background: var(--color-teal);
}

.actions button.active {
  background: var(--color-teal-dark);
}

.nav-divider {
  margin: 10px 8px 4px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #7c8998;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.content {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 64px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-page-bg);
}

.topbar h2 {
  margin: 0;
  flex: 1;
}

main,
.page {
  padding: 22px 24px 48px;
}

@media (max-width: 640px) {
  main,
  .page {
    padding: 16px 14px 36px;
  }
}

.menu-button {
  display: none;
  flex: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-paper);
  color: var(--color-ink);
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(300px, 88vw);
    transform: translateX(-104%);
    transition: transform 160ms ease;
  }
  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }
  .menu-button {
    display: inline-flex;
  }
}

/* ---------- Login / user badge ---------- */

.login-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.user-badge {
  background: var(--color-soft);
  border: 1px solid var(--color-line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--color-teal-dark);
  background: var(--color-teal-soft);
  font-size: 0.8rem;
  font-weight: 700;
}

/* ---------- Cards, hero, stats ---------- */

.card {
  background: var(--color-paper);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.card > div:has(> input),
.card > div:has(> select) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 16px;
}

.hero {
  padding: 36px 32px;
  margin-bottom: 18px;
  border-radius: var(--radius);
  color: #fff;
  background:
    linear-gradient(110deg, rgba(23, 33, 43, 0.95) 0 48%, rgba(23, 33, 43, 0.68) 70%, rgba(23, 33, 43, 0.18)),
    linear-gradient(90deg, #bd8f56 0 16%, #e9bd83 16% 18%, #bd8f56 18% 36%, #e9bd83 36% 38%, #bd8f56 38% 56%, #e9bd83 56% 58%, #bd8f56 58%);
  box-shadow: var(--shadow-lg);
}

.hero h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.05;
}

.hero p {
  max-width: 640px;
  margin: 14px 0 0;
  color: #dce6ee;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-top: 22px;
}

.hero-stat {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.hero-stat b {
  font-size: 2rem;
  color: #fff;
}

.hero-stat span {
  margin-top: 2px;
  color: #cdd9e5;
  font-size: 0.85rem;
}

.stats-grid,
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.metric {
  padding: 16px 18px;
}

.metric b {
  display: block;
  font-size: 28px;
}

.metric span {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

/* ---------- Tables (standings / schedule / rankings) ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

/* Each round is a separate <table>; without a fixed layout the browser sizes
   columns per-table based on that round's own content, so column widths drift
   between rounds even though every round shares the same 3-column shape. */
.schedule-table {
  table-layout: fixed;
}

.schedule-table th:nth-child(1),
.schedule-table td:nth-child(1),
.schedule-table th:nth-child(2),
.schedule-table td:nth-child(2) {
  width: 40%;
}

.schedule-table th:nth-child(3),
.schedule-table td:nth-child(3) {
  width: 20%;
  text-align: center;
}

.text-center {
  text-align: center;
}

@media (max-width: 640px) {
  /* Each wide table becomes its own horizontal scroller on mobile. The cross-table is excluded:
     it already scrolls inside .cross-table-wrap, so making it scroll too would stack two scrollbars. */
  table:not(.cross-table) {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* Freeze the first two columns (rank + name) of the league/player tables so the row stays
     identifiable while scrolling the stats horizontally. Column 1 is a fixed 50px so column 2's
     sticky offset lines up; opaque backgrounds keep scrolled cells from showing through. */
  .sticky-2 th:nth-child(1),
  .sticky-2 td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 50px;
    width: 50px;
  }
  .sticky-2 th:nth-child(2),
  .sticky-2 td:nth-child(2) {
    position: sticky;
    left: 50px;
    z-index: 1;
  }
  .sticky-2 td:nth-child(1),
  .sticky-2 td:nth-child(2) {
    background: var(--color-paper);
  }
  .sticky-2 th:nth-child(1),
  .sticky-2 th:nth-child(2) {
    background: var(--color-soft);
  }

  /* Match-result duel entry: stack each duel into a labelled card so score entry fits the screen
     width with no horizontal scroll (overrides the generic block-scroll table rule above). */
  .paper-style-table {
    display: block;
    overflow-x: visible;
    white-space: normal;
  }
  .paper-style-table tr {
    display: block;
    border: 1px solid var(--color-line);
    border-radius: var(--radius);
    padding: 6px 12px 8px;
    margin-bottom: 10px;
  }
  .paper-style-table tr:first-child {
    display: none; /* header row — replaced by per-cell labels */
  }
  .paper-style-table td {
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    padding: 5px 0;
    text-align: left;
  }
  .paper-style-table td::before {
    content: attr(data-label);
    flex: none;
    width: 64px;
    color: var(--color-muted);
    font-size: 0.85rem;
  }
  .paper-style-table td[data-label="Duel"] {
    font-weight: 700;
    border-bottom: 1px solid var(--color-line);
    padding-bottom: 6px;
    margin-bottom: 2px;
  }
  .paper-style-table td[data-label="Duel"]::before {
    content: "Duel ";
    width: auto;
  }
  .paper-style-table .duel-result-cell {
    justify-content: flex-start;
  }
  .paper-style-table td.duel-points-cell {
    display: none; /* per-duel points still summarised below the table */
  }
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--color-line);
  vertical-align: middle;
}

th {
  color: var(--color-muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-soft);
}

tr td:first-child,
tr th:first-child {
  cursor: pointer;
}

tr:hover > td {
  background: var(--color-soft);
}

table button {
  padding: 4px 10px;
  font-size: 0.85rem;
  margin-right: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 800;
  color: var(--color-teal-dark);
  background: var(--color-teal-soft);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: #fff;
  background: var(--color-orange);
  font-weight: 800;
}

.rank-badge.gold {
  color: #3b2a05;
  background: #f2c94c;
}

.rank-badge.silver {
  color: #24303c;
  background: #c8d0d8;
}

.rank-badge.bronze {
  color: #fff;
  background: #cd7f32;
  font-size: 0.85rem;
}

.unranked-row td {
  color: var(--color-muted);
}

.unranked-row.unranked-first td {
  border-top: 2px solid var(--color-line);
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--color-orange);
  background: var(--color-orange-soft);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tag.final {
  color: var(--color-win-text);
  background: var(--color-win);
}

.tag.provisional {
  color: var(--color-muted);
  background: var(--color-soft);
}

.winner-row td {
  font-weight: 800;
  background: rgba(242, 201, 76, 0.16);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--color-soft);
}

.round-detail-row td {
  background: var(--color-page-bg);
  padding: 10px 10px 14px 28px;
}

.nested-table {
  width: auto;
  min-width: 320px;
}

/* ---------- Cross table (head-to-head) ---------- */

.cross-table-wrap {
  overflow-x: auto;
}

.cross-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.cross-table th,
.cross-table td {
  min-width: 64px;
  text-align: center;
  white-space: nowrap;
  border-right: 1px solid var(--color-line);
}

.cross-table th:first-child,
.cross-table td:first-child {
  position: sticky;
  left: 0;
  min-width: 150px;
  text-align: left;
  background: var(--color-soft);
}

.cross-table td.self {
  color: var(--color-muted);
  background: var(--color-soft);
}

.cross-table td.planned {
  color: var(--color-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
}

/* A cell can hold up to 2 results (double round-robin: each direction's match). */
.cross-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: stretch;
}

.cross-cell .win,
.cross-cell .draw,
.cross-cell .loss {
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.cross-cell .win {
  color: var(--color-win-text);
  background: var(--color-win);
  font-weight: 800;
}

.cross-cell .draw {
  color: var(--color-draw-text);
  background: var(--color-draw);
  font-weight: 800;
}

.cross-cell .loss {
  color: var(--color-loss-text);
  background: var(--color-loss);
}

/* ---------- Match detail modal ---------- */

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
}

.match-modal {
  width: min(680px, 100%);
  max-height: min(80vh, 680px);
  overflow: auto;
  border-radius: var(--radius);
  background: var(--color-paper);
  box-shadow: var(--shadow-lg);
  padding: 20px 22px;
}

.match-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.match-modal-meta {
  color: var(--color-muted);
  font-size: 0.85rem;
  margin: -6px 0 12px;
}

.match-scoreline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--color-soft);
}

.match-scoreline-pins {
  flex: 1;
  text-align: center;
  color: var(--color-muted);
}

.match-scoreline b {
  font-size: 1.7rem;
  color: var(--color-teal-dark);
}

.duel-winner {
  font-weight: 800;
}

.lineup-columns {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin: 10px 0 20px;
}

.lineup-column {
  flex: 1;
  min-width: 220px;
}

.lineup-column > div {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.duel-name-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  white-space: nowrap;
}

.duel-name-cell input[type="checkbox"] {
  accent-color: var(--color-muted);
  cursor: help;
  flex: none;
}

.score-input {
  width: 58px;
  padding: 7px 6px;
  text-align: center;
  flex: none;
}

.score-input-invalid {
  border-color: var(--color-danger, #d33);
  background: rgba(221, 51, 51, 0.08);
  outline: 1px solid var(--color-danger, #d33);
}

.match-paper-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface-alt, rgba(0, 0, 0, 0.02));
}

.match-paper-row {
  display: flex;
  gap: 6px;
}

.match-paper-label {
  min-width: 100px;
  color: var(--color-muted);
}

.duel-result-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.duel-result-sep {
  font-weight: 700;
}

.duel-points-cell {
  text-align: center;
  font-weight: 700;
  color: var(--color-teal-dark);
}

.match-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-line);
}

.summary-row {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-teal-dark);
}

.save-action {
  margin-top: 32px;
}

.save-action button + button {
  margin-left: 8px;
}

/* ---------- Forms / buttons / inputs (shared everywhere) ---------- */

button {
  font: inherit;
  background: var(--color-teal);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: var(--color-teal-dark);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input,
select {
  font: inherit;
  background: var(--color-paper);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}

input:focus,
select:focus {
  outline: 2px solid var(--color-teal);
  outline-offset: -1px;
}

/* ---------- CMS: rich content rendering + editor (spec 10) ---------- */

.rich-content h2 { font-size: 1.3rem; margin: 18px 0 8px; }
.rich-content h3 { font-size: 1.1rem; margin: 16px 0 6px; }
.rich-content h4 { font-size: 1rem; margin: 14px 0 6px; }
.rich-content p { margin: 8px 0; line-height: 1.55; }
.rich-content ul,
.rich-content ol { margin: 8px 0 8px 24px; line-height: 1.55; }
.rich-content a { color: var(--color-teal); }
.rich-content img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 8px 0; }
.rich-content blockquote {
  margin: 10px 0;
  padding: 6px 14px;
  border-left: 3px solid var(--color-line);
  color: var(--color-muted);
}
.rich-content table {
  border-collapse: collapse;
  margin: 10px 0;
  width: auto;
}
.rich-content th,
.rich-content td {
  border: 1px solid var(--color-line);
  padding: 6px 10px;
  text-align: left;
}
.rich-content th { background: var(--color-soft); }

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--color-line);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--color-soft);
}
.editor-tool {
  padding: 4px 9px;
  font-size: 0.85rem;
  background: var(--color-paper);
  color: var(--color-ink, #1f2933);
  border: 1px solid var(--color-line);
  border-radius: 6px;
  cursor: pointer;
}
.editor-tool:hover { background: var(--color-teal-soft); }
.editor-area {
  min-height: 220px;
  padding: 12px 14px;
  border: 1px solid var(--color-line);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--color-paper);
  outline: none;
}
.editor-area:focus { border-color: var(--color-teal); }
.editor-error { color: var(--color-danger, #d33); margin-top: 6px; font-size: 0.9rem; }

/* ---------- Aktuality (news on the home page) ---------- */
.news-item { padding: 12px 0; border-top: 1px solid var(--color-line); }
.news-item:first-of-type { border-top: none; padding-top: 4px; }
.news-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.news-title { font-weight: 700; font-size: 1.05rem; }
.news-pin { flex: none; }
.news-date { margin-left: auto; color: var(--color-muted); font-size: 0.85rem; }
