*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-main: #050608;
  --bg-card: #17191f;
  --bg-card-soft: #101218;
  --bg-elevated: #111827;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --accent-green: #15803d;
  --accent-red: #ef4444;
  --accent-blue: #2563eb;
  --accent-border: #374151;
  --radius-card: 16px;
  --radius-pill: 999px;
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.7);
  --bottom-nav-height: 64px;
  --max-width: 480px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  background: #000;
  color: var(--text-main);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: radial-gradient(circle at top, #064e3b 0, #020617 40%, #000 100%);
}

.app-shell {
  width: 100%;
  max-width: var(--max-width);
  min-height: 100vh;
  background: #020617;
  color: var(--text-main);
  position: relative;
  padding-bottom: var(--bottom-nav-height);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, #020617 0, rgba(2, 6, 23, 0.95) 95%);
  padding: 10px 14px 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.app-header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.app-header-titles h1 {
  margin: 0;
  font-size: 1.1rem;
}

.app-header-titles p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Main */
.app-main {
  padding: 8px 10px 10px;
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 12px 14px 14px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(55, 65, 81, 0.7);
  margin-bottom: 10px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Status card innerhalb Live */
.status-inner-card {
  background: #14532d;
  border-color: #15803d;
  margin: 8px 0 10px;
}

.status-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
}

/* Toggle */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  display: none;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #6b7280;
  transition: 0.2s;
  border-radius: 999px;
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
  background-color: #22c55e;
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

/* Overview */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.overview-box {
  background: var(--bg-card-soft);
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(75, 85, 99, 0.7);
}

.overview-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.overview-value {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 2px;
}

.overview-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Player list */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 10px;
  border: 1px solid rgba(75, 85, 99, 0.9);
}

.player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: #111827;
  overflow: hidden;
  background: #1f2937;
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-name {
  font-size: 1.05rem;
  font-weight: 600;
}

.player-team {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.player-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.player-amount-badge {
  background: #1f2933;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.8rem;
  border: 1px solid rgba(75, 85, 99, 0.9);
}

.player-actions-row {
  grid-column: 1 / 4;
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.player-actions-row .btn {
  flex: 1 1 45%;
}

/* Buttons */
.btn {
  border-radius: 999px;
  border: none;
  padding: 5px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  background: #4b5563;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s;
}

.btn:hover {
  background: #6b7280;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-small {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(75, 85, 99, 0.8);
}

.btn-ghost:hover {
  background: rgba(31, 41, 55, 0.7);
}

.primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.5);
}

.primary:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
}

.btn-penalty-red {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 8px 20px rgba(239, 68, 68, 0.55);
}

.btn-penalty-green {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.55);
}

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--max-width);
  height: var(--bottom-nav-height);
  background: #020617;
  border-top: 1px solid rgba(55, 65, 81, 0.9);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 0 8px;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.7);
  z-index: 30;
}

.nav-item {
  flex: 1 1 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.8rem;
  cursor: pointer;
}

.nav-item .nav-icon {
  font-size: 1.2rem;
}

.nav-item.active {
  color: #22c55e;
}

/* Forms etc. */
.penalty-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.penalty-form input,
.penalty-form select {
  width: 100%;
}

input[type="text"],
input[type="number"],
select {
  border-radius: 999px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: #020617;
  color: var(--text-main);
  padding: 7px 10px;
  font-size: 0.9rem;
  outline: none;
}

input[type="color"] {
  width: 100%;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: #020617;
  padding: 2px;
}

input::placeholder {
  color: #6b7280;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.4);
}

textarea {
  border-radius: 12px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: #020617;
  color: var(--text-main);
  padding: 7px 10px;
  resize: vertical;
  min-height: 60px;
  font-size: 0.9rem;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Penalty list */
.penalty-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.penalty-row {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(75, 85, 99, 0.9);
  font-size: 0.86rem;
}

.penalty-name {
  font-weight: 500;
}

.penalty-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.penalty-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  border-radius: 999px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  padding: 3px 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Teams config */
.teams-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.team-config label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.team-config input[type="text"] {
  margin-top: 2px;
}

/* Ranking */
.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ranking-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 6px 8px;
  border: 1px solid rgba(75, 85, 99, 0.8);
}

.ranking-row.leader {
  border-color: #facc15;
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.5);
}

.ranking-name {
  font-size: 0.92rem;
  font-weight: 500;
}

.ranking-team {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.ranking-sum {
  font-size: 0.9rem;
  font-weight: 500;
}

/* Abende-Liste */
.evening-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.evening-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 6px 8px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  cursor: pointer;
}

.evening-row.active {
  border-color: #22c55e;
  background: #14532d;
}

.evening-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.evening-label {
  font-size: 0.9rem;
  font-weight: 500;
}

.evening-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.evening-actions {
  display: flex;
  gap: 4px;
}

/* Königskegeln */
.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.koenig-player-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.koenig-row {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 0.7fr 0.5fr;
  gap: 6px;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 6px 8px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  align-items: center;
}

.koenig-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.koenig-team {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.koenig-sum {
  text-align: right;
  font-size: 0.9rem;
  font-weight: 500;
}

/* König Gesamt-Tabelle */
.table-wrapper {
  overflow-x: auto;
}

.koenig-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.koenig-table th,
.koenig-table td {
  padding: 4px 6px;
  text-align: left;
}

.koenig-table th {
  border-bottom: 1px solid rgba(75, 85, 99, 0.9);
}

.koenig-table tr:nth-child(even) td {
  background: rgba(15, 23, 42, 0.9);
}

.koenig-table tr:nth-child(odd) td {
  background: rgba(15, 23, 42, 0.6);
}

/* Abend-Strafen-Block */
.koenig-penalties {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.koenig-penalty-block {
  background: var(--bg-elevated);
  border-radius: 12px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  padding: 6px 8px;
}

.koenig-penalty-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.koenig-penalty-icons {
  display: flex;
  gap: 4px;
  font-size: 0.9rem;
}

.koenig-penalty-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.koenig-penalty-table th,
.koenig-penalty-table td {
  padding: 2px 4px;
}

.koenig-penalty-table th {
  border-bottom: 1px solid rgba(75, 85, 99, 0.9);
}

/* Dialog */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.dialog-backdrop.hidden {
  display: none;
}

.dialog {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 14px 14px 12px;
  width: 90%;
  max-width: 360px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(75, 85, 99, 0.9);
}

.dialog-large {
  max-width: 420px;
}

.dialog h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.dialog-form label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.dialog-form input,
.dialog-form select {
  margin-top: 2px;
  width: 100%;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* Evening Assign Dialog */
.evening-assign-list {
  max-height: 320px;
  overflow-y: auto;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.evening-assign-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 6px 8px;
  border: 1px solid rgba(75, 85, 99, 0.9);
}

.evening-assign-name {
  font-size: 0.9rem;
}

.evening-assign-team select {
  width: 100%;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-height) + 70px);
  background: #111827;
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(55, 65, 81, 0.9);
  z-index: 60;
}

.toast.hidden {
  display: none;
}

/* Game variant */
.player-list-game .player-card {
  padding-top: 8px;
  padding-bottom: 10px;
}

.player-list-game .player-actions-row .btn {
  font-size: 0.8rem;
}

/* Live-Game Header */
.live-game-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.live-game-select-wrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.live-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.live-game-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Game-Form */
.game-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.game-form textarea {
  grid-column: 1 / -1;
}

.game-form button[type="submit"] {
  grid-column: 1 / -1;
  justify-self: flex-end;
}

/* Game Dialog */
.game-dialog-list {
  margin-top: 6px;
}

.game-dialog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 2px 0;
}

/* Responsive Desktop */
@media (min-width: 768px) {
  .app-shell {
    margin-top: 16px;
    margin-bottom: 16px;
    border-radius: 26px;
    overflow: hidden;
  }
}