:root {
  --bg: #0d1b13;
  --bg-2: #11271a;
  --panel: #16301f;
  --panel-2: #1d3d29;
  --line: #2a5238;
  --green: #28c46c;
  --green-d: #1f8a4c;
  --red: #e0473f;
  --cream: #efe4c4;
  --text: #eef5ee;
  --muted: #9fb6a6;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 16px 32px;
}

/* Screens */
.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Welcome */
.hero { text-align: center; padding: 8vh 8px 0; }
.dart-logo { font-size: 72px; line-height: 1; }
h1 { font-size: 2rem; margin: 12px 0 4px; }
.lead { color: var(--muted); max-width: 30rem; margin: 8px auto 24px; line-height: 1.5; }
.hint { color: var(--muted); font-size: .85rem; line-height: 1.4; }

/* Bars */
.bar, .scorebar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.bar h2 { font-size: 1.25rem; margin: 0; }
.status-chip {
  font-size: .8rem; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.status-chip.good { color: #0c1a10; background: var(--green); border-color: var(--green); font-weight: 600; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 12px 18px; border-radius: 12px; font-size: 1rem;
  cursor: pointer; transition: transform .08s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { border-color: var(--green-d); }
.btn.primary { background: var(--green); color: #06170d; border-color: var(--green); font-weight: 700; }
.btn.primary:hover { background: #34d97a; }
.btn.big { font-size: 1.15rem; padding: 16px 26px; width: 100%; max-width: 22rem; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.round { width: 48px; height: 48px; border-radius: 50%; font-size: 1.4rem; padding: 0; }
.btn[hidden] { display: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--line); }

.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }

/* Camera stage */
.camera-stage {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #000;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.camera-stage.small { aspect-ratio: 4 / 3; }
.camera-stage video, .camera-stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.camera-stage canvas { pointer-events: none; }

/* Calibration markers */
.markers { position: absolute; inset: 0; }
.marker {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 3px solid var(--green); background: rgba(40, 196, 108, .25);
  cursor: grab; touch-action: none; display: grid; place-items: center;
  font-size: .6rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000;
}
.marker:active { cursor: grabbing; }
.marker .tag {
  position: absolute; top: -22px; white-space: nowrap; font-size: .7rem;
  background: #000a; padding: 2px 6px; border-radius: 6px;
}

/* Setup */
.setup-body { display: grid; gap: 22px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; background: var(--panel); }
legend { padding: 0 8px; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.opt {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 1rem;
}
.opt.active { background: var(--green); color: #06170d; border-color: var(--green); font-weight: 700; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--green); }
.switch.small { font-size: .9rem; }
.stepper { display: flex; align-items: center; gap: 18px; }
#players-count { font-size: 1.6rem; font-weight: 700; min-width: 1.5em; text-align: center; }
.player-names { display: grid; gap: 8px; margin-top: 14px; }
.player-names input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 1rem;
}

/* Play */
.scorebar { flex-wrap: wrap; gap: 8px; }
.pcard {
  flex: 1 1 120px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; min-width: 110px;
}
.pcard.active { border-color: var(--green); box-shadow: 0 0 0 2px rgba(40,196,108,.3) inset; }
.pcard .pname { font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; }
.pcard .pscore { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.pcard.active .pscore { color: var(--green); }
.pcard .legs { font-size: .7rem; color: var(--muted); }

.play-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 720px) { .play-grid { grid-template-columns: 1fr; } }

.detect-status {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: .95rem;
}
.detect-status.live { border-color: var(--green-d); color: var(--text); }
.play-toggles { display: flex; justify-content: space-between; margin-top: 10px; gap: 12px; }

.board-col { display: grid; gap: 12px; justify-items: center; }
#play-board { width: 100%; max-width: 360px; height: auto; aspect-ratio: 1; touch-action: manipulation; cursor: crosshair; border-radius: 50%; }

.pending {
  width: 100%; background: var(--panel); border: 1px solid var(--green-d);
  border-radius: var(--radius); padding: 14px; text-align: center;
}
.pending-score { font-size: 2.4rem; font-weight: 800; color: var(--green); }
.pending-actions { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }

.turn-darts { display: flex; gap: 8px; justify-content: center; min-height: 44px; }
.dchip {
  min-width: 52px; padding: 8px 10px; border-radius: 10px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 700;
}
.dchip.empty { color: var(--muted); font-weight: 400; opacity: .5; }
.dchip.bust { border-color: var(--red); color: var(--red); }

.checkout { text-align: center; color: var(--green); font-weight: 600; min-height: 1.4em; }

/* Camera-move alert */
.move-alert {
  background: rgba(224, 71, 63, .15); border: 1px solid var(--red);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; color: #ffd9d6; font-weight: 600;
}
.move-alert[hidden] { display: none; }
.move-alert-actions { display: flex; gap: 8px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 60;
  display: grid; place-items: center; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; max-width: 360px; width: 100%; text-align: center; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; }
#pair-qr { width: 240px; height: 240px; background: #fff; border-radius: 12px; padding: 8px; margin: 12px auto; }
.pair-url {
  display: block; font-size: .72rem; color: var(--muted); word-break: break-all;
  margin: 8px 0 14px; text-decoration: none;
}
.modal-card .status-chip { display: inline-block; margin-bottom: 14px; }

/* Remote (phone) page */
.remote-body { max-width: 520px; margin: 0 auto; padding: 16px; }
.remote-snap {
  width: 100%; border-radius: var(--radius); border: 1px solid var(--line);
  background: #000; aspect-ratio: 4 / 3; object-fit: cover; margin-bottom: 12px;
}
.remote-pending {
  text-align: center; font-size: 2rem; font-weight: 800; color: var(--green);
  min-height: 1.2em; margin: 6px 0;
}
.remote-board { width: 100%; max-width: 360px; aspect-ratio: 1; display: block; margin: 0 auto 12px; touch-action: manipulation; }
.remote-conn {
  position: sticky; top: 0; text-align: center; padding: 8px; font-size: .85rem;
  background: var(--bg-2); border-bottom: 1px solid var(--line); margin: -16px -16px 12px;
}
.remote-conn.bad { color: var(--red); }
.remote-conn.ok { color: var(--green); }

/* Toast / announcement */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--green); color: #06170d; padding: 14px 22px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; text-align: center;
  animation: pop .3s ease;
}
.toast[hidden] { display: none; }
@keyframes pop { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
