:root {
    --bg: #070b14;
    --bg-soft: #0c1220;
    --panel: rgba(255, 255, 255, 0.045);
    --panel-strong: rgba(17, 24, 39, 0.9);
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text: #e9eef7;
    --muted: #8b98ad;
    --accent: #5eead4;
    --accent-deep: #2dd4bf;
    --accent2: #8b8cf8;
    --danger: #fb7185;
    --warn: #fbbf24;
    --radius: 18px;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

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

body {
    background:
        radial-gradient(900px 500px at 12% -8%, rgba(94, 234, 212, 0.13), transparent 62%),
        radial-gradient(800px 520px at 88% 4%, rgba(139, 140, 248, 0.13), transparent 60%),
        radial-gradient(700px 500px at 50% 110%, rgba(45, 212, 191, 0.08), transparent 65%),
        var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.muted {
    color: var(--muted);
}

h1,
h2,
h3 {
    margin: 0;
    line-height: 1.3;
}

/* ---------- 通用按钮 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn.primary {
    border-color: transparent;
    background: linear-gradient(135deg, var(--accent-deep), var(--accent2));
    color: #04121a;
}

.btn.primary:hover {
    filter: brightness(1.06);
}

.btn.ghost {
    background: transparent;
}

.btn.wide {
    width: 100%;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    text-decoration: none;
}

.icon-btn svg {
    width: 21px;
    height: 21px;
}

.icon-btn .icon-off,
.icon-btn.muted .icon-on {
    display: none;
}

.icon-btn.muted .icon-off {
    display: block;
}

.ghost-btn {
    padding: 8px 14px;
    border-radius: 11px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.ghost-btn:hover {
    color: var(--text);
    border-color: var(--line-strong);
}

/* ---------- 对话页布局 ---------- */

.chat-page {
    height: 100dvh;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 62px;
    flex: 0 0 auto;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.02em;
    text-decoration: none;
}

.brand:hover {
    text-decoration: none;
}

.brand-name {
    font-size: 15px;
}

.brand-orb {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: conic-gradient(from 120deg, var(--accent), var(--accent2), #f0abfc, var(--accent));
    box-shadow: 0 0 18px rgba(94, 234, 212, 0.45);
    animation: orb-spin 9s linear infinite;
}

.brand-orb.large {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    box-shadow: 0 0 46px rgba(94, 234, 212, 0.35), 0 0 90px rgba(139, 140, 248, 0.22);
    animation: orb-spin 14s linear infinite, orb-float 6s ease-in-out infinite;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.setup-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(94, 234, 212, 0.3);
    background: rgba(94, 234, 212, 0.08);
    color: #c8fff4;
    font-size: 13px;
}

.setup-banner.warn {
    border-color: rgba(251, 191, 36, 0.32);
    background: rgba(251, 191, 36, 0.08);
    color: #fde68a;
}

.setup-banner a {
    white-space: nowrap;
    font-weight: 600;
    color: inherit;
    text-decoration: underline;
}

.chat {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 4px 18px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat::-webkit-scrollbar {
    width: 6px;
}

.chat::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
}

.welcome-card {
    margin: 8vh auto 0;
    max-width: 520px;
    padding: 38px 28px;
    border-radius: 26px;
    border: 1px solid var(--line);
    background:
        radial-gradient(500px 200px at 50% -20%, rgba(94, 234, 212, 0.14), transparent 70%),
        var(--panel);
    text-align: center;
    box-shadow: var(--shadow);
    animation: fade-up 0.5s ease both;
}

.welcome-card h1 {
    font-size: 22px;
    margin-bottom: 10px;
}

.welcome-card p {
    margin: 0 auto;
    max-width: 420px;
    color: var(--muted);
    font-size: 14px;
}

.pipeline-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 22px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.04em;
}

.pipeline-hint i {
    width: 18px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.welcome-card.hidden {
    display: none;
}

.msg {
    display: flex;
    flex-direction: column;
    margin: 14px 0;
    animation: fade-up 0.28s ease both;
}

.msg.user {
    align-items: flex-end;
}

.msg.assistant {
    align-items: flex-start;
}

.bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 15px;
    line-height: 1.65;
}

.msg.user .bubble {
    border-bottom-right-radius: 6px;
    background: linear-gradient(135deg, rgba(45, 212, 191, 0.92), rgba(139, 140, 248, 0.92));
    color: #051018;
    font-weight: 500;
    box-shadow: 0 10px 26px rgba(45, 212, 191, 0.16);
}

.msg.assistant .bubble {
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
    background: rgba(255, 255, 255, 0.055);
    color: var(--text);
}

.meta {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    padding: 0 4px;
    opacity: 0.7;
}

.speak-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
}

.speak-btn:hover {
    color: var(--accent);
    border-color: rgba(94, 234, 212, 0.4);
}

.typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}

.typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: typing 1.2s infinite ease-in-out;
}

.typing i:nth-child(2) {
    animation-delay: 0.15s;
}

.typing i:nth-child(3) {
    animation-delay: 0.3s;
}

/* ---------- 流程状态 ---------- */

.steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
    padding: 4px 0 10px;
    opacity: 0.55;
    transition: opacity 0.3s ease;
}

.steps .step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 11.5px;
    letter-spacing: 0.02em;
    transition: all 0.25s ease;
}

.steps .step i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.25s ease;
}

.steps .step.active {
    border-color: rgba(94, 234, 212, 0.35);
    background: rgba(94, 234, 212, 0.09);
    color: #d4fff8;
}

.steps .step.active i {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    animation: blink 1s ease-in-out infinite;
}

.steps .step.done {
    color: rgba(94, 234, 212, 0.75);
}

.steps .step.done i {
    background: rgba(94, 234, 212, 0.6);
}

/* ---------- 输入区 ---------- */

.composer {
    flex: 0 0 auto;
    margin-bottom: 14px;
    padding: 14px 16px 16px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: var(--panel-strong);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(14px);
}

.rec-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 20px;
    color: var(--muted);
    font-size: 12.5px;
}

.rec-status .timer {
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.level {
    height: 3px;
    margin: 8px 0 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
}

.level i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-deep), var(--accent2));
    transition: width 0.08s linear;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-row input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
    height: 46px;
    padding: 0 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.24);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-row input[type="text"]::placeholder {
    color: rgba(139, 152, 173, 0.7);
}

.input-row input[type="text"]:focus {
    border-color: rgba(94, 234, 212, 0.55);
    box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.12);
}

.send-btn {
    height: 46px;
    padding: 0 18px;
    border-radius: 14px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
}

.send-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mic-btn {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent-deep), var(--accent2));
    color: #051018;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.mic-btn svg {
    width: 23px;
    height: 23px;
}

.mic-btn:hover:not(:disabled) {
    transform: scale(1.05);
    filter: brightness(1.07);
}

.mic-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.mic-btn.recording {
    background: linear-gradient(135deg, #fb7185, #f472b6);
    animation: mic-pulse 1.4s ease-out infinite;
}

.mic-btn.recording::after {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    border: 2px solid rgba(5, 16, 24, 0.55);
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 130px;
    z-index: 50;
    max-width: min(86vw, 460px);
    padding: 11px 18px;
    border-radius: 12px;
    border: 1px solid rgba(251, 113, 133, 0.35);
    background: rgba(40, 12, 20, 0.92);
    color: #fecdd3;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translate(-50%, 12px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- 登录 / 口令页 ---------- */

.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-shell {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    padding: 36px 30px 32px;
    border-radius: 24px;
    border: 1px solid var(--line);
    background:
        radial-gradient(420px 180px at 50% -30%, rgba(94, 234, 212, 0.14), transparent 70%),
        rgba(13, 19, 32, 0.92);
    box-shadow: var(--shadow);
    text-align: center;
}

.auth-card h1 {
    font-size: 21px;
    margin-bottom: 8px;
}

.auth-card > p {
    margin: 0 0 22px;
    font-size: 13.5px;
}

.auth-card .stack {
    text-align: left;
}

.alert {
    margin-bottom: 14px;
    padding: 10px 13px;
    border-radius: 10px;
    font-size: 13px;
    text-align: left;
}

.alert.error {
    border: 1px solid rgba(251, 113, 133, 0.35);
    background: rgba(251, 113, 133, 0.1);
    color: #fecdd3;
}

.alert.ok {
    border: 1px solid rgba(94, 234, 212, 0.35);
    background: rgba(94, 234, 212, 0.09);
    color: #c8fff4;
}

/* ---------- 表单通用 ---------- */

.field {
    display: block;
    margin-bottom: 16px;
}

.field > span,
.field > label > span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.field input,
.field select,
.field textarea,
.input {
    width: 100%;
    padding: 11px 13px;
    border-radius: 11px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.26);
    color: var(--text);
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.input:focus {
    border-color: rgba(94, 234, 212, 0.55);
    box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.11);
}

.field textarea {
    min-height: 92px;
    resize: vertical;
    line-height: 1.6;
}

.field select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

.field .hint {
    display: block;
    margin-top: 6px;
    color: rgba(139, 152, 173, 0.8);
    font-size: 12px;
    line-height: 1.5;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ---------- 管理页 ---------- */

.admin-page {
    min-height: 100dvh;
    padding: 28px 20px 120px;
}

.admin-shell {
    max-width: 960px;
    margin: 0 auto;
}

.admin-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.admin-head h1 {
    font-size: 24px;
}

.admin-head p {
    margin: 6px 0 0;
    font-size: 13px;
}

.admin-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-actions form {
    margin: 0;
}

.card {
    margin-bottom: 18px;
    padding: 22px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.032);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.card-head h2 {
    font-size: 16px;
    font-weight: 700;
}

.card-head .tag {
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(94, 234, 212, 0.1);
    border: 1px solid rgba(94, 234, 212, 0.25);
    color: var(--accent);
    font-size: 11px;
    white-space: nowrap;
}

.card-foot {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.test-result {
    flex: 1 1 240px;
    min-height: 20px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
}

.test-result.ok {
    color: #9df5e6;
}

.test-result.err {
    color: #fda4af;
}

.save-bar {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    width: min(920px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 16px;
    border: 1px solid var(--line-strong);
    background: rgba(11, 17, 28, 0.94);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    transform: translateX(-50%);
    backdrop-filter: blur(16px);
}

.save-bar .status {
    flex: 1 1 auto;
    font-size: 13px;
    color: var(--muted);
}

.save-bar .status.ok {
    color: #9df5e6;
}

.save-bar .status.err {
    color: #fda4af;
}

.hidden {
    display: none !important;
}

.provider-section {
    margin-top: 4px;
}

.persona-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.persona {
    padding: 16px 16px 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.16);
}

.persona-head {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.persona-head .field {
    flex: 1;
}

.persona-head .btn {
    flex-shrink: 0;
    margin-bottom: 1px;
}

.persona .field,
.persona .field-row {
    margin-top: 12px;
}

.persona-file {
    padding: 9px 12px !important;
    font-size: 12.5px;
}

.persona-active {
    margin-top: 13px;
    color: var(--muted);
    font-size: 12.5px;
}

.key-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 12.5px;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.switch input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-deep);
}

.range-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 14px;
}

@media (max-width: 640px) {
    .app {
        padding: 0 10px;
    }

    .topbar {
        height: 56px;
    }

    .brand-name {
        font-size: 14px;
    }

    .welcome-card {
        margin-top: 4vh;
        padding: 30px 20px;
    }

    .welcome-card h1 {
        font-size: 19px;
    }

    .composer {
        margin-bottom: 10px;
        padding: 12px 12px 14px;
    }

    .send-btn {
        height: 44px;
        padding: 0 14px;
    }

    .bubble {
        max-width: 86%;
    }

    .admin-page {
        padding: 20px 12px 120px;
    }

    .admin-head {
        flex-direction: column;
    }

    .card {
        padding: 18px 16px;
    }

    .field-row,
    .range-row {
        grid-template-columns: 1fr;
    }

    .persona-head {
        flex-direction: column;
        align-items: stretch;
    }

    .persona-head .btn {
        align-self: flex-start;
    }

    .steps {
        gap: 4px;
    }

    .steps .step {
        padding: 3px 8px;
        font-size: 10.5px;
    }

    .toast {
        bottom: 118px;
    }
}

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

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

@keyframes orb-float {
    0%,
    100% {
        translate: 0 0;
    }
    50% {
        translate: 0 -7px;
    }
}

@keyframes mic-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.5);
    }
    70% {
        box-shadow: 0 0 0 16px rgba(251, 113, 133, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(251, 113, 133, 0);
    }
}

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

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

@keyframes blink {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}
