/*
 * Any Theme Detector — design tokens + result components.
 * Shared by the extension and the website (copied by scripts/sync-shared.sh).
 */

/* Light is the default. Dark applies when the system asks for it (unless the
 * page pins data-theme="light"), or when the page pins data-theme="dark". */
:root {
  color-scheme: light;

  --atd-bg: #f5f5f7;
  --atd-surface: #ffffff;
  --atd-surface-2: #fafafc;
  --atd-label: #1d1d1f;
  --atd-label-2: #6e6e73;
  --atd-label-3: #8e8e93;
  --atd-sep: rgba(60, 60, 67, 0.12);
  --atd-fill: rgba(118, 118, 128, 0.12);
  --atd-fill-2: rgba(118, 118, 128, 0.07);
  --atd-accent: #4f46e5;
  --atd-accent-ink: #ffffff;
  --atd-accent-soft: rgba(79, 70, 229, 0.1);
  --atd-brand: linear-gradient(135deg, #8b5cf6 0%, #5b5bf0 46%, #2f7cf6 100%);
  --atd-green: #1f8a3c;
  --atd-amber: #b25e00;
  --atd-red: #d7263d;
  --atd-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --atd-shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 40px rgba(60, 50, 160, 0.1);
  --atd-glyph-pct: 82%;
  --atd-glyph-base: var(--atd-label);
  --atd-glyph-bg: 14%;
  --atd-badge-ink: #7f54b3;
  --atd-badge-bg: rgba(127, 84, 179, 0.12);
  --atd-selected: #ffffff;
  --atd-selected-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  --atd-glow: 1;

  --atd-radius: 16px;
  --atd-radius-sm: 10px;
  --atd-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --atd-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --atd-font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --atd-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --atd-bg: #111114;
    --atd-surface: #1c1c21;
    --atd-surface-2: #24242a;
    --atd-label: #f2f2f5;
    --atd-label-2: #a3a3ab;
    --atd-label-3: #77777f;
    --atd-sep: rgba(255, 255, 255, 0.09);
    --atd-fill: rgba(130, 130, 145, 0.24);
    --atd-fill-2: rgba(130, 130, 145, 0.13);
    --atd-accent: #8483ff;
    --atd-accent-ink: #0d0c22;
    --atd-accent-soft: rgba(132, 131, 255, 0.15);
    --atd-green: #3ddc6a;
    --atd-amber: #ffb340;
    --atd-red: #ff6961;
    --atd-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --atd-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.35);
    --atd-glyph-pct: 48%;
    --atd-glyph-base: #ffffff;
    --atd-glyph-bg: 24%;
    --atd-badge-ink: #c9adf0;
    --atd-badge-bg: rgba(155, 110, 214, 0.2);
    --atd-selected: #3a3a42;
    --atd-selected-shadow: none;
    --atd-glow: 1.5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --atd-bg: #111114;
  --atd-surface: #1c1c21;
  --atd-surface-2: #24242a;
  --atd-label: #f2f2f5;
  --atd-label-2: #a3a3ab;
  --atd-label-3: #77777f;
  --atd-sep: rgba(255, 255, 255, 0.09);
  --atd-fill: rgba(130, 130, 145, 0.24);
  --atd-fill-2: rgba(130, 130, 145, 0.13);
  --atd-accent: #8483ff;
  --atd-accent-ink: #0d0c22;
  --atd-accent-soft: rgba(132, 131, 255, 0.15);
  --atd-green: #3ddc6a;
  --atd-amber: #ffb340;
  --atd-red: #ff6961;
  --atd-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --atd-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.35);
  --atd-glyph-pct: 48%;
  --atd-glyph-base: #ffffff;
  --atd-glyph-bg: 24%;
  --atd-badge-ink: #c9adf0;
  --atd-badge-bg: rgba(155, 110, 214, 0.2);
  --atd-selected: #3a3a42;
  --atd-selected-shadow: none;
  --atd-glow: 1.5;
}

/* Brief cross-fade when the theme changes (set by the page for ~400ms). */
.atd-theme-anim,
.atd-theme-anim * {
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease !important;
}

/* ------------------------------------------------------------------ */

.atd-icon { flex: none; display: block; }

.atd-section {
  animation: atd-rise 0.48s var(--atd-ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes atd-rise {
  from { opacity: 0; transform: translateY(6px) scale(0.995); }
  to { opacity: 1; transform: none; }
}

.atd-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--atd-label-2);
}
.atd-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--atd-label-3);
}

/* Hero: the detected platform, lit in its brand color ------------------ */

.atd-hero {
  position: relative;
  padding: 18px;
  border-radius: var(--atd-radius);
  background:
    radial-gradient(130% 120% at 0% 0%, color-mix(in srgb, var(--tint, #8e8e93) 16%, transparent) 0%, transparent 58%),
    var(--atd-surface);
  box-shadow: var(--atd-shadow), inset 0 0 0 1px color-mix(in srgb, var(--tint, #8e8e93) 22%, var(--atd-sep));
  overflow: hidden;
}
.atd-hero-empty { background: var(--atd-surface); box-shadow: var(--atd-shadow), inset 0 0 0 0.5px var(--atd-sep); }

.atd-brand { display: flex; align-items: center; gap: 13px; }
.atd-brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.atd-brand-top { display: flex; align-items: center; gap: 8px; }
.atd-brand-top .atd-confidence { padding: 1px 7px 1px 6px; font-size: 10.5px; }
.atd-brand-name {
  font: 700 20px/1.15 var(--atd-font-display);
  letter-spacing: -0.02em;
  color: var(--atd-label);
}
.atd-brand-meta {
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--atd-label-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.atd-site { color: inherit; text-decoration: none; }
.atd-site:hover { color: var(--atd-accent); text-decoration: underline; }

.atd-glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font: 700 16px/1 var(--atd-font-display);
  letter-spacing: -0.02em;
  color: color-mix(in srgb, var(--tint, #8e8e93) var(--atd-glyph-pct), var(--atd-glyph-base));
  background: color-mix(in srgb, var(--tint, #8e8e93) var(--atd-glyph-bg), var(--atd-surface));
  box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--tint, #8e8e93) 24%, transparent);
}
.atd-glyph-sm { font-size: 11.5px; letter-spacing: 0; }
.atd-logo { display: block; flex: none; }
.atd-logo-img { border-radius: 3px; object-fit: contain; }
.atd-glyph-solid .atd-logo-img { width: 30px; height: 30px; padding: 3px; border-radius: 8px; background: #fff; }
.atd-glyph:not(.atd-glyph-solid) .atd-logo-img { width: 60%; height: 60%; }

/* Solid brand tile used for the detected platform */
.atd-glyph-solid {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 24px;
  color: #ffffff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 60%),
    var(--tint, #8e8e93);
  box-shadow:
    0 6px 16px color-mix(in srgb, var(--tint, #8e8e93) 32%, transparent),
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.18);
  animation: atd-pop 0.5s var(--atd-ease) both;
}
@keyframes atd-pop {
  from { transform: scale(0.82); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.atd-confidence {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  padding: 3px 8px 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--atd-fill-2);
  color: var(--atd-label-2);
  cursor: default;
}
.atd-confidence::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.atd-confidence.atd-high { color: var(--atd-green); background: color-mix(in srgb, var(--atd-green) 12%, transparent); }
.atd-confidence.atd-medium { color: var(--atd-amber); background: color-mix(in srgb, var(--atd-amber) 12%, transparent); }

.atd-theme { margin-top: 16px; }
.atd-eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--atd-label-3);
}
.atd-theme-name {
  margin: 2px 0 0;
  font: 700 26px/1.12 var(--atd-font-display);
  letter-spacing: -0.025em;
  color: var(--atd-label);
  word-break: break-word;
}
.atd-version {
  display: inline-block;
  vertical-align: 0.32em;
  margin-left: 2px;
  padding: 2px 7px;
  border-radius: 6px;
  font: 600 11px/1.4 var(--atd-mono);
  letter-spacing: 0;
  color: var(--atd-label-2);
  background: var(--atd-fill-2);
}
.atd-source { margin: 4px 0 0; font-size: 13px; color: var(--atd-label-2); }
.atd-note { margin: 14px 0 0; font-size: 13px; line-height: 1.45; color: var(--atd-label-2); }

.atd-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.atd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  font: 600 12.5px/1 var(--atd-font);
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  color: var(--atd-accent);
  background: var(--atd-accent-soft);
  cursor: pointer;
  transition: transform 0.12s ease-out, background-color 0.2s ease, filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.atd-btn:hover { background: color-mix(in srgb, var(--atd-accent) 16%, transparent); }
.atd-btn:active { transform: scale(0.96); }
.atd-btn:focus-visible { outline: 2px solid var(--atd-accent); outline-offset: 2px; }
.atd-btn-primary { color: var(--atd-accent-ink); background: var(--atd-accent); }
.atd-btn-primary:hover { background: var(--atd-accent); filter: brightness(1.08); }
.atd-btn-icon { width: 32px; padding: 0; color: var(--atd-label-2); background: var(--atd-fill-2); }
.atd-btn-icon:hover { color: var(--atd-label); background: var(--atd-fill); }
.atd-btn.is-copied { color: var(--atd-green); }

.atd-badges { display: flex; gap: 6px; margin-top: 12px; }
.atd-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--atd-badge-ink);
  background: var(--atd-badge-bg);
}

/* Grouped list (iOS Settings style) ----------------------------------- */

.atd-list {
  margin: 0;
  border-radius: var(--atd-radius-sm);
  background: var(--atd-surface);
  box-shadow: inset 0 0 0 0.5px var(--atd-sep);
  overflow: hidden;
}
.atd-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  min-height: 38px;
  padding: 9px 12px;
  font-size: 13px;
}
.atd-row + .atd-row { box-shadow: inset 0 0.5px 0 var(--atd-sep); }
.atd-row dt { flex: none; color: var(--atd-label-2); }
.atd-row dd { margin: 0; min-width: 0; text-align: right; }
.atd-value {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: 500 13px/1.35 var(--atd-font);
  color: var(--atd-label);
  text-align: right;
  overflow-wrap: anywhere;
  cursor: copy;
  transition: color 0.15s ease;
}
.atd-value:hover { color: var(--atd-accent); }
.atd-value.is-copied { color: var(--atd-green); }

/* Chips --------------------------------------------------------------- */

.atd-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.atd-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px 0 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--atd-label);
  background: var(--atd-surface);
  box-shadow: inset 0 0 0 0.5px var(--atd-sep);
  text-decoration: none;
  list-style: none;
  white-space: nowrap;
}
.atd-chip .atd-logo { color: color-mix(in srgb, var(--c, #8e8e93) var(--atd-glyph-pct), var(--atd-glyph-base)); }
.atd-chip-mono {
  display: grid;
  place-items: center;
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--atd-label-2);
  background: var(--atd-fill);
}
.atd-chip-link { transition: color 0.15s ease, transform 0.12s ease-out, box-shadow 0.15s ease; }
.atd-chip-link:hover { color: var(--atd-accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--atd-accent) 40%, transparent); }
.atd-chip-link:active { transform: scale(0.96); }
summary.atd-chip { cursor: pointer; color: var(--atd-accent); }
summary.atd-chip::-webkit-details-marker { display: none; }
.atd-more { margin-top: 6px; }
.atd-more[open] summary { display: none; }

.atd-tech { display: flex; align-items: flex-start; gap: 10px; }
.atd-tech + .atd-tech { margin-top: 6px; }
.atd-tech-cat {
  flex: none;
  width: 76px;
  padding: 5px 0 0 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--atd-label-3);
}

/* Partner offers ------------------------------------------------------- */

.atd-disclosure {
  margin-left: auto;
  margin-right: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--atd-label-3);
  cursor: help;
}
.atd-offers {
  border-radius: var(--atd-radius-sm);
  background: var(--atd-surface);
  box-shadow: inset 0 0 0 0.5px var(--atd-sep);
  overflow: hidden;
}
.atd-offer {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.atd-offer + .atd-offer { border-top: 0.5px solid var(--atd-sep); }
.atd-offer:hover { background: var(--atd-fill-2); }
.atd-offer:active { background: var(--atd-fill); }
.atd-offer .atd-glyph { width: 30px; height: 30px; border-radius: 8px; font-size: 14px; }
.atd-offer .atd-glyph .atd-logo { width: 16px; height: 16px; }
.atd-offer-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.atd-offer-title { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; }
.atd-offer-sub { font-size: 12px; color: var(--atd-label-2); }
.atd-offer > .atd-icon { color: var(--atd-label-3); }

/* Also detected -------------------------------------------------------- */

.atd-others {
  border-radius: var(--atd-radius-sm);
  background: var(--atd-surface);
  box-shadow: inset 0 0 0 0.5px var(--atd-sep);
}
.atd-other { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; }
.atd-other + .atd-other { box-shadow: inset 0 0.5px 0 var(--atd-sep); }
.atd-other .atd-glyph { width: 26px; height: 26px; border-radius: 7px; font-size: 12px; }
.atd-other .atd-glyph .atd-logo { width: 15px; height: 15px; }
.atd-other-name { font-weight: 600; }
.atd-other-theme { margin-left: auto; color: var(--atd-label-2); }

/* Signals disclosure -------------------------------------------------- */

.atd-signals summary {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--atd-label-3);
  list-style: none;
  cursor: pointer;
}
.atd-signals summary::-webkit-details-marker { display: none; }
.atd-signals summary .atd-icon { transition: transform 0.25s var(--atd-ease); }
.atd-signals[open] summary .atd-icon { transform: rotate(90deg); }
.atd-signals ul {
  margin: 8px 0 0;
  padding: 10px 12px 10px 28px;
  border-radius: var(--atd-radius-sm);
  background: var(--atd-fill-2);
  font: 12px/1.7 var(--atd-mono);
  color: var(--atd-label-2);
}

/* Messages ------------------------------------------------------------ */

.atd-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 8px 10px;
}
.atd-message-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 16px;
  color: var(--atd-label-2);
  background: var(--atd-fill-2);
}
.atd-message-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--atd-label); }
.atd-message-sub { margin: 4px 0 0; max-width: 34ch; font-size: 13px; line-height: 1.45; color: var(--atd-label-2); }

/* Skeleton ------------------------------------------------------------ */

.atd-skeleton {
  padding: 16px;
  border-radius: var(--atd-radius);
  background: var(--atd-surface);
  box-shadow: var(--atd-shadow), inset 0 0 0 0.5px var(--atd-sep);
}
.atd-bone {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--atd-fill-2) 0%, var(--atd-fill) 50%, var(--atd-fill-2) 100%);
  background-size: 200% 100%;
  animation: atd-shimmer 1.4s ease-in-out infinite;
}
.atd-bone + .atd-bone { margin-top: 10px; }
@keyframes atd-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  .atd-glyph-solid { animation: none; }
  .atd-section { animation: atd-fade 0.2s ease both; animation-delay: 0s; }
  .atd-bone { animation: none; }
  .atd-btn, .atd-chip-link { transition: none; }
  .atd-btn:active, .atd-chip-link:active { transform: none; }
}
@keyframes atd-fade { from { opacity: 0; } to { opacity: 1; } }

/* Custom-code result */
.atd-glyph-custom { background: var(--atd-brand); color: #fff; }

/* Folded sections */
.atd-fold > summary,
.atd-more-rows > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--atd-label-2);
  list-style: none;
  cursor: pointer;
}
.atd-fold > summary::-webkit-details-marker,
.atd-more-rows > summary::-webkit-details-marker { display: none; }
.atd-fold > summary .atd-icon,
.atd-more-rows > summary .atd-icon { transition: transform 0.25s var(--atd-ease); }
.atd-fold[open] > summary .atd-icon,
.atd-more-rows[open] > summary .atd-icon { transform: rotate(90deg); }
.atd-fold[open] > summary { margin-bottom: 8px; }
.atd-fold > summary:hover,
.atd-more-rows > summary:hover { color: var(--atd-label); }
.atd-more-rows { margin-top: 8px; }
.atd-more-rows > summary { margin: 0 0 0 2px; font-weight: 500; color: var(--atd-accent); }
.atd-more-rows[open] > summary { margin-bottom: 6px; }
