/*
 * Light / Dark / Auto color mode for the frontend.
 * <html data-theme="light|dark"> is set by the inline head script (resolved value),
 * <html data-theme-pref="light|dark|auto"> holds the user's choice.
 * Light mode keeps the original palette from resources/css/app.css.
 */
html[data-theme="light"] { color-scheme: light; }

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220;
    --bg-soft: #111a2b;
    --surface: #131d30;
    --surface-2: #1a263c;
    --surface-3: #22314d;
    --text: #e6edf7;
    --muted: #9aabc4;
    --line: rgba(148, 178, 230, 0.16);
    --primary: #f87171;
    --primary-strong: #ef4444;
    --accent: #60a5fa;
    --accent-2: #fbbf24;
    --accent-3: #34d399;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
}

/* Hard-coded light values in app.css that variables do not cover. */
html[data-theme="dark"] body { background: linear-gradient(180deg, #0b1220 0%, #0e1729 100%); }
html[data-theme="dark"] .site-header { background: rgba(11, 18, 32, 0.92); }
html[data-theme="dark"] .site-nav { background: linear-gradient(90deg, rgba(248, 113, 113, 0.08), rgba(96, 165, 250, 0.1), rgba(52, 211, 153, 0.08)); }
html[data-theme="dark"] .site-nav a { background: rgba(255, 255, 255, 0.06); }
html[data-theme="dark"] .site-nav a:hover,
html[data-theme="dark"] .sidebar-nav a:hover,
html[data-theme="dark"] .sidebar-article:hover,
html[data-theme="dark"] .sidebar-link:hover,
html[data-theme="dark"] .footer-links a:hover { box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35); }
html[data-theme="dark"] .pill { background: rgba(251, 191, 36, 0.14); color: #fcd34d; }
html[data-theme="dark"] .tag-cloud a { background: rgba(96, 165, 250, 0.14); }
html[data-theme="dark"] .list-order { background: rgba(96, 165, 250, 0.08); }
html[data-theme="dark"] .button-main { background: var(--primary-strong); }
html[data-theme="dark"] .button-main:hover { background: #dc2626; }
html[data-theme="dark"] .pagination-wrap span[aria-current="page"] span { background: #2563eb; border-color: #2563eb; }

/* Article HTML from the editor: keep tables/quotes/code readable in dark mode. */
html[data-theme="dark"] .article-body a { color: var(--accent); }
html[data-theme="dark"] .article-body blockquote { border-left: 4px solid var(--line); margin-left: 0; padding-left: 16px; color: var(--muted); }
html[data-theme="dark"] .article-body table,
html[data-theme="dark"] .article-body th,
html[data-theme="dark"] .article-body td { border-color: var(--line); }
html[data-theme="dark"] .article-body pre,
html[data-theme="dark"] .article-body code { background: var(--surface-2); color: var(--text); }

/* Theme switcher (header). */
.theme-switch {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-2);
}
.theme-switch button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
html[data-theme="dark"] .theme-switch button[aria-pressed="true"] { background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.35); }
@media (max-width: 480px) { .theme-switch button span { display: none; } }

/* Smooth swap when the user changes theme (not on first paint). */
html.theme-transition,
html.theme-transition * { transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease !important; }
