:root {
    color-scheme: light;
    --page: #ffffff;
    --sidebar: #ffffff;
    --surface: #ffffff;
    --ink: #292621;
    --muted: #8b857b;
    --line: #e9e2d6;
    --accent: rgb(255, 153, 0);
    --accent-dark: #965900;
    --accent-soft: #fff0d6;
    --on-accent: #2d1c00;
    --sidebar-width: 286px;
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    color: var(--ink);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

button,
input,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

button,
a,
input,
textarea {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(255, 153, 0, 0.28);
    outline-offset: 3px;
}

button {
    cursor: pointer;
}

svg {
    display: block;
}

[hidden] {
    display: none !important;
}

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

.app-shell {
    display: flex;
    height: 100%;
    min-height: 540px;
    overflow: hidden;
}

.sidebar {
    position: relative;
    z-index: 20;
    display: flex;
    flex: 0 0 var(--sidebar-width);
    flex-direction: column;
    width: var(--sidebar-width);
    min-width: 0;
    padding: 27px 18px 18px;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 8px;
    margin-bottom: 30px;
}

.brand-mark {
    display: grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    color: var(--on-accent);
    background: var(--accent);
    border-radius: 12px;
    place-items: center;
    box-shadow: 0 4px 12px rgba(255, 153, 0, 0.22);
}

.brand-mark svg {
    width: 29px;
    height: 29px;
}

.brand-name {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 26px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.8px;
}

.brand-name span {
    color: var(--accent);
}

.new-chat-button {
    display: flex;
    align-items: center;
    width: 100%;
    height: 48px;
    padding: 0 15px;
    color: var(--on-accent);
    font-size: 14px;
    font-weight: 500;
    background: var(--accent);
    border: 0;
    border-radius: 12px;
    box-shadow: 0 5px 14px rgba(255, 153, 0, 0.2);
    transition: background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.new-chat-button:hover {
    background: #e68a00;
    box-shadow: 0 7px 17px rgba(255, 153, 0, 0.26);
    transform: translateY(-1px);
}

.new-chat-button:active {
    transform: translateY(0);
}

.new-chat-button svg {
    width: 19px;
    height: 19px;
    margin-right: 10px;
}

.new-chat-button kbd {
    padding: 2px 5px;
    margin-left: auto;
    color: rgba(255, 255, 255, 0.56);
    font-family: inherit;
    font-size: 10px;
    font-weight: 400;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.conversation-nav {
    flex: 1;
    min-height: 0;
    margin: 22px -5px 0;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #d8ddd3 transparent;
}

.conversation-list {
    padding: 0 5px;
}

.conversation-group + .conversation-group {
    margin-top: 22px;
}

.conversation-group-title {
    padding: 0 10px;
    margin: 0 0 8px;
    color: #969c91;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 1.5px;
}

.conversation-item {
    position: relative;
    display: flex;
    align-items: center;
    margin: 3px 0;
}

.conversation-button {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    height: 43px;
    padding: 0 34px 0 11px;
    color: #666d63;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 9px;
    transition: color 140ms ease, background 140ms ease;
}

.conversation-button:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.62);
}

.conversation-item.active .conversation-button {
    color: #855100;
    font-weight: 500;
    background: #ffebc7;
}

.conversation-button svg {
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    margin-right: 9px;
    opacity: 0.66;
}

.conversation-button span {
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-chat-button {
    position: absolute;
    right: 7px;
    display: grid;
    width: 25px;
    height: 25px;
    padding: 0;
    color: #80887b;
    background: transparent;
    border: 0;
    border-radius: 6px;
    opacity: 0;
    place-items: center;
    transition: opacity 140ms ease, background 140ms ease;
}

.conversation-item:hover .delete-chat-button,
.delete-chat-button:focus-visible {
    opacity: 1;
}

.delete-chat-button:hover {
    color: #4f594c;
    background: rgba(255, 255, 255, 0.7);
}

.delete-chat-button svg {
    width: 14px;
    height: 14px;
}

.sidebar-close,
.sidebar-backdrop,
.mobile-menu {
    display: none;
}

.chat-panel {
    display: flex;
    flex: 1;
    min-width: 0;
    background: var(--page);
    flex-direction: column;
}

.chat-header {
    display: flex;
    flex: 0 0 83px;
    align-items: center;
    justify-content: space-between;
    padding: 0 38px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}

.chat-header-title {
    display: flex;
    align-items: center;
    min-width: 0;
}

.chat-header h1 {
    max-width: 460px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #d9ded4 transparent;
}

.messages-inner {
    width: min(100%, 880px);
    min-height: 100%;
    padding: 38px 48px;
    margin: 0 auto;
}

.welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 25px 0 30px;
    text-align: center;
    flex-direction: column;
    animation: fade-up 420ms ease both;
}

.welcome-symbol {
    width: 58px;
    height: 58px;
    margin-bottom: 22px;
    color: var(--accent);
}

.welcome-symbol svg {
    width: 100%;
    height: 100%;
}

.welcome h2 {
    margin: 0;
    font-family: "Songti SC", "STSong", Georgia, serif;
    font-size: clamp(29px, 3vw, 39px);
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 1px;
}

.conversation {
    display: flex;
    max-width: 730px;
    margin: 0 auto;
    flex-direction: column;
    gap: 30px;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 13px;
}

.message-avatar {
    display: grid;
    flex: 0 0 31px;
    width: 31px;
    height: 31px;
    margin-top: 1px;
    border-radius: 9px;
    place-items: center;
}

.message-avatar svg {
    width: 19px;
    height: 19px;
}

.message.assistant .message-avatar {
    color: var(--on-accent);
    background: var(--accent);
    box-shadow: 0 3px 9px rgba(255, 153, 0, 0.18);
}

.message.user {
    padding-left: 52px;
    flex-direction: row-reverse;
}

.message.user .message-avatar {
    color: #76654d;
    font-family: Georgia, serif;
    font-size: 12px;
    background: #f1ebdf;
    border: 1px solid #e5dac7;
    border-radius: 50%;
}

.message-body {
    min-width: 0;
    max-width: calc(100% - 44px);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 600;
}

.message-meta time {
    color: #a2a89f;
    font-size: 9px;
    font-weight: 400;
}

.message.user .message-meta {
    justify-content: flex-end;
}

.message-content {
    color: #565049;
    font-size: 13px;
    line-height: 1.9;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-content p {
    margin: 0 0 10px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message.user .message-content {
    padding: 12px 16px;
    color: #5b4a31;
    line-height: 1.7;
    background: #fff1dc;
    border: 1px solid #f2dfc0;
    border-radius: 4px 15px 15px 15px;
}

.message.assistant .message-content {
    padding-top: 1px;
    white-space: normal;
}

.message-content a {
    color: #b26a00;
    text-decoration: underline;
    text-underline-offset: 3px;
    overflow-wrap: anywhere;
}

.message-content a:hover {
    color: #855100;
}

.message.assistant.streaming .message-content::after {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 3px;
    vertical-align: -0.15em;
    background: var(--accent);
    content: "";
    animation: stream-caret 0.9s steps(1) infinite;
}

.markdown-file-list {
    display: grid;
    gap: 8px;
}

.message-content + .markdown-file-list {
    margin-top: 10px;
}

.markdown-file {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 520px;
    min-width: 0;
    padding: 12px 14px;
    color: var(--ink);
    text-align: left;
    background: var(--surface);
    border: 1px solid #eadfcd;
    border-radius: 13px;
    box-shadow: 0 3px 12px rgba(43, 59, 42, 0.04);
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.markdown-file:hover {
    border-color: #f2c46f;
    box-shadow: 0 6px 18px rgba(43, 59, 42, 0.08);
    transform: translateY(-1px);
}

.markdown-file-icon {
    display: grid;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    color: var(--accent-dark);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: -0.3px;
    background: var(--accent-soft);
    border-radius: 10px;
    place-items: center;
}

.markdown-file-copy {
    display: flex;
    min-width: 0;
    margin-left: 12px;
    flex-direction: column;
}

.markdown-file-copy strong {
    overflow: hidden;
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.markdown-file-copy small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
}

.markdown-file > svg {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    margin-left: auto;
    color: #94a18f;
}

body.markdown-preview-open {
    overflow: hidden;
}

.markdown-dialog {
    width: min(960px, calc(100% - 48px));
    max-width: none;
    height: min(88dvh, 960px);
    max-height: none;
    padding: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--surface);
    border: 0;
    border-radius: 18px;
    box-shadow: 0 28px 90px rgba(31, 43, 30, 0.24);
}

.markdown-dialog[open] {
    display: flex;
    flex-direction: column;
}

.markdown-dialog::backdrop {
    background: rgba(30, 38, 29, 0.46);
    backdrop-filter: blur(4px);
}

.markdown-dialog-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    background: #fbfcf9;
    border-bottom: 1px solid var(--line);
}

.markdown-dialog-heading {
    display: flex;
    align-items: center;
    min-width: 0;
}

.markdown-dialog-heading > div {
    min-width: 0;
    margin-left: 12px;
}

.markdown-dialog-heading h2 {
    margin: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.markdown-dialog-heading p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 10px;
}

.markdown-dialog-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 10px;
}

.markdown-download {
    padding: 8px 12px;
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid #f2c46f;
    border-radius: 9px;
}

.markdown-download:hover {
    background: var(--accent-soft);
}

.markdown-download:focus-visible,
.markdown-close:focus-visible {
    outline: 3px solid rgba(255, 153, 0, 0.28);
    outline-offset: 3px;
}

.markdown-close {
    display: grid;
    width: 34px;
    height: 34px;
    padding: 0;
    color: #75816f;
    background: transparent;
    border: 0;
    border-radius: 9px;
    place-items: center;
}

.markdown-close:hover {
    background: #fff0d6;
}

.markdown-close svg {
    width: 20px;
    height: 20px;
}

.markdown-dialog-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
}

.markdown-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    padding: 40px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    flex-direction: column;
}

.markdown-spinner {
    width: 25px;
    height: 25px;
    border: 2px solid #e1e7dc;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: markdown-spin 700ms linear infinite;
}

.markdown-retry {
    padding: 8px 15px;
    color: var(--on-accent);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
}

.markdown-content {
    width: min(100%, 820px);
    padding: 34px 42px 60px;
    margin: 0 auto;
    color: #464038;
    font-size: 15px;
    line-height: 1.85;
    overflow-wrap: anywhere;
}

.markdown-content > :first-child {
    margin-top: 0;
}

.markdown-content > :last-child {
    margin-bottom: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin: 1.7em 0 0.75em;
    color: #2e2923;
    font-weight: 650;
    line-height: 1.4;
}

.markdown-content h1 {
    padding-bottom: 0.55em;
    font-size: 1.75em;
    border-bottom: 1px solid var(--line);
}

.markdown-content h2 {
    padding-bottom: 0.4em;
    font-size: 1.4em;
    border-bottom: 1px solid #edf0e9;
}

.markdown-content h3 {
    font-size: 1.2em;
}

.markdown-content p,
.markdown-content ul,
.markdown-content ol,
.markdown-content blockquote,
.markdown-content pre,
.markdown-content table {
    margin: 0 0 1.2em;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.7em;
}

.markdown-content li + li {
    margin-top: 0.35em;
}

.markdown-content a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.markdown-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.4em auto;
    border-radius: 10px;
}

.markdown-content blockquote {
    padding: 2px 0 2px 16px;
    color: #74806e;
    border-left: 3px solid #f2c46f;
}

.markdown-content code {
    padding: 0.15em 0.4em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.88em;
    background: #f0f3ed;
    border-radius: 5px;
}

.markdown-content pre {
    padding: 16px;
    overflow: auto;
    background: #f4f6f1;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.markdown-content pre code {
    padding: 0;
    background: transparent;
}

.markdown-content table {
    display: block;
    width: 100%;
    overflow: auto;
    border-collapse: collapse;
}

.markdown-content th,
.markdown-content td {
    padding: 8px 12px;
    text-align: left;
    border: 1px solid var(--line);
}

.markdown-content th {
    background: #f4f6f1;
}

.markdown-content hr {
    margin: 2em 0;
    border: 0;
    border-top: 1px solid var(--line);
}

@keyframes markdown-spin {
    to {
        transform: rotate(360deg);
    }
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 26px;
}

.typing-dots i {
    width: 5px;
    height: 5px;
    background: #d89b3c;
    border-radius: 50%;
    animation: typing 1.1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
    animation-delay: 140ms;
}

.typing-dots i:nth-child(3) {
    animation-delay: 280ms;
}

.composer-area {
    flex: 0 0 auto;
    padding: 13px 36px 17px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--page) 18px);
}

.composer-inner {
    width: min(100%, 784px);
    margin: 0 auto;
}

.composer {
    padding: 15px 15px 11px 19px;
    background: var(--surface);
    border: 1px solid #e8dfd1;
    border-radius: 17px;
    box-shadow: 0 6px 26px rgba(43, 59, 42, 0.06), 0 1px 3px rgba(43, 59, 42, 0.03);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer:focus-within {
    border-color: #f2c46f;
    box-shadow: 0 7px 28px rgba(109, 75, 24, 0.08), 0 0 0 3px rgba(255, 153, 0, 0.08);
}

.composer textarea {
    display: block;
    width: 100%;
    max-height: 150px;
    padding: 0 3px;
    resize: none;
    overflow-y: auto;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.6;
    background: transparent;
    border: 0;
    outline: 0;
}

.composer textarea::placeholder {
    color: #a2a89e;
}

.composer-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-top: 10px;
}

.composer-hint {
    display: flex;
    align-items: center;
    gap: 13px;
    min-height: 30px;
}

.model-pill {
    display: flex;
    align-items: center;
    color: #687362;
    font-size: 9px;
    font-weight: 500;
}

.model-pill > span {
    width: 5px;
    height: 5px;
    margin-right: 5px;
    background: var(--accent);
    border-radius: 50%;
}

.keyboard-hint {
    color: #adb2a8;
    font-size: 9px;
}

.keyboard-hint kbd {
    font-family: inherit;
}

.send-button {
    display: grid;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    padding: 0;
    color: var(--on-accent);
    background: var(--accent);
    border: 0;
    border-radius: 10px;
    place-items: center;
    transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.send-button svg {
    width: 17px;
    height: 17px;
}

.send-button:hover:not(:disabled) {
    background: #e68a00;
    transform: translateY(-1px);
}

.send-button:disabled {
    color: #aaa297;
    background: #f1ede6;
    cursor: default;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes stream-caret {
    50% {
        opacity: 0;
    }
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

@media (max-width: 980px) {
    :root {
        --sidebar-width: 256px;
    }

    .sidebar {
        padding-right: 14px;
        padding-left: 14px;
    }

    .chat-header {
        padding: 0 26px;
    }

    .messages-inner {
        padding-right: 34px;
        padding-left: 34px;
    }

    .composer-area {
        padding-right: 27px;
        padding-left: 27px;
    }
}

@media (max-width: 720px) {
    .app-shell {
        min-height: 480px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 280px;
        transform: translateX(-102%);
        transition: transform 220ms ease;
        box-shadow: 12px 0 36px rgba(32, 44, 31, 0.12);
    }

    body.sidebar-open {
        overflow: hidden;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-close {
        display: grid;
        width: 30px;
        height: 30px;
        margin-left: auto;
    }

    .sidebar-backdrop {
        position: fixed;
        z-index: 10;
        inset: 0;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgba(32, 38, 31, 0.26);
        border: 0;
        opacity: 0;
        pointer-events: none;
        transition: opacity 220ms ease;
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-menu {
        display: grid;
        margin-right: 12px;
    }

    .icon-button {
        width: 34px;
        height: 34px;
        padding: 0;
        color: #76654d;
        background: transparent;
        border: 0;
        border-radius: 8px;
        place-items: center;
    }

    .icon-button:hover {
        background: #f4ecdd;
    }

    .icon-button svg {
        width: 20px;
        height: 20px;
    }

    .chat-header {
        flex-basis: 73px;
        padding: 0 18px;
    }

    .chat-header h1 {
        max-width: min(54vw, 380px);
        font-size: 13px;
    }

    .messages-inner {
        padding: 25px 20px;
    }

    .welcome {
        padding-top: 14px;
    }

    .welcome-symbol {
        width: 47px;
        height: 47px;
        margin-bottom: 16px;
    }

    .composer textarea {
        font-size: 14px;
    }

    .composer-area {
        padding: 10px 16px 13px;
    }

    .keyboard-hint {
        display: none;
    }

    .markdown-dialog {
        width: 100%;
        height: 100dvh;
        margin: 0;
        border-radius: 0;
    }

    .markdown-dialog-header {
        gap: 8px;
        padding: 13px 14px;
    }

    .markdown-dialog-heading .markdown-file-icon {
        flex-basis: 32px;
        width: 32px;
        height: 32px;
    }

    .markdown-dialog-heading > div {
        margin-left: 9px;
    }

    .markdown-dialog-actions {
        gap: 6px;
    }

    .markdown-download {
        padding: 7px 9px;
        font-size: 11px;
    }

    .markdown-content {
        padding: 25px 20px 45px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .messages-inner {
        padding: 22px 16px;
    }

    .welcome h2 {
        font-size: 28px;
    }

    .message {
        gap: 9px;
    }

    .message.user {
        padding-left: 25px;
    }

    .message-content {
        font-size: 12px;
    }

    .conversation {
        gap: 24px;
    }

    .composer {
        padding-left: 15px;
        border-radius: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
