/* Dart Scorer - gemeinsames Stylesheet */

:root {
  --ink: #1c1a17;
  --ink-soft: #4a453d;
  --paper: #f6f1e7;
  --paper-raised: #ffffff;
  --line: #e3dbc8;
  --red: #c81e3a;
  --red-dark: #9c1730;
  --green: #1f7a4d;
  --green-dark: #155c39;
  --amber: #b8860b;
  --shadow: 0 2px 10px rgba(28, 26, 23, 0.08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f2ede2;
    --ink-soft: #b9b2a3;
    --paper: #17140f;
    --paper-raised: #221e17;
    --line: #332d22;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  min-height: 100%;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.app-header h1 {
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.app-header .subtitle {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

a.back-link {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
}
a.back-link:hover { color: var(--red); }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

h2 { font-size: 1.05rem; margin: 0 0 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: white;
  background: var(--ink);
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--red); }
.btn.primary:hover { background: var(--red-dark); }
.btn.success { background: var(--green); }
.btn.success:hover { background: var(--green-dark); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.small { padding: 8px 12px; font-size: 0.85rem; width: auto; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
}

.field { margin-bottom: 14px; }

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.player-list li:last-child { border-bottom: none; }
.player-list .player-name { font-weight: 600; }
.player-list .player-meta { color: var(--ink-soft); font-size: 0.8rem; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.chip.selected { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .order-badge {
  display: inline-block;
  background: var(--red);
  color: white;
  border-radius: 50%;
  width: 18px; height: 18px;
  line-height: 18px;
  font-size: 0.7rem;
  margin-right: 6px;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 24px 12px;
  font-size: 0.9rem;
}

/* ---- Scoreboard ------------------------------------------------------ */

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.score-tile {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.score-tile.active {
  border-color: var(--red);
  box-shadow: 0 0 0 2px var(--red) inset;
}
.score-tile .name {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score-tile .remaining {
  font-size: 2.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.score-tile .legs {
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.score-tile .checkout {
  margin-top: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-dark);
  min-height: 1.1em;
}
@media (prefers-color-scheme: dark) {
  .score-tile .checkout { color: #4fd08a; }
}

.turn-darts {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 10px 0;
}
.turn-darts .dart-slot {
  width: 56px;
  height: 44px;
  border-radius: 8px;
  border: 1.5px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.turn-darts .dart-slot.filled {
  border-style: solid;
  border-color: var(--red);
  color: var(--ink);
  background: var(--paper);
}

/* ---- Kamera / Kalibrierung ------------------------------------------- */

.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}
.camera-wrap video, .camera-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-wrap canvas { pointer-events: none; }
.camera-hint {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
}
.camera-status {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.camera-status.tracking { background: rgba(31, 122, 77, 0.85); }
.camera-status.waiting { background: rgba(184, 134, 11, 0.85); }

.confirm-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.confirm-panel .detected-label {
  font-size: 1.3rem;
  font-weight: 800;
}
.confirm-panel .detected-points {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.manual-grid button {
  padding: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
}
.ring-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.ring-toggle button {
  flex: 1;
  padding: 9px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-weight: 700;
  font-size: 0.8rem;
}
.ring-toggle button.selected { background: var(--red); color: #fff; border-color: var(--red); }

.history-log {
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.85rem;
}
.history-log .entry {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dotted var(--line);
  color: var(--ink-soft);
}
.history-log .entry.bust { color: var(--red); font-weight: 600; }

.winner-banner {
  text-align: center;
  padding: 28px 16px;
}
.winner-banner .trophy { font-size: 2.6rem; }
.winner-banner h2 { font-size: 1.6rem; margin: 6px 0 4px; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.stats-table th, .stats-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}
.stats-table td.num, .stats-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.notice {
  background: rgba(184, 134, 11, 0.12);
  border: 1px solid rgba(184, 134, 11, 0.4);
  color: var(--amber);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
