:root {
    /* Modern Dark Palette */
    --bg-dark: #0d1117;
    --bg-glass: rgba(22, 27, 34, 0.70);
    --bg-panel: #161b22;
    --bg-header: #1f242c;

    --primary: #58a6ff;
    --primary-glow: rgba(88, 166, 255, 0.15);
    --secondary: #a371f7;
    /* Purple accent */

    --text-main: #e6edf3;
    --text-muted: #8b949e;

    --border: #30363d;
    --glass-border: rgba(255, 255, 255, 0.08);

    --success: #238636;
    --danger: #da3633;

    /* Fonts */
    --font-heading: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: var(--font-heading);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* Subtle background gradient */
    background: radial-gradient(circle at top left, #161b22, #0d1117 60%);
}

/* Scrollbars - Chrome/Safari/Edge */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.logo ion-icon {
    font-size: 1.8rem;
    color: var(--text-main);
}

.subtitle {
    margin-top: 5px;
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 500;
}

.file-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0;
}

/* Search Bar - Modern Glassmorphism Fix */
.search-wrapper {
    padding: 0 20px 15px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-box:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.search-box ion-icon[name="search-outline"] {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
}

#file-search {
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px 35px 10px 38px;
    color: var(--text-main);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    outline: none;
}

.clear-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.2s;
}

.clear-btn:hover {
    color: var(--text-main);
}

.search-box input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.file-list-container h3 {
    padding: 10px 25px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    font-weight: 700;
    opacity: 0.8;
}

.file-list {
    list-style: none;
}

.file-item {
    padding: 10px 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.file-item ion-icon {
    color: var(--text-muted);
    font-size: 1.1rem;
    transition: color 0.2s;
}

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

.file-item.active {
    background-color: var(--primary-glow);
    border-left-color: var(--primary);
    color: #fff;
}

.file-item.active ion-icon {
    color: var(--primary);
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s;
    border: 1px solid var(--glass-border);
}

.github-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--text-muted);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.copyright {
    margin-top: 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.copyright a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.copyright a:hover {
    color: var(--primary);
}

.heart-icon {
    color: #ed254e;
    font-size: 0.75rem;
    animation: heart-beat 1.5s infinite;
}

@keyframes heart-beat {
    0% {
        transform: scale(1);
    }

    25% {
        transform: scale(1.2);
    }

    50% {
        transform: scale(1);
    }

    75% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* Main Area */
.main-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: transparent;
    /* Show body gradient */
}

/* Top Bar */
.top-bar {
    height: 64px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    z-index: 9;
}

.current-file {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    color: var(--text-main);
}

.current-file ion-icon {
    color: var(--primary);
    font-size: 1.2rem;
}

.badge {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 20px;
    color: var(--primary);
    border: 1px solid var(--glass-border);
    font-weight: 500;
}

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

.btn {
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: linear-gradient(135deg, #238636, #2ea043);
    color: white;
    box-shadow: 0 2px 8px rgba(35, 134, 54, 0.4);
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(35, 134, 54, 0.5);
    filter: brightness(1.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--border);
    box-shadow: none;
}

/* Code Editor */
.editor-container {
    flex: 1;
    overflow: auto;
    position: relative;
    background-color: transparent;
}

/* Overriding Prism styles */
pre[class*="language-"] {
    margin: 0 !important;
    border-radius: 0 !important;
    height: 100%;
    background: transparent !important;
    font-family: var(--font-mono) !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    padding: 25px !important;
    text-shadow: none !important;
}

/* Resizer */
.resizer {
    height: 12px;
    background-color: var(--bg-dark);
    border-top: 1px solid var(--border);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    touch-action: none;
    /* Critical for mobile touch resizing */
}

.resizer:hover,
.resizer.resizing {
    background-color: #1c2128;
}

.resizer-handle {
    width: 40px;
    height: 4px;
    background-color: var(--border);
    border-radius: 2px;
    transition: background-color 0.2s;
}

.resizer:hover .resizer-handle {
    background-color: var(--text-muted);
}

/* Terminal */
.terminal-container {
    height: 250px;
    min-height: 100px;
    max-height: 80vh;
    background-color: #0d1117;
    display: flex;
    flex-direction: column;
    /* Box shadow to create elevation */
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.terminal-header {
    height: 40px;
    background-color: #161b22;
    /* Slightly lighter than body */
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    /* justify-content: space-between; -- Changed to flex-start to align title left */
    justify-content: flex-start;
    padding: 0 15px;
}

/* Mac-style window controls */
.window-controls {
    display: flex;
    gap: 8px;
    margin-right: 15px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.red {
    background-color: #ff5f56;
}

.yellow {
    background-color: #ffbd2e;
}

.green {
    background-color: #27c93f;
}

.terminal-title {
    /* flex: 1; -- Removed to prevent taking up all space */
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Push the trash button to the far right */
.terminal-header .icon-btn {
    margin-left: auto;
}

.terminal-body {
    flex: 1;
    overflow: hidden;
    background-color: #0d1117;
    /* Dark background for terminal */
    position: relative;
    padding: 0;
}

#output-frame {
    width: 100%;
    height: 100%;
    border: none;
    /* Invert colors for iframe if it contains white bg content defaults, 
       but script.js handles styling, checks script.js to ensure dark mode output */
    background-color: #ffffff;
}

/* Utility Helper for Icon Button */
.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
}

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

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

/* Tooltip for copy button */
.copy-tooltip {
    position: absolute;
    top: -35px;
    right: 0;
    background: var(--success);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
}

.copy-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

/* Loading Spinner */
.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 40px 0;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(88, 166, 255, 0.3);
    border-bottom-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
}

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

/* Sidebar Toggle Button (Hidden on Desktop) */
.sidebar-toggle {
    display: none;
    font-size: 1.4rem;
    color: var(--text-main);
    padding: 8px;
    margin-right: 15px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        position: relative;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 280px;
        background-color: #161b22;
        /* Solid color for better mobile performance */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Mobile Backdrop */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 9;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .main-editor {
        width: 100%;
        height: 100vh;
    }

    .top-bar {
        padding: 0 15px;
        height: 60px;
    }

    .current-file span {
        font-size: 0.9rem;
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .actions .badge {
        display: none;
    }

    .btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .terminal-container {
        min-height: 150px;
        max-height: 60vh;
    }

    /* Mobile Search Refinements */
    .search-wrapper {
        padding: 5px 15px 15px;
    }

    .search-box {
        background: rgba(255, 255, 255, 0.07);
    }
}