/* ==========================================================================
   Theme switch — outline, pill-shaped, icon led.

   Deliberately colour-agnostic: everything is currentColor or a token, so the
   one control works on the dark sidebar and on a light page body without a
   per-context override.
   ========================================================================== */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Fixed square + 50% radius, so it is a circle whatever the icon inside
       measures. Sized to stay a comfortable touch target. */
    width: 38px;
    height: 38px;
    padding: 0;
    flex: 0 0 auto;
    border: 1px solid currentColor;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.18s ease, background-color 0.18s ease,
                transform 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
    opacity: 1;
    background: color-mix(in srgb, currentColor 12%, transparent);
}

.theme-toggle:active {
    transform: scale(0.97);
}

.theme-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    opacity: 1;
}

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

.theme-toggle__icon svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* Show the icon for the theme the button would switch TO, which is the
   convention people already know from every other app: a moon means "go
   dark". The sun therefore only appears once dark is active. */
.theme-toggle__icon--sun { display: none; }
.theme-toggle__icon--moon { display: inline-flex; }

:root[data-theme="dark"] .theme-toggle__icon--sun { display: inline-flex; }
:root[data-theme="dark"] .theme-toggle__icon--moon { display: none; }

/* Floating variant, for pages with no sidebar to sit in. Sits clear of the
   iOS home indicator and any notch-driven safe area. */
.theme-toggle--floating {
    position: fixed;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 900;
    background: var(--card, #fff);
    color: var(--text, #111827);
    border-color: var(--border, #e5e7eb);
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.12));
    opacity: 1;
}

.theme-toggle--floating:hover {
    background: var(--card, #fff);
    border-color: currentColor;
}

@media (prefers-reduced-motion: reduce) {
    .theme-toggle {
        transition: none;
    }
    .theme-toggle:active {
        transform: none;
    }
}

/* A control for changing screen colours has no business on paper. */
@media print {
    .theme-toggle {
        display: none !important;
    }
}
