/* START: Design System Variables (keeping your existing design system) */
:root {
  /* ... (your existing :root variables are unchanged) ... */
}

/* ========================================================================== */
/* THEME DEFINITIONS
/* ========================================================================== */

/* --- Theme 1: Amber (Default) --- */
.screen.theme-amber {
    --theme-text-primary: #FFB000;
    --theme-text-secondary: #885500;
    --theme-text-highlight: #FFA500;
    --theme-text-inverted: #0a0500;
    --theme-bg-primary: #0a0500;
    --theme-bg-secondary: rgba(26, 15, 0, 0.8);
    --theme-bg-tertiary: #1a0f00;
    --theme-bg-faint: rgba(255, 176, 0, 0.02);
    --theme-bg-highlight: rgba(255, 176, 0, 0.2);
    --theme-bg-highlight-hover: rgba(255, 176, 0, 0.4);
    --theme-bg-help-overlay: rgba(10, 5, 0, 0.95);
    --theme-border-primary: #FFB000;
    --theme-accent-primary: #FFB000;
    --theme-accent-hover: #FFA500;
    --theme-selection-bg: #FFB000;
    --theme-selection-text: #0a0500;
    --theme-shadow-faint: rgba(255, 176, 0, 0.6);
    --theme-shadow-medium: rgba(255, 176, 0, 0.8);
    --theme-shadow-glow: rgba(255, 176, 0, 0.5);
    --theme-shadow-inset: rgba(255, 176, 0, 0.1);
    --theme-shadow-outer: rgba(255, 176, 0, 0.2);
    --theme-scanline-opacity: 0.3;
    --theme-flicker-opacity: 1;
    --theme-vignette-opacity: 0.5;
}

/* --- Theme 2: Terminal Green --- */
.screen.theme-green {
    --theme-text-primary: #00FF00;
    --theme-text-secondary: #008800;
    --theme-text-highlight: #33FF33;
    --theme-text-inverted: #000;
    --theme-bg-primary: #000;
    --theme-bg-secondary: rgba(0, 26, 0, 0.8);
    --theme-bg-tertiary: #001a00;
    --theme-bg-faint: rgba(0, 255, 0, 0.02);
    --theme-bg-highlight: rgba(0, 255, 0, 0.2);
    --theme-bg-highlight-hover: rgba(0, 255, 0, 0.4);
    --theme-bg-help-overlay: rgba(0, 10, 0, 0.95);
    --theme-border-primary: #00FF00;
    --theme-accent-primary: #00FF00;
    --theme-accent-hover: #33FF33;
    --theme-selection-bg: #00FF00;
    --theme-selection-text: #000;
    --theme-shadow-faint: rgba(0, 255, 0, 0.6);
    --theme-shadow-medium: rgba(0, 255, 0, 0.8);
    --theme-shadow-glow: rgba(0, 255, 0, 0.5);
    --theme-shadow-inset: rgba(0, 255, 0, 0.1);
    --theme-shadow-outer: rgba(0, 255, 0, 0.2);
    --theme-scanline-opacity: 0.3;
    --theme-flicker-opacity: 1;
    --theme-vignette-opacity: 0.5;
}

/* --- Theme 3: Sci-Fi Blue --- */
.screen.theme-blue {
    --theme-text-primary: #00FFFF;
    --theme-text-secondary: #008888;
    --theme-text-highlight: #33FFFF;
    --theme-text-inverted: #020510;
    --theme-bg-primary: #020510;
    --theme-bg-secondary: rgba(0, 20, 26, 0.8);
    --theme-bg-tertiary: #001a1a;
    --theme-bg-faint: rgba(0, 255, 255, 0.02);
    --theme-bg-highlight: rgba(0, 255, 255, 0.2);
    --theme-bg-highlight-hover: rgba(0, 255, 255, 0.4);
    --theme-bg-help-overlay: rgba(0, 10, 10, 0.95);
    --theme-border-primary: #00FFFF;
    --theme-accent-primary: #00FFFF;
    --theme-accent-hover: #33FFFF;
    --theme-selection-bg: #00FFFF;
    --theme-selection-text: #020510;
    --theme-shadow-faint: rgba(0, 255, 255, 0.6);
    --theme-shadow-medium: rgba(0, 255, 255, 0.8);
    --theme-shadow-glow: rgba(0, 255, 255, 0.5);
    --theme-shadow-inset: rgba(0, 255, 255, 0.1);
    --theme-shadow-outer: rgba(0, 255, 255, 0.2);
    --theme-scanline-opacity: 0.3;
    --theme-flicker-opacity: 1;
    --theme-vignette-opacity: 0.5;
}

/* --- Theme 4: White --- */
.screen.theme-white {
    --theme-text-primary: #000000;
    --theme-text-secondary: #555555;
    --theme-text-highlight: #000000;
    --theme-text-inverted: #FFFFFF;
    --theme-bg-primary: #F0F0F0;
    --theme-bg-secondary: #DDDDDD;
    --theme-bg-tertiary: #E5E5E5;
    --theme-bg-faint: rgba(0, 0, 0, 0.01);
    --theme-bg-highlight: #CCCCCC;
    --theme-bg-highlight-hover: #BBBBBB;
    --theme-bg-help-overlay: rgba(255, 255, 255, 0.95);
    --theme-border-primary: #000000;
    --theme-accent-primary: #000000;
    --theme-accent-hover: #333333;
    --theme-selection-bg: #000000;
    --theme-selection-text: #FFFFFF;
    --theme-shadow-faint: rgba(0, 0, 0, 0.2);
    --theme-shadow-medium: rgba(0, 0, 0, 0.4);
    --theme-shadow-glow: rgba(0, 0, 0, 0.3);
    --theme-shadow-inset: rgba(0, 0, 0, 0.05);
    --theme-shadow-outer: rgba(0, 0, 0, 0.1);
    --theme-scanline-opacity: 0;
    --theme-flicker-opacity: 0;
    --theme-vignette-opacity: 0.1;
}

/* Your existing font face */
@font-face {
  font-family: 'FKGroteskNeue';
  src: url('https://r2cdn.perplexity.ai/fonts/FKGroteskNeue.woff2') format('woff2');
}

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

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #000;
    font-family: 'VT323', 'Courier New', monospace;
}

/* CRT Container */
.crt-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    padding: 20px;
}

.screen {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    max-height: 900px;
    background: var(--theme-bg-primary);
    border: 20px solid #1a1a1a;
    border-radius: 20px;
    box-shadow: 
        inset 0 0 100px var(--theme-shadow-inset),
        0 0 100px rgba(0, 0, 0, 0.8),
        0 0 50px var(--theme-shadow-outer);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Scanlines effect */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, var(--theme-scanline-opacity)) 2px,
        rgba(0, 0, 0, var(--theme-scanline-opacity)) 4px
    );
    pointer-events: none;
    z-index: 100;
}

/* Flicker effect */
.flicker {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--theme-bg-faint);
    pointer-events: none;
    z-index: 99;
    animation: flicker 0.15s infinite;
    opacity: var(--theme-flicker-opacity);
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.97; }
}

/* Vignette effect */
.vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 60%,
        rgba(0, 0, 0, var(--theme-vignette-opacity)) 100%
    );
    pointer-events: none;
    z-index: 98;
}

/* Top Bar */
.top-bar {
    background: var(--theme-bg-secondary);
    color: var(--theme-text-primary);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 22px;
    border-bottom: 2px solid var(--theme-border-primary);
    text-shadow: 0 0 10px var(--theme-shadow-medium);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 10px;
}

.branding {
    font-weight: bold;
    letter-spacing: 2px;
}

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

.modified {
    color: var(--theme-text-highlight);
    font-style: italic;
}

/* --- Theme Switcher Styles --- */
.theme-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    color: var(--theme-text-primary);
    margin-left: auto; /* Pushes it to the right, before sync controls */
}

.theme-switcher label {
    text-shadow: 0 0 8px var(--theme-shadow-faint);
}

.theme-switcher select {
    background: var(--theme-bg-tertiary);
    color: var(--theme-text-primary);
    border: 1px solid var(--theme-border-primary);
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 18px;
    outline: none;
    border-radius: 4px;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    cursor: pointer;
}

.theme-switcher select:focus {
    box-shadow: 0 0 10px var(--theme-shadow-glow);
}

.theme-switcher option {
    background: var(--theme-bg-primary);
    color: var(--theme-text-primary);
}

/* Cloud Sync Controls */
.sync-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sync-status {
    font-size: 16px;
    color: var(--theme-text-secondary);
    text-shadow: none;
    min-width: 120px;
}

.sync-status.status-synced {
    color: var(--theme-text-primary);
}

.sync-status.status-syncing {
    color: var(--theme-text-highlight);
    animation: pulse 1s infinite;
}

.sync-status.status-offline {
    color: var(--theme-text-secondary);
}

.sync-status.status-premium {
    color: var(--theme-text-highlight);
}

.sync-status.status-ready {
    color: var(--theme-text-primary);
}

.premium-badge {
    background: var(--theme-bg-highlight);
    color: var(--theme-text-primary);
    padding: 2px 8px;
    border: 1px solid var(--theme-border-primary);
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 0 8px var(--theme-shadow-medium);
    animation: glow 2s infinite;
}

@keyframes glow {
    0%, 100% { 
        opacity: 1;
        box-shadow: 0 0 5px var(--theme-shadow-glow);
    }
    50% { 
        opacity: 0.8;
        box-shadow: 0 0 15px var(--theme-shadow-medium);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.sync-btn {
    background: var(--theme-bg-highlight);
    color: var(--theme-text-primary);
    border: 1px solid var(--theme-border-primary);
    padding: 4px 12px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 18px;
    cursor: pointer;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 4px;
}

.sync-btn:hover:not(:disabled) {
    background: var(--theme-bg-highlight-hover);
    box-shadow: 0 0 10px var(--theme-shadow-medium);
    transform: translateY(-1px);
}

.sync-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.sync-icon {
    font-size: 20px;
    display: inline-block;
}

/* --- NEW: Main App Layout --- */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    background: var(--theme-bg-primary);
}

.editor-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- NEW: File Sidebar --- */
.file-sidebar {
    display: flex;
    flex-direction: column;
    width: 250px;
    min-width: 200px;
    max-width: 400px;
    background: var(--theme-bg-tertiary);
    border-right: 2px solid var(--theme-border-primary);
    overflow-y: auto;
    resize: horizontal;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--theme-border-primary);
    background: var(--theme-bg-secondary);
}

.sidebar-header h3 {
    color: var(--theme-text-primary);
    font-size: 20px;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
}

.file-new-btn {
    background: var(--theme-accent-primary);
    color: var(--theme-text-inverted);
    border: none;
    padding: 4px 12px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 18px;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
    transition: all 0.2s;
}

.file-new-btn:hover {
    background: var(--theme-accent-hover);
    box-shadow: 0 0 10px var(--theme-shadow-medium);
}

.file-list {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    font-size: 18px;
    color: var(--theme-text-secondary);
    border-bottom: 1px solid var(--theme-bg-highlight);
    cursor: pointer;
    transition: all 0.2s;
}

.file-item:hover {
    background: var(--theme-bg-highlight);
    color: var(--theme-text-primary);
}

.file-item.active {
    background: var(--theme-bg-highlight-hover);
    color: var(--theme-text-highlight);
    font-weight: bold;
}

.file-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}

.file-delete-btn {
    background: none;
    border: none;
    color: var(--theme-text-secondary);
    font-family: 'Courier New', monospace;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    padding: 0 5px;
    border-radius: 4px;
    transition: all 0.2s;
}

.file-item:hover .file-delete-btn {
    color: var(--theme-text-primary);
}

.file-delete-btn:hover {
    background: var(--theme-bg-highlight-hover);
    color: var(--theme-accent-hover);
}


/* Editor Container */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    background: var(--theme-bg-primary);
}

/* Line Numbers */
.line-numbers {
    background: var(--theme-bg-primary); /* Changed from secondary */
    color: var(--theme-text-secondary);
    padding: 12px 8px;
    font-size: 20px;
    line-height: 1.5;
    text-align: right;
    min-width: 50px;
    user-select: none;
    border-right: 1px solid var(--theme-bg-highlight); /* Changed */
    overflow: hidden;
    white-space: pre;
}

/* Editor */
.editor {
    flex: 1;
    background: transparent;
    color: var(--theme-text-primary);
    border: none;
    outline: none;
    padding: 12px 16px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 20px;
    line-height: 1.5;
    resize: none;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    caret-color: var(--theme-text-primary);
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.editor::-webkit-scrollbar {
    width: 12px;
}

.editor::-webkit-scrollbar-track {
    background: var(--theme-bg-tertiary);
}

.editor::-webkit-scrollbar-thumb {
    background: var(--theme-accent-primary);
    border-radius: 6px;
}

.editor::selection {
    background: var(--theme-selection-bg);
    color: var(--theme-selection-text);
}

/* Status Bar */
.status-bar {
    background: var(--theme-bg-secondary);
    color: var(--theme-text-primary);
    padding: 6px 16px;
    font-size: 20px;
    border-top: 1px solid var(--theme-border-primary);
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    min-height: 32px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Prompt Area */
.prompt-area {
    background: var(--theme-bg-secondary);
    color: var(--theme-text-primary);
    padding: 12px 16px;
    font-size: 20px;
    border-top: 2px solid var(--theme-border-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.prompt-text {
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    white-space: pre-wrap;
}

.prompt-input {
    flex: 1;
    background: var(--theme-bg-tertiary);
    color: var(--theme-text-primary);
    border: 1px solid var(--theme-border-primary);
    padding: 4px 8px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 20px;
    outline: none;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
}

.prompt-input:focus {
    box-shadow: 0 0 10px var(--theme-shadow-glow);
}

.prompt-buttons {
    display: flex;
    gap: 8px;
}

.prompt-btn {
    background: var(--theme-accent-primary);
    color: var(--theme-text-inverted);
    border: none;
    padding: 4px 16px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 20px;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
    transition: all 0.2s;
}

.prompt-btn:hover {
    background: var(--theme-accent-hover);
    box-shadow: 0 0 10px var(--theme-shadow-medium);
}

/* Command Bar */
.command-bar {
    background: var(--theme-bg-secondary);
    padding: 8px 0;
    border-top: 2px solid var(--theme-border-primary);
    flex-shrink: 0;
}

.command-row {
    display: flex;
    justify-content: space-evenly;
    padding: 4px 8px;
}

.shortcut {
    background: transparent;
    color: var(--theme-text-primary);
    border: none;
    padding: 4px 8px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 18px;
    cursor: pointer;
    text-shadow: 0 0 8px var(--theme-shadow-faint);
    transition: all 0.2s;
    border-radius: 4px;
}

.shortcut:hover {
    background: var(--theme-bg-highlight);
    text-shadow: 0 0 12px var(--theme-shadow-medium);
}

.shortcut .key {
    color: var(--theme-text-highlight);
    font-weight: bold;
    margin-right: 4px;
}

/* Help Overlay */
.help-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--theme-bg-help-overlay);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow-y: auto;
}

.help-content {
    color: var(--theme-text-primary);
    max-width: 800px;
    width: 100%;
}

.help-content h2 {
    font-size: 32px;
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 0 0 15px var(--theme-shadow-medium);
    border-bottom: 2px solid var(--theme-border-primary);
    padding-bottom: 10px;
}

.help-content h3 {
    font-size: 24px;
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--theme-text-highlight);
    text-shadow: 0 0 10px var(--theme-shadow-faint);
}

.help-section {
    margin-bottom: 20px;
}

.help-content p {
    font-size: 20px;
    margin: 8px 0;
    padding-left: 20px;
    line-height: 1.4;
}

.help-key {
    display: inline-block;
    background: var(--theme-bg-highlight);
    color: var(--theme-text-highlight);
    padding: 2px 8px;
    border: 1px solid var(--theme-border-primary);
    margin-right: 10px;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
    border-radius: 3px;
}

.close-help {
    display: block;
    margin: 30px auto 0;
    background: var(--theme-accent-primary);
    color: var(--theme-text-inverted);
    border: 2px solid var(--theme-border-primary);
    padding: 8px 24px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 22px;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-help:hover {
    background: var(--theme-accent-hover);
    box-shadow: 0 0 20px var(--theme-shadow-medium);
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .shortcut {
        font-size: 16px;
        padding: 4px 6px;
    }
    
    .editor {
        font-size: 18px;
    }

    .top-bar, .status-bar, .prompt-area {
        font-size: 18px;
    }
}

@media (max-width: 768px) {
    .crt-container {
        padding: 5px;
    }
    
    .screen {
        border-width: 5px;
        border-radius: 5px;
    }

    /* --- Sidebar on Mobile --- */
    .main-container {
        flex-direction: column;
        position: relative;
    }

    .file-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 150;
        border-right: none;
        resize: none;
        max-width: none;
    }

    .editor-main-area {
        width: 100%;
        height: 100%;
    }
    /* --- End Sidebar on Mobile --- */
    
    .command-bar {
        padding: 4px 0;
    }
    
    .command-row {
        flex-wrap: wrap;
        justify-content: center;
        padding: 0;
    }
    
    .shortcut {
        font-size: 14px;
        padding: 2px 4px;
        flex-basis: 30%;
        text-align: left;
    }
    
    .top-bar {
        font-size: 16px;
        padding: 6px 10px;
    }

    .theme-switcher {
        font-size: 14px;
        gap: 4px;
    }
    .theme-switcher select {
        font-size: 14px;
    }
    
    .sync-btn {
        font-size: 14px;
        padding: 2px 6px;
    }

    .editor {
        font-size: 16px;
        padding: 8px;
    }

    .line-numbers {
        font-size: 16px;
        padding: 8px 4px;
        min-width: 35px;
    }

    .status-bar, .prompt-area {
        font-size: 16px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .theme-switcher {
        font-size: 12px;
        margin-left: 0;
    }
    .theme-switcher label {
        display: none;
    }

    .sync-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .shortcut {
        flex-basis: 45%;
        font-size: 13px;
    }
}

/* ========================================================================== */
/* PASSWORD PROTECTION / LOCK BUTTON STYLES
/* ========================================================================== */

/* Lock button in top bar */
#lockBtn {
    position: relative;
}

#lockBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.lock-icon {
    display: inline-block;
    font-size: 14px;
    margin-right: 2px;
}

/* Lock icon in file list */
.file-lock-icon {
    display: inline-block;
    font-size: 12px;
    margin-right: 4px;
    opacity: 0.8;
}

.file-item:hover .file-lock-icon {
    opacity: 1;
}

/* Special styling for locked documents */
.file-item.locked {
    font-style: italic;
}

/* Password prompt input - make it password type visually */
.prompt-input[type="text"] {
    /* By default, our prompt uses text input
       For better UX, we could modify the prompt function
       to support type="password" when needed */
}