@font-face {
  font-family: "Questrial";
  src: url("fonts/questrial-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Geologica";
  src: url("fonts/geologica-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #30ced5;
  --primary: rgb(105, 189, 185);
  --primary-light: rgb(135, 202, 199);
  --secondary: rgb(48, 52, 138);
  --secondary-dark: rgb(38, 41, 110);
  --cream: rgb(254, 246, 220);
  --cream-dark: rgb(244, 232, 196);
  --yellow: rgb(249, 221, 105);
  --red: rgb(221, 89, 105);
  --green: #61be9e;
  --ink: #23264f;
  --muted: #6b6e8f;
  --line: rgba(48, 52, 138, 0.15);
  --radius: 12px;
  --font: "Questrial", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Geologica", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

html, body { overflow: hidden; }

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 12px 0;
}

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 10px;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-card {
  display: grid;
  place-items: center;
  width: 34px;
  height: 46px;
  border-radius: 7px;
  background: var(--cream);
  border: 3px solid var(--secondary);
  color: var(--red);
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 26px;
  transform: rotate(-8deg);
  box-shadow: 3px 3px 0 var(--secondary);
}
.logo-text {
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 2px 2px 0 var(--secondary), -1px -1px 0 var(--secondary), 1px -1px 0 var(--secondary), -1px 1px 0 var(--secondary);
}
.logo-text b { color: var(--yellow); margin-left: 2px; }
.topbar-sub {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--secondary);
}

/* ---------- Spielbrett-Rahmen (wie Original) ---------- */
.frame {
  min-height: 0;
  border: 2px solid var(--secondary);
  border-left-width: 1px;
  border-right-width: 1px;
  border-radius: 16px;
  border-top: 8px solid var(--yellow);
  border-bottom: 8px solid var(--yellow);
  outline: 2px solid var(--secondary);
  outline-offset: -2px;
  background: var(--primary-light);
  overflow: hidden;
  display: flex;
}
.frame-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px 18px;
  scrollbar-color: rgba(48, 52, 138, 0.3) transparent;
}

/* ---------- Tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px 0 max(calc(var(--safe-bottom) - 14px), 6px);
}
.tab {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 700;
}
.tab svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab.active { background: var(--secondary); color: #fff; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  font-weight: 900;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--cream);
  color: var(--secondary);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.45; }
.btn.primary { background: var(--secondary); color: #fff; }
.btn.accent { background: var(--yellow); color: var(--secondary); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid var(--secondary); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn.block { width: 100%; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}
.icon-btn:disabled { opacity: 0.35; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- Punktetafel ---------- */
.board-head {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}
.sort { display: flex; gap: 6px; }
.chip {
  padding: 7px 10px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.chip.active { border-color: #fff; }

.round-nav {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  justify-items: center;
}
.round-nav .icon-btn { color: rgba(255, 255, 255, 0.75); }
.round-nav .icon-btn.pulse { color: var(--yellow); animation: pulse 1.2s ease-in-out infinite; }
.round-labels { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; text-align: center; }
.round-label { font-family: var(--font-num); font-weight: 800; font-size: 14px; letter-spacing: 0.3px; }
.round-label small { display: block; font-weight: 500; font-size: 10px; opacity: 0.7; }

@keyframes pulse { 50% { transform: scale(1.18); } }

.board-body {
  margin-top: 12px;
  border-radius: 0 0 6px 6px;
  background: var(--cream);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
  padding: 4px 12px;
}

.row {
  --cols: 1;
  display: grid;
  grid-template-columns: 64px 64px 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  animation: slideIn 250ms ease-out;
}
.row:last-child { border-bottom: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-12px); } }

.avatar {
  display: grid;
  place-items: center;
  align-content: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--c, var(--secondary));
  color: #fff;
  font-family: var(--font-num);
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.25);
  position: relative;
}
.avatar small {
  display: block;
  max-width: 52px;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 400;
  opacity: 0.9;
}
.avatar.sm { width: 34px; height: 34px; font-size: 12px; box-shadow: none; flex: none; }
.row.leader .avatar::after {
  content: "★";
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 16px;
  color: var(--yellow);
  text-shadow: 0 0 2px var(--secondary), 0 0 2px var(--secondary);
}

.gauge { position: relative; width: 64px; height: 64px; }
.gauge svg { width: 100%; height: 100%; }
.g-track { fill: none; stroke: rgba(0, 0, 0, 0.12); stroke-width: 7; }
.g-val { fill: none; stroke: var(--primary); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 400ms ease; }
.gauge.done .g-val { stroke: var(--green); }
.g-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 17px;
}

.cells { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 10px; }
.cell {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: 0 4px;
  border: 2px solid rgba(48, 52, 138, 0.35);
  border-radius: 8px;
  background: #fff;
}
.cell:focus-within { border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(48, 52, 138, 0.15); }
.cell.filled { background: #fffdf4; }
.sign {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--primary-light);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  line-height: 1;
  transition: transform 250ms ease, background 200ms;
}
.sign.neg { background: var(--red); transform: rotate(180deg); }
.sign:disabled { background: #d4d4d4; }
.score {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 24px;
}
.score::placeholder { color: rgba(48, 52, 138, 0.25); }

.board-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.empty {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 40px 16px;
  text-align: center;
  color: var(--secondary);
}
.empty h2 { margin: 0; font-size: 22px; }
.empty p { margin: 0; color: var(--muted); max-width: 32ch; }

/* Gewinner */
.winner {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 34px 16px 28px;
  text-align: center;
  animation: slideIn 300ms ease-out;
}
.winner .avatar { width: 84px; height: 84px; font-size: 26px; }
.winner h2 { margin: 6px 0 0; color: var(--secondary); font-size: 26px; }
.winner p { margin: 0; color: var(--muted); }
.winner .btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* ---------- Listen / Panels ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; color: var(--secondary); font-size: 22px; }

.card {
  background: var(--cream);
  border-radius: var(--radius);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  padding: 12px;
  margin-bottom: 10px;
}
.card h3 { margin: 0 0 6px; color: var(--secondary); font-size: 17px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.card.current { box-shadow: 0 0 0 3px var(--secondary), 0 3px 8px rgba(0, 0, 0, 0.1); }

.player-item { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.player-item .name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.player-item .meta { font-size: 13px; color: var(--muted); }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--secondary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.badge.open { background: var(--yellow); color: var(--secondary); }
.badge.done { background: var(--green); }

.game-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.game-meta strong { color: var(--ink); font-size: 15px; }
.standings { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }
.standings li { display: grid; grid-template-columns: 22px 34px 1fr auto; align-items: center; gap: 8px; }
.standings .pos { font-family: var(--font-num); font-weight: 700; color: var(--muted); text-align: right; }
.standings .pts { font-family: var(--font-num); font-weight: 700; }
.standings .win .pts::after { content: " 🏆"; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: 8px; padding: 10px; text-align: center; }
.stat b { display: block; font-family: var(--font-num); font-size: 26px; color: var(--secondary); }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Dialog ---------- */
dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(23, 26, 70, 0.55); backdrop-filter: blur(3px); }
dialog.wide { width: min(900px, calc(100vw - 24px)); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); margin: 0; }
.dlg-title { margin: 0; padding: 16px 18px 6px; color: var(--secondary); font-size: 20px; }
.dlg-body { padding: 6px 18px 12px; overflow-y: auto; line-height: 1.45; }
.dlg-body p { margin: 0 0 10px; }
.dlg-actions {
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
}
.dlg-actions .btn { flex: 1 1 auto; }

.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label, .field .label { font-size: 13px; font-weight: 700; color: var(--secondary); }
.input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid rgba(48, 52, 138, 0.3);
  border-radius: 8px;
  background: #fff;
  font-size: 16px;
}
.input:focus { outline: 0; border-color: var(--secondary); }
.input.upper { text-transform: uppercase; }
.error { color: var(--red); font-size: 13px; font-weight: 700; min-height: 1em; }
.hint { font-size: 13px; color: var(--muted); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span {
  display: block;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--c);
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}
.swatch input:checked + span { border-color: #fff; box-shadow: 0 0 0 3px var(--secondary); }
.swatch input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 2px; }

.pick-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.pick-list label {
  display: grid;
  grid-template-columns: 34px 1fr 28px;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #fff;
  border: 2px solid transparent;
  cursor: pointer;
}
.pick-list input { position: absolute; opacity: 0; pointer-events: none; }
.pick-list label:has(input:checked) { border-color: var(--secondary); }
.pick-list label:has(input:focus-visible) { outline: 3px solid var(--yellow); }
.pick-order {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(48, 52, 138, 0.3);
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 13px;
}
.pick-list input:checked ~ .pick-order { background: var(--secondary); border-color: var(--secondary); color: #fff; }
.quick-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.table-wrap { overflow-x: auto; }
table.scores { border-collapse: collapse; width: 100%; font-size: 14px; }
table.scores th, table.scores td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.scores thead th { color: var(--secondary); position: sticky; top: 0; background: var(--cream); }
table.scores td { font-family: var(--font-num); }
table.scores tfoot td { font-weight: 800; border-top: 2px solid var(--secondary); border-bottom: 0; }
table.scores th:first-child, table.scores td:first-child { text-align: left; color: var(--muted); font-family: var(--font); }
table.scores .win { color: var(--green); }

/* ---------- Toast / Konfetti ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 84px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--secondary);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms, transform 200ms;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .btn { min-height: 32px; padding: 4px 10px; font-size: 12px; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; display: none; }
#confetti.on { display: block; }

/* ---------- Größere Bildschirme ---------- */
@media (min-width: 860px) {
  .app { padding-left: 20px; padding-right: 20px; }
  .frame-inner { padding: 20px 28px 24px; }
  .row { grid-template-columns: 90px 72px 1fr; }
  .gauge { width: 72px; height: 72px; }
  .avatar { width: 64px; height: 64px; }
  .board-head { grid-template-columns: 176px 1fr; padding: 8px 12px; }
  .sort { flex-direction: column; }
  .round-nav { grid-template-columns: 40px 1fr 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .players-grid, .games-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .players-grid .card, .games-grid .card { margin: 0; }
  .tabs { max-width: 560px; width: 100%; justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
