* { margin: 0; padding: 0; box-sizing: border-box; }

/* UI: Schwarz-Weiß — Tabellenzonen (Legende, Range-Bar, Matrix-Zeilen) bleiben bunt */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #121212;
  --elevated: #1a1a1a;
  --border: #2e2e2e;
  --text: #f5f5f5;
  --text-dim: #9a9a9a;
  --accent: #ffffff;
  --accent-contrast: #0a0a0a;
  --danger: #b0b0b0;
  --promotion: #22c55e;
  --promotion-playoff: #84cc16;
  --midfield: #3b82f6;
  --relegation-playoff: #f97316;
  --relegation: #ef4444;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --elevated: #f0f0f0;
  --border: #d4d4d4;
  --text: #0f0f0f;
  --text-dim: #5a5a5a;
  --accent: #0f0f0f;
  --accent-contrast: #fafafa;
  --danger: #3d3d3d;
  --promotion: #15803d;
  --promotion-playoff: #4d7c0f;
  --midfield: #1d4ed8;
  --relegation-playoff: #c2410c;
  --relegation: #b91c1c;
}

/* System theme: follow OS preference when no data-theme is set */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
    --bg: #0a0a0a;
    --surface: #121212;
    --elevated: #1a1a1a;
    --border: #2e2e2e;
    --text: #f5f5f5;
    --text-dim: #9a9a9a;
    --accent: #ffffff;
    --accent-contrast: #0a0a0a;
    --danger: #b0b0b0;
    --promotion: #22c55e;
    --promotion-playoff: #84cc16;
    --midfield: #3b82f6;
    --relegation-playoff: #f97316;
    --relegation: #ef4444;
  }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    color-scheme: light;
    --bg: #fafafa;
    --surface: #ffffff;
    --elevated: #f0f0f0;
    --border: #d4d4d4;
    --text: #0f0f0f;
    --text-dim: #5a5a5a;
    --accent: #0f0f0f;
    --accent-contrast: #fafafa;
    --danger: #3d3d3d;
    --promotion: #15803d;
    --promotion-playoff: #4d7c0f;
    --midfield: #1d4ed8;
    --relegation-playoff: #c2410c;
    --relegation: #b91c1c;
  }
}

html {
  overflow-x: hidden;
  overflow-x: clip;
  max-width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-x: clip;
  max-width: 100%;
}

/* Prevent initial "default state" flicker before URL state applies */
body.preinit #meta,
body.preinit #table-view,
body.preinit #matrix-view,
body.preinit .toolbar,
body.preinit .league-tabs {
  display: none;
}

/* ── Header ── */

header {
  max-width: min(1200px, 100%);
  margin: 0 auto;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-x: hidden;
  overflow-x: clip;
  background: var(--bg);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.65rem;
}

.header-top h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.header-util {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* ── Shared control token (capsule) ── */

.ctrl {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.75rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
}

.ctrl-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  transition: border-color 0.15s, background 0.15s;
}

.ctrl-btn:hover {
  border-color: var(--text-dim);
  background: var(--elevated);
}

.ctrl-btn[aria-expanded="true"] {
  border-color: var(--text);
  background: var(--elevated);
}

/* ── League Tabs ── */

.league-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  min-width: 0;
  max-width: 100%;
}

.league-tabs button {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 0.55rem 0;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}

.league-tabs button:hover {
  color: var(--text);
}

.league-tabs button.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.league-tab-short {
  display: none;
}

/* ── Toolbar (season, matchday, view) ── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  min-width: 0;
  max-width: 100%;
}

.toolbar-spacer {
  flex: 1;
}

.season-wrap {
  padding: 3px;
  flex: 0 0 auto;
}

.season-select {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.75rem;
  height: 28px;
  width: auto;
  max-width: 100%;
  padding: 0 1.4rem 0 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239a9a9a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  outline: none;
}

.season-select:hover {
  background-color: var(--elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239a9a9a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
}

html[data-theme="light"] .season-select,
html[data-theme="light"] .season-select:hover {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a5a5a'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: light) {
  html:not([data-theme]) .season-select,
  html:not([data-theme]) .season-select:hover {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235a5a5a'/%3E%3C/svg%3E");
  }
}

.matchday-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 2px;
  flex: 0 1 auto;
}

.md-btn {
  border: none;
  background: transparent;
  color: var(--text);
  width: 26px;
  height: 26px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  line-height: 1;
  border-radius: 999px;
  transition: background 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.md-btn:hover {
  background: var(--elevated);
}

.md-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.md-display {
  min-width: 72px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text);
  user-select: none;
  white-space: nowrap;
  line-height: 1;
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
}

.view-toggle button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0 0.7rem;
  height: 28px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.view-toggle button:hover {
  color: var(--text);
  background: var(--elevated);
}

.view-toggle button.active {
  color: var(--accent-contrast);
  background: var(--accent);
}

/* ── Meta ── */

.meta {
  font-size: 0.68rem;
  color: var(--text-dim);
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
  max-width: 100%;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

main {
  max-width: min(1200px, 100%);
  margin: 0 auto;
  padding: 0.75rem max(1.5rem, env(safe-area-inset-right)) 3rem max(1.5rem, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-x: clip;
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
}

.view {
  position: relative;
  transition: opacity 0.2s ease;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

.view.loading-overlay {
  opacity: 0.4;
  pointer-events: none;
}

.cell-enter {
  animation: cellIn 350ms ease both;
}

.cell-exit {
  animation: cellOut 350ms ease both;
}

@keyframes cellIn {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 0.9; }
}

@keyframes cellOut {
  from { transform: scale(1); opacity: 0.9; }
  to { transform: scale(0.3); opacity: 0; }
}

.hidden { display: none !important; }

/* ── Übersicht (Spieltag nach Wochentag / Uhrzeit) ── */

.overview-wrap {
  max-width: 720px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.overview-head {
  margin-bottom: 1.25rem;
}

.overview-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.overview-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 1rem 0;
}

.overview-day {
  margin-bottom: 1.75rem;
}

.overview-day:last-child {
  margin-bottom: 0;
}

.overview-day-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.65rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.overview-match-list {
  list-style: none;
}

.overview-match {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.overview-match:last-child {
  border-bottom: none;
}

.overview-time {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.overview-match-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
  min-width: 0;
}

.overview-team {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.overview-team img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
}

.overview-team--home {
  justify-content: flex-start;
}

.overview-team--away {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.overview-score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: center;
  min-width: 3.25rem;
}

.overview-score--pending {
  color: var(--text-dim);
  font-weight: 500;
}

.overview-score--live {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

/* Red pulsing dot */
.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e53e3e;
  flex-shrink: 0;
  transform-origin: center;
  animation: live-pulse 2.2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.8); }
}

/* Capsule wrapping dot + score */
.live-capsule {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(229, 62, 62, 0.12);
  border: 1px solid rgba(229, 62, 62, 0.3);
  border-radius: 999px;
  padding: 0.18rem 0.55rem 0.18rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #e53e3e;
  line-height: 1;
  overflow: visible;
}

/* Table: small capsule under team name */
.table-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(229, 62, 62, 0.12);
  border: 1px solid rgba(229, 62, 62, 0.3);
  border-radius: 999px;
  padding: 0.14rem 0.45rem 0.14rem 0.3rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #e53e3e;
  line-height: 1;
  margin-top: 0.15rem;
  cursor: pointer;
  overflow: visible;
}

/* Modal: big live match card */
.modal-live-card {
  margin: 0 0 0.25rem;
  background: rgba(229, 62, 62, 0.07);
  border: 1px solid rgba(229, 62, 62, 0.22);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.modal-live-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  color: #e53e3e;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.modal-live-match {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 700;
}

.modal-live-match img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.modal-live-match .modal-live-score {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

.modal-live-match .modal-live-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  max-width: 80px;
  text-align: center;
  line-height: 1.2;
}

.modal-live-match .modal-live-team--active {
  color: var(--text);
  font-weight: 700;
}

/* Match list live row highlight */
.match-item--live {
  background: rgba(229, 62, 62, 0.06);
  border-radius: 6px;
  margin: 0 -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.standings-table tr.is-live td {
  background: rgba(229, 62, 62, 0.07);
}

.standings-table tr.is-live td.col-team .team-name {
  flex-wrap: wrap;
}

.overview-extra {
  grid-column: 1 / -1;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: -0.15rem;
}

.match-extras {
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.35;
}

.match-extras-hz {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.match-extras-meta {
  margin-top: 0.2rem;
}

.match-extras-lbl {
  color: var(--text-dim);
  font-weight: 500;
  margin-right: 0.25rem;
}

.match-extras-upd {
  margin-top: 0.35rem;
  font-size: 0.62rem;
  opacity: 0.85;
}

.goal-chronicle {
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
}

.goal-chronicle li {
  padding: 0.08rem 0;
  border-bottom: 1px solid var(--border);
}

.goal-chronicle li:last-child {
  border-bottom: none;
}

.goal-chronicle--compact {
  font-size: 0.62rem;
}

.goal-chronicle--compact li {
  padding: 0.04rem 0;
}

.tmi-extras {
  grid-column: 1 / -1;
  margin-top: 0.25rem;
}

.match-item-extras {
  flex: 1 1 100%;
  margin-top: 0.15rem;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border);
}

.modal-live-card .match-extras {
  width: 100%;
  text-align: left;
  margin-top: 0.25rem;
}

/* ── Table View ── */

.standings-table {
  width: 100%;
  max-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  table-layout: fixed;
}

/* Team-Spalte: bekommt den größten Anteil; Statistik bleibt schmal (table-layout: fixed) */
.standings-table th.col-team,
.standings-table td.col-team {
  width: auto;
  min-width: 0;
}

.standings-table td.col-team .team-cell {
  min-width: 0;
}

.standings-table td.col-team .team-name {
  min-width: 0;
  max-width: 100%;
  flex: 1;
  flex-wrap: nowrap;
}

.standings-table td.col-team .team-name-full,
.standings-table td.col-team .team-name-short {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Zahlen & Tore: feste, enge Breite, damit „Team“ den Rest füllt */
.standings-table th.num:not(:first-child),
.standings-table td.num:not(:first-child) {
  width: 2.65rem;
  max-width: 3.15rem;
  padding-left: 0.3rem;
  padding-right: 0.3rem;
  box-sizing: border-box;
}

.standings-table th.col-goals,
.standings-table td.col-goals {
  width: 3.15rem;
  min-width: 2.75rem;
  max-width: 3.6rem;
}

.standings-table th.col-range,
.standings-table td.col-range {
  width: 6.5rem;
  min-width: 4.5rem;
  max-width: 8rem;
}

.standings-table th {
  text-align: left;
  padding: 0.5rem 0.45rem;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: none;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}

.standings-table th.num,
.standings-table td.num,
.standings-table th.col-goals,
.standings-table td.col-goals {
  font-variant-numeric: tabular-nums;
}

.standings-table td.col-goals,
.standings-table th.col-goals {
  text-align: center;
  white-space: nowrap;
}

.standings-table th.num,
.standings-table td.num {
  text-align: center;
}

.standings-table th:first-child,
.standings-table td:first-child {
  width: 1.85rem;
  max-width: 2rem;
  padding-left: 0.3rem;
  padding-right: 0.3rem;
  box-sizing: border-box;
}

.standings-table th:nth-child(2),
.standings-table td:nth-child(2) {
  width: 1.5rem;
  max-width: 1.65rem;
  padding-left: 0.15rem;
  padding-right: 0.15rem;
  box-sizing: border-box;
}

.rank-move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  margin: 0;
  border: none;
  outline: none;
  box-shadow: none;
  border-radius: 0;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-dim);
  background: transparent;
  vertical-align: middle;
}

.rank-move.up {
  color: var(--promotion);
  background: transparent;
}

.rank-move.down {
  color: var(--relegation);
  background: transparent;
}

.rank-move.same {
  color: var(--text-dim);
  background: transparent;
}

.standings-table tbody td:nth-child(2) {
  text-align: center;
  vertical-align: middle;
}

.standings-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.standings-table tr:hover td {
  background: var(--surface);
}

.team-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
}

.team-logo {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.team-logo img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
}

.team-name {
  font-weight: 500;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
  min-width: 0;
}

.zone-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.zone-promotion { background: var(--promotion); }
.zone-promotion_playoff { background: var(--promotion-playoff); }
.zone-midfield { background: var(--midfield); }
.zone-relegation_playoff { background: var(--relegation-playoff); }
.zone-relegation { background: var(--relegation); }

/* ── Range Bar ── */

.range-bar-container {
  position: relative;
  height: 18px;
  min-width: 0;
  max-width: 100%;
}

.range-bar-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
  transform: translateY(-50%);
}

.range-bar-fill {
  position: absolute;
  top: 50%;
  height: 7px;
  border-radius: 4px;
  transform: translateY(-50%);
  opacity: 0.85;
}

.range-bar-fill.zone-tone-promotion { background: var(--promotion); }
.range-bar-fill.zone-tone-promotion_playoff { background: var(--promotion-playoff); }
.range-bar-fill.zone-tone-midfield { background: var(--midfield); }
.range-bar-fill.zone-tone-relegation_playoff { background: var(--relegation-playoff); }
.range-bar-fill.zone-tone-relegation { background: var(--relegation); }

.range-bar-current {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-contrast);
  border: 2px solid var(--accent);
  transform: translate(-50%, -50%);
  z-index: 1;
}

.range-bar-current.zone-tone-promotion { background: var(--promotion); border-color: var(--text); }
.range-bar-current.zone-tone-promotion_playoff { background: var(--promotion-playoff); border-color: var(--text); }
.range-bar-current.zone-tone-midfield { background: var(--midfield); border-color: var(--text); }
.range-bar-current.zone-tone-relegation_playoff { background: var(--relegation-playoff); border-color: var(--text); }
.range-bar-current.zone-tone-relegation { background: var(--relegation); border-color: var(--text); }

.range-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.th-range-short {
  display: none;
}

td.col-range {
  vertical-align: middle;
}

/* ── Matrix View ── */

.matrix-grid {
  /* Schmale Viewports: begrenzte Breite; ab lg siehe Media Query */
  width: 100%;
  max-width: min(100%, 31rem);
  margin-left: auto;
  margin-right: auto;
  overflow-x: hidden;
  overflow-x: clip;
  padding-bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  position: relative;
  touch-action: manipulation;
}

.matrix-grid > .matrix-table.matrix-base {
  width: 100%;
  max-width: 100%;
}

.matrix-overlay-layer .matrix-table {
  width: 100%;
  max-width: 100%;
}

.matrix-base thead {
  visibility: hidden;
}

.matrix-base .rank-header {
  visibility: hidden;
}

.matrix-overlay-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  pointer-events: none;
}

.matrix-overlay-layer .matrix-table {
  pointer-events: auto;
}

.overlay-empty .matrix-cell-face {
  background: transparent !important;
}

.matrix-table {
  border-collapse: separate;
  border-spacing: clamp(1px, 0.35vw, 2px);
  font-size: 0.7rem;
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
}

.matrix-table th {
  padding: 0.25rem;
  font-weight: 500;
  color: var(--text-dim);
  text-align: center;
  min-width: 0;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg);
}

.matrix-table.matrix-overlay-table th:first-child,
.matrix-table.matrix-overlay-table td:first-child {
  z-index: 4;
}

.matrix-table.matrix-base th:first-child,
.matrix-table.matrix-base td:first-child {
  z-index: 3;
}

.matrix-table th.team-col-header {
  padding: 0.25rem 0.1rem 0.35rem;
  vertical-align: bottom;
  text-align: center;
}

.matrix-table th.team-col-header img {
  display: block;
  margin: 0 auto;
}

.matrix-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  outline: none;
  background: transparent;
  padding: 1px;
  cursor: pointer;
  border-radius: 999px;
}

.team-col-header {
  position: relative;
}

.matrix-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text);
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  z-index: 50;
  pointer-events: none;
}

.matrix-table th.rank-header {
  text-align: right;
  padding-right: 0.4rem;
  padding-left: 0.25rem;
  white-space: nowrap;
  font-size: 0.72rem;
  color: var(--text);
  font-weight: 500;
  vertical-align: middle;
  line-height: 1.15;
}

.matrix-icon {
  width: min(20px, 100%);
  height: min(20px, 100%);
  max-width: 100%;
  object-fit: contain;
  display: block;
  border: none;
  outline: none;
  border-radius: 999px;
}

/*
 * Quadratische Kacheln: aspect-ratio auf <td> wird vom Tabellen-Layout oft ignoriert,
 * daher der sichtbare Farbkörper als inneres Block-Element .matrix-cell-face (1:1).
 */
.matrix-table td.matrix-cell {
  width: 100%;
  min-width: 0;
  padding: 0;
  vertical-align: top;
  line-height: 0;
  font-size: 0;
  box-sizing: border-box;
}

.matrix-table td.matrix-cell .matrix-cell-face {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  box-sizing: border-box;
}

.matrix-base .matrix-cell .matrix-cell-face {
  background: var(--elevated);
}

.matrix-cell.reachable {
  opacity: 0.9;
  transition: opacity 0.1s;
}

.matrix-cell.reachable:hover {
  opacity: 1;
}

.matrix-cell.current {
  opacity: 1;
}

/* ── Legende (Info-Popover) ── */

.legend-popover-wrap {
  position: relative;
}


.legend-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  min-width: 240px;
  max-width: min(320px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.45;
}

.legend-panel h4 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.legend-panel-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.legend-panel-row:last-child {
  margin-bottom: 0;
}


.mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  accent-color: var(--accent);
}

.eliminated-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: none;
  background: color-mix(in srgb, var(--relegation) 20%, transparent);
  color: var(--relegation);
  margin-left: 0.4rem;
  vertical-align: middle;
}

.note-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  border: none;
  background: color-mix(in srgb, var(--midfield) 20%, transparent);
  color: var(--midfield);
  margin-left: 0.4rem;
  vertical-align: middle;
  letter-spacing: 0.01em;
}

.note-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.35rem;
  padding: 0 0.3rem;
  height: 16px;
  border-radius: 999px;
  border: none;
  background: color-mix(in srgb, var(--relegation-playoff) 20%, transparent);
  color: var(--relegation-playoff);
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
  letter-spacing: 0.02em;
}

.confirmed-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: none;
  background: color-mix(in srgb, var(--promotion) 20%, transparent);
  color: var(--promotion);
  margin-left: 0.4rem;
  vertical-align: middle;
}

.status-note {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-left: 0.25rem;
  vertical-align: middle;
}

/* ── Team Detail Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: min(700px, 100%);
  width: 100%;
  max-height: 85vh;
  overflow-x: hidden;
  overflow-x: clip;
  overflow-y: auto;
  padding: 1.5rem;
  box-sizing: border-box;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.modal-header img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-header .modal-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.modal-header .modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-section {
  margin-bottom: 1.25rem;
}

.modal-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.4rem;
}

.stat-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.stat-card .stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

.projection-bar {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.projection-bar .range-bar-container {
  flex: 1;
}

.match-list {
  list-style: none;
}

.match-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.match-item:last-child { border-bottom: none; }

.match-date {
  color: var(--text-dim);
  font-size: 0.7rem;
  min-width: 80px;
}

.match-teams {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.match-teams img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex-shrink: 0;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
  vertical-align: middle;
}

.match-score {
  font-weight: 600;
  min-width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.match-matchday {
  color: var(--text-dim);
  font-size: 0.65rem;
  min-width: 24px;
  flex-shrink: 0;
}

.standings-table tr { cursor: pointer; }

/* ── Spiel-Detail ── */

.game-page {
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: 3rem;
}

.game-page-status {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.35rem;
}

.game-page-status-pill {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border-radius: 4px;
  font-size: 0.65rem;
}
.game-page-status-pill--live {
  background: rgba(229, 62, 62, 0.12);
  color: #e53e3e;
  border: 1px solid rgba(229, 62, 62, 0.35);
}
.game-page-status-pill--finished {
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.game-page-status-pill--upcoming {
  color: var(--text-dim);
  border: 1px dashed var(--border);
}

.game-page-datetime {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--text);
}

.game-page-group {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.game-page-match {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.game-page-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  text-align: center;
}

.game-page-side img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.game-page-teamlink {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  max-width: 100%;
}

.game-page-teamlink:hover {
  color: var(--text-dim);
}

.game-page-score {
  font-size: 1.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.game-page-detail-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.5rem;
}

.game-page-error {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 0;
}

.team-live-teaser-hint {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}

.team-live-teaser:hover .team-live-teaser-hint {
  color: var(--text);
}

/* ── Team Page ── */

.team-page {
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: 3rem;
}

.team-page-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.35rem 0;
  margin-bottom: 1rem;
}
.team-page-back:hover { color: var(--text); }

.team-page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.team-page-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
}

.team-page-info { flex: 1; min-width: 0; }
.team-page-info h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 0.2rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.team-page-meta {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.team-section {
  margin-bottom: 1.5rem;
}
.team-section h3 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
}

/* Form strip */
.form-strip {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.form-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}
.form-pill--W { background: #22c55e22; color: #16a34a; border: 1.5px solid #22c55e55; }
.form-pill--D { background: #f59e0b22; color: #d97706; border: 1.5px solid #f59e0b55; }
.form-pill--L { background: #ef444422; color: #dc2626; border: 1.5px solid #ef444455; }

/* Season block */
.season-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.season-pts-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.season-pts {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
.season-pts-sub {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.82rem;
  font-weight: 600;
}
.season-pts-meta {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-dim);
}

/* WDL bar */
.wdl-bar {
  display: flex;
  height: 7px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;
  margin-bottom: 0.35rem;
}
.wdl-seg { height: 100%; border-radius: 3px; }
.wdl-w { background: #22c55e; }
.wdl-d { background: #f59e0b; }
.wdl-l { background: #ef4444; }
.wdl-labels {
  display: flex;
  gap: 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
}
.wdl-labels .wdl-w { color: #16a34a; background: none; height: auto; }
.wdl-labels .wdl-d { color: #d97706; background: none; height: auto; }
.wdl-labels .wdl-l { color: #dc2626; background: none; height: auto; }
.season-extra {
  display: flex;
  gap: 1.5rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}
.season-extra-item { display: flex; flex-direction: column; gap: 0.1rem; }
.season-extra-val { font-size: 1rem; font-weight: 700; }
.season-extra-lbl { font-size: 0.65rem; color: var(--text-dim); }

/* Streak badge */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
}
.streak-badge--W { border-color: #22c55e55; color: #16a34a; background: #22c55e0d; }
.streak-badge--D { border-color: #f59e0b55; color: #d97706; background: #f59e0b0d; }
.streak-badge--L { border-color: #ef444455; color: #dc2626; background: #ef44440d; }

/* HA comparison table */
.ha-compare {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.35rem 1.25rem;
  font-size: 0.82rem;
  align-items: center;
}
.ha-head {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  text-align: right;
  padding-bottom: 0.3rem;
}
.ha-lbl {
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.3rem 0;
}
.ha-val {
  font-weight: 600;
  text-align: right;
  padding: 0.3rem 0;
}
/* Row separators via box-shadow on the whole row of 3 cells */
.ha-compare > .ha-lbl {
  box-shadow: 0 -1px 0 var(--border);
}
.ha-compare > .ha-val {
  box-shadow: 0 -1px 0 var(--border);
}

/* Records list */
.records-list { display: flex; flex-direction: column; gap: 0; }
.record-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.record-row:last-child { border-bottom: none; }
.record-row-title { color: var(--text-dim); font-size: 0.75rem; min-width: 120px; flex-shrink: 0; }
.record-row-score { font-weight: 700; font-size: 0.9rem; }
.record-row-detail { color: var(--text-dim); font-size: 0.75rem; }

/* Prognose block */
.prognose-block { display: flex; flex-direction: column; gap: 0.5rem; }
.prognose-range-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Team page match list */
.team-match-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 0.5rem 0 0.3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.team-match-item {
  display: grid;
  grid-template-columns: 1.5rem 5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
}
.team-match-item:last-child { border-bottom: none; }
.team-match-item--live { background: rgba(229,62,62,0.06); border-radius: 6px; }
.team-match-item--upcoming { color: var(--text-dim); }
.team-match-item--won .tmi-score { color: #16a34a; font-weight: 700; }
.team-match-item--lost .tmi-score { color: #dc2626; font-weight: 700; }
.tmi-md { color: var(--text-dim); font-size: 0.65rem; text-align: center; }
.tmi-date { font-size: 0.72rem; color: var(--text-dim); }
.tmi-opponent { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.tmi-opponent img { width: 16px; height: 16px; object-fit: contain; flex-shrink: 0; }
.tmi-opponent span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tmi-score { text-align: right; font-size: 0.82rem; white-space: nowrap; }
.tmi-ha { font-size: 0.6rem; color: var(--text-dim); white-space: nowrap; }

/* Clickable teams in overview */
.overview-match { cursor: pointer; }
.overview-team { cursor: pointer; }
.overview-team:hover span { text-decoration: underline; }

body.team-view-active header .league-tabs,
body.team-view-active header .toolbar,
body.team-view-active header #meta,
body.game-view-active header .league-tabs,
body.game-view-active header .toolbar,
body.game-view-active header #meta {
  display: none;
}

/* ── Responsive ── */

/* Handy / schmale Ansicht: nur Pl., Pfeil, Team (+ Live), Sp., Diff., Punkte */
@media (max-width: 768px) {
  .standings-table th.col-record,
  .standings-table td.col-record,
  .standings-table th.col-goals,
  .standings-table td.col-goals,
  .standings-table th.col-range,
  .standings-table td.col-range {
    display: none;
  }
}

@media (max-width: 640px) {
  .toolbar {
    flex-wrap: wrap;
    row-gap: 0.45rem;
    column-gap: 0.4rem;
    padding: 0.5rem 0;
    align-items: center;
  }

  .toolbar-spacer {
    display: none;
  }

  /* Saison + Spieltag: nebeneinander, nur so breit wie nötig (keine breiten Kapseln) */
  .season-wrap.ctrl {
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
    min-width: 0;
  }

  .season-wrap.ctrl .season-select {
    width: auto;
    max-width: 100%;
  }

  .matchday-nav.ctrl {
    flex: 0 1 auto;
    min-width: 0;
    justify-content: flex-start;
  }

  .view-toggle {
    flex: 1 1 100%;
    width: 100%;
    justify-content: stretch;
    margin-left: 0 !important;
  }

  .view-toggle button {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .league-tab-long {
    display: none;
  }

  .league-tab-short {
    display: inline;
  }

  .league-tabs button {
    font-size: 0.78rem;
    padding: 0.5rem 0.15rem;
  }
}

@media (max-width: 480px) {
  header {
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) 0 max(0.75rem, env(safe-area-inset-left));
  }

  .header-top h1 { font-size: 1.05rem; }
  .header-top { padding-bottom: 0.45rem; }

  .league-tabs button { font-size: 0.72rem; padding: 0.45rem 0; }

  .toolbar {
    gap: 0.4rem;
    padding: 0.5rem 0;
  }

  main {
    padding: 0.6rem max(0.75rem, env(safe-area-inset-right)) 2rem max(0.75rem, env(safe-area-inset-left));
  }

  .standings-table { font-size: 0.72rem; }
  .standings-table th { padding: 0.4rem 0.35rem; font-size: 0.62rem; }
  .standings-table td { padding: 0.4rem 0.35rem; }

  .team-name-full { display: none; }
  .team-name-short { display: inline; }

  .range-bar-container { min-width: 0; max-width: 100%; }
  .team-logo { width: 18px; height: 18px; }
  .team-cell { gap: 0.35rem; }

  .matrix-grid { justify-content: center; }
  .matrix-table { border-spacing: 1px; }
  .matrix-table th { padding: 0.1rem; }
  .matrix-table th.rank-header { font-size: 0.55rem; padding-right: 0.15rem; }
  .matrix-table th.rank-header .zone-dot { width: 5px; height: 5px; }

  .modal { padding: 1rem; border-radius: 10px; max-height: 90vh; }
  .modal-overlay { padding: 0.5rem; }
  .modal-header img { width: 32px; height: 32px; }
  .modal-header h2 { font-size: 1rem; }

  .stats-grid { grid-template-columns: repeat(4, 1fr); gap: 0.3rem; }
  .stat-card { padding: 0.4rem 0.3rem; }
  .stat-card .stat-value { font-size: 0.95rem; }
  .stat-card .stat-label { font-size: 0.58rem; }

}

@media (min-width: 481px) and (max-width: 768px) {
  header { padding: 0.65rem 1rem 0; }
  main { padding: 0.75rem 1rem 2.5rem; }

  .league-tabs button { font-size: 0.75rem; }

  .team-name-full { display: none; }
  .team-name-short { display: inline; }

  .standings-table { font-size: 0.78rem; }
}

@media (min-width: 769px) {
  .team-name-short { display: none; }
}

/* Große Viewports: volle Viewport-Höhe; Header/Main bleiben Standardbreite (1200px); Matrix zentriert & begrenzt */
@media (min-width: 1024px) {
  html {
    height: 100%;
  }

  body {
    min-height: 100%;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  /* Flex-Stretch würde sonst volle Viewport-Breite erzwingen — gleiche Standardbreite wie main */
  header {
    flex-shrink: 0;
    align-self: center;
    width: 100%;
    max-width: min(1200px, 100%);
    box-sizing: border-box;
  }

  main {
    flex: 1 1 auto;
    min-height: 0;
    align-self: center;
    width: 100%;
    max-width: min(1200px, 100%);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
  }

  #matrix-view {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  /* Matrix: nicht über volle Laptop-Breite — kompakter, zentriert */
  .matrix-grid {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: min(42rem, calc(100vw - 3rem));
    margin-left: auto;
    margin-right: auto;
    padding-bottom: 0.5rem;
  }
}
