/*
 * YouTube Thumbnail Downloader — Public Styles
 * Version: 1.0.0
 * Package: YTD_Downloader
 */

/* ── Custom Properties ─────────────────────────────────────────────────────── */
:root {
  --ytd-accent:       #FF0000;
  --ytd-btn-color:    #FF0000;

  /* Surfaces */
  --ytd-bg:           #ffffff;
  --ytd-surface:      #f8f8f8;
  --ytd-border:       #e5e7eb;

  /* Text */
  --ytd-text:         #111827;
  --ytd-text-muted:   #6b7280;

  /* States */
  --ytd-error-bg:     #fef2f2;
  --ytd-error-border: #fca5a5;
  --ytd-error-text:   #991b1b;

  /* Radius / shadow */
  --ytd-radius-sm:    6px;
  --ytd-radius:       12px;
  --ytd-radius-lg:    16px;
  --ytd-shadow:       0 2px 12px rgba(0, 0, 0, 0.07);
  --ytd-shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.13);

  /* Transitions */
  --ytd-transition:   0.2s ease;
}

/* ── Dark mode ──────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --ytd-bg:           #1a1a1a;
    --ytd-surface:      #242424;
    --ytd-border:       #333333;
    --ytd-text:         #f3f4f6;
    --ytd-text-muted:   #9ca3af;
    --ytd-error-bg:     #2d1515;
    --ytd-error-border: #7f1d1d;
    --ytd-error-text:   #fca5a5;
  }
}

/* ── Wrapper ────────────────────────────────────────────────────────────────── */
.ytd-wrap {
  background: var(--ytd-bg);
  border: 1px solid var(--ytd-border);
  border-radius: var(--ytd-radius-lg);
  box-shadow: var(--ytd-shadow);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  max-width: 760px;
  padding: 28px 28px 32px;
  margin: 0 auto;
  color: var(--ytd-text);
  box-sizing: border-box;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.ytd-header {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}

.ytd-logo-icon {
  flex-shrink: 0;
  height: 26px;
  width: 36px;
}

.ytd-title {
  color: var(--ytd-text);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* ── Input row ──────────────────────────────────────────────────────────────── */
.ytd-input-row {
  display: flex;
  gap: 10px;
}

.ytd-url-input {
  background: var(--ytd-surface);
  border: 1.5px solid var(--ytd-border);
  border-radius: var(--ytd-radius);
  color: var(--ytd-text);
  flex: 1;
  font-size: 0.95rem;
  min-width: 0;
  outline: none;
  padding: 11px 14px;
  transition: border-color var(--ytd-transition), box-shadow var(--ytd-transition);
}

.ytd-url-input::placeholder {
  color: var(--ytd-text-muted);
}

.ytd-url-input:focus {
  border-color: var(--ytd-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ytd-accent) 15%, transparent);
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.ytd-btn {
  align-items: center;
  border: none;
  border-radius: var(--ytd-radius);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.9rem;
  font-weight: 600;
  gap: 7px;
  justify-content: center;
  padding: 11px 20px;
  transition: filter var(--ytd-transition), transform var(--ytd-transition), opacity var(--ytd-transition);
  white-space: nowrap;
}

.ytd-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.ytd-btn:active {
  transform: translateY(0);
}

.ytd-btn-primary {
  background: var(--ytd-btn-color);
  color: #fff;
  min-width: 140px;
}

.ytd-btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
}

.ytd-btn-download {
  background: var(--ytd-accent);
  color: #fff;
  font-size: 0.82rem;
  padding: 7px 14px;
}

.ytd-btn-copy {
  background: var(--ytd-surface);
  border: 1.5px solid var(--ytd-border);
  color: var(--ytd-text);
  font-size: 0.82rem;
  padding: 7px 14px;
}

.ytd-btn-copy:hover {
  border-color: var(--ytd-accent);
  color: var(--ytd-accent);
}

/* ── Spinner ────────────────────────────────────────────────────────────────── */
.ytd-spinner {
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  height: 14px;
  width: 14px;
  animation: ytd-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.ytd-btn.is-loading .ytd-spinner {
  display: block;
}

.ytd-btn.is-loading .ytd-btn-label {
  opacity: 0.75;
}

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

/* ── Hidden state — must override any theme that resets [hidden] ─────────────── */
.ytd-wrap [hidden] {
  display: none !important;
}

/* ── Error ──────────────────────────────────────────────────────────────────── */
.ytd-error {
  align-items: flex-start;
  background: var(--ytd-error-bg);
  border: 1px solid var(--ytd-error-border);
  border-radius: var(--ytd-radius-sm);
  color: var(--ytd-error-text);
  display: flex;
  font-size: 0.9rem;
  gap: 8px;
  margin-top: 14px;
  padding: 11px 14px;
}

.ytd-error::before {
  content: "⚠";
  flex-shrink: 0;
}

/* ── Large preview ──────────────────────────────────────────────────────────── */
.ytd-preview-wrap {
  border-radius: var(--ytd-radius);
  margin-top: 22px;
  overflow: hidden;
  position: relative;
}

.ytd-preview-img {
  border-radius: var(--ytd-radius);
  display: block;
  height: auto;
  object-fit: cover;
  width: 100%;
  transition: transform 0.3s ease;
}

.ytd-preview-img:hover {
  transform: scale(1.015);
}

.ytd-video-id-badge {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  border-radius: 0 0 var(--ytd-radius) var(--ytd-radius);
  bottom: 0;
  color: #e5e7eb;
  display: flex;
  font-size: 0.78rem;
  gap: 6px;
  left: 0;
  padding: 8px 14px;
  position: absolute;
  right: 0;
}

.ytd-video-id-text {
  color: #fff;
  font-family: monospace;
}

/* ── Resolution section ─────────────────────────────────────────────────────── */
.ytd-resolutions {
  margin-top: 24px;
}

.ytd-resolutions-title {
  color: var(--ytd-text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin: 0 0 14px;
  text-transform: uppercase;
}

/* ── Resolution grid ────────────────────────────────────────────────────────── */
.ytd-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* ── Resolution card ────────────────────────────────────────────────────────── */
.ytd-res-card {
  background: var(--ytd-surface);
  border: 1.5px solid var(--ytd-border);
  border-radius: var(--ytd-radius);
  box-shadow: var(--ytd-shadow);
  overflow: hidden;
  transition: box-shadow var(--ytd-transition), transform var(--ytd-transition), border-color var(--ytd-transition);
}

.ytd-res-card:hover {
  border-color: var(--ytd-accent);
  box-shadow: var(--ytd-shadow-hover);
  transform: translateY(-3px);
}

.ytd-res-thumb-wrap {
  aspect-ratio: 16/9;
  overflow: hidden;
  width: 100%;
}

.ytd-res-thumb {
  display: block;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
  width: 100%;
}

.ytd-res-card:hover .ytd-res-thumb {
  transform: scale(1.04);
}

.ytd-res-info {
  padding: 12px 14px;
}

.ytd-res-label {
  color: var(--ytd-text);
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0 0 3px;
}

.ytd-res-dimensions {
  color: var(--ytd-text-muted);
  font-size: 0.78rem;
  margin: 0 0 12px;
}

.ytd-res-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ytd-btn,
  .ytd-res-card,
  .ytd-preview-img,
  .ytd-res-thumb {
    transition: none;
  }
  .ytd-spinner {
    animation: none;
    border-top-color: #fff;
  }
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .ytd-wrap {
    border-radius: var(--ytd-radius);
    padding: 18px 16px 22px;
  }

  .ytd-input-row {
    flex-direction: column;
  }

  .ytd-btn-primary {
    width: 100%;
  }

  .ytd-grid {
    grid-template-columns: 1fr;
  }
}
