html {
  font-size: 16px; /* Establish a base for rem units */
}

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

body {
  background-color: black;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

/* JS toggles many elements with the hidden attribute; it must beat the display rules below. */
[hidden] { display: none !important; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.player-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: black;
}

/* Basic CSS Spinner */
.spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 4px solid #fff;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ---- Status screen (waiting / error) ---- */
.status-screen {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  box-sizing: border-box;
  text-align: center;
  color: #fff;
  z-index: 10;
}
.status-error .spinner { display: none; }
.status-title {
  margin: 0.75rem 0 0;
  font-size: 1.125rem;
  font-weight: 600;
}
.status-hint {
  margin: 0.4rem 0 0;
  color: #bbb;
  font-size: 0.9rem;
  max-width: 32rem;
}
.status-detail {
  margin: 0.4rem 0 0;
  color: #777;
  font-family: monospace;
  font-size: 0.75rem;
  max-width: 32rem;
  word-break: break-all;
}
.status-detail:empty, .status-hint:empty { display: none; }
.status-retry {
  margin-top: 1rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 4px;
  color: #fff;
  padding: 0.45rem 1.25rem;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
}
.status-retry:hover { background: rgba(255, 255, 255, 0.25); }

/* ---- Control bar ---- */
.custom-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7), rgba(0,0,0,0));
  display: flex;
  flex-direction: column;
  padding: 0.625rem 1.25rem calc(1rem + env(safe-area-inset-bottom)) 1.25rem;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 5;
  pointer-events: none;
}

.controls-active .custom-controls {
  opacity: 1;
  pointer-events: auto;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.controls-left, .controls-right {
  display: flex;
  align-items: center;
  min-width: 0;
}

.control-button {
  background: none;
  border: none;
  width: 2.25rem;
  height: 2.25rem;
  margin-right: 0.3125rem;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-button svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: white;
  transition: transform 0.2s ease;
}

.control-button:hover svg {
  transform: scale(1.1);
}

.volume-container {
  display: flex;
  align-items: center;
  margin-right: 1rem;
}

.volume-slider {
  width: 5rem;
  margin-left: 0.625rem;
  -webkit-appearance: none;
  appearance: none;
  height: 0.25rem;
  border-radius: 0.125rem;
  background: rgba(255, 255, 255, 0.3);
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: white;
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  border: none;
}

/* Hide volume slider on iOS devices */
.ios-device .volume-slider {
  display: none !important;
}

.time-display {
  color: #fff;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-right: 0.75rem;
}

/* ---- Seek bar ---- */
.seek-bar {
  --track: 3px;
  position: relative;
  height: 1rem; /* hit area is taller than the visible track */
  margin-bottom: 0.25rem;
  cursor: pointer;
}
.seek-bar:hover, .seek-bar:focus-visible { --track: 5px; }
.seek-bar::before,
.seek-buffered,
.seek-played {
  position: absolute;
  left: 0;
  top: 50%;
  height: var(--track);
  transform: translateY(-50%);
  border-radius: 2px;
  transition: height 0.15s ease;
}
.seek-bar::before {
  content: "";
  right: 0;
  background: rgba(255, 255, 255, 0.25);
}
.seek-buffered { width: 0; background: rgba(255, 255, 255, 0.4); }
.seek-played { width: 0; background: #fff; }
.seek-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.15s ease;
}
.seek-bar:hover .seek-handle,
.seek-bar:focus-visible .seek-handle,
.seek-bar:active .seek-handle { transform: translate(-50%, -50%) scale(1); }

/* ---- LIVE badge ---- */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  padding: 0.25rem 0.4rem;
  color: #aaa;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
  cursor: default;
}
.live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #6b7280;
}
.live-badge.at-edge { color: #fff; }
.live-badge.at-edge .live-dot { background: #ef4444; }
.live-behind {
  color: #aaa;
  font-weight: 400;
  letter-spacing: 0;
}
.is-dvr .live-badge { cursor: pointer; }
.is-dvr .live-badge:not(.at-edge):hover { color: #fff; }

/* ---- Quality menu ---- */
.quality-container { position: relative; }
.quality-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 8rem;
  max-height: 50vh;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.92);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.quality-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-radius: 4px;
  color: #ccc;
  padding: 0.35rem 0.75rem 0.35rem 1.5rem;
  text-align: left;
  font-family: inherit;
  font-size: 0.8125rem;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}
.quality-menu button:hover, .quality-menu button:focus-visible { background: rgba(255, 255, 255, 0.1); color: #fff; }
.quality-menu button[aria-checked="true"] { color: #fff; font-weight: 600; }
.quality-menu button[aria-checked="true"]::before {
  content: "";
  position: absolute;
  left: 0.6rem;
  top: 50%;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #22c55e;
  transform: translateY(-50%);
}

/* ---- Big play + unmute pill ---- */
.big-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 6;
  transition: background 0.2s ease;
}
.big-play:hover { background: rgba(0, 0, 0, 0.8); }
.big-play svg { width: 2.75rem; height: 2.75rem; fill: #fff; margin-left: 0.25rem; }

.unmute-pill {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.92);
  color: #000;
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 7;
}
.unmute-pill svg { width: 1.125rem; height: 1.125rem; fill: #000; }

/* ---- Start screen ---- */
.start-screen {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  overflow-y: auto;
}

.start-card {
  background-color: #222;
  padding: 2rem;
  border-radius: 8px;
  width: 80%;
  max-width: 32rem;
  max-height: 85%;
  overflow-y: auto;
  box-sizing: border-box;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  color: #fff;
}

.start-card h1 {
  margin: 0 0 1.5rem;
  text-align: center;
  font-weight: 500;
  font-size: 1.5rem;
}

.start-form {
  display: flex;
  gap: 0.5rem;
}

.start-form input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid #444;
  background-color: #333;
  color: #fff;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  box-sizing: border-box;
}

.submit-btn {
  padding: 0.75rem 1.5rem;
  background-color: #0078d4;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.submit-btn:hover {
  background-color: #0066b3;
}

.form-error {
  color: #ff6b6b;
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
  min-height: 1.2rem;
}

.recent-section { margin-top: 1rem; }
.recent-heading {
  color: #aaa;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.recent-list li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 4px;
}
.recent-list li:hover { background: rgba(255, 255, 255, 0.06); }
.recent-list li > button:first-child {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  background: none;
  border: none;
  color: #ddd;
  padding: 0.45rem 0.5rem;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.recent-list li > button:first-child > :first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-list li > button:first-child > :last-child:not(:first-child) {
  color: #888;
  white-space: nowrap;
  flex-shrink: 0;
}
.recent-list li > button:last-child:not(:first-child) {
  background: none;
  border: none;
  color: #888;
  font-size: 1.125rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}
.recent-list li > button:last-child:not(:first-child):hover { color: #fff; }
.recent-clear {
  margin-top: 0.5rem;
  background: none;
  border: none;
  color: #888;
  padding: 0;
  font-family: inherit;
  font-size: 0.8125rem;
  text-decoration: underline;
  cursor: pointer;
}
.recent-clear:hover { color: #fff; }

/* ---- Stats popup ---- */
.stats-popup {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  padding: 0.75rem;
  min-width: 220px;
  max-width: 320px;
  color: #fff;
  font-size: 0.875rem;
  z-index: 15;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.stats-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-weight: 600;
  cursor: move;
  touch-action: none; /* header drags the popup; don't let the page scroll instead */
  user-select: none;
}

.stats-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.stats-close-btn:hover {
  color: #ccc;
}

.stats-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stats-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0.5rem 0;
}

.metric-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: monospace;
}

.metric-label {
  color: #aaa;
  flex-shrink: 0;
}

.metric-value {
  color: #fff;
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.metric-value.green { color: #22c55e; }
.metric-value.amber { color: #f59e0b; }
.metric-value.red { color: #ef4444; }

.metric-spark {
  display: none;
  width: 100%;
  height: 39px;
  margin: 1px 0 5px;
}

.stats-build-id {
  margin-top: 0.75rem;
  font-size: 0.6875rem;
  color: #666;
  text-align: right;
  font-family: monospace;
}

/* ---- Stream title ---- */
.stream-title {
  position: absolute;
  top: 1.25rem;
  left: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: #fff;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 6;
  min-width: 0;
}
#title-host { text-transform: uppercase; white-space: nowrap; }
#title-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.stream-title:has(#title-host:empty) .title-chevron { display: none; }

.controls-active .stream-title { opacity: 1; }
.controls-active .change-stream-btn { pointer-events: auto; }

.title-chevron {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  fill: rgba(255, 255, 255, 0.55);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.change-stream-btn {
  margin-left: 0.75rem;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 4px;
  color: #fff;
  padding: 0.25rem 0.6rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0;
  text-shadow: none;
  cursor: pointer;
  pointer-events: none;
}
.change-stream-btn:hover { background: rgba(255, 255, 255, 0.25); }

/* ---- Settings + embed modals ---- */
.settings-modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.settings-window {
  background: rgba(0, 0, 0, 0.92);
  border-radius: 8px;
  padding: 1rem;
  width: min(20rem, 90%);
  max-height: 85%;
  overflow-y: auto;
  box-sizing: border-box;
  color: #fff;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.settings-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
}
.setting-label small { color: #888; }

.setting-options { display: flex; gap: 0.25rem; }
.setting-options button {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 4px;
  color: #ccc;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.8125rem;
}
.setting-options button.on {
  background: #22c55e;
  color: #000;
  font-weight: 600;
}
.setting-options button:disabled { opacity: 0.5; cursor: default; }

/* an active "Off" reads as neutral, not positive */
.setting-options button.on[data-on="false"],
.setting-options button.on[data-value="false"] {
  background: #6b7280;
  color: #fff;
}

.settings-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 0.5rem;
}
.settings-tab {
  background: none;
  border: none;
  border-radius: 4px;
  color: #aaa;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.8125rem;
}
.settings-tab.on { background: rgba(255, 255, 255, 0.15); color: #fff; font-weight: 600; }

.setting-select {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 4px;
  color: #fff;
  padding: 0.25rem 0.4rem;
  font-size: 0.8125rem;
  max-width: 11rem;
}
.setting-select option { background: #111; }

.setting-note { color: #888; font-size: 0.75rem; margin-top: 0.5rem; }

.setting-action {
  display: block;
  margin-top: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 4px;
  color: #ccc;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
}
.setting-action:hover { background: rgba(255, 255, 255, 0.2); }

.settings-window .stats-build-id { text-align: left; margin-top: 0.25rem; }

.embed-window { width: min(30rem, 92%); }
.embed-body input[type="text"],
.embed-body input[type="url"],
.embed-body input[type="number"],
.embed-body textarea {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: #fff;
  padding: 0.35rem 0.5rem;
  font-size: 0.8125rem;
  box-sizing: border-box;
}
.embed-body input[type="number"] { width: 5rem; }
.embed-body input[readonly]:not([type="number"]),
.embed-body textarea {
  width: 100%;
  font-family: monospace;
}
.embed-body textarea {
  min-height: 6rem;
  resize: vertical;
  margin-top: 0.5rem;
}
.embed-body a { color: #9cc8ff; font-size: 0.8125rem; }

/* ---- Overlays ---- */
.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

#guides-svg { position: absolute; display: none; }

.clock-overlay {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  display: none;
  color: #fff;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  font-family: monospace;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.vu-meter {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  width: 4rem;
  height: 60%;
  display: none;
}

/* ---- Mode / state visibility ---- */
.mode-start .custom-controls,
.mode-start .stream-title,
.mode-start .big-play,
.mode-start .unmute-pill { display: none; }
.mode-start .stats-popup { display: none !important; }  /* stats.js sets inline display */

.mode-embed #start-screen,
.mode-embed #btn-embed,
.mode-embed #btn-change-stream { display: none; }
/* customers see only video + controls unless the embed turns debug on */
.mode-embed:not(.debug-tools) #btn-settings,
.mode-embed:not(.debug-tools) #stream-title { display: none; }

/* seek bar only where there is something to seek; LIVE badge only on live */
.seek-bar { display: none; }
.is-vod .seek-bar, .is-dvr .seek-bar { display: block; }
.live-badge { display: none; }
.is-live .live-badge, .is-dvr .live-badge { display: inline-flex; }
.is-live:not(.is-dvr) .time-display { display: none; }

@media (max-width: 480px) {
  .custom-controls { padding-left: 0.75rem; padding-right: 0.75rem; }
  .volume-slider { width: 3.5rem; }
  .live-behind { display: none; }
}
