* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1115; color: #f1f3f5;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app { height: 100%; }

.screen { display: none; padding: 12px; min-height: 100vh; }
.screen.active { display: block; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 16px 4px;
}
.topbar h1 { font-size: 20px; margin: 0; }
.match-label { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
.pill { background: #2a2e37; padding: 4px 10px; border-radius: 20px; font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  border: none; border-radius: 10px; padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: #2563eb; color: white; }
.btn-secondary { background: #2a2e37; color: #f1f3f5; }
.btn-warn { background: #d97706; color: white; }
.btn-danger { background: #b91c1c; color: white; }
.btn-undo { background: #4b5563; color: white; }
.btn-undo:disabled { opacity: 0.4; }
.btn-large { padding: 18px 24px; font-size: 18px; width: 100%; }

/* ---- Setup form ---- */
.setup-form { display: flex; flex-direction: column; gap: 18px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.field-grid label, fieldset label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; color: #9aa3af; }
input, select {
  background: #1b1e25; border: 1px solid #2e333d; color: #f1f3f5;
  border-radius: 8px; padding: 10px; font-size: 15px;
}
input[type="color"] {
  -webkit-appearance: none;
  height: 48px; padding: 3px; cursor: pointer; background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }
.btn-clear-team { margin-top: 4px; font-size: 13px; padding: 8px 12px; }
.team-setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .team-setup-grid { grid-template-columns: 1fr; } }
fieldset { border: 2px solid #2e333d; border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.team-fieldset.team-a { border-color: #1d4ed8; }
.team-fieldset.team-b { border-color: #dc2626; }
legend { font-weight: 700; padding: 0 6px; }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.setup-actions .btn { flex: 1; }

/* ---- Live screen ---- */
.status-banner {
  text-align: center; font-weight: 700; padding: 8px; border-radius: 8px;
  margin-bottom: 10px; min-height: 20px; font-size: 14px;
}
.status-banner.set_point { background: #92400e; }
.status-banner.match_point { background: #7f1d1d; }
.status-banner.set_complete { background: #166534; }
.status-banner.match_complete { background: #1e3a8a; }

.scoreboard-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.team-block {
  flex: 1; border-radius: 14px; padding: 14px; text-align: center;
  position: relative; min-height: 110px;
}
.team-block.team-a { background: linear-gradient(160deg, #1d4ed8, #1e3a8a); }
.team-block.team-b { background: linear-gradient(160deg, #dc2626, #7f1d1d); }
.team-name { font-size: 14px; font-weight: 700; opacity: 0.9; }
.sets-won { font-size: 13px; opacity: 0.8; margin-top: 2px; }
.score { font-size: 52px; font-weight: 800; line-height: 1; margin-top: 4px; }
.serve-dot {
  width: 14px; height: 14px; border-radius: 50%; background: #facc15;
  position: absolute; top: 10px; right: 10px; display: none;
  box-shadow: 0 0 8px #facc15;
}
.serve-dot.active { display: block; }
.vs-divider { font-size: 11px; color: #6b7280; writing-mode: vertical-rl; }

.controls-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px;
}
.ctrl-btn {
  background: #1b1e25; border: 2px solid #2e333d; color: #f1f3f5;
  border-radius: 14px; padding: 18px 10px; font-size: 20px; font-weight: 700;
  min-height: 64px;
}
.ctrl-btn.wide { grid-column: span 2; font-size: 16px; }
.ctrl-btn.score-btn { font-size: 30px; min-height: 80px; }
.ctrl-btn.score-btn.team-a { background: #1d4ed8; border-color: #1d4ed8; }
.ctrl-btn.score-btn.team-b { background: #dc2626; border-color: #dc2626; }
.ctrl-sub { font-size: 13px; font-weight: 500; opacity: 0.85; }
.ctrl-btn:active { transform: scale(0.97); }

.secondary-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.secondary-controls .btn { flex: 1; min-width: 120px; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-content { background: #1b1e25; border-radius: 14px; padding: 20px; width: 90%; max-width: 420px; max-height: 80vh; overflow-y: auto; }
.template-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.template-item { background: #2a2e37; border-radius: 8px; padding: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.profile-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.profile-swatch { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.15); flex-shrink: 0; }
.profile-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-actions { display: flex; gap: 6px; flex-shrink: 0; }
.profile-actions .btn { padding: 8px 10px; font-size: 13px; }
.btn-delete { background: #7f1d1d; color: white; border: none; border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-delete:active { transform: scale(0.97); }
.profile-empty { color: #6b7280; font-size: 14px; padding: 8px 0; }

/* ---- Serve picker ---- */
.serve-modal-heading { margin: 0 0 4px 0; font-size: 20px; }
.serve-picker { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.serve-pick-btn { border-radius: 14px; font-size: 22px; padding: 28px 24px; color: white; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1b1e25; border: 1px solid #2e333d; padding: 10px 18px;
  border-radius: 10px; font-size: 14px; z-index: 100;
}
.toast.hidden { display: none; }
.toast.error { border-color: #b91c1c; color: #fca5a5; }

.final-summary { background: #1b1e25; border-radius: 14px; padding: 20px; margin-bottom: 16px; font-size: 16px; }
.final-summary .winner-line { font-size: 24px; font-weight: 800; margin-bottom: 10px; }
.final-summary .set-line { padding: 4px 0; border-bottom: 1px solid #2e333d; }
