/*
 * leons-site-tweaks/custom.css
 *
 * Site-wide CSS overrides. Loaded with priority 999, so this file wins over
 * kenta theme + kenta plugin CSS for any selector you write here.
 *
 * Add CSS rules below as needed. Cache is auto-busted by file mtime.
 *
 * NOTE on dark mode: kenta switches via `data-kenta-theme="dark"` on <html>.
 * Use that attribute selector — NOT a `.dark-mode` class — for any dark-only
 * rules. (.dark-mode appears in kenta's CSS file only as a leftover from an
 * earlier theme version; it's not the runtime switch.)
 */

/* ===========================================================================
 * Dark mode fixes
 * =========================================================================== */

/* Side-matter footnote text: plugin hardcodes color:#4c4c4c inline.
 * Warm creamy white in dark mode — softer than pure white, easier to read. */
[data-kenta-theme="dark"] .side-matter-text,
[data-kenta-theme="dark"] .side-matter-text p {
    color: #fbf2da !important;
}

/* Post card shadow: kenta's dark-mode shadow halos white. Replace with a
 * heavier dark drop shadow so cards feel elevated rather than glowing. */
[data-kenta-theme="dark"] .card {
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.75) !important;
}

/* "Decline" button: text colour is unreadable in both modes — dark text on
 * dark button in light mode, white text on white button in dark mode.
 * Force readable contrast in each. */
.kenta-button.decline-button {
    color: #ffffff !important;
}
[data-kenta-theme="dark"] .kenta-button.decline-button {
    color: #1a1a1a !important;
}

/* The subscribe modal now uses .leons-popup for its frame (background,
 * border, shadow) — kenta CSS variables already adapt to dark mode, so
 * no per-mode overrides are needed for the modal itself. */

/* ===========================================================================
 * Shared popup / modal style — used by leons-subscribe, leons-translate,
 * and any future popup. Mimics the kenta post card: solid 2px border, hard
 * 10px/10px offset shadow (no blur), 18px radius. Colors via kenta CSS
 * variables so dark/light mode are automatic.
 *
 * Markup pattern:
 *   <div class="leons-popup-overlay" hidden>
 *     <div class="leons-popup">
 *       <button class="leons-popup-close">&times;</button>
 *       <h2>Title</h2>
 *       ...content...
 *     </div>
 *   </div>
 * =========================================================================== */

.leons-popup-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0, 0, 0, 0.55);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: leonsPopupFade .15s ease-out;
}
.leons-popup-overlay[hidden] { display: none; }
@keyframes leonsPopupFade { from { opacity: 0; } to { opacity: 1; } }

.leons-popup {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 28px 28px 24px;
    background: var(--kenta-base-color, #fff);
    color: var(--kenta-content-base-color, #1a1a1a);
    border: 2px solid var(--kenta-base-300, rgba(0, 0, 0, 0.15));
    border-radius: 18px;
    box-shadow: var(--kenta-base-200, rgba(0, 0, 0, 0.5)) 10px 10px 0 0;
    font-family: inherit;
}
.leons-popup h2 { margin: 0 0 10px; font-size: 20px; }
.leons-popup p { margin: 0 0 14px; font-size: 14px; opacity: 0.85; }
.leons-popup-close {
    position: absolute; top: 10px; right: 14px;
    background: none; border: 0;
    font-size: 26px; line-height: 1;
    cursor: pointer; color: inherit;
    opacity: 0.55;
}
.leons-popup-close:hover { opacity: 1; }

/* ===========================================================================
 * Floating action buttons (translate, comment) — shared visual style.
 * Stacked above the kenta back-to-top button. Width matches the back-to-top
 * button (42px) so right edges line up. Colors pull from kenta variables so
 * dark/light mode is automatic.
 * =========================================================================== */

/* FAB layout vars live on :root so non-.leons-fab elements (separator,
 * tooltip) can also read them. CSS vars are inherited properties, so
 * everything cascades down naturally.
 *
 * kenta's own --kenta-to-top-* variables are scoped to .kenta-to-top, so
 * we can't read them from here. The values below match kenta's current
 * Customizer settings (48/48). If Leon changes the back-to-top offsets in
 * the Customizer, update these to match. */
:root {
    --leons-fab-side-offset: 48px;
    --leons-fab-bottom-offset: 48px;
    --leons-fab-size: 42px;
    --leons-fab-gap: 8px;
}
.leons-fab {
    position: fixed;
    right: var(--leons-fab-side-offset);
    z-index: 999;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--kenta-accent-active, #1a1a1a);
    color: var(--kenta-base-color, #fff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 20px rgba(44, 62, 80, 0.15);
    transition: transform .15s ease, background .25s ease;
    text-decoration: none;
}
.leons-fab:hover {
    background: var(--kenta-primary-color, #1a1a1a);
    transform: translateY(-1px);
    color: var(--kenta-base-color, #fff);
}
.leons-fab svg { display: block; width: 24px; height: 24px; }

/* Stack slots, counted from the back-to-top button upward. */
.leons-fab--slot-1 { bottom: calc(var(--leons-fab-bottom-offset) + var(--leons-fab-size) + var(--leons-fab-gap)); }
.leons-fab--slot-2 { bottom: calc(var(--leons-fab-bottom-offset) + (var(--leons-fab-size) + var(--leons-fab-gap)) * 2); }

/* Sort-toggle buttons stack directly above the translate FAB on listing
 * pages. Same visual style as translate (kenta accent + white icon) in
 * both active and inactive states — the only visual difference is the
 * small pink direction arrow that appears to the left of the active button.
 * Clicking the active button toggles asc ↔ desc; clicking the inactive
 * one switches sort key (default direction = desc).
 *
 * Stack (bottom → top):
 *   [ to-top         ]  (kenta)
 *   [ translate FAB  ]  slot-1
 *   ─── separator ───
 *   [ sort by views  ]  sort-1
 *   [ sort by date   ]  sort-2
 */
.leons-fab--sort-1 {
    bottom: calc(
        var(--leons-fab-bottom-offset)
        + (var(--leons-fab-size) + var(--leons-fab-gap)) * 2
        + var(--leons-fab-gap)
    );
}
.leons-fab--sort-2 {
    bottom: calc(
        var(--leons-fab-bottom-offset)
        + (var(--leons-fab-size) + var(--leons-fab-gap)) * 3
        + var(--leons-fab-gap)
    );
}
.leons-fab-separator {
    position: fixed;
    right: var(--leons-fab-side-offset, 48px);
    width: var(--leons-fab-size, 42px);
    height: 1px;
    background: rgba(127, 127, 127, 0.35);
    z-index: 999;
    pointer-events: none;
    /* Midpoint of the gap above the translate button's top edge. */
    bottom: calc(
        var(--leons-fab-bottom-offset)
        + var(--leons-fab-size) + var(--leons-fab-gap)
        + var(--leons-fab-size)
        + var(--leons-fab-gap)
    );
}
[data-kenta-theme="dark"] .leons-fab-separator {
    background: rgba(255, 255, 255, 0.22);
}

/* Directional arrow on the active sort button. Small CSS triangle anchored
 * just outside the RIGHT edge of the FAB. The tooltip lives on the left
 * (::after), so the arrow goes opposite to avoid colliding. Color is
 * kenta's primary pink (#f32d71 in Leon's theme). Up = asc, down = desc. */
.leons-fab[aria-current="true"]::before {
    content: '';
    position: absolute;
    right: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
}
.leons-fab[data-dir="desc"]::before {
    border-top: 7px solid var(--kenta-primary-color, #f32d71);
}
.leons-fab[data-dir="asc"]::before {
    border-bottom: 7px solid var(--kenta-primary-color, #f32d71);
}

/* Hover tooltip. Lives on .leons-fab[data-leons-tooltip] elements; pulled
 * from the attribute so each FAB just adds its own label. Shows on hover
 * to the left of the button, dark pill with white text, fades in. */
.leons-fab[data-leons-tooltip]::after {
    content: attr(data-leons-tooltip);
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 1000;
}
.leons-fab[data-leons-tooltip]:hover::after,
.leons-fab[data-leons-tooltip]:focus-visible::after {
    opacity: 1;
}
[data-kenta-theme="dark"] .leons-fab[data-leons-tooltip]::after {
    background: rgba(255, 255, 255, 0.92);
    color: #1a1a1a;
}

/* ===========================================================================
 * Post view-count badge on archive cards. Matches kenta's .meta-item rhythm
 * (date · views) and uses a muted grey so it doesn't compete with the
 * category badge or post title.
 * =========================================================================== */
.leons-views-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--kenta-content-meta-color, #888);
    opacity: 0.85;
    font-variant-numeric: tabular-nums;
}
/* Force outline-eye rendering. Kenta has a global `svg { fill: currentColor }`
 * rule somewhere that beats the SVG's inline fill="none" attribute (CSS wins
 * over presentation attrs), turning the eye into a solid blob. !important
 * required to outrank kenta's authored rule. */
.leons-views-badge svg {
    flex-shrink: 0;
    fill: none !important;
    stroke: currentColor !important;
    opacity: 0.85;
}
[data-kenta-theme="dark"] .leons-views-badge {
    color: var(--kenta-content-meta-color, #aaa);
}
/* Admin-only breakdown (real + manual). Slightly lighter and smaller so
 * the total stays the dominant number. Only ever rendered when the page
 * payload was built for a logged-in admin — never present in anon HTML. */
.leons-views-breakdown {
    font-size: 0.85em;
    opacity: 0.75;
}

/* ===========================================================================
 * Mobile horizontal-overflow guards
 *
 * Two patterns cause post content to extend past the viewport on mobile:
 *
 *   (a) Embedded media wider than the column. Mostly iframes whose inner
 *       content has fixed pixel dimensions (the kenta-archived demos), but
 *       also any image/video missing the standard max-width: 100%.
 *
 *   (b) Long unbreakable inline content. Inline <code> with code-identifier
 *       text like `Player.PlayAmbient(currentLevel.Theme)` has no whitespace
 *       and the dots/parens aren't break points for default `overflow-wrap`.
 *       The token sits at its natural width, dragging the column wider than
 *       the viewport. Same story for long URL anchor text.
 *
 * Fixing each pattern at the source per-post is fragile; these rules catch
 * the entire class. `overflow-wrap: anywhere` allows mid-token breaking
 * only as a last resort — text that already fits keeps its normal flow.
 * =========================================================================== */
.entry-content img,
.entry-content iframe,
.entry-content video,
.entry-content embed,
.entry-content object {
    max-width: 100%;
}
.entry-content iframe {
    /* iframe height is set by the HTML attribute; ensure width never
     * exceeds the column even if the contained page has fixed-width markup. */
    box-sizing: border-box;
}
/* Inline <code> only — NOT code inside <pre> (those are syntax-highlighted
 * blocks that should scroll horizontally inside themselves, not wrap). */
.entry-content :not(pre) > code,
.entry-content p code,
.entry-content li code {
    overflow-wrap: anywhere;
    word-break: break-word;
}
/* Long URLs in anchor text — same fix. Restricted to anchors inside post
 * content so it doesn't affect nav, sidebar widgets, etc. */
.entry-content a {
    overflow-wrap: anywhere;
}
/* Code Block Pro / pre wrappers: keep horizontal overflow inside the
 * block itself, never letting it push the page wider. */
.entry-content pre {
    max-width: 100%;
    overflow-x: auto;
}

/* ===========================================================================
 * Mobile tweaks (≤ 768px)
 * - FABs sit closer to the edge so they don't waste a thumb's worth of
 *   width on small phones.
 * - Match kenta's back-to-top button so the stack stays aligned.
 * =========================================================================== */
@media (max-width: 768px) {
    :root {
        --leons-fab-side-offset: 16px;
        --leons-fab-bottom-offset: 16px;
    }
    .kenta-to-top.kenta-to-top-right {
        right: 16px !important;
        bottom: 16px !important;
    }
}

/* ===========================================================================
 * Cookies-banner overlap
 * When kenta's accept/decline banner is showing, the FAB stack would cover
 * its buttons (or vice versa). JS in custom.js toggles .has-cookies-banner
 * on <body> and sets `--leons-fab-bottom-offset-cookies` to the banner's
 * height; this rule applies that offset to the stack so both stay usable.
 * =========================================================================== */
body.has-cookies-banner {
    --leons-fab-bottom-offset: var(--leons-fab-bottom-offset-cookies, 48px);
}

/* ===========================================================================
 * Side-matter footnotes on mobile
 *
 * The kenta side-matter plugin positions notes alongside their <sup> markers
 * in the desktop sidebar. On narrow viewports there's no sidebar, and the
 * plugin's fallback is to dump the entire .widget_side_matter section at the
 * bottom of the post — which (a) makes the page much longer and (b) loses
 * the in-place reading context.
 *
 * On mobile: hide that bottom widget AND let JS bind a click-to-popup on
 * each <sup> instead. The notes stay in the DOM (just visually hidden) so
 * the JS can pull their HTML for the popup body.
 * =========================================================================== */
@media (max-width: 1023px) {
    .widget_side_matter {
        display: none !important;
    }
    .side-matter-sup {
        cursor: pointer;
        /* Touch-friendly tap target — surround with a bit more clickable
         * area without changing the visual size of the superscript. */
        padding: 0 2px;
        position: relative;
        z-index: 1;
    }
}

/* Side-matter popup — the modal that opens on <sup> tap. Inherits the
 * shared .leons-popup frame; this block only sizes/spaces the content. */
.leons-sm-popup {
    max-width: 520px;
}
.leons-sm-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.6;
    margin: 0 0 8px;
}
.leons-sm-content {
    font-size: 15px;
    line-height: 1.55;
}
.leons-sm-content p:first-child { margin-top: 0; }
.leons-sm-content p:last-child  { margin-bottom: 0; }
.leons-sm-content code {
    font-size: 0.92em;
}
