* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #18181b;
  overflow: hidden;
  font-family: system-ui, sans-serif;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

.status {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fafafa;
  font-size: 14px;
}

.download {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 24px;
  padding: 32px 24px;
  overflow: hidden;
  background: #18181b;
  color: #fafafa;
}

.download-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #3f3f46;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.download-panel {
  width: min(28rem, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.download-heading {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.download-current-title {
  margin: 0;
  font-size: 14px;
  color: #a1a1aa;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-bytes {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #3b82f6;
}

.download-current-file {
  margin: 0;
  font-size: 13px;
  color: #a1a1aa;
  font-variant-numeric: tabular-nums;
}

.download-bar {
  width: 100%;
  height: 12px;
  margin-top: 8px;
  border-radius: 999px;
  background: #3f3f46;
  overflow: hidden;
}

.download-fill {
  height: 100%;
  width: 0%;
  background: #3b82f6;
  transition: width 0.2s ease-out;
}

.download-percent {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 500;
  color: #a1a1aa;
  font-variant-numeric: tabular-nums;
}

.download-detail {
  margin: 8px 0 0;
  font-size: 12px;
  color: #71717a;
  font-variant-numeric: tabular-nums;
}

.download-items {
  width: 100%;
  margin-top: 16px;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.download-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(39, 39, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.download-item-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #27272a;
}

.download-item-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: #a1a1aa;
}

.download-item-body {
  flex: 1;
  min-width: 0;
}

.download-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.download-item-meta {
  font-size: 11px;
  color: #a1a1aa;
  margin-top: 2px;
}

.download-item-bar {
  height: 4px;
  margin-top: 6px;
  border-radius: 999px;
  background: #3f3f46;
  overflow: hidden;
}

.download-item-fill {
  height: 100%;
  background: #3b82f6;
  transition: width 0.15s linear;
}

.overlays {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.overlay-block {
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.overlay-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.overlay-text,
.overlay-time {
  font-size: clamp(12px, 2.5vw, 48px);
  font-weight: 600;
  text-align: center;
}

.overlay-time-text {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avplay-debug-panel {
  position: absolute;
  left: 8px;
  top: 8px;
  bottom: 8px;
  z-index: 45;
  width: min(680px, 72vw);
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.5);
  background: rgba(10, 10, 12, 0.94);
  color: #f4f4f5;
  font-size: 12px;
  line-height: 1.45;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
}

.avplay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  background: rgba(30, 58, 138, 0.25);
}

.avplay-header-title {
  font-size: 14px;
  font-weight: 700;
  color: #bfdbfe;
  letter-spacing: 0.02em;
}

.avplay-header-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
  border: 1px solid rgba(74, 222, 128, 0.35);
  font-family: ui-monospace, Menlo, monospace;
}

.avplay-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 8px 10px;
}

.avplay-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
  align-items: start;
  height: 100%;
}

.avplay-col {
  min-width: 0;
}

.avplay-col .avplay-block {
  margin-bottom: 10px;
}

.avplay-block {
  margin-bottom: 14px;
}

.avplay-block-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  color: #a1a1aa;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.avplay-row {
  display: grid;
  grid-template-columns: 5.25rem 1fr;
  gap: 4px 8px;
  margin-bottom: 4px;
  align-items: start;
}

.avplay-label {
  color: #a1a1aa;
  font-size: 11px;
}

.avplay-val {
  color: #fafafa;
  word-break: break-word;
  font-size: 12px;
}

.avplay-val-mono {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

.avplay-val-hi {
  color: #4ade80;
  font-weight: 600;
}

.avplay-pre {
  margin: 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(39, 39, 42, 0.95);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 10px;
  font-family: ui-monospace, Menlo, monospace;
  max-height: 72px;
  overflow: hidden;
  color: #e4e4e7;
}

.avplay-pre-sm {
  max-height: 56px;
  font-size: 9px;
  overflow: hidden;
}

.avplay-track-detail {
  margin: 6px 0 0;
  border-radius: 6px;
  background: rgba(39, 39, 42, 0.6);
  padding: 4px 8px;
}

.avplay-track-detail summary {
  cursor: pointer;
  color: #93c5fd;
  font-size: 11px;
  font-weight: 600;
}

.avplay-events-panel {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 32%;
  min-height: 120px;
  border-top: 2px solid rgba(59, 130, 246, 0.35);
  background: rgba(0, 0, 0, 0.35);
}

.avplay-events-title {
  margin: 0;
  padding: 10px 12px 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fde68a;
}

.avplay-events-sub {
  font-weight: 400;
  color: #a1a1aa;
  font-size: 10px;
}

.avplay-events-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 10px;
}

.avplay-events-empty {
  padding: 8px 12px;
  color: #71717a;
  font-style: italic;
}

.avplay-event {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(39, 39, 42, 0.85);
  border-left: 3px solid rgba(113, 113, 122, 0.6);
}

.avplay-event-latest {
  border-left-color: #fbbf24;
  background: rgba(59, 130, 246, 0.12);
}

.avplay-event-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 4px;
}

.avplay-event-time {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: #71717a;
  flex-shrink: 0;
}

.avplay-event-name {
  font-size: 12px;
  font-weight: 600;
  color: #fbbf24;
  word-break: break-word;
}

.avplay-event-data {
  margin: 0;
  padding: 6px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 10px;
  font-family: ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d4d4d8;
  max-height: 120px;
  overflow-y: auto;
}

.debug-panel {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 40;
  width: min(420px, 92vw);
  max-height: 42vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.88);
  color: #e4e4e7;
  font-size: 11px;
  font-family: ui-monospace, Menlo, monospace;
}

.debug-state {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  max-height: 18vh;
  overflow-y: auto;
}

.debug-key {
  color: #93c5fd;
  display: block;
  margin-top: 6px;
}

.debug-val {
  margin: 2px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: #d4d4d8;
}

.debug-log {
  padding: 8px 10px;
  overflow-y: auto;
  flex: 1;
  max-height: 24vh;
}

.debug-log-line {
  margin-bottom: 2px;
  color: #a1a1aa;
}

.stage {
  position: absolute;
  inset: 0;
}

.fill {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #18181b;
}

.image {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #18181b;
}

.video {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}

.hidden {
  display: none !important;
}

/* —— Pairing (React TV home) —— */
.pairing {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #fafafa;
  background-color: #09090b;
  background-image:
    radial-gradient(circle at top, rgba(148, 163, 184, 0.28), transparent 55%),
    radial-gradient(circle at bottom, rgba(59, 130, 246, 0.35), transparent 55%);
}

.pairing-content {
  width: 100%;
  display: flex;
  justify-content: center;
}

.pairing-shell {
  position: relative;
  width: 100%;
  max-width: 64rem;
}

.pairing-loading,
.pairing-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

.pairing-loading-text {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}

.spinner {
  width: 64px;
  height: 64px;
  border: 4px solid #3f3f46;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pairing-grid {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 40px;
  width: 100%;
}

@media (min-width: 768px) {
  .pairing-grid {
    flex-direction: row;
    align-items: center;
    gap: 64px;
  }
}

.pairing-left,
.pairing-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 24px;
}

@media (min-width: 768px) {
  .pairing-right {
    padding-left: 48px;
  }
}

.pairing-code-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.pairing-logo {
  height: 48px;
  width: auto;
  opacity: 0.9;
}

.pairing-tagline {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  max-width: 320px;
}

@media (min-width: 768px) {
  .pairing-tagline {
    font-size: 20px;
  }
}

.pairing-divider {
  display: none;
}

@media (min-width: 768px) {
  .pairing-divider {
    display: block;
    position: absolute;
    top: 40px;
    bottom: 40px;
    left: 50%;
    width: 1px;
    transform: translateX(-50%);
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      transparent,
      rgba(255, 255, 255, 0.14),
      transparent
    );
  }
}

.pairing-heading {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pairing-heading h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

@media (min-width: 640px) {
  .pairing-heading h1 {
    font-size: 36px;
  }
}

.pairing-muted {
  margin: 0;
  font-size: 14px;
  color: #a1a1aa;
}

@media (min-width: 640px) {
  .pairing-muted {
    font-size: 16px;
  }
}

.pairing-code-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

@media (min-width: 640px) {
  .pairing-code-row {
    flex-direction: row;
    gap: 24px;
  }
}

.pairing-qr-wrap {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.pairing-code-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 20px 32px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(39, 39, 42, 0.7);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.pairing-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 36px;
  letter-spacing: 0.35em;
  white-space: nowrap;
  margin-right: -0.35em;
}

@media (min-width: 640px) {
  .pairing-code {
    font-size: 48px;
  }
}

.pairing-footnote {
  margin: 0;
  font-size: 12px;
  color: #a1a1aa;
}

.pairing-retry {
  background: none;
  border: none;
  color: #3b82f6;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 16px;
}

.pairing-retry:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.find-screen-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  background: rgba(37, 99, 235, 0.9);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s;
}

.find-screen-overlay.find-screen-visible {
  opacity: 1;
}

.find-screen-inner {
  text-align: center;
}

.find-screen-name {
  margin: 0 0 16px;
  font-size: 3.75rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.find-screen-subtitle {
  margin: 0;
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.playback {
  position: absolute;
  inset: 0;
}
