/* ==========================================================================
   1. Typography / Fonts
   ========================================================================== */
@font-face {
    font-family: 'Monotype Corsiva Custom';
    src: url('../fonts/Monotype-Corsiva.woff2') format('woff2'),
    url('../fonts/Monotype-Corsiva.woff') format('woff');
    font-style: normal;
    font-weight: normal;
    font-display: swap; /* 优化：使用 swap 提升 LCP（最大内容绘制）性能 */
}

@font-face {
    font-family: 'Monotype Corsiva Local';
    src: url('../fonts/Monotype-Corsiva.woff2') format('woff2'),
    url('../fonts/Monotype-Corsiva.woff') format('woff');
    font-style: normal;
    font-weight: normal;
    font-display: swap; /* 优化：使用 swap 提升 LCP（最大内容绘制）性能 */
}

@font-face {
    font-family: 'Georgia Custom';
    src: url('../fonts/Georgia.woff2') format('woff2'),
    url('../fonts/Georgia.woff') format('woff');
    font-style: normal;
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Georgia Custom'; /* 合并同族字体，利用 font-style 区分 */
    src: url('../fonts/Georgia-i.woff2') format('woff2'),
    url('../fonts/Georgia-i.woff') format('woff');
    font-style: italic;
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Georgia Local';
    src: url('../fonts/Georgia.woff2') format('woff2'),
    url('../fonts/Georgia.woff') format('woff');
    font-style: normal;
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Georgia Local'; /* 合并同族字体，利用 font-style 区分 */
    src: url('../fonts/Georgia-i.woff2') format('woff2'),
    url('../fonts/Georgia-i.woff') format('woff');
    font-style: italic;
    font-weight: normal;
    font-display: swap;
}

/* ==========================================================================
   2. Design Tokens / Variables
   ========================================================================== */
:root {
    --global-bg: seashell;

    /* 博客字号共用同一套层级，间距仍以根字号为基准。 */
    --blog-font-body: 0.875rem;
    --blog-font-small: 0.8125rem;
    --blog-font-subheading: 0.9375rem;
    --blog-font-heading: 1rem;

    /* 滚动条颜色 */
    --thumb-bg: rgb(139, 139, 139);
    --thumb-hover-bg: rgb(99, 99, 99);

    /* 选中文本 */
    --selection-text-color: #fff;
    --selection-bg-color: #8fdd89;

    /* 导航栏 */
    --navbar-hover-color: rgb(0, 127, 255);
    --navbar-underline-color: rgba(128, 128, 128, 0.85);

    /* 回到顶部按钮 */
    --scroll-btn-bg: rgba(103, 105, 107, .8);
    --scroll-btn-bg-hover: rgba(62, 63, 65, .9);

    /* 超链接 */
    --link-color: rgb(96, 92, 233);
    --link-hover-color: rgb(0, 115, 230);
    --heading-color: rgb(8, 109, 177);

    /* 边框 */
    --border-color-light: #cdcdcd;
    --border-color-heavy: black;
    --border-color-dark: #666666;
    --layout-color-border-light: #cdcdcd;
    --layout-color-border-dark: #666;
    --layout-color-border-heavy: black;
}

/* ==========================================================================
   3. Reset & Base Settings
   ========================================================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

::selection {
    color: var(--selection-text-color);
    background-color: var(--selection-bg-color);
}

::-moz-selection {
    color: var(--selection-text-color);
    background-color: var(--selection-bg-color);
}

html {
    width: 100%;
    height: 100%;
    font-size: clamp(16px, 0.75vw + 0.2rem, 20px);
}

body {
    width: 100%;
    height: 100%;
    background-color: var(--global-bg);

    font-family: "Merriweather", Times, serif;
    font-optical-sizing: auto;
    font-weight: 300;
    font-style: normal;
    font-variation-settings: "wdth" 100;

    line-height: 1.6;
    font-size: var(--blog-font-body);
    letter-spacing: 0.3px;
    word-spacing: 1.5px;
}

/* ==========================================================================
   4. Layout Containers (Flexbox 架构驱动)
   ========================================================================== */
.app-layout {
    position: relative;
    height: 100dvh;
    overflow-y: auto; /* 优先使用 auto，仅在需要时出现滚动条 */
    overflow-x: hidden;

    /* 构建 Flex 垂直格式化上下文，取代 JS 高度计算 */
    display: flex;
    flex-direction: column;

    &::-webkit-scrollbar {
        display: none;
    }
}

/* Shared container sizing */
.site-header,
.site-main,
.site-footer {
    width: 50%;
    margin: 0 auto;
}

/* ==========================================================================
   5. Header & Navigation
   ========================================================================== */
.site-header {
    border-top: 4px solid var(--layout-color-border-heavy);
    border-bottom: 2px solid var(--layout-color-border-dark);
}

.main-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2.1rem 0 1.15rem;
}

.main-nav__logo {
    font-family: "Monotype Corsiva Local", cursive;
    font-size: 1.75rem;
}

.main-nav__menu {
    display: flex;
    gap: 2.07rem;
    list-style: none;

    font-family: "Georgia Local", Times, serif;
    font-size: var(--blog-font-heading);
    font-style: italic;
}

.main-nav a {
    color: black;
    text-decoration: none;
    transition: color 0.2s ease;
}

.main-nav a:hover,
.main-nav a:focus-visible {
    color: var(--navbar-hover-color);
    outline: none;
}

.main-nav__menu a:hover,
.main-nav__menu a:focus-visible {
    border-bottom: 2px dotted var(--navbar-underline-color);
}

/* ==========================================================================
   6. Main Content & Typography
   ========================================================================== */
.site-main {
    /* 允许主内容区域自动扩张以填满视口剩余空间 */
    flex: 1 0 auto;
    border-top: 1px solid var(--layout-color-border-light);
    border-bottom: 1px solid var(--layout-color-border-light);
    padding-bottom: 2.5rem;
}

/* Keep contextual text available to assistive technology without rendering it. */
.visually-hidden {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ==========================================================================
   7. Footer
   ========================================================================== */
.site-footer {
    /* 严格禁止 Footer 在内容过长时被 Flex 引擎强行压缩 */
    flex-shrink: 0;
    border-top: 1px solid var(--border-color-dark);
    border-bottom: 4px solid var(--border-color-heavy);
    font-size: var(--blog-font-small);
    padding: 30px 0 24px;
    text-align: center;

    & a {
        color: var(--link-color);
        text-decoration: none;
        transition: color 0.2s ease;

        &:hover, &:focus-visible {
            color: var(--link-hover-color);
            text-decoration: underline;
            text-underline-offset: 2px;
            outline: none;
        }
    }
}

.delimiter {
    margin: 0 0.5rem;
    color: #888;
}

/* ==========================================================================
   8. Custom Scrollbar (脱离文档流架构)
   ========================================================================== */
.custom-scrollbar {
    /* 将定位基准切换至 Viewport，彻底免疫 Flex 布局的干扰 */
    position: fixed;
    top: 0;
    right: 2px;
    width: 0;
    height: 100%;
    touch-action: none;
    z-index: 100;

    & .custom-scrollbar__track {
        position: absolute;
        top: 0;
        right: 0;
        width: 8px;
        height: 100%;
    }

    & .custom-scrollbar__thumb {
        position: absolute;
        width: 100%;
        background: var(--thumb-bg);
        top: 0;
        border-radius: 5px;
        transition: background 0.2s ease;
        user-select: none;

        &::after {
            content: "";
            position: absolute;
            top: 0;
            right: -2px;
            width: 2px;
            height: 100%;
            background: transparent;
        }

        &:hover,
        &:active {
            background: var(--thumb-hover-bg);
        }
    }
}

/* ==========================================================================
   9. UI Components (Buttons)
   ========================================================================== */
.scroll-to-top {
    display: none;
    position: fixed;
    right: 60px;
    bottom: 60px;
    z-index: 99;
    width: 43px;
    height: 43px;
    font-size: 18px;
    color: white;
    background-color: var(--scroll-btn-bg);
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    border: none;
    outline: none;
    transition: background-color 0.3s ease;

    &:hover {
        background-color: var(--scroll-btn-bg-hover);
    }

    &:active {
        background-color: rgba(31, 35, 39, .95);
    }
}

/* ==========================================================================
   # DESIGN TOKENS (CSS Variables)
   ========================================================================== */
:root {
    /* Colors - Backgrounds & Overlays */
    --overlay-bg: rgba(15, 23, 42, 0.28);
    --panel-bg: #16181d;
    --input-bg: #1f232b;

    /* Colors - Text */
    --panel-text: #eef2f7;
    --panel-muted: #9aa4b2;
    --input-text: #eef2f7;
    --input-placeholder: #7b8494;

    /* Colors - Borders & Focus States */
    --panel-border: rgba(255, 255, 255, 0.08);
    --input-border: #333946;
    --input-border-focus: #5b8cff;

    /* Colors - Buttons */
    --button-bg: #4f8cff;
    --button-bg-hover: #3f7ae0;
    --button-bg-active: #3468c8;
    --button-text: #ffffff;
    --button-disabled: #5a6472;

    /* Colors - Error States */
    --error-bg: rgba(255, 90, 90, 0.10);
    --error-border: rgba(255, 90, 90, 0.24);
    --error-text: #ffb3b3;

    /* Box Model - Shadows & Radii */
    --shadow-lg: 0 30px 60px rgba(0, 0, 0, 0.30),
    0 10px 20px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.04);
    --radius-lg: 16px;
    --radius-md: 10px;

    /* Animations & Transitions */
    --transition-fast: 160ms ease;
    --transition-normal: 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   # BASE & OVERLAYS
   ========================================================================== */
.admin-panel::backdrop {
    /* Visual */
    background: var(--overlay-bg);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);

    /* Effects */
    animation: overlay-fade-in var(--transition-fast) forwards;
}

/* ==========================================================================
   # LAYOUT & CONTAINER
   ========================================================================== */
.admin-panel {
    /* Box Model */
    width: min(100%, 380px);
    margin: auto;
    padding: 28px;

    /* Typography */
    color: var(--panel-text);
    font-family: inherit;

    /* Visual */
    background: linear-gradient(180deg, #171a20 0%, #14171c 100%);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-md); /* Optimized: Replaced hardcoded 10px with token */
    box-shadow: var(--shadow-lg);

    /* Effects */
    animation: panel-slide-up var(--transition-normal) forwards;
}

.admin-panel__header {
    margin-bottom: 20px;
}

.admin-panel__title {
    font-size: 18px;
    font-weight: bold;
    letter-spacing: -0.02em;
}

/* ==========================================================================
   # FORM COMPONENTS
   ========================================================================== */
.admin-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.input-shell {
    position: relative;
}

.input-icon {
    /* Positioning */
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);

    /* Typography */
    font-size: 14px;

    /* Interaction */
    pointer-events: none;
    user-select: none;
}

.admin-input {
    /* Box Model */
    width: 100%;
    min-height: 46px;
    padding: 12px 14px 12px 38px;

    /* Typography */
    color: var(--input-text);
    font-family: inherit;
    font-size: 13px;

    /* Visual */
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 5px;
    outline: none;

    /* Effects */
    transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-fast);
}

.admin-input::placeholder {
    color: var(--input-placeholder);
}

/* Input States */
.admin-input:focus {
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.14);
}

.admin-input[aria-invalid="true"] {
    border-color: rgba(255, 90, 90, 0.52);
    box-shadow: 0 0 0 3px rgba(255, 90, 90, 0.10);
}

.admin-session-message {
    margin: 0;
    padding: 12px;
    color: var(--panel-text);
    font-size: 13px;
    line-height: 1.45;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--panel-border);
    border-radius: 5px;
}

/* Error Messaging */
.error-message {
    /* Layout */
    display: none;

    /* Box Model */
    min-height: 46px;
    padding: 0 12px;

    /* Typography */
    color: var(--error-text);
    font-size: 13px;

    /* Visual */
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 5px;
}

.error-message.is-visible {
    display: flex;
    align-items: center;
}

/* ==========================================================================
   # BUTTONS & ACTIONS
   ========================================================================== */
.admin-actions {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.admin-button {
    /* Box Model */
    min-height: 44px;
    padding: 0 16px;

    /* Typography */
    font-family: inherit;
    font-size: 14px;
    font-weight: bold;

    /* Visual */
    appearance: none;
    border: 0;
    border-radius: 5px;

    /* Interaction & Effects */
    cursor: pointer;
    transition: transform var(--transition-fast),
    background-color var(--transition-fast),
    opacity var(--transition-fast);
}

/* Button Global States */
.admin-button:active {
    transform: translateY(1px);
}

.admin-button:focus-visible {
    outline: 2px solid rgba(91, 140, 255, 0.95);
    outline-offset: 2px;
}

.admin-button:disabled {
    opacity: 0.72;
    cursor: not-allowed;
    transform: none;
}

/* Button Modifiers */
.admin-button--primary {
    flex: 1;
    background: var(--button-bg);
    color: var(--button-text);
}

.admin-button--primary:hover {
    background: var(--button-bg-hover);
}

.admin-button--primary:active {
    background: var(--button-bg-active);
}

.admin-button--secondary {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--panel-muted);
}

.admin-button--secondary:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--panel-text);
}

/* ==========================================================================
   # KEYFRAMES
   ========================================================================== */
@keyframes overlay-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes panel-slide-up {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
