/* 基础：重置、排版、页面骨架与导航 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-padding-top: calc(var(--topbar-height) + var(--space-4));
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, ol, ul, dl, dd, figure {
    margin: 0;
}

ol, ul {
    padding: 0;
    list-style: none;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
}

mark {
    background: var(--mark);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

kbd {
    font-family: var(--font-mono);
    font-size: 0.8em;
    padding: 1px 6px;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    background: var(--surface);
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    top: var(--space-2);
}

.icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* 顶栏 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--paper) 86%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    max-width: var(--page-width);
    height: var(--topbar-height);
    margin: 0 auto;
    padding: 0 var(--space-5);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
}

.brand-seal {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: var(--cinnabar);
    color: var(--on-accent);
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.brand-name {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: 0.2em;
}

.nav {
    display: flex;
    gap: var(--space-1);
    margin: 0 auto;
}

.nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-full);
    color: var(--ink-3);
    text-decoration: none;
    font-size: var(--text-sm);
    letter-spacing: 0.08em;
    transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.nav-link .icon {
    width: 16px;
    height: 16px;
}

.nav-link:hover {
    color: var(--ink);
    background: var(--surface-sunk);
}

.nav-link[aria-current="page"] {
    color: var(--ink);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    gap: var(--space-1);
}

/* 页面 */
.page {
    max-width: var(--page-width);
    margin: 0 auto;
    padding: var(--space-6) var(--space-5) calc(var(--space-7) + var(--bottom-nav-height));
    outline: none;
}

.view {
    animation: view-in var(--dur) var(--ease-out);
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.view-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.view-title {
    font-family: var(--font-serif);
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: 0.12em;
    line-height: 1.3;
}

.view-desc {
    margin-top: var(--space-1);
    color: var(--ink-3);
    font-size: var(--text-sm);
}

.view-actions {
    display: flex;
    gap: var(--space-2);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}

.startup-error,
.noscript {
    position: fixed;
    inset: auto var(--space-4) var(--space-4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 1px solid var(--cinnabar);
    border-radius: var(--radius-md);
}

/* 窄屏：导航移至底部，避免与内容争夺顶部空间 */
@media (max-width: 720px) {
    :root {
        --topbar-height: 52px;
        --bottom-nav-height: calc(60px + env(safe-area-inset-bottom));
    }

    /* backdrop-filter 会让内部 fixed 元素相对顶栏定位，窄屏改为实色背景 */
    .topbar {
        background: var(--paper);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .topbar-inner {
        padding: 0 var(--space-4);
        justify-content: space-between;
    }

    .nav {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 20;
        justify-content: space-around;
        margin: 0;
        padding: 6px var(--space-2) calc(6px + env(safe-area-inset-bottom));
        background: var(--paper);
        border-top: 1px solid var(--line);
    }

    .nav-link {
        flex-direction: column;
        gap: 2px;
        height: auto;
        min-width: 64px;
        padding: 4px var(--space-2);
        border-radius: var(--radius-md);
        font-size: var(--text-xs);
    }

    .nav-link .icon {
        width: 20px;
        height: 20px;
    }

    .nav-link[aria-current="page"] {
        background: transparent;
        box-shadow: none;
        color: var(--cinnabar);
    }

    .page {
        padding: var(--space-5) var(--space-4) calc(var(--space-6) + var(--bottom-nav-height));
    }

    .view-title {
        font-size: var(--text-xl);
    }
}
