/* ============================
   Design Tokens
   ============================ */
:root {
    --bg-primary: #0d0d1a;
    --bg-secondary: #13132b;
    --bg-panel: rgba(20, 20, 50, 0.65);
    --bg-panel-header: rgba(30, 30, 65, 0.8);
    --bg-editor: #0a0a1e;
    --bg-output: #080818;

    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #555570;

    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.35);
    --accent-light: #a29bfe;

    --green: #00e676;
    --green-glow: rgba(0, 230, 118, 0.25);
    --red: #ff5252;
    --red-glow: rgba(255, 82, 82, 0.25);
    --yellow: #ffd740;

    --border: rgba(108, 92, 231, 0.15);
    --border-focus: rgba(108, 92, 231, 0.4);

    --radius: 10px;
    --radius-sm: 6px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================
   Reset & Base
   ============================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
    opacity: 0;
    transition: opacity 0.6s ease;
}

body.loaded {
    opacity: 1;
}

/* Ambient gradient backdrop */
.backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 60% 50% at 20% 10%, rgba(108, 92, 231, 0.12) 0%, transparent 70%),
        radial-gradient(ellipse 50% 40% at 80% 80%, rgba(0, 230, 118, 0.06) 0%, transparent 60%),
        var(--bg-primary);
}

/* ============================
   Container
   ============================ */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 24px 40px;
}

/* ============================
   Header
   ============================ */
header {
    text-align: center;
    margin-bottom: 28px;
    padding-top: 16px;
}

header h1 {
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--green) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.15;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 4px;
    letter-spacing: 0.03em;
}

/* ============================
   Toolbar
   ============================ */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.engine-toggle {
    display: flex;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    backdrop-filter: blur(12px);
}

.engine-btn {
    padding: 8px 18px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.engine-btn:hover {
    color: var(--text-primary);
    background: rgba(108, 92, 231, 0.1);
}

.engine-btn.active {
    color: var(--bg-primary);
    background: var(--accent-light);
    font-weight: 600;
}

.toolbar-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ============================
   Panels (Editor & Output)
   ============================ */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition);
}

.editor-panel {
    grid-column: 1 / 2;
}

.output-panel {
    grid-column: 2 / 3;
}

.compiler-main-panel {
    grid-column: 1 / 2;
}

.compiler-constants-panel {
    grid-column: 2 / 3;
}

.panel:focus-within {
    border-color: var(--border-focus);
}

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

.panel-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

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

.hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ============================
   Code Editor
   ============================ */
#code-editor {
    width: 100%;
    height: 480px;
    padding: 16px;
    border: none;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.65;
    resize: none;
    outline: none;
    background: var(--bg-editor);
    color: var(--text-primary);
    tab-size: 4;
    -moz-tab-size: 4;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
}

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

#code-editor::selection {
    background: rgba(108, 92, 231, 0.35);
}

/* ============================
   Output
   ============================ */
.output-container {
    height: 480px;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg-output);
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.65;
}

.compiler-container {
    height: 300px;
}

.output-placeholder {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    margin-top: 60px;
    font-size: 0.85rem;
}

.output-content {
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-word;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
}

.output-status {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.error-msg {
    color: var(--red);
    background: var(--red-glow);
    border: 1px solid rgba(255, 82, 82, 0.3);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

/* ============================
   Buttons
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-run {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 0 var(--accent-glow);
}

.btn-run:hover {
    background: #7c6cf0;
    box-shadow: 0 0 20px 2px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-stop {
    background: var(--red);
    color: #fff;
    animation: pulse-stop 1.5s ease-in-out infinite;
}

@keyframes pulse-stop {

    0%,
    100% {
        box-shadow: 0 0 0 0 var(--red-glow);
    }

    50% {
        box-shadow: 0 0 16px 4px var(--red-glow);
    }
}

.btn-stop:hover {
    background: #ff3333;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text-primary);
    border-color: var(--border-focus);
    background: rgba(108, 92, 231, 0.08);
}

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

/* ============================
   Select
   ============================ */
select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--transition);
    backdrop-filter: blur(8px);
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888aa' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

select:focus {
    outline: none;
    border-color: var(--border-focus);
    color: var(--text-primary);
}

select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ============================
   Info Bar
   ============================ */
.info-bar {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    backdrop-filter: blur(12px);
}

.info-items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    justify-content: center;
}

.dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.info-items code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: rgba(108, 92, 231, 0.12);
    color: var(--accent-light);
    padding: 1px 6px;
    border-radius: 3px;
}

/* ============================
   Scrollbar
   ============================ */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(108, 92, 231, 0.25);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(108, 92, 231, 0.45);
}

/* ============================
   Responsive
   ============================ */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    header h1 {
        font-size: 1.8rem;
    }

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

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .engine-toggle {
        justify-content: center;
    }

    .toolbar-right {
        justify-content: center;
    }

    #code-editor,
    .output-container {
        height: 350px;
    }

    .info-items {
        justify-content: center;
    }
}
