/* Dark mode
/* ----------------------------------------------------------
   Loaded after built/screen.css (see default.hbs). Active when
   <html data-theme="dark">, which the inline script in default.hbs sets
   from the visitor's toggle choice, the site setting, or the device.

   --color-white is NOT redefined: the theme also uses it for text on top of
   photos (post cards, lightbox), which must stay white. Surfaces that use
   it as a background are overridden one by one below instead.
/* ---------------------------------------------------------- */

html[data-theme="dark"] {
    color-scheme: dark;

    --dm-bg: #111;
    --dm-surface: #1c1c1c;

    /* Shared Ghost theme variables */
    --color-primary-text: #d4d4d4;
    --color-secondary-text: #8c8c8c;
    --color-lighter-gray: #1c1c1c;
    --color-light-gray: #2e2e2e;
    --color-mid-gray: #444;
    --color-dark-gray: #bbb;
    --color-darker-gray: #f0f0f0;

    /* London's own variables */
    --color-base: #f0f0f0;
    --color-border: #2e2e2e;
}

/* Page and header backgrounds */
html[data-theme="dark"] body,
html[data-theme="dark"] .gh-head,
html[data-theme="dark"] .is-head-open:not(.is-head-brand):not(.is-head-dark):not(.is-head-transparent) #gh-head,
html[data-theme="dark"] .is-head-open #gh-head .gh-head-actions {
    background-color: var(--dm-bg);
}

/* Dark text on light buttons would invert badly: keep buttons readable */
html[data-theme="dark"] .gh-btn {
    color: var(--dm-bg);
}

/* "More" dropdown in the navigation */
html[data-theme="dark"] .gh-dropdown {
    background-color: var(--dm-surface);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 7px 20px -5px rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] .gh-dropdown li a {
    color: var(--color-primary-text) !important;
}

/* Share button on posts */
html[data-theme="dark"] .gh-button-share {
    color: rgba(255, 255, 255, 0.85);
    border-color: rgba(255, 255, 255, 0.2);
}

html[data-theme="dark"] .gh-button-share:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

/* Tables in post content */
html[data-theme="dark"] .gh-content table:not(.gist table) th {
    background-color: var(--dm-bg);
}

html[data-theme="dark"] .gh-content table:not(.gist table) td:first-child {
    background-image: linear-gradient(90deg, var(--dm-bg) 50%, rgba(17, 17, 17, 0));
}

html[data-theme="dark"] .gh-content table:not(.gist table) td:last-child {
    background-image: linear-gradient(270deg, var(--dm-bg) 50%, rgba(17, 17, 17, 0));
}

/* Fade above members-only call-to-action */
html[data-theme="dark"] .gh-cta-gradient {
    background: linear-gradient(180deg, rgba(17, 17, 17, 0), var(--dm-bg));
}

/* Editor cards that hard-code a white background */
html[data-theme="dark"] .kg-audio-card,
html[data-theme="dark"] .kg-bookmark-card a.kg-bookmark-container,
html[data-theme="dark"] .kg-bookmark-card a.kg-bookmark-container:hover,
html[data-theme="dark"] .kg-file-card-container,
html[data-theme="dark"] .kg-file-card-container:hover,
html[data-theme="dark"] .kg-product-card-container {
    background: var(--dm-surface) !important;
    color: var(--color-primary-text) !important;
}

html[data-theme="dark"] .kg-bookmark-container,
html[data-theme="dark"] .kg-callout-card-grey,
html[data-theme="dark"] .kg-toggle-card {
    border-color: var(--color-border);
}

/* Optional: make a dark logo image visible (setting "Invert logo in dark mode") */
html[data-theme="dark"] .has-dm-invert-logo .gh-head-logo img {
    filter: invert(1);
}

/* Theme toggle button
/* ---------------------------------------------------------- */

.gh-theme-toggle {
    color: var(--color-darker-gray);
}

.gh-theme-toggle:hover {
    opacity: 0.8;
}

.gh-theme-toggle .icon-sun,
html[data-theme="dark"] .gh-theme-toggle .icon-moon {
    display: none;
}

html[data-theme="dark"] .gh-theme-toggle .icon-sun {
    display: block;
}

/* Same placement rules as the search button: the one in the logo bar is for
   mobile, the one in the header actions for desktop */
@media (min-width: 768px) {
    .gh-head-brand .gh-theme-toggle {
        display: none;
    }
}

@media (max-width: 767px) {
    .gh-head-actions .gh-theme-toggle {
        display: none;
    }

    .gh-head-brand .gh-theme-toggle {
        margin-right: 8px;
    }
}

/* Stacked layout: keep the toggle on the right */
.is-head-stacked .gh-head-actions .gh-theme-toggle {
    margin-left: auto;
}

/* Header styles with a coloured or transparent background keep white icons */
.is-head-transparent .gh-theme-toggle,
.is-head-dark:not(.is-head-transparent) .gh-theme-toggle,
.is-head-brand:not(.is-head-transparent) .gh-theme-toggle {
    color: var(--color-white);
}
