:root {
  --color-bg: #f4f7f5;
  --color-surface: #ffffff;
  --color-primary: #1f5f4a;
  --color-primary-dark: #163f32;
  --color-accent: #2f9e6a;
  --color-warn: #c0562b;
  --color-text: #1c2521;
  --color-text-muted: #5b6a63;
  --color-border: #dbe3df;
  --color-winner: #fff4d6;
  --color-winner-border: #e0ac16;
  --color-active: #dcecff;
  --color-active-border: #3d7fd9;
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.app-header h1 {
  font-size: 1.15rem;
  margin: 0;
  white-space: nowrap;
}

.app-actions {
  display: flex;
  gap: 0.4rem;
}

.btn {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
}

.btn-small { padding: 0.35rem 0.6rem; font-size: 0.85rem; }

.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:active { background: #257e54; }

.btn-warn { background: #f6e3d8; color: var(--color-warn); }
.btn-warn:active { background: #f0d0bc; }

.btn-ghost { background: rgba(255, 255, 255, 0.15); color: #fff; }
.app-header .btn-ghost { background: rgba(255, 255, 255, 0.18); }
.score-dialog .btn-ghost { background: #edf1ef; color: var(--color-text); }

.btn:disabled { opacity: 0.4; cursor: default; }

main#app-root {
  padding: 0.75rem;
  max-width: 1100px;
  margin: 0 auto;
}

.players-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.ruleset-badge {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.table-scroll {
  overflow-x: auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.score-table {
  border-collapse: collapse;
  width: 100%;
}

/* Bis zu 4 Spieler: Tabelle nutzt die volle Breite gleichmäßig aus, kein
   horizontaler Scrollbalken. table-layout:fixed + eine feste Breite für die
   Kategorie-Spalte lässt den Browser die restlichen (Spieler-)Spalten exakt
   gleich verteilen. Ab 5 Spielern (keine .layout-fit-Klasse) bleibt die
   Tabelle im automatischen Layout mit Mindestbreiten pro Spalte, wodurch sie
   breiter als der Bildschirm wird und der Container horizontal scrollt. */
.score-table.layout-fit { table-layout: fixed; }

.score-table th, .score-table td {
  border-bottom: 1px solid var(--color-border);
  padding: 0.35rem 0.4rem;
  text-align: center;
  white-space: nowrap;
}

.score-table .col-category, .score-table .cell-label {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--color-surface);
  z-index: 1;
  min-width: 5.2rem;
  max-width: 6.5rem;
  font-size: 0.85rem;
  white-space: normal;
}

.score-table.layout-fit .col-category,
.score-table.layout-fit .cell-label {
  width: 5.5rem;
  min-width: 0;
  max-width: none;
}

.col-player { min-width: 6.5rem; position: relative; }

.score-table.layout-fit .col-player,
.score-table.layout-fit .cell-value {
  min-width: 0;
}

.player-name-input {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 700;
  text-align: center;
  color: var(--color-primary-dark);
  border-radius: 6px;
  padding: 0.2rem;
}
.player-name-input:focus { background: #eef4f1; outline: none; }

.btn-remove-player {
  position: absolute;
  top: -2px;
  right: -2px;
  border: none;
  background: transparent;
  color: #b5493a;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.winner-flag {
  font-size: 0.7rem;
  font-weight: 700;
  color: #8a6100;
}

.active-flag {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}

.row-section td {
  background: #eef3f0;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary-dark);
  text-align: left;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.row-sum td { background: #f7faf8; font-weight: 700; }
.row-total td { background: #e4f0e9; font-weight: 800; font-size: 1.02rem; }
.row-bonus-stepper td { background: #fbf6ea; }

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: var(--color-text-muted);
  color: #fff;
  font-size: 0.68rem;
  font-style: italic;
  font-weight: 700;
  cursor: pointer;
  vertical-align: middle;
  flex-shrink: 0;
}

.cell-btn {
  width: 100%;
  min-width: 2.6rem;
  min-height: 2.2rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--color-text);
}

.cell-btn--empty { color: var(--color-text-muted); }
.cell-btn--empty::after { content: '–'; opacity: 0.4; }
.cell-btn--filled { background: #eaf6ef; border-color: #bfe3cd; color: var(--color-primary-dark); }
.cell-btn--struck { background: #f4f0ee; color: #9a8f89; text-decoration: line-through; }

.col-winner { background: var(--color-winner) !important; }
.col-winner .cell-btn { border-color: var(--color-winner-border); }

.col-active { background: var(--color-active); }
.col-active .cell-btn { border-color: var(--color-active-border); }
th.col-active { box-shadow: inset 0 3px 0 var(--color-active-border); }

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.stepper--count { justify-content: flex-start; margin-bottom: 0.5rem; }

.btn-step {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-step:disabled { opacity: 0.3; }

.stepper-value { min-width: 1.4rem; text-align: center; font-weight: 700; }

/* ---- Dialoge ---- */

dialog.score-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(30rem, 92vw);
  max-height: 88vh;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}
dialog.score-dialog::backdrop { background: rgba(10, 20, 15, 0.5); }

.score-dialog__header {
  padding: 1rem 1.1rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.score-dialog__header h2 { margin: 0; font-size: 1.05rem; color: var(--color-primary-dark); }

.score-dialog__body {
  padding: 0.9rem 1.1rem;
  overflow-y: auto;
  max-height: 60vh;
}

.score-dialog__hint { color: var(--color-text-muted); font-size: 0.88rem; margin-top: 0; }
.score-dialog__score { font-weight: 700; font-size: 1.05rem; text-align: center; margin: 0.7rem 0 0.2rem; }
.score-dialog__score--zero { color: var(--color-warn); }

.score-dialog__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
  padding: 0.7rem 1.1rem 1rem;
  border-top: 1px solid var(--color-border);
}

.dice-row {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.4rem 0;
}

.dice-grid {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  overflow-x: auto;
  padding: 0.3rem 0;
}
.dice-grid__col {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
}

.ruleset-choice { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; }
.ruleset-option {
  display: block;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
}
.ruleset-option input { margin-right: 0.4rem; }
.ruleset-option__title { font-weight: 700; }
.ruleset-option__desc { margin: 0.3rem 0 0; font-size: 0.82rem; color: var(--color-text-muted); }

.player-name-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-top: 0.4rem; }
.text-input {
  font: inherit;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.sheet-list { display: flex; flex-direction: column; gap: 0.4rem; }
.sheet-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
}
.sheet-list__item:active { background: #f2f6f3; }
.sheet-list__title { font-weight: 700; }
.sheet-list__meta { font-size: 0.78rem; color: var(--color-text-muted); }
.btn-delete-sheet { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 0.3rem; }

.toast-root {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
}
.toast {
  background: var(--color-primary-dark);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.toast--visible { opacity: 1; transform: translateY(0); }

.pull-refresh-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  text-align: center;
  padding: 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: var(--color-primary);
  transform: translateY(-100%);
  transition: transform 0.2s ease, background 0.15s ease;
  pointer-events: none;
}
.pull-refresh-indicator--dragging { transition: none; }
.pull-refresh-indicator--ready { background: var(--color-accent); }

@media (min-width: 640px) {
  main#app-root { padding: 1.2rem; }
  .score-table { min-width: 100%; }
}

/* Kompaktes Layout auf schmalen Bildschirmen (Hochformat, Handys):
   möglichst bis zu 4 Spieler ohne Scrollen sichtbar. Betrifft bewusst nur
   Header/Tabelle, nicht die Dialoge – dort bleiben die Tipp-Ziele groß genug. */
@media (max-width: 480px) {
  .app-header { padding: 0.4rem 0.6rem; }
  .app-header h1 { font-size: 0.95rem; }
  .app-header .btn { padding: 0.35rem 0.55rem; font-size: 0.78rem; }

  main#app-root { padding: 0.35rem; }

  .players-bar { margin-bottom: 0.35rem; gap: 0.4rem; }
  .ruleset-badge { font-size: 0.68rem; padding: 0.18rem 0.5rem; }
  .players-bar .btn { padding: 0.3rem 0.5rem; font-size: 0.72rem; }

  .score-table th, .score-table td { padding: 0.18rem 0.22rem; }
  .score-table .col-category, .score-table .cell-label { min-width: 3.6rem; max-width: 4.4rem; font-size: 0.7rem; }
  .score-table.layout-fit .col-category, .score-table.layout-fit .cell-label { width: 4rem; }
  .col-player { min-width: 3.5rem; }
  .player-name-input { font-size: 0.72rem; padding: 0.1rem; }
  .winner-flag, .active-flag { font-size: 0.56rem; }

  .row-section td { padding-top: 0.28rem; padding-bottom: 0.28rem; font-size: 0.62rem; }
  .row-total td { font-size: 0.82rem; }

  .cell-btn { min-width: 2rem; min-height: 1.7rem; font-size: 0.75rem; }

  .stepper { gap: 0.2rem; }
  .btn-step { width: 1.5rem; height: 1.5rem; font-size: 0.85rem; }
  .stepper-value { min-width: 1rem; font-size: 0.75rem; }
  .info-icon { width: 0.9rem; height: 0.9rem; font-size: 0.58rem; }
}

/* ---- Druckansicht ---- */
@media print {
  .app-header, .players-bar button, .btn-remove-player, dialog, .toast-root {
    display: none !important;
  }
  body { background: #fff; }
  .table-scroll { overflow: visible; box-shadow: none; }
  .score-table { min-width: 0; width: 100%; font-size: 0.62rem; }
  .cell-btn { border: 1px solid #999; min-width: 1.4rem; min-height: 1.3rem; }
  .col-winner { background: #fdf1cf !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: portrait; margin: 8mm; }
}
