* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root,
html {
    --nav-gap: 0.7rem;
    --nav-margin-bottom: 0.8rem;
    --nav-padding-block: 0.65rem;
    --nav-padding-inline: 0.8rem;
    --nav-control-size: 42px;
    --bg-gradient-start: #f8f5f0;
    --bg-gradient-end: #e8e0d5;
    --surface: rgba(255, 250, 240, 0.85);
    --surface-solid: #fffaf0;
    --surface-muted: rgba(255, 247, 235, 0.92);
    --text-primary: #2c2418;
    --text-secondary: #5e4b3c;
    --accent-gold: #c9a03d;
    --accent-red: #b34e3a;
    --border-light: rgba(180, 140, 100, 0.25);
    --chat-bubble-user: #e6dfd3;
    --chat-bubble-ai: #fff6ea;
    --input-bg: #ffffffcc;
    --toggle-bg: #d9cdb0;
    --sidebar-bg: rgba(253, 247, 237, 0.94);
    --sidebar-card: rgba(255, 255, 255, 0.72);
    --sidebar-card-hover: rgba(255, 250, 241, 0.98);
    --sidebar-card-active: rgba(245, 229, 191, 0.92);
    --toolbar-bg: rgba(255, 250, 240, 0.94);
    --nav-bg: linear-gradient(180deg, rgba(255, 250, 240, 0.78), rgba(255, 250, 240, 0.42));
    --nav-border: rgba(180, 140, 100, 0.16);
    --chat-main-bg: rgba(255, 252, 246, 0.5);
    --panel-shadow: 0 20px 48px -26px rgba(47, 31, 12, 0.28);
    --sidebar-header-glow: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent);
    --glass-blur: 18px;
    --glass-blur-strong: 28px;
    --glass-saturate: 160%;
    --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.28);
    --glass-outline: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

html.dark,
html:has(body.dark),
body.dark {
    --bg-gradient-start: #0a0c12;
    --bg-gradient-end: #11151c;
    --surface: rgba(17, 21, 28, 0.9);
    --surface-solid: #171c24;
    --surface-muted: rgba(15, 19, 26, 0.97);
    --text-primary: #ece7e0;
    --text-secondary: #bcae9a;
    --accent-gold: #e6b450;
    --chat-bubble-user: #242a35;
    --chat-bubble-ai: #1b212b;
    --input-bg: rgba(31, 37, 48, 0.9);
    --toggle-bg: #3e3a30;
    --sidebar-bg: rgba(13, 17, 23, 0.98);
    --sidebar-card: rgba(29, 35, 45, 0.92);
    --sidebar-card-hover: rgba(35, 42, 54, 0.98);
    --sidebar-card-active: rgba(66, 54, 31, 0.78);
    --toolbar-bg: rgba(20, 25, 33, 0.97);
    --nav-bg: linear-gradient(180deg, rgba(13, 17, 23, 0.82), rgba(13, 17, 23, 0.46));
    --nav-border: rgba(230, 180, 80, 0.18);
    --chat-main-bg: rgba(18, 23, 31, 0.94);
    --panel-shadow: 0 24px 56px -30px rgba(0, 0, 0, 0.62);
    --sidebar-header-glow: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
    --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    --glass-outline: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

body {
    font-family: "Inter", sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    min-height: 100vh;
    color: var(--text-primary);
    transition: background 0.3s, color 0.2s;
    overflow-x: hidden;
}

html.dark,
html:has(body.dark) {
    background: linear-gradient(135deg, #0a0c12, #11151c);
}

html.dark body,
html:has(body.dark) body,
body.dark {
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-primary);
}

html.dark body::before,
html:has(body.dark) body::before,
body.dark::before {
    opacity: 0.35;
}

body.chat-active {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
}

body.chat-active .app-container {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 1200" opacity="0.08"><path fill="none" stroke="%23c9a03d" stroke-width="1.2" d="M100 200 L120 180 L140 210 L180 170 M620 800 L650 770 L680 810 M300 950 L310 930 L330 960 M500 400 L520 380 L540 410 L570 390" stroke-linecap="round"/><path d="M700 100 L720 90 L710 70 M40 1050 L60 1040 L50 1020" stroke="%23b34e3a" stroke-width="1.5" fill="none"/><circle cx="420" cy="600" r="2" fill="%23c9a03d"/><circle cx="350" cy="700" r="1.5" fill="%23c9a03d"/></svg>');
    background-repeat: repeat;
    background-size: 180px;
    pointer-events: none;
    z-index: 0;
}

.app-container {
    position: relative;
    z-index: 2;
    max-width: 1520px;
    margin: 0 auto;
    padding: 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.chat-active .app-container {
    max-width: none;
    padding: 1.5rem;
}

body.dialog-open {
    overflow: hidden;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: var(--nav-margin-bottom);
    padding: var(--nav-padding-block) var(--nav-padding-inline);
    background: var(--nav-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 0;
    border-bottom: 1px solid var(--nav-border);
    border-radius: 0;
    margin-top: -1.5rem;
    margin-left: -1.5rem;
    margin-right: -1.5rem;
}

.site-dialog {
    position: fixed;
    inset: 0;
    z-index: 1800;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.2rem;
}

.site-dialog.is-open {
    display: flex;
}

.site-dialog-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(13, 10, 8, 0.42);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.site-dialog-panel {
    position: relative;
    z-index: 1;
    width: min(440px, calc(100vw - 2rem));
    padding: 1.25rem 1.15rem 1.1rem;
    border-radius: 22px;
    border: 1px solid var(--border-light);
    background: var(--surface);
    backdrop-filter: blur(var(--glass-blur-strong)) saturate(var(--glass-saturate));
    -webkit-backdrop-filter: blur(var(--glass-blur-strong)) saturate(var(--glass-saturate));
    box-shadow: var(--panel-shadow), var(--glass-highlight), var(--glass-outline);
}

.site-dialog-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.36rem 0.72rem;
    border-radius: 999px;
    border: 1px solid rgba(201, 160, 61, 0.26);
    background: rgba(201, 160, 61, 0.12);
    color: var(--text-primary);
    font-size: 0.82rem;
}

.site-dialog-title {
    margin-top: 0.95rem;
    font-family: "Noto Serif SC", serif;
    font-size: 1.35rem;
    line-height: 1.3;
}

.site-dialog-message {
    margin-top: 0.7rem;
    color: var(--text-secondary);
    line-height: 1.75;
    font-size: 0.96rem;
}

.site-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    margin-top: 1.15rem;
}

.site-dialog-btn {
    -webkit-appearance: none;
    appearance: none;
    min-width: 108px;
    min-height: 44px;
    padding: 0.72rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    color: var(--text-primary);
}

.site-dialog-btn-secondary {
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    background: var(--input-bg);
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
}

.site-dialog-btn-primary {
    border: 0;
    color: #1f1b14;
    background: linear-gradient(95deg, var(--accent-gold), #c48a3c);
    box-shadow: 0 14px 28px -20px rgba(201, 160, 61, 0.72);
}

@media (max-width: 680px) {
    .site-dialog {
        align-items: flex-end;
        padding: 0.8rem;
    }

    .site-dialog-panel {
        width: 100%;
        border-bottom-left-radius: 18px;
        border-bottom-right-radius: 18px;
        padding: 1rem 0.95rem calc(0.95rem + env(safe-area-inset-bottom));
    }

    .site-dialog-title {
        font-size: 1.18rem;
    }

    .site-dialog-message {
        font-size: 0.92rem;
    }

    .site-dialog-actions {
        flex-direction: column-reverse;
    }

    .site-dialog-btn {
        width: 100%;
    }
}

.logo {
    font-family: "Noto Serif SC", serif;
    font-size: 1.8rem;
    font-weight: 700;
    text-decoration: none;
    background: linear-gradient(135deg, var(--accent-gold), #d4993b);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    letter-spacing: 2px;
    line-height: 1.2;
}

.theme-toggle {
    background: var(--toggle-bg);
    border: none;
    width: 42px;
    height: 42px;
    min-height: var(--nav-control-size);
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    gap: 0;
    align-items: center;
    color: var(--text-primary);
    font-size: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.round-nav-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border-light);
    border-radius: 50%;
    background: var(--input-bg);
    color: var(--text-primary);
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
}

.round-nav-btn i {
    font-size: 1rem;
    line-height: 1;
}

.theme-icon {
    width: 17px;
    height: 17px;
    fill: currentColor;
    display: block;
}

@media (max-width: 680px) {
    .app-container {
        width: 100%;
        padding: 0.9rem;
    }

    body.chat-active .app-container {
        height: 100dvh;
        max-height: 100dvh;
        padding: 0.9rem 0.9rem max(0.35rem, env(safe-area-inset-bottom));
    }

    .header {
        align-items: center;
        flex-wrap: nowrap;
        gap: 0.75rem;
        margin-bottom: var(--nav-margin-bottom);
        padding: var(--nav-padding-block) var(--nav-padding-inline);
        margin-top: -0.9rem;
        margin-left: -0.9rem;
        margin-right: -0.9rem;
    }

    .logo {
        font-size: 1.35rem;
        line-height: 1.25;
        letter-spacing: 1px;
    }

    .logo span {
        display: inline;
        font-size: 0.88rem;
        margin-top: 0;
    }

    .logo {
        flex: 1;
        min-width: 0;
    }

    .theme-toggle {
        width: 40px;
        height: 40px;
        min-height: 40px;
        flex: 0 0 40px;
    }

    .round-nav-btn {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 420px) {
    .header {
        align-items: center;
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .theme-toggle {
        width: 38px;
        height: 38px;
        min-height: 38px;
        flex: 0 0 38px;
    }

    .round-nav-btn {
        width: 38px;
        height: 38px;
    }
}

.seal-mark {
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-size: 0.7rem;
    opacity: 0.4;
    pointer-events: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
