/* ==========================================================================
   me.shigure.io — shared theme
   Light is the default (also what visitors see with JavaScript disabled).
   Dark applies through <html data-theme="dark">.
   Load this AFTER each page's own <style> so these tokens win.
   ========================================================================== */

:root {
    color-scheme: light;

    /* Surfaces */
    --bg-primary: #f7f8fb;
    --bg-secondary: rgba(15, 23, 42, 0.035);
    --bg-tertiary: rgba(15, 23, 42, 0.05);
    --bg-hover: rgba(15, 23, 42, 0.065);
    --bg-card: #ffffff;

    /* Borders */
    --border-primary: rgba(15, 23, 42, 0.08);
    --border-secondary: rgba(15, 23, 42, 0.13);
    --border-hover: rgba(63, 99, 214, 0.38);

    /* Text */
    --text-primary: #14161c;
    --text-secondary: #3a4050;
    --text-tertiary: #4d5566;
    --text-muted: #5f6779;
    --text-dimmed: #656d7f;

    /* Accent */
    --accent: #3f63d6;
    --accent-hover: #2b4cb8;
    --accent-muted: #7b8ab0;
    --accent-soft: rgba(63, 99, 214, 0.09);
    --accent-glow: rgba(63, 99, 214, 0.26);
    --accent-faint: rgba(63, 99, 214, 0.05);
    --on-accent: #ffffff;

    /* Feedback */
    --success-bg: rgba(63, 99, 214, 0.1);
    --success-border: rgba(63, 99, 214, 0.3);
    --success-text: #2b4cb8;

    /* Semantic status (kept distinct from the accent) */
    --status-ok: #0a6f4b;
    --status-ok-soft: rgba(15, 138, 95, 0.12);
    --status-warn: #9a4a08;
    --status-warn-soft: rgba(180, 83, 9, 0.12);
    --status-err: #cf222e;
    --status-err-soft: rgba(207, 34, 46, 0.1);

    /* Effects */
    --inset-highlight: rgba(255, 255, 255, 0.9);
    --shadow-text: none;
    --shadow-card: 0 12px 30px rgba(23, 33, 64, 0.1);

    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "Noto Sans JP", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

    --bg-primary: #111216;
    --bg-secondary: rgba(255, 255, 255, 0.035);
    --bg-tertiary: rgba(255, 255, 255, 0.045);
    --bg-hover: rgba(255, 255, 255, 0.075);
    --bg-card: #18191f;

    --border-primary: rgba(255, 255, 255, 0.075);
    --border-secondary: rgba(255, 255, 255, 0.12);
    --border-hover: rgba(190, 207, 255, 0.34);

    --text-primary: #f4f6fb;
    --text-secondary: #d7dce6;
    --text-tertiary: #b8bfcc;
    --text-muted: #8b93a3;
    --text-dimmed: #7c8496;

    --accent: #9db7ff;
    --accent-hover: #c7d5ff;
    --accent-muted: #8f9fbd;
    --accent-soft: rgba(157, 183, 255, 0.08);
    --accent-glow: rgba(157, 183, 255, 0.34);
    --accent-faint: rgba(157, 183, 255, 0.03);
    --on-accent: #10131c;

    --success-bg: rgba(157, 183, 255, 0.12);
    --success-border: rgba(157, 183, 255, 0.28);
    --success-text: #c7d5ff;

    --status-ok: #34d399;
    --status-ok-soft: rgba(52, 211, 153, 0.14);
    --status-warn: #f5b544;
    --status-warn-soft: rgba(245, 181, 68, 0.14);
    --status-err: #f85149;
    --status-err-soft: rgba(248, 81, 73, 0.1);

    --inset-highlight: rgba(255, 255, 255, 0.035);
    --shadow-text: 0 14px 42px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 12px 34px rgba(0, 0, 0, 0.2);
}

/* Short aliases used by the older pages, so their CSS needs no renaming. */
:root {
    --bg: var(--bg-primary);
    --bg-2: var(--bg-card);
    --panel: var(--bg-card);
    --ink: var(--text-primary);
    --text: var(--text-primary);
    --muted: var(--text-muted);
    --line: var(--border-primary);
    --soft: var(--accent-soft);
}

/* ==========================================================================
   Shared UI primitives
   ========================================================================== */

/* Page canvas: keeps the iOS overscroll / safe-area edges from flashing white. */
html {
    background-color: var(--bg-primary);
}

.top-controls,
.topbar-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 var(--inset-highlight);
}

.top-controls {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 100;
}

/* In-flow controls for pages that already have a header bar (leverage). */
.topbar-controls {
    flex: 0 0 auto;
}

@media (max-width: 1024px) {
    .top-controls {
        position: static;
        width: fit-content;
        margin: 0 0 24px auto;
    }
}

.lang-switcher,
.languages {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.lang-btn,
.languages button,
.lang > button {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: 0;
    color: var(--text-dimmed);
    padding: 6px 11px;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.4;
    min-width: 0;
    height: auto;
    transition: color 0.18s ease, background 0.18s ease;
}

.lang-btn:hover,
.languages button:hover,
.lang > button:hover {
    color: var(--text-tertiary);
    background: var(--bg-hover);
}

.lang-btn.active,
.languages button[aria-pressed="true"],
.lang > button.active {
    background: var(--accent-soft);
    color: var(--text-primary);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 999px;
    box-shadow: none;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.theme-toggle svg {
    width: 17px;
    height: 17px;
    display: block;
}

/* Light (the default) shows the moon; dark shows the sun. */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (max-width: 768px) {
    .lang-btn,
    .languages button,
    .lang > button {
        min-height: 40px;
    }
    .theme-toggle {
        width: 40px;
        height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lang-btn,
    .languages button,
    .lang > button,
    .theme-toggle {
        transition: none;
    }
}
