:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #0f0f1a;
    --bg-dark: #0d1117;
    --border: rgba(255, 255, 255, 0.08);
    --text: #e2e8f0;
    --text-2: #94a3b8;
    --text-3: #64748b;
    --green: #4ade80;
    --yellow: #f7df1e;
    --radius: 12px;
    --token-tag: #f07178;
    --token-attr: #ffcb6b;
    --token-string: #c3e88d;
    --token-keyword: #c792ea;
    --token-function: #82aaff;
    --token-number: #f78c6c;
    --token-comment: #546e7a;
    --token-bracket: #a0aec0;
}

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

html,
body {
    height: 100%;
}

body {
    scroll-behavior: smooth;
    min-height: 100vh;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #0a0a0f 0%, #0f0f1a 50%, #13131f 100%);
    color: var(--text);
    line-height: 1.6;
}

nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: 60px;
    background: rgba(15, 15, 26, 0.85);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.nav-inner {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 100%;
    gap: 16px;
    padding: 0 24px;
}

.logo {
    font-family: 'Fira Code', monospace;
    background: var(--yellow);
    color: #111;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    flex-shrink: 0;
}

.nav-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}

.back-link {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-2);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
    text-decoration: none;
    flex-shrink: 0;
}

.back-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.workspace {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - 60px);
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 280px;
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-3);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.categories-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.category {
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.category-header {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.02);
    -webkit-user-select: none;
    user-select: none;
}

.category-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.category-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.category-toggle {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    transition: transform 0.2s;
}

.category.collapsed .category-toggle {
    transform: rotate(-90deg);
}

.projects-list {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.category.collapsed .projects-list {
    display: none;
}

.project-item {
    padding: 10px 16px 10px 32px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-2);
    font-size: 0.9rem;
    -webkit-user-select: none;
    user-select: none;
    border-left: 3px solid transparent;
    flex-shrink: 0;
}

.project-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-left-color: var(--green);
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.tabs-container {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.01);
    overflow-x: auto;
    padding: 0;
    align-items: stretch;
    flex-shrink: 0;
    min-height: 0;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

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

.tab.active {
    color: var(--text);
    border-bottom-color: var(--green);
    background: rgba(74, 222, 128, 0.08);
}

.tab-close {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s;
}

.tab-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ef4444;
}

.content-area {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 6px 1fr;
    gap: 0;
    overflow: hidden;
    min-height: 0;
    transition: grid-template-columns 0.1s ease;
}

.code-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    min-height: 0;
    transition: box-shadow 0.3s ease;
}

.code-panel.active {
    box-shadow: inset 0 0 20px rgba(74, 222, 128, 0.1);
}

.resizer {
    width: 6px;
    cursor: col-resize;
    background: rgba(255, 255, 255, 0.08);
    transition: all 0.1s linear;
    -webkit-user-select: none;
    user-select: none;
    z-index: 10;
    flex-shrink: 0;
}

.resizer:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.2);
}

.resizer.dragging {
    background: rgba(74, 222, 128, 0.4);
    box-shadow: 0 0 25px rgba(74, 222, 128, 0.5);
}

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

.panel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.panel-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-run {
    background: rgba(74, 222, 128, 0.1);
    border-color: rgba(74, 222, 128, 0.22);
    color: var(--green);
}

.btn-run:hover {
    background: rgba(74, 222, 128, 0.18);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.15);
    transform: translateY(-1px);
}

.fullscreen-btn {
    padding: 6px 12px;
    font-size: 0.75rem;
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--green);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.fullscreen-btn:hover {
    background: rgba(74, 222, 128, 0.2);
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.2);
}

.code-wrapper {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.code-container {
    display: flex;
    flex: 1;
    height: 100%;
    overflow: hidden;
    min-height: 0;
    align-items: stretch;
}

.line-numbers {
    background: var(--bg-dark);
    color: var(--text-3);
    padding: 20px 10px;
    text-align: right;
    -webkit-user-select: none;
    user-select: none;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.65;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
    min-width: 40px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-height: 0;
}

.line-numbers span {
    display: block;
}

#code-display {
    flex: 1;
    overflow: auto;
    overflow-x: auto;
    overflow-y: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.65;
    padding: 20px;
    background: var(--bg-dark);
    color: #c9d1d9;
    margin: 0;
    -webkit-user-select: none;
    user-select: none;
    white-space: pre;
    tab-size: 2;
    cursor: default;
    min-height: 0;
}

#code-display::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#code-display::-webkit-scrollbar-track {
    background: transparent;
}

#code-display::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#code-display::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.token {
    position: relative;
}

.token.tag {
    color: var(--token-tag);
    font-weight: 600;
}

.token.attr-name {
    color: var(--token-attr);
}

.token.attr-value {
    color: var(--token-string);
}

.token.string {
    color: var(--token-string);
}

.token.keyword {
    color: var(--token-keyword);
    font-weight: 600;
}

.token.function {
    color: var(--token-function);
}

.token.number {
    color: var(--token-number);
}

.token.comment {
    color: var(--token-comment);
    font-style: italic;
    opacity: 0.9;
}

.token.bracket {
    color: var(--token-bracket);
}

.preview-panel {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.02);
    overflow: hidden;
    min-height: 0;
    transition: box-shadow 0.3s ease;
    position: relative;
}

.preview-panel.active {
    box-shadow: inset 0 0 20px rgba(74, 222, 128, 0.1);
}

.fullscreen-exit-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10001;
    padding: 8px 16px;
    background: rgba(15, 15, 26, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: none;
    backdrop-filter: blur(10px);
}

.fullscreen-exit-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.12);
}

.preview-fullscreen {
    overflow: hidden;
    background: #050505;
}

.preview-fullscreen nav,
.preview-fullscreen .sidebar,
.preview-fullscreen #code-panel,
.preview-fullscreen .resizer,
.preview-fullscreen .tabs-container {
    display: none !important;
}

.preview-fullscreen .workspace {
    grid-template-columns: 1fr;
    top: 0;
    height: 100vh;
}

.preview-fullscreen .main-area {
    width: 100vw;
    height: 100vh;
}

.preview-fullscreen #preview-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    margin: 0;
    border: none;
    border-radius: 0;
    background: #050505;
    animation: fadeIn 0.3s ease;
}

.preview-fullscreen #preview-panel .panel-header {
    display: none;
}

.preview-fullscreen #preview-panel .fullscreen-exit-btn {
    display: inline-flex;
}

.preview-fullscreen #preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.preview-wrapper {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

#preview-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-3);
    font-size: 0.95rem;
    transition: opacity 0.3s, visibility 0.3s;
}

#preview-placeholder.hidden {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    pointer-events: none;
}

.placeholder-icon {
    font-size: 3rem;
    animation: pulse 2s ease-in-out infinite;
}

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

#preview-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: #ffffff;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    min-height: 0;
}

#preview-iframe.visible {
    opacity: 1;
    visibility: visible;
}

body.dragging {
    cursor: col-resize;
    -webkit-user-select: none;
    user-select: none;
}

@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .content-area {
        grid-template-columns: 1fr;
    }

    .resizer {
        display: none;
    }
}

@media (max-width: 768px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .sidebar {
        width: 100%;
        max-height: 180px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        display: flex;
    }

    .main-area {
        flex: 1;
        min-height: 0;
    }

    .content-area {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .code-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        height: 50vh;
    }

    .preview-panel {
        height: 50vh;
    }

    .resizer {
        display: none;
    }

    .tab {
        padding: 10px 12px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .code-panel,
    .preview-panel {
        height: auto;
        min-height: 400px;
    }

    .panel-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .panel-title {
        font-size: 0.9rem;
    }

    .fullscreen-btn {
        padding: 5px 10px;
        font-size: 0.7rem;
    }
}

/* Fullscreen Mode */
body.preview-fullscreen .sidebar,
body.preview-fullscreen #code-panel,
body.preview-fullscreen .resizer,
body.preview-fullscreen .tabs-container {
    display: none !important;
}

body.preview-fullscreen .workspace {
    grid-template-columns: 1fr;
    top: 0;
    height: 100vh;
}

body.preview-fullscreen .main-area {
    width: 100vw;
    height: 100vh;
}

body.preview-fullscreen #preview-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border: none;
    margin: 0;
    border-radius: 0;
    background: #050505;
    animation: fadeIn 0.3s ease;
}
