:root {
    --primary-blue: #58a6ff;
    --primary-purple: #9333ea;
}

/* GitHub Dark Theme (Default) */
:root[data-theme="dark"] {
    --bg-body: #0d1117;
    /* Level 1: Deepest Base */
    --bg-main: #0d1117;
    --bg-panel: #161b22;
    /* Level 2: Lighter Panel (Editor) */
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-workspace: #010409;
    --bg-console: #010409;
    /* Level 3: Darkest Terminal (Distinct from Editor) */

    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-primary: #58a6ff;
    --accent-hover: #79c0ff;
    --border-main: #30363d;
}

/* Eye Saver Theme */
:root[data-theme="eye-saver"] {
    --bg-body: #f5f1e8;
    /* Level 1: Base Cream */
    --bg-main: #f5f1e8;
    --bg-panel: #fdfbf7;
    /* Level 2: Lightest Paper (Editor) */
    --bg-secondary: #ede7d9;
    --bg-tertiary: #d4c9b5;
    --bg-workspace: #ffffff;
    --bg-console: #efeadf;
    /* Level 3: Mutated Cream (Distinct from Editor) */

    --text-primary: #3d3226;
    --text-secondary: #6b5d4f;
    --text-muted: #8b7d6b;
    --accent-primary: #a67c52;
    --accent-hover: #c9a882;
    --border-main: #d4c9b5;
}

/* Light Theme */
:root[data-theme="light"] {
    --bg-body: #ffffff;
    /* Level 1: Pure White Base */
    --bg-main: #ffffff;
    --bg-panel: #f6f8fa;
    /* Level 2: Subtle Grey (Editor) */
    --bg-secondary: #f6f8fa;
    --bg-workspace: #ffffff;
    --bg-tertiary: #e5e7eb;
    --bg-console: #f0f2f4;
    /* Level 3: Deeper Grey (Distinct from Editor) */

    --text-primary: #24292f;
    --text-secondary: #57606a;
    --text-muted: #6e7781;
    --accent-primary: #0969da;
    --accent-hover: #0550ae;
    --border-main: #d0d7de;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: var(--bg-body) !important;
    transition: background-color 0.3s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    background-color: var(--bg-body) !important;
    color: var(--text-primary);
}

/* Grid Container - 4 Columns (Symmetric Ad Layout) */
.grid-container {
    display: grid;
    grid-template-areas:
        "header header header header"
        "left-ad editor console right-ad"
        "how-to-use how-to-use how-to-use how-to-use"
        "status-bar status-bar status-bar status-bar";
    grid-template-columns: 180px 7fr 3fr 180px;
    grid-template-rows: 70px 1fr auto 40px;
    height: 100vh;
    width: 100vw;
}

.grid-header {
    grid-area: header;
    border-bottom: 1px solid var(--border-main);
    background: var(--bg-secondary);
}

.grid-left-ad {
    grid-area: left-ad;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-main);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}


.grid-editor {
    grid-area: editor;
    background: transparent;
    overflow: hidden;
}

.grid-editor .glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-main);
    border-right: none;
    /* Avoid double borders with Console */
}

.grid-console {
    grid-area: console;
    background: transparent;
    overflow: hidden;
}

.grid-console .glass-panel {
    background: var(--bg-console);
    border: 1px solid var(--border-main);
    /* border-left is needed now that editor has no right border */
}

.grid-right-ad {
    grid-area: right-ad;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-main);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-how-to-use {
    grid-area: how-to-use;
    grid-column: 1 / -1;
    background: var(--bg-main);
    border-top: 1px solid var(--border-main);
    padding: 24px;
}

.grid-status-bar {
    grid-area: status-bar;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-main);
    display: flex;
    align-items: center;
}

/* Sidebar Icons */
.sidebar-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Ad Space */
.ad-space-vertical {
    width: 100%;
    height: 100%;
    border: 2px dashed var(--border-main);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.02);
}

/* Trust Badge */
.trust-badge {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-main);
    border-radius: 20px;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
}

.trust-badge svg {
    color: var(--accent-primary);
}

/* File Tabs */
.file-tabs-container {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-workspace);
    border-bottom: 1px solid var(--border-main);
}

.file-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.file-tabs::-webkit-scrollbar {
    height: 4px;
}

.file-tabs::-webkit-scrollbar-thumb {
    background: var(--border-main);
    border-radius: 2px;
}

.file-tab {
    padding: 3px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.file-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.file-tab.active {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    font-weight: 600;
}

.new-file-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-main);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-file-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Download Button */
.download-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.download-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.download-btn:active {
    transform: translateY(0);
}

/* Status Badge */
#status-badge {
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 500;
}

/* Filename Pill Input */
.filename-pill {
    padding: 6px 16px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-main);
    color: var(--text-primary);
    font-size: 13px;
    width: 140px;
    transition: all 0.2s ease;
}

.filename-pill:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-secondary);
}

/* How to Use Section */
.how-to-use-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 48px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.how-to-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
    text-align: center;
}

.how-to-steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 32px;
}

.how-to-step {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.step-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    color: var(--bg-body);
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
}

.step-content {
    flex: 1;
}

.step-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.step-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Theme Toggle Buttons */
.theme-toggle-btn {
    padding: 4px 12px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid var(--border-main);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.theme-toggle-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Glass Panel Effect */
.glass-panel {
    background: var(--bg-workspace);
    border: 1px solid var(--border-main);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

body[data-theme="dark"] .glass-panel {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

body[data-theme="light"] .glass-panel,
body[data-theme="eye-saver"] .glass-panel {
    background: var(--bg-secondary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-main);
}

.glass-panel:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
    border-color: rgba(99, 102, 241, 0.3);
}

body[data-theme="light"] .glass-panel:hover,
body[data-theme="eye-saver"] .glass-panel:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Monaco Editor Container */
#editor-container {
    width: 100%;
    height: 100%;
    min-height: 300px;
}

/* Output Console */
#output-console {
    background: var(--bg-console);
    color: var(--text-primary);
    line-height: 1.6;
}

#output-console::-webkit-scrollbar {
    width: 8px;
}

#output-console::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#output-console::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.5);
    border-radius: 4px;
}

#output-console::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.7);
}

/* Output Styles */
.output-line {
    margin-bottom: 4px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.output-error {
    color: #ef4444;
    font-weight: 500;
}

.output-success {
    color: #10b981;
}

body[data-theme="eye-saver"] .output-success {
    color: #059669;
}

.output-timestamp {
    color: #6b7280;
    font-size: 0.75rem;
    margin-bottom: 8px;
    display: block;
}

body[data-theme="eye-saver"] .output-timestamp {
    color: var(--text-muted);
}

/* Loading Overlay */
#loading-overlay {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

/* Loading Spinner */
.loading-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Run Button Animation */
.run-button {
    position: relative;
    overflow: hidden;
}

.run-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.run-button:active::before {
    width: 300px;
    height: 300px;
}

.run-button.running {
    background: linear-gradient(90deg, #3b82f6, #9333ea, #3b82f6);
    background-size: 200% 100%;
    animation: gradient-shift 2s ease infinite;
}

@keyframes gradient-shift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* 3D Button Effect */
.btn-3d {
    transition: all 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-3d:active {
    transform: translateY(4px) !important;
    box-shadow: none !important;
}

/* Specific Shadow Colors for 3D Effect */
.run-button {
    box-shadow: 0 4px 0 #5b21b6;
    /* darker purple */
    margin-bottom: 4px;
    /* Space for shadow */
}

/* Download Button Re-styling */
.download-btn-3d {
    background: linear-gradient(90deg, #10b981, #059669);
    /* Emerald Gradient */
    color: white;
    border: none;
    box-shadow: 0 4px 0 #047857;
    /* darker emerald */
    margin-bottom: 4px;
}

.download-btn-3d:hover {
    background: linear-gradient(90deg, #059669, #047857);
}

/* Responsive Design */
@media (max-width: 1600px) {
    .grid-container {
        grid-template-columns: 160px 7fr 3fr 160px;
    }
}

@media (max-width: 1280px) {
    .grid-container {
        grid-template-areas:
            "header header header header"
            "icon-sidebar editor console right-ad"
            "how-to-use how-to-use how-to-use how-to-use"
            "status-bar status-bar status-bar status-bar";
        grid-template-columns: 60px 1fr 350px 250px;
    }

    .grid-left-ad {
        display: none;
    }
}

@media (max-width: 1024px) {
    .grid-container {
        grid-template-areas:
            "header header header"
            "icon-sidebar editor console"
            "how-to-use how-to-use how-to-use"
            "status-bar status-bar status-bar";
        grid-template-columns: 60px 1fr 300px;
    }

    .grid-left-ad,
    .grid-right-ad {
        display: none;
    }

    .how-to-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .grid-container {
        grid-template-areas:
            "header"
            "editor"
            "console"
            "how-to-use"
            "status-bar";
        grid-template-columns: 1fr;
        grid-template-rows: 70px 1fr 200px auto 40px;
    }

    .grid-icon-sidebar,
    .grid-left-ad,
    .grid-right-ad {
        display: none;
    }
}

/* Smooth Transitions */
button {
    transition: all 0.2s ease;
}

/* Focus Styles */
button:focus {
    outline: 2px solid rgba(99, 102, 241, 0.5);
    outline-offset: 2px;
}

/* Status Badge Animation */
@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(34, 197, 94, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(34, 197, 94, 0.8);
    }
}

#status-badge {
    animation: pulse-glow 2s ease-in-out infinite;
}