:root {
    --color-bg: #111317;
    --color-panel: #181b21;
    --color-surface: #1f232a;
    --color-surface-alt: #242832;
    --color-border: #2f343d;
    --color-text: #f3f4f6;
    --color-muted: #a9afbd;
    --color-chip-bg: #242831;
    --color-chip-active-text: #f9fafb;
    --color-chip-active-border: #cdd3de;
    --color-handle: #2a2f39;
    --color-handle-active: #9ea3b1;
    --color-console-bg: #161920;
    --color-code-bg: #1b1f27;
    --color-code-border: #2b3038;
    --color-run-bg: #cfe8d7;
    --color-run-text: #15171b;
    --color-inline-code: rgba(255, 255, 255, 0.08);
    --editor-gutter-width: 52px;
    --editor-bg: #1E1E1E;
    --editor-border: #2d2d2d;
    --editor-gutter-bg: #252526;
    --editor-text-default: #D4D4D4;
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Top bar */

.topbar {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--color-panel);
    border-bottom: 1px solid var(--color-border);
}

.exam-title {
    font-size: 22px;
    font-weight: 500;
    color: var(--color-text);
}

/* Layout */

.layout {
    flex: 1;
    display: flex;
    height: calc(100vh - 48px);
}

/* LEFT */

.left-panel {
    padding: 18px 20px;
    background: var(--color-panel);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    min-width: 200px; /* Largeur minimum */
    width: 50%; /* Largeur initiale */
}

.chips-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--color-muted);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.chip {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-chip-bg);
    color: var(--color-muted);
    cursor: pointer;
}

.chip.active {
    border-color: var(--color-chip-active-border);
    color: var(--color-chip-active-text);
}

/* Subject */

.subject {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 10px;
}

.subject-box {
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-muted);
    white-space: normal;
}

.markdown-viewer {
    overflow: auto;
    max-height: calc(100vh - 220px);
    line-height: 1.6;
    font-size: 14px;
}

.markdown-viewer h1,
.markdown-viewer h2,
.markdown-viewer h3,
.markdown-viewer h4,
.markdown-viewer h5,
.markdown-viewer h6 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    color: var(--color-text);
}

.markdown-viewer p {
    margin-bottom: 1em;
    color: var(--color-muted);
}

.markdown-viewer ul,
.markdown-viewer ol {
    margin: 0 0 1em 1.2em;
    padding-left: 1.2em;
}

.markdown-viewer li {
    margin-bottom: 0.4em;
}

.markdown-viewer pre {
    background: var(--color-code-bg);
    border-radius: 8px;
    padding: 12px;
    border: 1px solid var(--color-code-border);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 12px;
    overflow-x: auto;
}

.markdown-viewer code {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    background: var(--color-inline-code);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 12px;
}

/* Resize handles */
.resize-handle {
    background: var(--color-handle);
    transition: background-color 0.2s;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--color-handle-active);
}

.resize-handle.vertical {
    cursor: col-resize;
    width: 4px;
}

.resize-handle.horizontal {
    cursor: row-resize;
    height: 4px;
}

/* RIGHT */

.right-panel {
    flex: 1;
    padding: 18px 20px 14px 20px;
    background: var(--color-panel);
    display: flex;
    flex-direction: column;
    min-width: 300px; /* Largeur minimum */
}

.editor-container {
    display: flex;
    flex-direction: column;
    min-height: 100px; /* Hauteur minimum de l'éditeur */
    height: 60%; /* Hauteur initiale */
}

.console-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100px; /* Hauteur minimum de la console */
}

/* Editor */

.editor-header {
    height: 24px;
    display: flex;
    align-items: flex-end;
}

.editor-tab {
    padding: 4px 10px;
    border-radius: 6px 6px 0 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom: none;
    font-size: 10px;
    color: var(--color-muted);
}

.editor-box {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    background: var(--editor-bg);
    border: 1px solid var(--editor-border);
    display: flex;
}

#code-editor {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: transparent; /* hide native glyphs */
    -webkit-text-fill-color: transparent; /* ensure WebKit/Blink also hide glyphs */
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
}

/* wrapper for highlighted layer + textarea */
.editor-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

.line-numbers {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--editor-gutter-width);
    padding: 6px 8px;
    background: var(--editor-gutter-bg);
    border-right: 1px solid var(--editor-border);
    text-align: right;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--color-muted);
    user-select: none;
    pointer-events: none;
    overflow: hidden;
    z-index: 2;
}

.line-numbers pre {
    margin: 0;
    font: inherit;
    color: inherit;
    white-space: pre;
    tab-size: 4;
}

.highlighted-code {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 6px 8px 6px calc(var(--editor-gutter-width) + 8px);
    pointer-events: none; /* let textarea receive events */
    color: var(--editor-text-default);
    overflow: auto;
    white-space: pre-wrap;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
    background: transparent;
    z-index: 0;
    tab-size: 4;
    word-break: normal;
}

.highlighted-code code {
    font: inherit;
    line-height: inherit;
    white-space: inherit;
    tab-size: inherit;
}

.editor-wrapper.show-plain .highlighted-code {
    opacity: 0;
}

.editor-wrapper.show-plain #code-editor {
    color: var(--editor-text-default);
    -webkit-text-fill-color: var(--editor-text-default);
}

#code-editor {
    position: absolute;
    inset: 0;
    z-index: 1;
    padding: 6px 8px 6px calc(var(--editor-gutter-width) + 8px);
    caret-color: var(--editor-text-default);
    /* show selection background even though text is transparent */
    background-clip: padding-box;
    tab-size: 4;
    white-space: pre-wrap;
}

/* Syntax token colors (VS Code dark palette inspired) */
.tok-keyword { color: #C586C0; }
.tok-type { color: #569CD6; }
.tok-function { color: #DCDCAA; }
.tok-variable { color: #9CDCFE; }
.tok-string { color: #CE9178; }
.tok-import { color: #CE9178; }
.tok-number { color: #B5CEA8; }
.tok-comment { color: #6A9955; }


/* Console */

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.console-label {
    font-size: 10px;
    color: var(--color-muted);
}

.btn-small {
    padding: 2px 8px;
    border-radius: 14px;
    border: none;
    font-size: 9px;
    background: var(--color-surface-alt);
    color: var(--color-muted);
    cursor: pointer;
}

.console-box {
    /* Make console responsive: take remaining space in the right panel */
    flex: 1 1 auto;
    min-height: 80px;
    margin-top: 4px;
    padding: 8px;
    border-radius: 8px;
    background: var(--color-console-bg);
    border: 1px solid var(--color-border);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 11px;
    color: var(--color-muted);
    white-space: pre-wrap;
    overflow-y: auto;
}

/* Actions */

.actions {
    margin-top: 6px;
    display: flex;
    gap: 8px;
}

.btn-run {
    padding: 4px 14px;
    border-radius: 18px;
    border: none;
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}

.btn-run {
    background: var(--color-run-bg);
    color: var(--color-run-text);
    font-weight: 600;
}
