:root {
  --divider: #000000;
  --bg: #444444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: #fff;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Verbindungsanzeige ---------- */
#conn {
  width: 14px; height: 14px; border-radius: 50%;
  background: #e53935; border: 2px solid rgba(255,255,255,.6);
  transition: background .2s;
}
#conn.ok { background: #43a047; }

/* ---------- Lobby ---------- */
.lobby {
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 24px;
  background: linear-gradient(160deg, #1f2937, #111827);
}
.lobby h1 { font-size: 28px; margin: 0 0 4px; }
.lobby .sub { color: #9ca3af; margin: 0 0 24px; font-size: 15px; }
.lobby h2 { font-size: 18px; margin: 24px 0 12px; color: #e5e7eb; }

.lanes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}
.lane-btn {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none; border-radius: 12px;
  background: #374151; color: #fff;
  font-size: 26px; font-weight: 800;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.lane-btn:hover { background: #4b5563; }
.lane-btn:active { transform: scale(.95); }
.lane-btn.active { background: #2563eb; }
.lane-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #22c55e;
}
.lane-btn small {
  position: absolute; bottom: 6px; left: 0; right: 0;
  font-size: 10px; font-weight: 600; color: #d1d5db;
}

.role-row { display: flex; flex-wrap: wrap; gap: 10px; }
.role-btn {
  border: 2px solid transparent; border-radius: 10px;
  padding: 10px 16px; font-size: 15px; font-weight: 600;
  background: #374151; color: #fff; cursor: pointer;
}
.role-btn.sel { border-color: #60a5fa; background: #1e3a8a; }

.big-link {
  display: inline-block; margin-top: 8px;
  padding: 12px 20px; border-radius: 10px;
  background: #2563eb; color: #fff; text-decoration: none;
  font-weight: 700; font-size: 16px;
}
.secondary-link {
  display: inline-block; margin-top: 16px; color: #93c5fd;
  text-decoration: none; font-size: 15px;
}
.hint { color: #9ca3af; font-size: 13px; margin-top: 6px; }

/* ---------- Scoreboard (bahn) ---------- */
.board {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 6px;
  height: 100%;
  width: 100%;
  padding: 6px;
}

.total {
  flex: 2;
  position: relative;
  border: 2px solid var(--divider);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.total .score {
  font-weight: 800;
  line-height: 1;
}
.total .score.multi-digit {
  line-height: 1;
}
.total .name {
  position: absolute; bottom: 6px; left: 6px; right: 6px;
  text-align: center;
  font-size: clamp(16px, 3.2vh, 34px); font-weight: 800;
  background: transparent; border: none; color: inherit;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.total .name:focus { outline: none; }
.total.leading { box-shadow: inset 0 0 0 5px rgba(255,255,255,.5); }

.corner-btn {
  position: absolute; top: 10px;
  width: 46px; height: 46px; border-radius: 50%;
  border: none; cursor: pointer;
  background: rgba(255,255,255,.55);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #000;
}
.corner-btn.left { left: 10px; }
.corner-btn.right { right: 10px; }

/* Mittlere Kehren-Spalte */
.rounds {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.round-row {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-height: 0;
}
.cell {
  border: 1px solid var(--divider);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #000;
  min-width: 0;
}
.cell.score-cell {
  flex: 3;
  font-size: clamp(20px, 13vh, 160px);
  cursor: pointer;
  position: relative;
}
.cell.score-cell.readonly { cursor: default; }
.cell.score-cell.leading { background: #4caf50 !important; }
.cell.score-cell.pending {
  font-size: clamp(26px, 14vh, 170px);
  color: #e65100;
  background: repeating-linear-gradient(45deg, #fff3e0, #fff3e0 10px, #ffe0b2 10px, #ffe0b2 20px) !important;
}
.cell.round-num {
  flex: 1;
  font-weight: 800;
  font-size: clamp(16px, 6vh, 50px);
}
.cell.round-num.current {
  background: #ffeb3b !important;
  font-size: clamp(22px, 8vh, 64px);
}

/* Top-Leiste (nur Steuerung) */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 40px; display: flex; align-items: center; gap: 12px;
  padding: 0 12px; background: rgba(0,0,0,.55);
  font-size: 14px; z-index: 20;
  transition: transform .3s;
}
.board.with-topbar { padding-top: 46px; }
.topbar a { color: #93c5fd; text-decoration: none; }
.topbar .role-tag {
  padding: 2px 8px; border-radius: 6px; background: #374151; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.topbar button {
  background: #374151; color: #fff; border: none; border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font-size: 13px;
}

/* ---------- Uebersicht ---------- */
.overview {
  height: 100%; width: 100%; overflow: auto;
  padding: 10px;
  background: #111827;
}
.ov-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.ov-head h1 { font-size: 22px; margin: 0; }
.ov-head .spacer { flex: 1; }
.ov-head a, .ov-head button {
  color: #93c5fd; background: #1f2937; border: none;
  padding: 6px 12px; border-radius: 8px; text-decoration: none;
  font-size: 14px; cursor: pointer;
}
.ov-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}
.ov-card {
  border-radius: 12px; overflow: hidden;
  background: #1f2937; border: 1px solid #374151;
}
.ov-card .ov-bahn {
  font-size: 13px; font-weight: 700; color: #9ca3af;
  padding: 4px 10px; background: #111827;
}
.ov-teams { display: flex; }
.ov-team {
  flex: 1; padding: 12px 10px; text-align: center;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.ov-team .ov-name {
  font-weight: 700; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ov-team .ov-total { font-size: 44px; font-weight: 900; line-height: 1; }
.ov-team.lead { box-shadow: inset 0 0 0 3px rgba(255,255,255,.55); }
.ov-vs {
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px; font-weight: 800; color: #9ca3af;
}
.ov-kehren {
  display: flex; gap: 2px; padding: 6px 8px; background: #111827;
  font-size: 12px; color: #cbd5e1; justify-content: center;
}
.ov-kehren span {
  min-width: 34px; text-align: center;
  background: #1f2937; border-radius: 4px; padding: 2px 0;
}
.ov-empty { color: #6b7280; padding: 40px; text-align: center; font-size: 16px; }

/* ---------- 5er Ansicht (senkrecht) ---------- */
.ov-grid.paged {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  height: calc(100vh - 60px);
}
.ov-card-v {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.ov-card-v .ov-bahn { font-size: 16px; padding: 6px 12px; }
.ov-v-teams { display: flex; gap: 2px; }
.ov-v-team {
  flex: 1; padding: 10px 8px; text-align: center;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.ov-v-team.lead { box-shadow: inset 0 0 0 3px rgba(255,255,255,.55); }
.ov-v-name {
  font-weight: 700; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ov-v-total { font-size: 48px; font-weight: 900; line-height: 1; }
.ov-v-kehren {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 4px; background: #111827; min-height: 0;
}
.ov-v-row {
  flex: 1; display: flex; align-items: stretch; gap: 2px;
  min-height: 0; border-radius: 4px; overflow: hidden;
}
.ov-v-row.current { outline: 2px solid #ffeb3b; outline-offset: -1px; }
.ov-v-rn {
  flex: 0 0 28px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(14px, 3vh, 22px);
}
.ov-v-cell {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(18px, 4.5vh, 40px);
}
.ov-v-cell.leading { background: #4caf50 !important; color: #fff !important; }
.ov-v-cell.pending {
  color: #e65100 !important;
  background: repeating-linear-gradient(45deg, #fff3e0, #fff3e0 10px, #ffe0b2 10px, #ffe0b2 20px) !important;
}
#pageNav { align-items: center; gap: 6px; }
#pageNav button {
  background: #1f2937; color: #93c5fd; border: none; border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font-size: 16px;
}
#pageInfo { font-size: 14px; color: #9ca3af; min-width: 40px; text-align: center; }

/* ---------- Beamer ---------- */
.beamer .ov-v-team { padding: 1vh 0.5vw; gap: 0.5vh; }
.beamer .ov-v-name { font-size: 2.2vh; }
.beamer .ov-v-total { font-size: 14vh; line-height: 1; }
.beamer .ov-v-kehren { flex: 1; }
.beamer .ov-v-row { flex: 1; }
.beamer .ov-v-cell { font-size: 10vh; }
.beamer .ov-v-rn { font-size: 3.5vh; flex: 0 0 3vh; }
