:root {
    /* Color Palette - Premium Dark */
    --bg-main: #0B0F19;
    --bg-card: rgba(19, 26, 42, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #E2E8F0;
    --text-muted: #94A3B8;
    
    /* Vibrant Accents */
    --accent-cyan: #06B6D4;
    --accent-indigo: #6366F1;
    --accent-gradient: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
    
    /* Glassmorphism */
    --backdrop-blur: blur(16px);
    
    /* Transitions */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.12), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(6, 182, 212, 0.12), transparent 25%);
    background-attachment: fixed;
}

h1, h2, h3 {
    font-weight: 600;
    letter-spacing: -0.02em;
}

.mono {
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
}

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1000;
}

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

.logo-icon {
    color: var(--accent-cyan);
}

.logo h1 {
    font-size: 1.25rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 16px;
    align-items: center;
}

.api-key-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    width: 280px;
    transition: var(--transition-smooth);
}

.api-key-input:focus {
    outline: none;
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.primary-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

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

/* Main Layout */
.app-main {
    display: flex;
    gap: 24px;
    flex: 1;
    min-height: 0; 
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.card {
    background: var(--bg-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition-smooth);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.card:hover {
    border-color: rgba(255,255,255,0.15);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.card-header h2 {
    font-size: 1.05rem;
    color: #fff;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 20px;
    resize: none;
    line-height: 1.6;
}

textarea:focus {
    outline: none;
    color: var(--text-main);
}

.code-card {
    flex: 3;
}

.dictionary-card {
    flex: 2;
}

.dictionary-info {
    padding: 12px 20px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.dict-area {
    padding-top: 12px;
    color: var(--accent-cyan);
}

/* Output Panel */
.results-card {
    flex: 1;
    position: relative;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.tab-pane {
    display: none;
    padding: 24px;
    height: 100%;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Empty States */
.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
}

.empty-icon {
    color: var(--border-color);
    margin-bottom: 8px;
}

/* Markdown Rendering Styles */
.markdown-body {
    color: var(--text-main);
    line-height: 1.6;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    color: #fff;
    margin-top: 24px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.markdown-body h1:first-child, .markdown-body h2:first-child, .markdown-body h3:first-child {
    margin-top: 0;
}

.markdown-body h1 { font-size: 1.4rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.05rem; border-bottom: none; color: var(--accent-cyan); }

.markdown-body p { margin-bottom: 16px; }

.markdown-body ul, .markdown-body ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-body li { margin-bottom: 8px; }

.markdown-body strong { color: #fff; }

/* Diagram */
.diagram-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
}

.diagram-container svg {
    max-width: 100%;
    height: auto;
}

/* Loading Overlay */
.relative-container { position: relative; }

.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    border-radius: 0 0 16px 16px;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-cyan);
    animation: spin 1s ease-in-out infinite;
}

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

/* Error message styling */
.error-message {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Live Feed Styles */
.live-tab-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--accent-cyan);
}
.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-cyan);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.7);
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(6, 182, 212, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}
.live-feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.live-feed-header h2 { font-size: 1.1rem; color: #fff; }
.live-badge {
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
}

/* V2 Optimization Toggle */
.optimization-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
}

.optimize-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background: var(--accent-gradient);
}

input:checked + .slider:before {
    background-color: white;
    transform: translateX(16px);
}

/* Tooltip */
.info-tooltip {
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--text-muted);
    outline: none;
}

.info-tooltip:hover .info-icon,
.info-tooltip:focus .info-icon {
    color: var(--accent-cyan);
}

.tooltip-text {
    visibility: hidden;
    width: 250px;
    background-color: rgba(15, 23, 42, 0.95);
    color: #fff;
    text-align: left;
    border-radius: 8px;
    padding: 10px;
    font-size: 0.75rem;
    line-height: 1.4;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    
    position: absolute;
    z-index: 100;
    top: 150%;
    right: 50%;
    transform: translateX(50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.info-tooltip:hover .tooltip-text,
.info-tooltip:focus .tooltip-text,
.info-tooltip:active .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Responsive Mobile Layout */
@media (max-width: 1024px) {
    body {
        height: auto;
        overflow-y: auto;
    }
    .app-container {
        height: auto;
        padding: 16px;
    }
    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px;
    }
    .header-actions {
        flex-direction: column;
        width: 100%;
        gap: 12px;
    }
    .api-key-input {
        width: 100%;
        order: 1;
    }
    .optimization-wrapper {
        width: 100%;
        justify-content: space-between;
        order: 2;
        padding: 12px;
    }
    .primary-btn {
        width: 100%;
        justify-content: center;
        order: 3;
    }
    .tooltip-text {
        right: 0;
        transform: translateX(0);
        width: 200px;
    }
    .app-main {
        flex-direction: column;
    }
    .panel {
        min-height: auto;
    }
    .code-card, .dictionary-card {
        min-height: 250px;
    }
    .results-card {
        min-height: 400px;
    }
    .tabs {
        flex-wrap: wrap;
    }
    .tab-btn {
        padding: 12px 8px;
        font-size: 0.85rem;
    }
}
