:root {
  --bg: #0e1626;
  --bg-2: #16223b;
  --card: #1b2a4a;
  --card-2: #22345a;
  --text: #eef3fb;
  --muted: #9fb0cc;
  --line: #2e4064;
  --primary: #3b82f6;
  --primary-d: #2563eb;
  --p1: #ef4444;   /* Rot */
  --p1-d: #b91c1c;
  --p2: #f4c025;   /* Gelb */
  --p2-d: #c48a05;
  --board: #17408b;
  --hole: #0e1626;
  --win: #22c55e;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(14,22,38,.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 1.15rem; margin: 0; letter-spacing: .5px; }
.chip {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; font-weight: 600; cursor: pointer;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: .95rem; }
.link:hover, .chip:hover { color: #fff; }

/* Content + screens */
.content { flex: 1; display: flex; justify-content: center; padding: 18px 16px 40px; }
.screen { display: none; width: 100%; max-width: 640px; }
.screen.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none; } }

/* Cards & forms */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card h2 { margin: 0 0 6px; }
.card h3 { margin: 18px 0 8px; font-size: 1rem; color: var(--muted); }
.muted { color: var(--muted); font-size: .92rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row .field { flex: 1; }
input, select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font-size: 1rem; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

button.primary, button.ghost {
  cursor: pointer; border-radius: 10px; font-size: 1rem; font-weight: 600; padding: 11px 16px;
  border: 1px solid transparent; transition: transform .05s ease, background .15s ease;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-d); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--card-2); }
button.big { width: 100%; margin-top: 12px; padding: 14px; }
button:active { transform: translateY(1px); }
.hidden { display: none !important; }
.error { color: #fca5a5; min-height: 1.2em; margin: 8px 0 0; }

/* Menu */
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; text-align: left; color: var(--text);
  min-height: 120px; box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--primary); transform: translateY(-2px); transition: .15s; }
.tile-ico { font-size: 1.8rem; }
.tile-t { font-weight: 700; font-size: 1.05rem; }
.tile-s { color: var(--muted); font-size: .82rem; }

/* Profil-Zeile im Menü */
.profile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--muted); cursor: pointer; }
.check input { width: auto; }

/* Admin-Liste */
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
}
.admin-row .a-name { flex: 1; font-weight: 600; }
.admin-row .badge { font-size: .7rem; background: var(--primary); color: #fff; padding: 2px 8px; border-radius: 999px; }
.admin-row .a-info { color: var(--muted); font-size: .8rem; }
.admin-row button { padding: 6px 10px; font-size: .8rem; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; }
.admin-row button:hover { background: var(--bg); }
.admin-row button.danger { color: #fca5a5; border-color: #7f1d1d; }
#admin-edit { background: var(--bg); border: 1px solid var(--primary); border-radius: 12px; padding: 14px 16px; margin: 8px 0 4px; }
.edit-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.edit-actions button { padding: 9px 14px; }

/* Stats banner */
.stats-banner { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.3rem; }
.stat span { color: var(--muted); font-size: .78rem; }

/* Game */
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.turn { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.turn .disc-mini { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 -3px 6px rgba(0,0,0,.3); }
.game-meta { color: var(--muted); font-size: .85rem; text-align: right; }

.board-wrap { position: relative; }
.board {
  --cols: 7; --rows: 6;
  --c1: var(--p1); --c2: var(--p2);
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: clamp(4px, 1.4vw, 10px);
  background: var(--board);
  border-radius: var(--radius);
  padding: clamp(6px, 1.6vw, 12px);
  width: min(96vw, 560px);
  margin: 0 auto;
  box-shadow: var(--shadow), inset 0 2px 0 rgba(255,255,255,.08);
  touch-action: manipulation;
}
.cell {
  aspect-ratio: 1 / 1;
  background: var(--hole);
  border-radius: 50%;
  position: relative;
  box-shadow: inset 0 3px 8px rgba(0,0,0,.6);
  cursor: pointer;
  overflow: hidden;
}
.cell .disc {
  position: absolute; inset: 6%;
  border-radius: 50%;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,.35), inset 0 3px 6px rgba(255,255,255,.25);
}
.cell.p1 .disc { background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c1) 45%, #fff), var(--c1) 58%, color-mix(in srgb, var(--c1) 65%, #000)); }
.cell.p2 .disc { background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c2) 45%, #fff), var(--c2) 58%, color-mix(in srgb, var(--c2) 65%, #000)); }
.cell.win .disc { box-shadow: 0 0 0 3px var(--win), 0 0 14px var(--win); }

/* Spur: leuchtet entlang des Fallwegs kurz auf und zieht nach. */
.cell .trail {
  position: absolute; inset: 32%; border-radius: 50%;
  opacity: 0; pointer-events: none; z-index: 2;
  animation: trailFade .6s ease-out forwards;
}
@keyframes trailFade {
  0% { opacity: 0; transform: scale(.4); }
  25% { opacity: .8; transform: scale(.9); }
  100% { opacity: 0; transform: scale(1.15); }
}

/* Ablenker (schräge Rampe) */
.cell.deflect {
  background: var(--hole);
  cursor: default;
}
.cell.deflect::after {
  content: ''; position: absolute; inset: 10%;
  background: linear-gradient(135deg, #6b7a9c, #46547a);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 2px 4px rgba(0,0,0,.4);
}
/* Rampe zeigt in die Richtung, in die die Kugel abgelenkt wird. */
.cell.deflect-l::after { clip-path: polygon(0 100%, 100% 0, 100% 100%); } /* "/" – Kugel rollt nach links */
.cell.deflect-r::after { clip-path: polygon(0 0, 100% 100%, 0 100%); }    /* "\" – Kugel rollt nach rechts */

/* Freies Setzen: leeres Feld hervorheben */
.board.free .cell:not(.p1):not(.p2) { cursor: pointer; }
.board.free .cell.col-hover:not(.p1):not(.p2)::after {
  content: ''; position: absolute; inset: 18%; border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.4);
}

/* Segment-Auswahl (statt Dropdown) */
.seg { display: flex; gap: 8px; }
.seg.wrap { flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; min-width: 44px;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; font-size: .95rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s ease, border-color .12s ease;
}
.seg-btn:hover { border-color: var(--primary); }
.seg-btn.active { background: var(--primary); border-color: transparent; color: #fff; }
.seg.goals .seg-btn { flex: 0 1 auto; flex-direction: column; gap: 4px; padding: 8px 12px; font-size: .78rem; }
.goal-ico { display: flex; align-items: center; justify-content: center; height: 26px; color: currentColor; opacity: .9; }
.swatch.disabled { opacity: .28; cursor: not-allowed; box-shadow: inset 0 -3px 6px rgba(0,0,0,.3); }
.swatch.disabled:hover { transform: none; }

/* Farbauswahl */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; box-shadow: inset 0 -3px 6px rgba(0,0,0,.3);
  transition: transform .1s ease;
}
.swatch.selected { border-color: #fff; transform: scale(1.1); }
.swatch:hover { transform: scale(1.1); }

/* Pop-Out-Leiste unter dem Brett */
.pop-row {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr);
  gap: clamp(4px, 1.4vw, 10px); width: min(96vw, 560px);
  margin: 8px auto 0; padding: 0 clamp(6px, 1.6vw, 12px); box-sizing: border-box;
}
.pop-btn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 8px; padding: 7px 0; cursor: pointer; font-size: .85rem; line-height: 1;
}
.pop-btn:hover:not(:disabled) { background: var(--primary); border-color: transparent; }
.pop-btn:disabled { opacity: .3; cursor: default; }

/* Column hover highlight */
.board.hoverable .cell.col-hover { box-shadow: inset 0 3px 8px rgba(0,0,0,.6), 0 0 0 2px rgba(255,255,255,.25); }
.board.disabled { pointer-events: none; opacity: .96; }

.board-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8,12,22,.55); border-radius: var(--radius); backdrop-filter: blur(2px);
}
.overlay-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 26px; text-align: center; box-shadow: var(--shadow); max-width: 88%;
}
#overlay-text { font-size: 1.3rem; font-weight: 800; margin-bottom: 14px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; }

.game-foot { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

.code-badge {
  font-size: 2.4rem; font-weight: 800; letter-spacing: 8px; text-align: center;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 12px;
  padding: 14px; margin: 8px 0;
}

/* Scores */
.tabs { display: flex; gap: 8px; margin: 8px 0 14px; flex-wrap: wrap; }
.tab { background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: .88rem; }
.tab.active { background: var(--primary); color: #fff; border-color: transparent; }
.score-list { list-style: none; counter-reset: rank; padding: 0; margin: 0; }
.score-list li {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px;
  border-bottom: 1px solid var(--line);
}
.score-list li::before {
  counter-increment: rank; content: counter(rank);
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--card-2); border-radius: 50%; font-weight: 700; font-size: .85rem;
}
.score-list li:nth-child(1)::before { background: #f4c025; color: #3a2a00; }
.score-list li:nth-child(2)::before { background: #cbd5e1; color: #1e293b; }
.score-list li:nth-child(3)::before { background: #d08b52; color: #2a1500; }
.score-name { flex: 1; font-weight: 600; }
.score-val { font-weight: 800; }
.empty-note { color: var(--muted); padding: 16px 4px; }

@media (max-width: 420px) {
  .menu-grid { grid-template-columns: 1fr; }
  .brand { font-size: 1rem; }
}
