* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1e2420;
  --card: #2a322c;
  --card-hi: #343e36;
  --text: #f2ede3;
  --muted: #9aa89e;
  --gold: #c9a227;
  --gold-dark: #a5851f;
  --green: #7fc97f;
  --red: #e07a6a;
  --radius: 12px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

h1 { font-size: 1.5rem; margin-bottom: 4px; }
h2 { font-size: 1.1rem; margin: 20px 0 10px; color: var(--muted); font-weight: 600; }

.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.error-msg { color: var(--red); padding: 10px 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.topbar h1 { flex: 1; }

button {
  font-family: inherit;
  font-size: 1rem;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--gold);
  color: var(--bg);
  font-weight: 700;
  padding: 16px;
  width: 100%;
  font-size: 1.1rem;
}
.btn-secondary {
  background: var(--card-hi);
  color: var(--text);
  padding: 12px 16px;
}
.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 12px 16px;
}
.btn-small {
  padding: 8px 14px;
  font-size: 0.9rem;
}
.btn-back {
  background: var(--card);
  color: var(--text);
  padding: 10px 14px;
  font-size: 1.1rem;
  flex-shrink: 0;
}

input[type="text"], input[type="number"] {
  font-family: inherit;
  font-size: 1.1rem;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--card-hi);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}
input:focus { outline: 2px solid var(--gold); border-color: transparent; }

.player-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.player-input-row button {
  background: var(--card-hi);
  color: var(--red);
  padding: 0 18px;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

/* Spieleliste */
.game-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.game-row .game-list-item { flex: 1; }
.game-del {
  flex-shrink: 0;
  background: var(--card);
  color: var(--red);
  padding: 0 16px;
  font-size: 1.2rem;
  border: 1px solid transparent;
}
.game-del:active { background: var(--card-hi); border-color: var(--red); }
.game-list-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--text);
  padding: 14px;
  border-radius: var(--radius);
}
.game-list-item .gl-name { font-weight: 700; }
.game-list-item .gl-meta { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}
.badge.active { background: #2d5a3a; color: var(--green); }
.badge.finished { background: #3d3d3d; color: var(--muted); }

/* Startspieler / Banner */
.starter-banner {
  background: var(--card);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 1.05rem;
}
.starter-banner strong { color: var(--gold); }

.roll-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.roll-row label { flex: 1; font-size: 1.05rem; }
.roll-row input { width: 90px; text-align: center; font-size: 1.3rem; }

/* Spieler-Kacheln */
.player-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.player-tile {
  background: var(--card);
  color: var(--text);
  padding: 18px 10px;
  border-radius: var(--radius);
  font-size: 1.15rem;
  font-weight: 700;
  border: 2px solid transparent;
  min-height: 64px;
}
.player-tile.selected {
  border-color: var(--gold);
  background: var(--card-hi);
}

/* Hand-Buttons */
.hand-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.hand-tile {
  background: var(--card);
  color: var(--text);
  padding: 16px 10px;
  border-radius: var(--radius);
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.hand-tile .h-name { font-weight: 700; font-size: 1.05rem; }
.hand-tile .h-pts { color: var(--gold); font-size: 0.9rem; font-weight: 700; }

/* Rangliste */
.score-table { width: 100%; border-collapse: collapse; }
.score-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--card-hi);
  font-size: 1.1rem;
}
.score-table tr:first-child td { color: var(--gold); font-weight: 700; }
.score-table .rank { width: 36px; color: var(--muted); }
.score-table .pts { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Historie */
.history { list-style: none; }
.history li {
  display: flex;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--card-hi);
  font-size: 0.95rem;
}
.history .rno { color: var(--muted); width: 30px; flex-shrink: 0; }
.history .rwho { flex: 1; }
.history .rpts { color: var(--gold); font-weight: 700; }

.footer-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.footer-actions button { flex: 1; }

/* Endstand */
.winner-box {
  text-align: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 14px;
  margin-bottom: 16px;
}
.winner-box .trophy { font-size: 3rem; }
.winner-box .w-name { font-size: 1.6rem; font-weight: 800; color: var(--gold); margin-top: 6px; }
.winner-box .w-pts { color: var(--muted); margin-top: 4px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-hi);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 30;
  max-width: 90vw;
}
.toast.err { color: var(--red); }

/* ---------- Diverse ---------- */
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 10px 0 14px; line-height: 1.4; }
.btn-link {
  background: transparent;
  color: var(--muted);
  padding: 14px;
  width: 100%;
  margin-top: 12px;
  text-decoration: underline;
}
.btn-icon {
  background: var(--card);
  color: var(--text);
  padding: 10px 12px;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ---------- Startspieler auswürfeln ---------- */
.dice-roll-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.dice-roll-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px 16px;
}
.dice-roll-row.win { border-color: var(--gold); background: var(--card-hi); }
.drr-name { font-size: 1.05rem; font-weight: 600; }
.drr-die {
  font-size: 1.5rem;
  font-weight: 800;
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dice-roll-row.win .drr-die { color: var(--gold); }

/* ---------- Verrechnungsblatt ---------- */
.sheet-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--card-hi);
  margin-bottom: 8px;
}
.sheet {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
  font-variant-numeric: tabular-nums;
}
.sheet th, .sheet td {
  border: 1px solid var(--card-hi);
  text-align: center;
  padding: 0;
}
.sheet .corner, .sheet .p-head {
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 10px 8px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.sheet .corner { left: 0; z-index: 3; }
.sheet .p-head.turn { color: var(--gold); background: var(--card-hi); }

.sheet .row-label {
  background: var(--card);
  color: var(--text);
  font-weight: 700;
  padding: 0 12px;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 58px;
}
.sheet .rl-main { font-size: 1.05rem; }
.sheet .rl-sub { color: var(--muted); font-size: 0.7rem; margin-left: 2px; }

.sheet .cell {
  min-width: 54px;
  height: 44px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}
.sheet .cell.in-turn { background: rgba(201,162,39,0.07); }
.sheet .cell.editable {
  cursor: pointer;
  background: rgba(201,162,39,0.16);
  outline: 1px dashed var(--gold-dark);
  outline-offset: -3px;
}
.sheet .cell.editable:active { background: rgba(201,162,39,0.3); }
.sheet .cell.filled { color: var(--text); }
.sheet .cell.filled.serviert { color: var(--gold); }
.sheet .cell.struck { color: var(--muted); }
.sheet .cell.total { color: var(--gold); font-weight: 800; font-size: 1.1rem; }

.sheet .combo-start th, .sheet .combo-start td { border-top: 3px solid var(--muted); }
.sheet .total-row th, .sheet .total-row td { border-top: 3px solid var(--muted); background: var(--card); }
.sheet.readonly .cell { cursor: default; }

/* ---------- Eingabe-Overlay ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 0;
}
.sheet-modal {
  background: var(--bg);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
.sm-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 14px; text-align: center; }
.sm-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.sm-opt {
  background: var(--card);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  text-align: left;
}
.sm-opt .smo-label { font-weight: 700; }
.sm-opt .smo-note { color: var(--muted); font-size: 0.9rem; }
.sm-opt.strike { background: transparent; border: 1px solid var(--red); }
.sm-opt.strike .smo-label { color: var(--red); }

.sheet-modal.rules .rules-body { line-height: 1.5; font-size: 0.95rem; }
.sheet-modal.rules .rules-body p { margin-bottom: 10px; }
.sheet-modal.rules .rules-body ul { margin: 0 0 10px 18px; }
.sheet-modal.rules .rules-body li { margin-bottom: 6px; }
.sheet-modal.rules .rules-body strong { color: var(--gold); }
