/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, var(--surface-color) 0%, var(--background-color) 100%);
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Main content */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

/* Section styles */
.editor-section,
.controls-section,
.preview-section {
    display: flex;
    flex-direction: column;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Editor section */
#code-input {
    flex: 1;
    min-height: 400px;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    background-color: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    resize: vertical;
    transition: var(--transition);
}

#code-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

#code-input::placeholder {
    color: var(--text-muted);
}

/* Language select */
.language-select {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.language-select label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Controls section */
.controls-section {
    gap: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    padding-right: 0.5rem;
}

.control-group {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.control-group h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.control-item {
    margin-bottom: 1rem;
}

.control-item:last-child {
    margin-bottom: 0;
}

.control-item label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.control-item label span {
    color: var(--primary-color);
    font-weight: 500;
}

/* Checkbox items */
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-item label {
    margin-bottom: 0;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Input styles */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

input[type="color"] {
    width: 100%;
    height: 36px;
    padding: 2px;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

select {
    cursor: pointer;
}

/* Annotation controls */
.annotation-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.annotations-list {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.annotation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background-color: var(--background-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.annotation-item span {
    color: var(--text-secondary);
}

.annotation-item strong {
    color: var(--primary-color);
    margin-right: 0.5rem;
}

.annotation-item button {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.7;
    transition: var(--transition);
}

.annotation-item button:hover {
    opacity: 1;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

/* Export buttons */
.export-group {
    margin-top: auto;
}

.export-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.export-buttons .btn {
    width: 100%;
}

/* Preview section */
.preview-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    overflow: auto;
    min-height: 400px;
}

.preview-scale {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-scale label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.preview-scale select {
    width: auto;
    padding: 0.25rem 0.5rem;
}

/* Code preview */
.code-preview {
    display: inline-block;
    min-width: 300px;
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    transition: var(--transition);
}

.window-controls {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background-color: rgba(0, 0, 0, 0.3);
}

.window-controls.hidden {
    display: none;
}

.window-controls .control {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.window-controls .close {
    background-color: #ff5f57;
}

.window-controls .minimize {
    background-color: #febc2e;
}

.window-controls .maximize {
    background-color: #28c840;
}

.code-content {
    padding: 24px;
    overflow-x: auto;
}

.code-content pre {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 16px;
    line-height: 1.6;
}

.code-content code {
    font-family: inherit;
}

/* Code line styles */
.code-line {
    display: flex;
    align-items: flex-start;
    position: relative;
}

.code-line.highlighted {
    background-color: rgba(254, 240, 138, 0.3);
    margin: 0 -24px;
    padding: 0 24px;
}

.line-number {
    user-select: none;
    min-width: 2.5em;
    padding-right: 1em;
    text-align: right;
    opacity: 0.5;
    flex-shrink: 0;
}

.line-content {
    flex: 1;
    white-space: pre;
}

/* Annotation styles */
.line-annotation {
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translate(100%, -50%);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.line-annotation::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--primary-color);
}

/* Theme styles */
.theme-dark {
    background: linear-gradient(135deg, #272822 0%, #1e1f1c 100%);
    color: #f8f8f2;
}

.theme-dark .code-content {
    background-color: #272822;
}

.theme-light {
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
    color: #24292e;
}

.theme-light .code-content {
    background-color: #ffffff;
}

.theme-light .window-controls {
    background-color: #f0f0f0;
}

.theme-github {
    background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
    color: #c9d1d9;
}

.theme-github .code-content {
    background-color: #0d1117;
}

.theme-dracula {
    background: linear-gradient(135deg, #282a36 0%, #1e1f29 100%);
    color: #f8f8f2;
}

.theme-dracula .code-content {
    background-color: #282a36;
}

.theme-nord {
    background: linear-gradient(135deg, #2e3440 0%, #3b4252 100%);
    color: #eceff4;
}

.theme-nord .code-content {
    background-color: #2e3440;
}

/* Syntax highlighting colors by theme */
.theme-dark .keyword { color: #f92672; }
.theme-dark .string { color: #e6db74; }
.theme-dark .number { color: #ae81ff; }
.theme-dark .comment { color: #75715e; }
.theme-dark .function { color: #a6e22e; }
.theme-dark .operator { color: #f92672; }
.theme-dark .punctuation { color: #f8f8f2; }
.theme-dark .class-name { color: #66d9ef; font-style: italic; }
.theme-dark .tag { color: #f92672; }
.theme-dark .attr-name { color: #a6e22e; }
.theme-dark .attr-value { color: #e6db74; }

.theme-light .keyword { color: #d73a49; }
.theme-light .string { color: #032f62; }
.theme-light .number { color: #005cc5; }
.theme-light .comment { color: #6a737d; }
.theme-light .function { color: #6f42c1; }
.theme-light .operator { color: #d73a49; }
.theme-light .punctuation { color: #24292e; }
.theme-light .class-name { color: #22863a; }
.theme-light .tag { color: #22863a; }
.theme-light .attr-name { color: #6f42c1; }
.theme-light .attr-value { color: #032f62; }

.theme-github .keyword { color: #ff7b72; }
.theme-github .string { color: #a5d6ff; }
.theme-github .number { color: #79c0ff; }
.theme-github .comment { color: #8b949e; }
.theme-github .function { color: #d2a8ff; }
.theme-github .operator { color: #ff7b72; }
.theme-github .punctuation { color: #c9d1d9; }
.theme-github .class-name { color: #7ee787; }
.theme-github .tag { color: #7ee787; }
.theme-github .attr-name { color: #79c0ff; }
.theme-github .attr-value { color: #a5d6ff; }

.theme-dracula .keyword { color: #ff79c6; }
.theme-dracula .string { color: #f1fa8c; }
.theme-dracula .number { color: #bd93f9; }
.theme-dracula .comment { color: #6272a4; }
.theme-dracula .function { color: #50fa7b; }
.theme-dracula .operator { color: #ff79c6; }
.theme-dracula .punctuation { color: #f8f8f2; }
.theme-dracula .class-name { color: #8be9fd; font-style: italic; }
.theme-dracula .tag { color: #ff79c6; }
.theme-dracula .attr-name { color: #50fa7b; }
.theme-dracula .attr-value { color: #f1fa8c; }

.theme-nord .keyword { color: #81a1c1; }
.theme-nord .string { color: #a3be8c; }
.theme-nord .number { color: #b48ead; }
.theme-nord .comment { color: #616e88; }
.theme-nord .function { color: #88c0d0; }
.theme-nord .operator { color: #81a1c1; }
.theme-nord .punctuation { color: #eceff4; }
.theme-nord .class-name { color: #8fbcbb; }
.theme-nord .tag { color: #81a1c1; }
.theme-nord .attr-name { color: #8fbcbb; }
.theme-nord .attr-value { color: #a3be8c; }

/* Footer */
.footer {
    padding: 1.5rem 2rem;
    text-align: center;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--surface-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success-color);
}

.toast.error {
    border-color: var(--error-color);
}

/* Scrollbar styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
    border-radius: 4px;
}

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

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

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    .controls-section {
        grid-column: 1 / -1;
        grid-row: 2;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1rem;
        max-height: none;
        overflow-y: visible;
    }

    .preview-section {
        grid-column: 2;
        grid-row: 1;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .main-content {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }

    .editor-section,
    .preview-section {
        grid-column: 1;
    }

    .controls-section {
        grid-template-columns: 1fr;
    }

    #code-input {
        min-height: 250px;
    }

    .preview-container {
        min-height: 300px;
        padding: 1rem;
    }

    .code-preview {
        min-width: 100%;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .export-buttons {
        flex-direction: column;
    }

    .footer {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }

    .logo h1 {
        font-size: 1.1rem;
    }

    .control-group {
        padding: 0.75rem;
    }

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

    .code-content {
        padding: 16px;
    }

    .code-content pre {
        font-size: 12px;
    }
}

/* Print styles */
@media print {
    .header,
    .controls-section,
    .footer,
    .section-header {
        display: none;
    }

    .main-content {
        display: block;
        padding: 0;
    }

    .editor-section {
        display: none;
    }

    .preview-container {
        border: none;
        background: none;
        padding: 0;
    }
}
