:root {
    --bg: #f3efe5;
    --panel: #fffdf8;
    --panel-2: #f8f2e8;
    --text: #1d1a16;
    --muted: #6b6257;
    --line: #d8cdbd;
    --accent: #b45309;
    --accent-dark: #7c2d12;
    --user: #dbeafe;
    --assistant: #fef3c7;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(180, 83, 9, 0.12), transparent 30%),
        linear-gradient(180deg, #f9f4ea 0%, var(--bg) 100%);
}

.container {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 40px 0 64px;
}

.container.narrow {
    width: min(900px, calc(100% - 32px));
}

.hero {
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: rgba(255, 253, 248, 0.88);
    backdrop-filter: blur(8px);
}

.eyebrow,
.meta,
.back-link {
    color: var(--muted);
}

.lead {
    max-width: 620px;
}

.card-grid,
.info-grid {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

.card-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.info-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card,
.info-card,
.chat-shell,
.challenge-head {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
}

.card,
.info-card,
.challenge-head {
    padding: 24px;
}

.button {
    display: inline-block;
    padding: 10px 16px;
    border: 0;
    border-radius: 999px;
    color: #fff;
    text-decoration: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    cursor: pointer;
}

.button.secondary {
    background: #eadfce;
    color: var(--text);
}

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    text-decoration: none;
}

.chat-shell {
    margin-top: 24px;
    overflow: hidden;
}

.chat-log {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 420px;
    padding: 20px;
    overflow-y: auto;
    background: var(--panel-2);
}

.bubble {
    max-width: 80%;
    padding: 14px 16px;
    border-radius: 18px;
    line-height: 1.6;
}

.bubble p {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble.assistant {
    align-self: flex-start;
    background: var(--assistant);
}

.bubble.user {
    align-self: flex-end;
    background: var(--user);
}

.chat-form {
    padding: 20px;
    border-top: 1px solid var(--line);
    background: var(--panel);
}

textarea {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    resize: vertical;
    font: inherit;
    background: #fff;
}

input[type="text"] {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    font: inherit;
    background: #fff;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    justify-content: space-between;
}

.flag-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
}

.flag-result {
    min-height: 24px;
    margin: 12px 0 0;
    color: var(--muted);
}

.flag-result.success {
    color: #166534;
}

.flag-result.error {
    color: #b91c1c;
}

.flag-modal {
    width: calc(100% - 24px);
    max-width: 520px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    color: var(--text);
}

.flag-modal::backdrop {
    background: rgba(29, 26, 22, 0.35);
    backdrop-filter: blur(2px);
}

.flag-modal .flag-form {
    width: 100%;
    margin: 0;
    padding: 24px;
}

.modal-head {
    position: relative;
    padding-right: 48px;
}

.modal-head h2 {
    margin: 0;
}

.flag-modal input[type="text"] {
    width: 100%;
    min-width: 0;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    align-items: center;
}

.modal-actions .button {
    flex: 0 0 auto;
}

.modal-close {
    position: absolute;
    top: 0;
    right: 0;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

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

@media (max-width: 640px) {
    .container {
        width: min(100% - 20px, 1120px);
        padding-top: 20px;
    }

    .bubble {
        max-width: 92%;
    }

    .form-actions {
        flex-direction: column;
    }

    .modal-actions {
        flex-direction: column;
    }
}
