@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-primary: radial-gradient(circle at top, rgba(80, 70, 229, 0.25), transparent 55%),
                  radial-gradient(circle at bottom, rgba(14, 165, 233, 0.2), transparent 60%),
                  #050816;
    --panel-bg: rgba(17, 24, 39, 0.9);
    --panel-border: rgba(148, 163, 184, 0.35);
    --accent: #6366f1;
    --accent-strong: #4f46e5;
    --text-primary: #f9fafb;
    --text-secondary: #cbd5f5;
    --shadow-lg: 0 25px 50px -12px rgba(15, 23, 42, 0.65);
    --shadow-md: 0 20px 45px rgba(99, 102, 241, 0.25);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

#canvas-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: transparent;
}

#ui-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 48px;
    margin: 0 auto;
    width: min(90vw, 940px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

#status-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.thinking-dots {
    display: inline-flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--accent);
    animation: thinking-bounce 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.25; }
    40% { transform: scale(1); opacity: 1; }
}

#settings-button {
    position: fixed;
    top: 32px;
    right: 32px;
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(99, 102, 241, 0.5);
    color: var(--text-secondary);
    display: grid;
    place-items: center;
    z-index: 15;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(16px);
}

#settings-button:hover {
    transform: translateY(-2px) scale(1.02);
    border-color: var(--accent);
    color: #fff;
}

.settings-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(18px);
    padding: 32px;
}

.settings-modal.hidden {
    display: none;
}

.settings-content {
    width: min(960px, 92vw);
    max-height: 90vh;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.settings-header {
    padding: 24px 32px 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(51, 65, 85, 0.7);
    color: var(--text-primary);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(99, 102, 241, 0.85);
}

.settings-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    padding: 24px 32px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.6);
}

.tab-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: transparent;
    border-radius: 14px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.18s ease;
}

.tab-btn.active {
    color: #fff;
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.35);
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.15);
}

.tab-btn:hover {
    color: #fff;
    background: rgba(99, 102, 241, 0.12);
}

.tab-content {
    overflow-y: auto;
    padding: 28px 32px 8px;
    flex: 1;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-panel h3 {
    margin: 0 0 18px;
    font-size: 1.15rem;
    font-weight: 600;
    color: #fff;
}

.setting-group {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 18px;
    padding: 18px 20px;
    margin-bottom: 18px;
    box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-group label {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.setting-group select,
.setting-group input[type="password"],
.setting-group input[type="text"],
.setting-group textarea {
    width: 100%;
    background: rgba(10, 14, 28, 0.8);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.setting-group textarea {
    min-height: 110px;
    resize: vertical;
}

.setting-group select:focus,
.setting-group input:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.3);
}

.api-input-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.save-btn,
.danger-btn,
.export-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.save-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.25);
}

.save-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 40px rgba(99, 102, 241, 0.35);
}

.danger-btn {
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: #fff;
    box-shadow: 0 12px 30px rgba(248, 113, 113, 0.25);
}

.export-btn {
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    border: 1px solid rgba(99, 102, 241, 0.35);
}

.save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-container span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.toggle-container input {
    display: none;
}

.toggle-label {
    position: relative;
    width: 52px;
    height: 28px;
    border-radius: 999px;
    background: rgba(51, 65, 85, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.35);
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle-label::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 6px;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s ease;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.35);
}

.toggle-container input:checked + .toggle-label {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.toggle-container input:checked + .toggle-label::after {
    transform: translate(22px, -50%);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 16px;
}

.slider-container input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.slider-container span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 44px;
    text-align: right;
}

.color-options {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.color-option {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.color-option input[type="color"] {
    width: 56px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(15, 23, 42, 0.8);
    padding: 0;
}

.settings-footer {
    padding: 18px 24px 24px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.65);
}

.unsaved-changes {
    color: #fcd34d;
    font-weight: 500;
    font-size: 0.92rem;
}

.footer-buttons {
    display: flex;
    gap: 12px;
}

.cancel-btn,
.save-all-btn {
    border-radius: 12px;
    border: 1px solid transparent;
    padding: 12px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}

.cancel-btn {
    background: rgba(51, 65, 85, 0.6);
    color: var(--text-secondary);
}

.cancel-btn:hover {
    background: rgba(71, 85, 105, 0.75);
    color: #fff;
}

.save-all-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    box-shadow: 0 12px 25px rgba(99, 102, 241, 0.32);
}

.save-all-btn:hover {
    transform: translateY(-1px);
}

#api-limit-toggle {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 14;
    width: 34px;
    height: 34px;
    border-radius: 12px 12px 0 0;
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-bottom: none;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--text-secondary);
}

.api-limit-panel {
    position: fixed;
    top: 54px;
    left: 50%;
    transform: translateX(-50%);
    width: min(520px, 90vw);
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 20px 22px;
    z-index: 14;
    backdrop-filter: blur(14px);
}

.api-limit-panel.hidden {
    display: none;
}

.limit-panel-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.limit-header {
    font-size: 1rem;
    color: #fff;
    font-weight: 600;
}

.limit-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.limit-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(99, 102, 241, 0.18);
}

.limit-icon {
    font-size: 1.1rem;
}

.limit-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.limit-usage {
    margin-left: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: #e2e8f0;
}

.api-status,
.tier-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.tab-panel input[disabled],
.tab-panel button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

#userInput {
    backdrop-filter: blur(12px);
}

@media (max-width: 768px) {
    #settings-button {
        top: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
    }

    .settings-modal {
        padding: 18px;
    }

    .settings-content {
        border-radius: 22px;
    }

    .settings-tabs {
        padding: 18px;
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    }

    .tab-content {
        padding: 20px 22px 8px;
    }

    .setting-group {
        padding: 16px;
    }

    #ui-container {
        bottom: 32px;
        width: min(92vw, 720px);
    }
}

@media (max-width: 520px) {
    #ui-container {
        bottom: 24px;
        width: 92vw;
    }

    .settings-tabs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .settings-content {
        height: 90vh;
    }

    .api-input-container {
        flex-direction: column;
    }

    .settings-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .footer-buttons {
        width: 100%;
        flex-direction: column;
    }

    .footer-buttons button {
        width: 100%;
    }
}
