/* =============================================================================
   THEME SWITCHER CONTROL
   CoveredGeekly Limited

   The control consumes the same semantic tokens as everything else, so it
   themes itself: no light-mode rules are needed here beyond the icon swap.

   Icon visibility is keyed on the PREFERENCE (data-pref), not the resolved
   theme. A visitor on 'system' sees the monitor icon whatever their OS is
   doing, because the control reports what they chose.
   ============================================================================= */

.geekly-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast),
                border-color var(--transition-fast);
}

/* Main-site hover surfaces are borderless; standalone apps retain their
   contrasted control boundary through the original-value fallback. */
.geekly-theme-toggle:hover {
    background: var(--clr-bg-hover);
    border-color: var(--clr-border-rest, var(--clr-border-control));
    color: var(--clr-text-primary);
}

.geekly-theme-toggle:active {
    background: var(--clr-bg-active);
}

.geekly-theme-toggle:is(:focus-visible, :focus:where([data-gk-focus="keyboard"])):not(:where([data-gk-focus="pointer"])) {
    outline: 2px solid var(--clr-brand);
    outline-offset: var(--gk-site-focus-offset, 2px);
}

.geekly-theme-toggle__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* One icon at a time. All three are in the DOM so the swap is instant and
   needs no network round trip. */
.geekly-theme-toggle__svg {
    display: none;
}

.geekly-theme-toggle[data-pref="system"] .geekly-theme-toggle__svg--system,
.geekly-theme-toggle[data-pref="light"] .geekly-theme-toggle__svg--light,
.geekly-theme-toggle[data-pref="dark"] .geekly-theme-toggle__svg--dark {
    display: block;
}

/* Before the script runs there is no data-pref, so fall back to the monitor
   icon rather than showing nothing. */
.geekly-theme-toggle:not([data-pref]) .geekly-theme-toggle__svg--system {
    display: block;
}

/* The topbar hides non-essential controls at the narrowest widths; the theme
   control stays, because losing it on mobile would strand those visitors in
   whichever theme they last picked on desktop. */
@media (max-width: 374px) {
    .geekly-theme-toggle {
        width: 32px;
        height: 32px;
    }
}

/* =============================================================================
   LOGO VARIANTS

   Every logo in assets/images is pure white on transparency, which is correct
   on the dark header and invisible on a light one. Two mechanisms, in order of
   preference:

     1. A supplied light variant (assets/images/logo-light-*.{png,webp}). The
        partial renders both images and CSS shows one; the light one carries an
        empty alt because the anchor already has an accessible label, so it must
        not be announced twice.
     2. No variant yet: the white logo is inverted. This is a deliberate interim
        so the logo stays legible instead of vanishing, and it is dropped
        automatically the moment a real variant exists.

   Inverting is a stopgap, not the design: it cannot preserve a multi-colour
   mark. It is safe here only because the current logo is monochrome white.
   ============================================================================= */

/* Light variant hidden by default; the dark header wants the white logo. */
.geekly-topbar__logo-img--on-light {
    display: none;
}

/* A real variant has been supplied: swap them. */
:root[data-theme="light"] .geekly-topbar__logo--has-light .geekly-topbar__logo-img--on-light {
    display: block;
}

:root[data-theme="light"] .geekly-topbar__logo--has-light .geekly-topbar__logo-img--on-dark {
    display: none;
}

/* No variant yet: keep the white logo legible by inverting it. */
:root[data-theme="light"] .geekly-topbar__logo:not(.geekly-topbar__logo--has-light) .geekly-topbar__logo-img--on-dark {
    filter: invert(1);
}

/* The same applies to the no-JS light path.

   The marker class is required as well as the missing attribute, for the same
   reason as the token override in tokens.css: without it this would swap the
   logo on a visitor the switcher never offered a light theme to. Here the
   mismatch is worse than a wrong colour - a dark variant on a dark header is
   simply invisible. */
@media (prefers-color-scheme: light) {
    :root.geekly-theme-switcher-on:not([data-theme]) .geekly-topbar__logo--has-light .geekly-topbar__logo-img--on-light {
        display: block;
    }

    :root.geekly-theme-switcher-on:not([data-theme]) .geekly-topbar__logo--has-light .geekly-topbar__logo-img--on-dark {
        display: none;
    }

    :root.geekly-theme-switcher-on:not([data-theme]) .geekly-topbar__logo:not(.geekly-topbar__logo--has-light) .geekly-topbar__logo-img--on-dark {
        filter: invert(1);
    }
}
