/* ============================================================================
   YOSOnia RetroArch Thumbnails - front-end appearance
   ----------------------------------------------------------------------------
   Colour rules (kept in sync with the YOSOnia Xbox child theme):
   1. Every colour is a --yxt-* token. No hard-coded #fff / #333 in components.
   2. Light/dark only change token VALUES; selectors and layout stay the same.
   3. Light fills use dark text, dark fills use light text. Never stack a green
      fill under green text (the theme hit this bug before).
   4. The plugin has NO theme switcher of its own. It follows the site toggle:
      body.yxv2-dark (YOSOnia), body.is-dark, html[data-theme="dark"], the
      system preference, or whatever the site background actually is.
      A shortcode may pin one instance with theme="light" / theme="dark".
   5. IMPORTANT (0.1.13): all token values are literals, NOT var(--yx-*).
      The YOSOnia theme declares --yx-card:#fff on :root and only overrides it
      on <body class="yxv2-dark">. A custom property written as
      "--yxt-surface: var(--yx-card, #fff)" on :root is resolved ON <html>,
      so it freezes to white and never sees the body override. That was the
      source of the "still a white background in dark mode" report.
   6. .yxt-app is opaque. The gallery used to be fully transparent, so the
      toolbar, status, gaps between cards, pagination and footer simply showed
      the parent theme's white content wrapper while the text was light.
      It now paints its own surface, and 0.1.13 additionally darkens any
      ancestor of the gallery that would otherwise stay white.
   ============================================================================ */

/* ---- Light tokens (default). Values are copied from the theme's
       assets/css/theme.css :root so a customised site still looks native. ---- */
:root {
  --yxt-bg: #f4f7f6;
  --yxt-surface: #ffffff;
  --yxt-surface-2: #f2f8f2;
  --yxt-text: #172235;
  --yxt-muted: #5d6879;
  --yxt-placeholder: #7e8995;
  --yxt-border: #e2e9e4;
  --yxt-shadow: 0 8px 24px rgba(12, 35, 20, .07);
  --yxt-shadow-strong: 0 12px 40px rgba(6, 19, 11, .22);

  --yxt-brand: #0b9c25;
  --yxt-brand-lime: #65ef43;
  --yxt-brand-ink: #071a0b;         /* text on the lime / green fills */
  --yxt-link: #0a7d1c;              /* 5.3:1 on white */
  --yxt-focus: #0b9c25;
  --yxt-hover: rgba(11, 156, 37, .10);
  --yxt-img-bg: #eef4ef;
  --yxt-badge-bg: #e8f9e4;
  --yxt-badge-text: #193323;
  --yxt-spinner: #0b9c25;
  --yxt-spinner-track: rgba(11, 156, 37, .20);
  --yxt-overlay: rgba(6, 19, 11, .48);
  --yxt-danger: #b32d2e;
  --yxt-danger-bg: #fdeeee;
}

/* ---- Dark tokens. Values mirror the theme's .yxv2-dark block and the
       shared color-tokens.css (.is-dark): near-black green surfaces and a
       slightly tinted near-white for body text (never pure #fff). ---- */
html[data-yxt-theme="dark"],
html[data-theme="dark"] {
  --yxt-bg: #0a120d;
  --yxt-surface: #111b15;
  --yxt-surface-2: #0e1a12;
  --yxt-text: #e8eee9;
  --yxt-muted: #b3beb6;
  --yxt-placeholder: #93a096;
  --yxt-border: #29372e;
  --yxt-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --yxt-shadow-strong: 0 12px 40px rgba(0, 0, 0, .55);

  --yxt-brand: #65ef43;
  --yxt-brand-lime: #65ef43;
  --yxt-brand-ink: #071a0b;
  --yxt-link: #8bef6b;              /* 12.5:1 on #111b15 */
  --yxt-focus: #8bef6b;
  --yxt-hover: rgba(139, 239, 107, .14);
  --yxt-img-bg: #0e1a12;
  --yxt-badge-bg: #17351d;
  --yxt-badge-text: #e7f2e8;
  --yxt-spinner: #8bef6b;
  --yxt-spinner-track: rgba(139, 239, 107, .25);
  --yxt-overlay: rgba(2, 8, 4, .88);
  --yxt-danger: #ff8f8f;
  --yxt-danger-bg: #2a1414;
}

/* CSS-only fallback: even if JavaScript never runs, the site toggle (a body
   class) still recolours the widget. Explicit theme="light" always wins. */
body.yxv2-dark .yxt-app:not([data-theme="light"]),
body.yxv2-dark .yxt-busy:not([data-theme="light"]),
body.is-dark .yxt-app:not([data-theme="light"]),
body.is-dark .yxt-busy:not([data-theme="light"]),
body.dark-mode .yxt-app:not([data-theme="light"]),
body.dark-mode .yxt-busy:not([data-theme="light"]) {
  --yxt-bg: #0a120d;
  --yxt-surface: #111b15;
  --yxt-surface-2: #0e1a12;
  --yxt-text: #e8eee9;
  --yxt-muted: #b3beb6;
  --yxt-placeholder: #93a096;
  --yxt-border: #29372e;
  --yxt-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --yxt-shadow-strong: 0 12px 40px rgba(0, 0, 0, .55);
  --yxt-brand: #65ef43;
  --yxt-brand-lime: #65ef43;
  --yxt-brand-ink: #071a0b;
  --yxt-link: #8bef6b;
  --yxt-focus: #8bef6b;
  --yxt-hover: rgba(139, 239, 107, .14);
  --yxt-img-bg: #0e1a12;
  --yxt-badge-bg: #17351d;
  --yxt-badge-text: #e7f2e8;
  --yxt-spinner: #8bef6b;
  --yxt-spinner-track: rgba(139, 239, 107, .25);
  --yxt-overlay: rgba(2, 8, 4, .88);
  --yxt-danger: #ff8f8f;
  --yxt-danger-bg: #2a1414;
}

/* Per-instance override from theme="light" / theme="dark". These are literals
   so they cannot be polluted by a theme that is in the opposite mode. */
.yxt-app[data-theme="dark"],
.yxt-busy[data-theme="dark"] {
  --yxt-bg: #0a120d;
  --yxt-surface: #111b15;
  --yxt-surface-2: #0e1a12;
  --yxt-text: #e8eee9;
  --yxt-muted: #b3beb6;
  --yxt-placeholder: #93a096;
  --yxt-border: #29372e;
  --yxt-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --yxt-shadow-strong: 0 12px 40px rgba(0, 0, 0, .55);
  --yxt-brand: #65ef43;
  --yxt-brand-lime: #65ef43;
  --yxt-brand-ink: #071a0b;
  --yxt-link: #8bef6b;
  --yxt-focus: #8bef6b;
  --yxt-hover: rgba(139, 239, 107, .14);
  --yxt-img-bg: #0e1a12;
  --yxt-badge-bg: #17351d;
  --yxt-badge-text: #e7f2e8;
  --yxt-spinner: #8bef6b;
  --yxt-spinner-track: rgba(139, 239, 107, .25);
  --yxt-overlay: rgba(2, 8, 4, .88);
  --yxt-danger: #ff8f8f;
  --yxt-danger-bg: #2a1414;
}
.yxt-app[data-theme="light"],
.yxt-busy[data-theme="light"] {
  --yxt-bg: #f4f7f6;
  --yxt-surface: #ffffff;
  --yxt-surface-2: #f2f8f2;
  --yxt-text: #172235;
  --yxt-muted: #5d6879;
  --yxt-placeholder: #7e8995;
  --yxt-border: #e2e9e4;
  --yxt-shadow: 0 8px 24px rgba(12, 35, 20, .07);
  --yxt-shadow-strong: 0 12px 40px rgba(6, 19, 11, .22);
  --yxt-brand: #0b9c25;
  --yxt-brand-lime: #65ef43;
  --yxt-brand-ink: #071a0b;
  --yxt-link: #0a7d1c;
  --yxt-focus: #0b9c25;
  --yxt-hover: rgba(11, 156, 37, .10);
  --yxt-img-bg: #eef4ef;
  --yxt-badge-bg: #e8f9e4;
  --yxt-badge-text: #193323;
  --yxt-spinner: #0b9c25;
  --yxt-spinner-track: rgba(11, 156, 37, .20);
  --yxt-overlay: rgba(6, 19, 11, .48);
  --yxt-danger: #b32d2e;
  --yxt-danger-bg: #fdeeee;
}

/* Native selects / inputs follow the chosen scheme instead of staying white. */
.yxt-app, .yxt-busy { color-scheme: light; }
html[data-yxt-theme="dark"] .yxt-app,
html[data-yxt-theme="dark"] .yxt-busy,
html[data-theme="dark"] .yxt-app,
html[data-theme="dark"] .yxt-busy,
body.yxv2-dark .yxt-app:not([data-theme="light"]),
body.yxv2-dark .yxt-busy:not([data-theme="light"]),
body.is-dark .yxt-app:not([data-theme="light"]),
body.is-dark .yxt-busy:not([data-theme="light"]),
body.dark-mode .yxt-app:not([data-theme="light"]),
body.dark-mode .yxt-busy:not([data-theme="light"]),
.yxt-app[data-theme="dark"],
.yxt-busy[data-theme="dark"] { color-scheme: dark; }
.yxt-app[data-theme="light"],
.yxt-busy[data-theme="light"] { color-scheme: light; }

/* --------------------------------------------------------------------------
   No white around the gallery (0.1.13)
   --------------------------------------------------------------------------
   Some parent-theme / page-builder wrappers keep a hard-coded light
   background after the site toggle, and .yxt-app used to be transparent.
   JS tags every ancestor whose computed background is genuinely bright with
   .yxt-dark-ancestor (and removes the tag again in light mode). The :has()
   rule below is a no-JS enhancement for modern browsers. Neither rule
   touches an instance explicitly pinned with theme="light".
   -------------------------------------------------------------------------- */
html[data-yxt-theme="dark"] .yxt-dark-ancestor,
html[data-theme="dark"] .yxt-dark-ancestor,
body.yxv2-dark .yxt-dark-ancestor,
body.is-dark .yxt-dark-ancestor,
body.dark-mode .yxt-dark-ancestor {
  background-color: var(--yxt-bg) !important;
  color: var(--yxt-text);
}
/* Only site-owned dark signals are used here, never our own
   html[data-yxt-theme]: the JS detector reads computed backgrounds, and a
   rule keyed to its own output would lock it in dark mode forever. */
:is(html[data-theme="dark"] body, body.yxv2-dark, body.is-dark, body.dark-mode):has(.yxt-app:not([data-theme="light"])) {
  background-color: var(--yxt-bg) !important;
}
:is(html[data-theme="dark"] body, body.yxv2-dark, body.is-dark, body.dark-mode)
  :is(.wp-site-blocks, .site, .site-content, .content-area, .site-main, main,
      article, .entry-content, .entry-content-wrap, .wp-block-post-content,
      .wp-block-group, .wp-block-column, .wp-block-columns, .content-container,
      #inner-wrap, .kadence-content, .page-content, .post-content, .yxt-app-wrap):has(.yxt-app:not([data-theme="light"])) {
  background-color: var(--yxt-bg) !important;
  color: var(--yxt-text);
}

/* --------------------------------------------------------------------------
   Layout - unchanged between the two modes
   -------------------------------------------------------------------------- */
.yxt-app {
  /* Opaque on purpose: never let the parent's white wrapper show through. */
  background: var(--yxt-bg);
  border: 1px solid var(--yxt-border);
  border-radius: 12px;
  padding: 18px;
  color: var(--yxt-text);
  width: 100%;
  margin: 1.2rem 0;
  font-size: 15px;
  scrollbar-color: var(--yxt-border) var(--yxt-surface);
}
.yxt-app :focus-visible,
.yxt-busy :focus-visible {
  outline: 2px solid var(--yxt-focus);
  outline-offset: 2px;
}
/* Form-control details that browsers otherwise paint white regardless of
   color-scheme: option lists, autofill, selection, search clear button. */
.yxt-app option { background: var(--yxt-surface); color: var(--yxt-text); }
.yxt-app ::selection { background: var(--yxt-brand); color: var(--yxt-brand-ink); }
.yxt-app input:-webkit-autofill,
.yxt-app input:-webkit-autofill:hover,
.yxt-app input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--yxt-text);
  -webkit-box-shadow: 0 0 0 1000px var(--yxt-surface) inset;
  caret-color: var(--yxt-text);
}
.yxt-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) minmax(150px, 1fr) minmax(130px, 1fr) auto;
  gap: 10px;
  margin-bottom: 16px;
}
/* Before a keyword is entered the two filter selectors are hidden, so the
   toolbar collapses to search field + button. */
.yxt-toolbar.yxt-compact { grid-template-columns: minmax(180px, 1fr) auto; }
.yxt-toolbar [hidden] { display: none !important; }
.yxt-toolbar input,
.yxt-toolbar select {
  min-width: 0;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--yxt-border);
  border-radius: 8px;
  background: var(--yxt-surface);
  color: var(--yxt-text);
  box-shadow: none;
}
.yxt-toolbar input::placeholder { color: var(--yxt-placeholder); opacity: 1; }
.yxt-toolbar .yxt-search-button,
.yxt-pagination button {
  border: 0;
  border-radius: 8px;
  /* Theme CTA: lime fill + dark ink. Never white text on a light green fill. */
  background: var(--yxt-brand-lime);
  color: var(--yxt-brand-ink);
  font-weight: 800;
  padding: 10px 18px;
  cursor: pointer;
}
.yxt-toolbar .yxt-search-button:hover,
.yxt-pagination button:hover { filter: brightness(1.05); }
/* Visitor-controlled image source. Kept on its own row so the result-driven
   filters can still collapse without shifting this control around. */
.yxt-sourcebar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: -4px 0 12px; font-size: 13px; }
.yxt-sourcebar-label { color: var(--yxt-text); }
.yxt-sourcebar select {
  width: auto;
  min-width: 160px;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--yxt-border);
  border-radius: 8px;
  background: var(--yxt-surface);
  color: var(--yxt-text);
  font-size: 13px;
}
.yxt-sourcebar-hint { font-size: 12px; color: var(--yxt-muted); }
.yxt-status { margin: 10px 0 14px; color: var(--yxt-muted); }

/* Search-in-progress veil. Fixed to the viewport so the spinner stays
   visible even when the results grid is taller than the screen. It blocks
   clicks while a request is running, which also prevents double submits.
   JS moves it to <body>; the tokens above are re-declared on the element's
   container group, so it keeps the correct scheme after the move. */
.yxt-busy {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--yxt-overlay);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.yxt-busy[hidden] { display: none; }
.yxt-busy-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 150px;
  padding: 22px 30px;
  border: 1px solid var(--yxt-border);
  border-radius: 12px;
  background: var(--yxt-surface);
  color: var(--yxt-text);
  box-shadow: var(--yxt-shadow-strong);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
}
.yxt-busy-spinner {
  box-sizing: border-box;
  width: 30px;
  height: 30px;
  border: 3px solid var(--yxt-spinner-track);
  border-top-color: var(--yxt-spinner);
  border-radius: 50%;
  animation: yxt-spin .8s linear infinite;
}
@keyframes yxt-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .yxt-busy-spinner {
    animation: none;
    border-right-color: var(--yxt-spinner);
    border-bottom-color: var(--yxt-spinner);
  }
}

.yxt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.yxt-card {
  min-width: 0;
  border: 1px solid var(--yxt-border);
  border-radius: 10px;
  padding: 10px;
  background: var(--yxt-surface);
  box-shadow: var(--yxt-shadow);
  color: var(--yxt-text);
  overflow: hidden;
}
.yxt-image-link {
  position: relative;
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--yxt-img-bg);
  border-radius: 6px;
  overflow: hidden;
}
/* No filter/invert on artwork: box art is an image, not UI chrome. The image
   gets the same dark backdrop so a transparent PNG never flashes white. */
.yxt-image-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--yxt-img-bg);
}
.yxt-image-note { font-size: 12px; color: var(--yxt-muted); text-align: center; padding: 0 6px; }
.yxt-image-note[hidden] { display: none; }
.yxt-image-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  text-align: center;
  background: var(--yxt-surface-2);
}
.yxt-image-error-text { font-size: 13px; color: var(--yxt-text); }
.yxt-image-error-hint { font-size: 11px; color: var(--yxt-muted); line-height: 1.4; }
.yxt-retry {
  margin-top: 6px;
  border: 1px solid var(--yxt-border);
  border-radius: 6px;
  background: var(--yxt-surface);
  color: var(--yxt-text);
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.yxt-retry:hover { background: var(--yxt-hover); }
.yxt-card-title { font-weight: 800; margin: 9px 0 3px; overflow-wrap: anywhere; color: var(--yxt-text); }
.yxt-card-meta, .yxt-original { font-size: 12px; color: var(--yxt-muted); overflow-wrap: anywhere; }
.yxt-original { margin-top: 4px; }
.yxt-original[hidden] { display: none; }
.yxt-source-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--yxt-badge-bg);
  color: var(--yxt-badge-text);
}
.yxt-actions { display: flex; gap: 12px; margin-top: 9px; font-size: 13px; }
/* Only plain text links get the link colour; buttons above keep their own
   dark ink. This avoids the "green text on a green fill" trap. */
.yxt-actions a,
.yxt-footer a { color: var(--yxt-link); text-decoration: none; }
.yxt-actions a:hover,
.yxt-footer a:hover { text-decoration: underline; }

.yxt-pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 22px 0; }
.yxt-pagination button:disabled { opacity: .45; cursor: not-allowed; }
.yxt-page-label { color: var(--yxt-muted); }

/* Image source attribution + legal notice */
.yxt-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--yxt-border);
  font-size: 12px;
  line-height: 1.75;
  color: var(--yxt-muted);
}
.yxt-footer p { margin: 0 0 6px; }
.yxt-disclaimer { font-weight: 600; color: var(--yxt-text); }
.yxt-contact-email { color: var(--yxt-muted); word-break: break-all; }

@media (max-width: 700px) {
  .yxt-toolbar,
  .yxt-toolbar.yxt-compact { grid-template-columns: 1fr 1fr; }
  .yxt-toolbar .yxt-query { grid-column: 1 / -1; }
  .yxt-toolbar .yxt-search-button { grid-column: 1 / -1; }
  .yxt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .yxt-card { padding: 7px; }
  .yxt-image-link { height: 120px; }
  .yxt-app { padding: 12px; }
  .yxt-card-title { font-size: 13px; }
  .yxt-actions { gap: 8px; font-size: 12px; flex-wrap: wrap; }
}
