:root {
  --bg-page: #0a0e14;
  --bg-surface: #111822;
  --bg-elevated: #182231;
  --bg-overlay: rgba(8, 12, 18, 0.86);
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.3);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-pitch: #22c55e;
  --accent-pitch-dim: rgba(34, 197, 94, 0.16);
  --state-live: #ef4444;
  --state-live-bg: rgba(239, 68, 68, 0.16);
  --state-connecting: #f59e0b;
  --state-connecting-bg: rgba(245, 158, 11, 0.16);
  --state-offline: #94a3b8;
  --state-offline-bg: rgba(148, 163, 184, 0.14);
  --state-error: #f87171;
  --state-error-bg: rgba(248, 113, 113, 0.16);
  --focus-ring: #38bdf8;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-shell: 0 20px 50px rgba(0, 0, 0, 0.55);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #131d2b 0%, var(--bg-page) 60%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: var(--radius-md);
  background: var(--accent-pitch-dim);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: var(--accent-pitch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-copy {
  display: flex;
  flex-direction: column;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--state-offline);
  flex-shrink: 0;
}

/* Stage & Player Shell */
.stage {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.player-shell {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-shell);
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

#pitchcam-player {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
}

.overlay-card {
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem 1.4rem;
  border-radius: var(--radius-md);
  background: rgba(17, 24, 34, 0.94);
  border: 1px solid var(--border-subtle);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.overlay-indicator {
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.15rem;
}

.spinner {
  display: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid rgba(245, 158, 11, 0.25);
  border-top-color: var(--state-connecting);
  animation: pitchcam-spin 0.85s linear infinite;
}

.indicator-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: var(--state-offline);
  box-shadow: 0 0 0 6px var(--state-offline-bg);
}

.overlay-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-primary);
}

.overlay-message {
  margin: 0.25rem 0 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.overlay-detail {
  margin: 0;
  min-height: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.overlay-actions {
  margin-top: 0.25rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
}

.toolbar-info {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.toolbar-badge {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--state-offline);
  flex-shrink: 0;
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  appearance: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease;
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-pitch);
  color: #052e16;
  border-color: rgba(34, 197, 94, 0.6);
}

.btn-primary:hover:not(:disabled) {
  background: #4ade80;
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.22);
}

/* Footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 0.25rem;
}

/* State-driven styling */
body[data-state="live"] .status-pill {
  background: var(--state-live-bg);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

body[data-state="live"] .status-dot,
body[data-state="live"] .toolbar-badge {
  background: var(--state-live);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25);
  animation: pitchcam-pulse 1.8s ease-in-out infinite;
}

body[data-state="connecting"] .status-pill {
  background: var(--state-connecting-bg);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

body[data-state="connecting"] .status-dot,
body[data-state="connecting"] .toolbar-badge {
  background: var(--state-connecting);
}

body[data-state="connecting"] .spinner {
  display: block;
}

body[data-state="connecting"] .indicator-dot {
  display: none;
}

body[data-state="offline"] .status-pill {
  background: var(--state-offline-bg);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

body[data-state="offline"] .status-dot,
body[data-state="offline"] .toolbar-badge,
body[data-state="offline"] .indicator-dot {
  background: var(--state-offline);
}

body[data-state="error"] .status-pill,
body[data-state="unsupported"] .status-pill {
  background: var(--state-error-bg);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

body[data-state="error"] .status-dot,
body[data-state="error"] .toolbar-badge,
body[data-state="error"] .indicator-dot,
body[data-state="unsupported"] .status-dot,
body[data-state="unsupported"] .toolbar-badge,
body[data-state="unsupported"] .indicator-dot {
  background: var(--state-error);
  box-shadow: 0 0 0 6px var(--state-error-bg);
}

/* Embed mode (?embed=1) */
html.is-embed,
body.is-embed {
  background: #000;
  height: 100%;
  overflow: hidden;
}

body.is-embed .app {
  max-width: none;
  min-height: 100%;
  height: 100%;
  padding: 0;
  gap: 0;
}

body.is-embed .topbar,
body.is-embed .footer {
  display: none;
}

body.is-embed .stage {
  height: 100%;
  justify-content: flex-start;
}

body.is-embed .player-shell {
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

body.is-embed .video-frame {
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
}

body.is-embed .toolbar {
  padding: 0.5rem 0.75rem;
}

/* Animations */
@keyframes pitchcam-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pitchcam-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  body[data-state="live"] .status-dot,
  body[data-state="live"] .toolbar-badge {
    animation: none;
  }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .app {
    padding: 0.85rem 0.75rem 1rem;
  }

  .overlay-card {
    padding: 1.1rem 1rem;
  }

  .toolbar {
    padding: 0.65rem 0.75rem;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
  }
}
