/* ==========================================================================
   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;
    }
}

/* ==========================================================================
   Site menu — 默认隐藏；向下滚动时滑入，向上滚动时收起
   （放在共享 theme.css 里，所有带 #siteMenu 的页面共用）
   ========================================================================== */

.site-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    /* 半透明 + 毛玻璃，浅色 / 深色分别取值 */
    background: rgba(247, 248, 251, 0.72);
    border-bottom: 1px solid var(--border-primary);
    -webkit-backdrop-filter: blur(16px) saturate(1.6);
    backdrop-filter: blur(16px) saturate(1.6);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-100%);
    transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.2, 1),
                opacity 0.2s ease,
                visibility 0.28s;
    will-change: transform, opacity;
}

:root[data-theme="dark"] .site-menu {
    background: rgba(17, 18, 22, 0.72);
}

.site-menu.is-visible {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.site-menu-brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
    text-decoration: none;
    opacity: 0.85;
    transition: opacity 0.18s ease, color 0.18s ease;
}

.site-menu-brand::before {
    content: "";
    width: 3px;
    height: 15px;
    border-radius: 2px;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.site-menu-brand:hover,
.site-menu-brand:focus-visible {
    opacity: 1;
    color: var(--accent);
}

@media (max-width: 520px) {
    .site-menu {
        padding-left: 16px;
        padding-right: 16px;
        gap: 10px;
    }
    .site-menu-brand {
        font-size: 0.8rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-menu {
        transition: none;
    }
}

/* ==========================================================================
   Back button — 子页面底部的「返回主页」按钮（浅色胶囊）
   淡蓝底 + 蓝字，无边框无阴影；悬停变实心蓝，深色模式自动适配
   ========================================================================== */

a.site-back {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 11px 20px;
    border: 0;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 550;
    line-height: 1.25;
    text-decoration: none;
    transition: background-color 0.18s ease, color 0.18s ease,
                box-shadow 0.18s ease, transform 0.18s ease;
}

a.site-back svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

a.site-back:hover,
a.site-back:focus-visible {
    background: var(--accent);
    color: var(--on-accent);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px -12px rgba(63, 99, 214, 0.55);
}

a.site-back:active {
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    a.site-back {
        transition: none;
    }
}
