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

/* ===================================
   THEME VARIABLES
   =================================== */
html, .theme-intellij-dark {
    --bg-body: #1e1e1e;
    --bg-shell: #181818;
    --bg-editor: #1e1e1e;
    --bg-popup: #252526;
    --border-color: #2d2d2d;
    --border-popup: #3c3c3c;

    --text-primary: #d4d4d4;
    --text-secondary: #cccccc;
    --text-muted: #6e6e6e;
    --text-sidebar-file: #9e9e9e;
    --text-line-number: #4e4e4e;
    --text-folder-arrow: #8c8c8c;

    --accent: #007acc;
    --accent-hover: #1a8ad4;

    --hover-bg: #2a2d2e;
    --active-bg: #37373d;
    --active-text: #ffffff;
    --tab-active-bg: #1e1e1e;

    --line-hover: rgba(255, 255, 255, 0.03);
    --clickable-hover: rgba(0, 122, 204, 0.1);

    --cursor-color: #d4d4d4;

    /* Syntax */
    --syn-keyword: #cc7832;
    --syn-class: #a9b7c6;
    --syn-string: #6a8759;
    --syn-function: #ffc66d;
    --syn-comment: #808080;
    --syn-annotation: #bbb529;
    --syn-number: #6897bb;
    --syn-link-border: rgba(106, 135, 89, 0.5);

    /* Terminal */
    --term-prompt: #6a8759;
    --term-cmd: #d4d4d4;
    --term-info: #808080;
    --term-success: #6a8759;
    --term-highlight: #ffc66d;
}

.theme-one-dark {
    --bg-body: #282c34;
    --bg-shell: #21252b;
    --bg-editor: #282c34;
    --bg-popup: #2c313a;
    --border-color: #181a1f;
    --border-popup: #3e4452;

    --text-primary: #abb2bf;
    --text-secondary: #9da5b4;
    --text-muted: #636d83;
    --text-sidebar-file: #7f848e;
    --text-line-number: #495162;
    --text-folder-arrow: #636d83;

    --accent: #528bff;
    --accent-hover: #6da0ff;

    --hover-bg: #2c313a;
    --active-bg: #323842;
    --active-text: #ffffff;
    --tab-active-bg: #282c34;

    --line-hover: rgba(255, 255, 255, 0.03);
    --clickable-hover: rgba(82, 139, 255, 0.1);

    --cursor-color: #abb2bf;

    --syn-keyword: #c678dd;
    --syn-class: #e5c07b;
    --syn-string: #98c379;
    --syn-function: #61afef;
    --syn-comment: #5c6370;
    --syn-annotation: #e5c07b;
    --syn-number: #d19a66;
    --syn-link-border: rgba(152, 195, 121, 0.5);

    --term-prompt: #98c379;
    --term-cmd: #abb2bf;
    --term-info: #5c6370;
    --term-success: #98c379;
    --term-highlight: #e5c07b;
}

.theme-intellij-light {
    --bg-body: #ffffff;
    --bg-shell: #f5f5f5;
    --bg-editor: #ffffff;
    --bg-popup: #f0f0f0;
    --border-color: #d1d1d1;
    --border-popup: #c4c4c4;

    --text-primary: #2b2b2b;
    --text-secondary: #555555;
    --text-muted: #999999;
    --text-sidebar-file: #777777;
    --text-line-number: #adadad;
    --text-folder-arrow: #999999;

    --accent: #007acc;
    --accent-hover: #005a9e;

    --hover-bg: #e8e8e8;
    --active-bg: #d4d4d4;
    --active-text: #2b2b2b;
    --tab-active-bg: #ffffff;

    --line-hover: rgba(0, 0, 0, 0.03);
    --clickable-hover: rgba(0, 122, 204, 0.08);

    --cursor-color: #2b2b2b;

    --syn-keyword: #0033b3;
    --syn-class: #000000;
    --syn-string: #067d17;
    --syn-function: #00627a;
    --syn-comment: #8c8c8c;
    --syn-annotation: #9e880d;
    --syn-number: #1750eb;
    --syn-link-border: rgba(6, 125, 23, 0.4);

    --term-prompt: #067d17;
    --term-cmd: #2b2b2b;
    --term-info: #8c8c8c;
    --term-success: #067d17;
    --term-highlight: #00627a;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'JetBrains Mono', monospace;
    -webkit-font-smoothing: antialiased;
    background: var(--bg-body);
    color: var(--text-primary);
}

/* ===================================
   IDE SHELL
   =================================== */
.ide {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Title bar */
.titlebar {
    height: 38px;
    background: var(--bg-shell);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.titlebar-dots {
    display: flex;
    gap: 6px;
}

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

.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }

.titlebar-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Status bar */
.statusbar {
    height: 24px;
    background: var(--accent);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1rem;
    font-size: 0.6875rem;
    color: #fff;
    flex-shrink: 0;
}

.statusbar-right {
    margin-left: auto;
}

/* ===================================
   IDE BODY
   =================================== */
.ide-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ===================================
   SIDEBAR
   =================================== */
.sidebar {
    width: 240px;
    background: var(--bg-shell);
    border-right: 1px solid var(--border-color);
    padding: 0.75rem 0;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.25rem 1rem 0.5rem;
}

.tree-folder {
    padding: 0.2rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: default;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.folder-arrow {
    font-size: 0.5rem;
    width: 0.75rem;
    text-align: center;
    flex-shrink: 0;
    color: var(--text-folder-arrow);
}

.tree-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.tree-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-indent {
    padding-left: 1rem;
}

.tree-file {
    padding: 0.2rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-sidebar-file);
    cursor: pointer;
    border-radius: 4px;
    margin: 1px 0.5rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

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

.tree-file.active {
    background: var(--active-bg);
    color: var(--active-text);
}

/* ===================================
   EDITOR AREA
   =================================== */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-shell);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.tab {
    padding: 0.5rem 1.25rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
    border-right: 1px solid var(--border-color);
    transition: all 0.15s;
    white-space: nowrap;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background: var(--tab-active-bg);
    color: var(--active-text);
    border-bottom: 2px solid var(--accent);
}

/* Editor */
.editor {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-editor);
}

/* File content */
.file-content {
    display: none;
}

.file-content.active {
    display: block;
}

/* ===================================
   CODE BLOCK
   =================================== */
.code-block {
    padding: 1rem 0;
    font-size: 0.875rem;
    line-height: 1.65;
    counter-reset: line;
}

.line {
    padding: 0 1.5rem 0 4rem;
    position: relative;
    white-space: pre;
    transition: background 0.1s;
}

.line:hover {
    background: var(--line-hover);
}

.line::before {
    counter-increment: line;
    content: counter(line);
    position: absolute;
    left: 0;
    width: 3rem;
    text-align: right;
    color: var(--text-line-number);
    font-size: 0.8125rem;
    user-select: none;
}

.line.blank {
    height: 1.43em;
}

.line.blank::before {
    counter-increment: line;
    content: counter(line);
}

.i1 { padding-left: calc(4rem + 2rem); }
.i2 { padding-left: calc(4rem + 4rem); }
.i3 { padding-left: calc(4rem + 6rem); }
.i4 { padding-left: calc(4rem + 8rem); }
.i5 { padding-left: calc(4rem + 10rem); }

/* Clickable methods */
.line.clickable {
    cursor: pointer;
}

.line.clickable:hover {
    background: var(--clickable-hover);
}

.line.clickable .fn {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ===================================
   SYNTAX COLORS (IntelliJ Dark)
   =================================== */
.kw { color: var(--syn-keyword); font-weight: 600; }
.cls { color: var(--syn-class); font-weight: 700; }
.str { color: var(--syn-string); }
.fn { color: var(--syn-function); }
.cmt { color: var(--syn-comment); font-style: italic; }
.pkg { color: var(--syn-class); }
.ann { color: var(--syn-annotation); }
.num { color: var(--syn-number); }

.str a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed var(--syn-link-border);
    transition: border-color 0.2s;
}

.str a:hover {
    border-bottom-style: solid;
    border-bottom-color: var(--syn-string);
}

/* ===================================
   TERMINAL
   =================================== */
.terminal {
    height: 25vh;
    border-top: 1px solid var(--border-color);
    background: var(--bg-shell);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: height 0.2s ease;
}

.terminal.minimized {
    height: 0;
}

.terminal.minimized .terminal-body {
    display: none;
}

.terminal-header {
    padding: 0.375rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.terminal-header:hover {
    background: var(--hover-bg);
}

.terminal-toggle {
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.terminal.minimized .terminal-toggle {
    transform: rotate(180deg);
}

.terminal-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.terminal-body {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    overflow-y: auto;
    flex: 1;
}

.term-line {
    white-space: pre-wrap;
    line-height: 1.6;
}

.term-prompt {
    color: var(--term-prompt);
}

.term-cmd {
    color: var(--term-cmd);
}

.term-info {
    color: var(--term-info);
}

.term-success {
    color: var(--term-success);
}

.term-highlight {
    color: var(--term-highlight);
}

.cursor-blink {
    display: inline-block;
    width: 8px;
    height: 14px;
    background: var(--cursor-color);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

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

/* ===================================
   POPUP
   =================================== */
.popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.popup.visible {
    display: flex;
}

.popup-inner {
    background: var(--bg-popup);
    border: 1px solid var(--border-popup);
    border-radius: 8px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
}

.popup-title {
    font-size: 0.875rem;
    color: var(--syn-function);
    margin-bottom: 1rem;
}

.popup-content {
    font-size: 0.875rem;
    line-height: 2;
    margin-bottom: 1.5rem;
}

.popup-close {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.popup-close:hover {
    background: var(--accent-hover);
}

/* ===================================
   THEME PICKER
   =================================== */
.theme-picker {
    position: relative;
}

.theme-picker-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6875rem;
    transition: color 0.15s, background 0.15s;
}

.theme-picker-btn:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}

.theme-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-popup);
    border: 1px solid var(--border-popup);
    border-radius: 6px;
    padding: 4px 0;
    min-width: 150px;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.theme-dropdown.open {
    display: block;
}

.theme-option {
    padding: 6px 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.1s;
}

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

.theme-option.active {
    color: var(--accent);
}

/* ===================================
   RESPONSIVE
   =================================== */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .titlebar-text {
        display: none;
    }

    .code-block {
        font-size: 0.75rem;
    }

    .line {
        padding-left: 2.75rem;
    }

    .line::before {
        width: 2rem;
        font-size: 0.6875rem;
    }

    .i1 { padding-left: calc(2.75rem + 1.25rem); }
    .i2 { padding-left: calc(2.75rem + 2.5rem); }
    .i3 { padding-left: calc(2.75rem + 3.75rem); }
    .i4 { padding-left: calc(2.75rem + 5rem); }
    .i5 { padding-left: calc(2.75rem + 6.25rem); }

    .terminal {
        height: 20vh;
    }
}

@media (max-width: 480px) {
    .tabs {
        overflow-x: auto;
    }

    .tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }

    .code-block {
        font-size: 0.6875rem;
    }
}
