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

:root {
    --bg: #fff;
    --fg: #111;
    --muted: #666;
    --border: #e0e0e0;
    --hover: #f5f5f5;
    --radius: 6px;
    --mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --max-w: 720px;
}

html {
    font-size: 15px;
}

body {
    font-family: var(--sans);
    color: var(--fg);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--muted);
}

/* Layout */

.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 24px;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Header */

.header {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.logo:hover {
    color: var(--fg);
}

.nav {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav a {
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--muted);
}

.nav a:hover {
    color: var(--fg);
}

/* Hero */

.hero {
    padding: 120px 0 80px;
    text-align: center;
}

.hero h1 {
    font-size: 2.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-bottom: 16px;
}

.hero p {
    font-size: 1.1rem;
    color: var(--muted);
    max-width: 480px;
    margin: 0 auto 40px;
}

/* Sections */

.section {
    padding: 60px 0;
    border-top: 1px solid var(--border);
}

.section h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}

/* Features grid */

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 32px;
}

.feature h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.feature p {
    font-size: 0.85rem;
    color: var(--muted);
}

/* Code block */

.code-block {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    font-family: var(--mono);
    font-size: 0.8rem;
    line-height: 1.7;
    overflow-x: auto;
    white-space: pre;
}

/* Buttons */

.btn {
    display: inline-block;
    padding: 10px 24px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--fg);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    background: var(--fg);
    color: var(--bg);
    transition: opacity 0.15s;
    font-family: var(--sans);
}

.btn:hover {
    opacity: 0.85;
    color: var(--bg);
}

.btn-outline {
    background: var(--bg);
    color: var(--fg);
}

.btn-outline:hover {
    background: var(--hover);
    color: var(--fg);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

/* Forms */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: var(--mono);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--fg);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--fg);
}

.form-input::placeholder {
    color: #bbb;
}

/* Cards */

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.card + .card {
    margin-top: 16px;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.card-value-sm {
    font-size: 1rem;
    font-family: var(--mono);
    word-break: break-all;
}

/* Dashboard grid */

.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

/* Table */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th {
    text-align: left;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.8rem;
}

tr:last-child td {
    border-bottom: none;
}

/* Alerts */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    background: #fafafa;
}

.alert-success {
    border-color: #ccc;
    background: #f5f5f5;
}

.alert-error {
    border-color: #999;
    background: #f0f0f0;
    font-weight: 500;
}

/* Key display */

.key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.key-display .form-input {
    flex: 1;
    font-size: 0.85rem;
}

/* Footer */

.footer {
    margin-top: auto;
    padding: 24px 0;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--muted);
    text-align: center;
}

/* Auth box */

.auth-box {
    width: 100%;
    max-width: 400px;
    padding: 0 24px;
}

.auth-box h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.auth-box p {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 32px;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-link {
    text-align: center;
    font-size: 0.85rem;
    margin-top: 16px;
}

/* Dashboard header */

.dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 32px 0 24px;
}

.dash-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Hidden */

.hidden {
    display: none !important;
}

/* Pricing */

.pricing-note {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 8px;
}

/* Chat page */

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

.chat-page .header {
    flex-shrink: 0;
}

.chat-no-key {
    padding: 12px 24px;
    background: #f5f5f5;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    text-align: center;
    color: var(--muted);
}

/* Controls bar */

.chat-controls {
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    flex-shrink: 0;
    background: var(--bg);
}

.chat-controls-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Model picker */

.chat-model-picker {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.chat-model-selected {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    user-select: none;
    background: var(--bg);
    transition: border-color 0.15s;
}

.chat-model-selected:hover {
    border-color: var(--fg);
}

.chat-model-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    z-index: 100;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.chat-model-search {
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.85rem;
    padding: 10px 12px;
    font-family: var(--sans);
}

.chat-model-list {
    overflow-y: auto;
    max-height: 340px;
}

.chat-model-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    border-bottom: 1px solid #f5f5f5;
    gap: 8px;
}

.chat-model-item:hover {
    background: var(--hover);
}

.chat-model-item.active {
    background: #f0f0f0;
    font-weight: 500;
}

.chat-model-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-model-price {
    font-size: 0.72rem;
    color: var(--muted);
    flex-shrink: 0;
    font-family: var(--mono);
}

/* Stream toggle */

.chat-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--muted);
    user-select: none;
    flex-shrink: 0;
}

.chat-toggle input {
    accent-color: var(--fg);
    width: 14px;
    height: 14px;
}

.chat-toggle-label {
    font-family: var(--mono);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Chat main */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 0;
}

.chat-messages-inner {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

.chat-empty {
    margin: auto;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 0 32px;
}

.chat-scroll-anchor {
    height: 0;
    flex-shrink: 0;
}

.chat-msg {
    display: flex;
}

.chat-msg-user {
    justify-content: flex-end;
}

.chat-msg-assistant {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-bubble-user {
    background: #f0f0f0;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.chat-bubble-assistant {
    background: #fafafa;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-bubble-assistant p {
    margin: 0 0 8px;
}

.chat-bubble-assistant p:last-child {
    margin-bottom: 0;
}

.chat-bubble-assistant pre {
    background: #f0f0f0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.8rem;
    margin: 8px 0;
}

.chat-bubble-assistant code {
    font-family: var(--mono);
    font-size: 0.85em;
    background: #f0f0f0;
    padding: 1px 4px;
    border-radius: 3px;
}

.chat-bubble-assistant pre code {
    background: none;
    padding: 0;
}

.chat-bubble-assistant ul,
.chat-bubble-assistant ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-bubble-assistant blockquote {
    border-left: 3px solid var(--border);
    margin: 8px 0;
    padding-left: 12px;
    color: var(--muted);
}

/* Reasoning block */

.chat-reasoning {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f8f8f8;
    font-size: 0.82rem;
}

.chat-reasoning summary {
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 500;
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    user-select: none;
}

.chat-reasoning summary:hover {
    color: var(--fg);
}

.chat-reasoning-content {
    padding: 0 12px 10px;
    color: var(--muted);
    line-height: 1.5;
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
}

.chat-reasoning-content p {
    margin: 6px 0;
}

.chat-reasoning-content p:first-child {
    margin-top: 10px;
}

.chat-typing {
    color: var(--muted);
    animation: blink 1s infinite;
}

@keyframes blink {
    50% { opacity: 0.3; }
}

.chat-error {
    color: #c00;
    font-size: 0.85rem;
}

.btn-stop {
    background: #c00;
    border-color: #c00;
    color: #fff;
}

.btn-stop:hover {
    opacity: 0.85;
    color: #fff;
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.chat-input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}

.chat-textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-family: var(--sans);
    font-size: 0.9rem;
    line-height: 1.5;
    outline: none;
    min-height: 42px;
    max-height: 200px;
    transition: border-color 0.15s;
}

.chat-textarea:focus {
    border-color: var(--fg);
}

.chat-textarea::placeholder {
    color: #bbb;
}

/* Responsive */

@media (max-width: 600px) {
    .hero {
        padding: 60px 0 40px;
    }

    .hero h1 {
        font-size: 1.8rem;
    }

    .dash-grid {
        grid-template-columns: 1fr;
    }

    .header-inner {
        flex-direction: column;
        gap: 12px;
    }

    .chat-controls-inner {
        flex-wrap: wrap;
        gap: 10px;
    }

    .chat-model-picker {
        max-width: 100%;
        min-width: 0;
        flex-basis: 100%;
    }

    .chat-model-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 60vh;
        max-height: 60dvh;
        border-radius: var(--radius) var(--radius) 0 0;
    }

    .chat-messages {
        padding: 16px 0;
    }

    .chat-messages-inner {
        padding: 0 16px;
    }

    .chat-bubble {
        max-width: 90%;
    }

    .chat-input-area {
        padding: 12px 16px;
    }

    .chat-input-wrap {
        max-width: 100%;
    }

    .chat-textarea {
        font-size: 16px;
    }

    #btn-send {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}
