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

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #f4f6f9;
    color: #1a1a2e;
    min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
header {
    background: #1a1a2e;
    color: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    flex: 1;
}

#topic-select,
#question-select {
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    border: none;
    font-size: 0.95rem;
    background: #fff;
    color: #1a1a2e;
}

#topic-select    { min-width: 180px; }
#question-select { min-width: 220px; }

#question-select:disabled { opacity: 0.5; cursor: not-allowed; }

#browse-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.difficulty-filter {
    display: flex;
    gap: 0.25rem;
}

.difficulty-filter button {
    padding: 0.3rem 0.55rem;
    border: 1.5px solid rgba(255,255,255,0.35);
    background: transparent;
    color: #ffd700;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    transition: background 0.15s;
}

.difficulty-filter button:first-child { color: #fff; }

.difficulty-filter button.active,
.difficulty-filter button:hover {
    background: rgba(255,255,255,0.18);
    border-color: #fff;
}

#set-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
}

#set-title {
    font-weight: 700;
    font-size: 0.95rem;
}

#set-progress {
    background: rgba(255,255,255,0.15);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.85rem;
}

#prev-btn, #next-btn {
    padding: 0.3rem 0.6rem;
    border: 1.5px solid rgba(255,255,255,0.4);
    background: transparent;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
}

#prev-btn:disabled, #next-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

#prev-btn:not(:disabled):hover,
#next-btn:not(:disabled):hover {
    background: rgba(255,255,255,0.18);
}

#exit-set-btn {
    padding: 0.3rem 0.7rem;
    border: 1.5px solid rgba(255,255,255,0.35);
    background: transparent;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    margin-left: auto;
}

#exit-set-btn:hover { background: rgba(255,255,255,0.18); }

/* ── Board switcher ───────────────────────────────────────────────────────── */
.board-switcher {
    display: flex;
    gap: 0.3rem;
}

.board-switcher button {
    padding: 0.35rem 0.8rem;
    border: 1.5px solid rgba(255,255,255,0.4);
    background: transparent;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.board-switcher button.active,
.board-switcher button:hover {
    background: rgba(255,255,255,0.18);
    border-color: #fff;
}

/* ── Test code / attempt buttons ──────────────────────────────────────────── */
#test-code-btn,
#view-attempt-btn {
    padding: 0.35rem 0.9rem;
    border: 1.5px solid rgba(255,255,255,0.4);
    background: transparent;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
    transition: background 0.15s;
}
#test-code-btn:hover,
#view-attempt-btn:hover { background: rgba(255,255,255,0.18); }

/* ── Main content ─────────────────────────────────────────────────────────── */
main {
    max-width: 980px;
    margin: 1.5rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

section {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

section h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
    margin-bottom: 0.9rem;
}

/* ── Welcome screen ───────────────────────────────────────────────────────── */
.welcome h3 {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
    color: #1a1a2e;
}

.welcome h4 {
    font-size: 0.95rem;
    margin: 1rem 0 0.4rem;
    color: #1a1a2e;
}

.welcome p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #444;
    margin-bottom: 0.4rem;
}

.welcome ul {
    padding-left: 1.4rem;
    font-size: 0.95rem;
    line-height: 1.8;
    color: #444;
}

/* ── Code block ───────────────────────────────────────────────────────────── */
.code-block {
    background: #1e1e2e;
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.code-block-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 1rem;
    background: #16162a;
    border-bottom: 1px solid #2a2a3e;
}

.code-lang-badge {
    font-size: 0.72rem;
    font-weight: 700;
    color: #7a7a9a;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.code-pre {
    margin: 0;
    padding: 1rem 1.2rem;
    overflow-x: auto;
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: 0.92rem;
    line-height: 1.65;
    color: #cdd6f4;
    tab-size: 4;
    white-space: pre;
}

/* Syntax highlight token colours (Catppuccin-inspired) */
.hl-kw      { color: #cba6f7; font-weight: 600; }
.hl-builtin { color: #89dceb; }
.hl-str     { color: #a6e3a1; }
.hl-num     { color: #fab387; }
.hl-comment { color: #585b70; font-style: italic; }
.hl-op      { color: #89b4fa; }
.hl-bool    { color: #fab387; font-weight: 600; }

/* ── Inputs display ───────────────────────────────────────────────────────── */
.trace-inputs-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
}

.trace-inputs-label {
    color: #666;
    font-weight: 600;
}

.trace-input-value {
    background: #f0f3ff;
    border: 1.5px solid #c8cfe8;
    border-radius: 4px;
    padding: 0.15rem 0.55rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #1a1a2e;
}

/* ── Prompt & marks ───────────────────────────────────────────────────────── */
.prompt-text {
    font-size: 0.95rem;
    color: #444;
    line-height: 1.6;
    margin-bottom: 0.6rem;
}

.question-marks {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-top: 0.6rem;
}

.marks-badge {
    font-size: 0.8rem;
    font-weight: 700;
    background: #e8f0fb;
    color: #2c5aa0;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
}

.marks-note {
    font-size: 0.82rem;
    color: #777;
}

/* ── Trace table widget ───────────────────────────────────────────────────── */
.run-tabs {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.8rem;
    flex-wrap: wrap;
}

.run-tab {
    padding: 0.35rem 0.9rem;
    border: 1.5px solid #c8cfe8;
    border-radius: 5px 5px 0 0;
    background: #f0f3ff;
    color: #1a1a2e;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.1s;
}

.run-tab.active {
    background: #1a1a2e;
    color: #fff;
    border-color: #1a1a2e;
}

.trace-table-wrap {
    overflow-x: auto;
    margin: 0.3rem 0 0.5rem;
}

.trace-table {
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.trace-table th,
.trace-table td {
    border: 1px solid #dde;
    text-align: center;
    padding: 0;
}

.trace-th {
    background: #1a1a2e;
    color: #fff;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    font-style: italic;
    padding: 0.45rem 0.9rem;
    white-space: nowrap;
}

.trace-output-th {
    border-left: 3px solid #4a5080;
}

.trace-cell {
    padding: 2px;
    min-width: 80px;
}

.trace-cell-output {
    border-left: 3px solid #c8cfe8;
}

.trace-input {
    width: 100%;
    min-width: 72px;
    height: 34px;
    border: 2px solid #ccc;
    border-radius: 4px;
    background: #fff;
    text-align: center;
    font-size: 0.92rem;
    font-family: 'Courier New', monospace;
    font-variant-numeric: tabular-nums;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.1s, background 0.1s;
    color: #1a1a2e;
}

.trace-input:focus {
    border-color: #6680dd;
    background: #f4f6ff;
}

/* Row highlight when a cell is focused */
.trace-row-active td {
    background-color: #f8f9ff;
}

/* Feedback states after checking */
.trace-cell-correct .trace-input,
.trace-cell-correct .trace-input {
    background: #c8f0c8 !important;
    border-color: #4a9a4a !important;
    color: #1a4a1a;
}

.trace-cell-wrong .trace-input {
    background: #fcd8d8 !important;
    border-color: #cc4444 !important;
    color: #5a0000;
}

/* ── Check button & feedback ──────────────────────────────────────────────── */
.check-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#check-btn {
    padding: 0.6rem 1.8rem;
    font-size: 1rem;
    font-weight: 700;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s;
}

#check-btn:hover { background: #2e2e5a; }

.feedback {
    padding: 0.6rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    min-height: 1rem;
    transition: opacity 0.5s ease;
}

.feedback-correct    { background: #d8f5d8; color: #1a5c1a; }
.feedback-incorrect  { background: #fde8e8; color: #8a0000; }
.feedback-incomplete { background: #fff8e1; color: #7a5800; }
.feedback-error      { background: #fde8e8; color: #8a0000; }

/* ── Modal overlay ────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 2rem;
    width: min(380px, 90vw);
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.modal-box h2 {
    font-size: 1.15rem;
    color: #1a1a2e;
    margin-bottom: 1rem;
}

#test-code-input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    font-size: 1.6rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    border: 2px solid #c8cfe8;
    border-radius: 6px;
    text-align: center;
    outline: none;
    margin-bottom: 0.7rem;
    color: #1a1a2e;
}
#test-code-input:focus { border-color: #6680dd; }

.test-code-error {
    color: #8a0000;
    background: #fde8e8;
    padding: 0.4rem 0.7rem;
    border-radius: 5px;
    font-size: 0.9rem;
    margin-bottom: 0.7rem;
}

.modal-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    border: 1.5px solid;
    transition: background 0.15s;
}

.modal-buttons button:first-child {
    background: #1a1a2e;
    color: #fff;
    border-color: #1a1a2e;
}
.modal-buttons button:first-child:hover { background: #2e2e5a; }

.modal-buttons button:last-child {
    background: transparent;
    color: #557;
    border-color: #c8cfe8;
}
.modal-buttons button:last-child:hover { background: #f0f3ff; }

.check-input-label {
    display: block;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #888;
    margin-bottom: 0.3rem;
}

.check-code-input {
    width: 100%;
    padding: 0.5rem 0.8rem;
    font-size: 1.3rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    border: 2px solid #c8cfe8;
    border-radius: 6px;
    text-align: center;
    outline: none;
    margin-bottom: 0.8rem;
    color: #1a1a2e;
}
.check-code-input:focus { border-color: #6680dd; }

/* ── Test completion ──────────────────────────────────────────────────────── */
.test-complete-box { text-align: center; }

.test-complete-box h2 {
    font-size: 1.4rem;
    color: #1a5c1a;
    margin-bottom: 0.7rem;
}

.test-complete-box p {
    color: #555;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.completion-code {
    font-size: 2rem;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: #1a1a2e;
    background: #f0f3ff;
    border: 2px solid #c8cfe8;
    border-radius: 8px;
    padding: 0.8rem 1.5rem;
    margin-bottom: 1.5rem;
}

#test-complete-close {
    padding: 0.6rem 1.8rem;
    font-size: 1rem;
    font-weight: 700;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s;
}
#test-complete-close:hover { background: #2e2e5a; }

.completion-error {
    color: #8a0000;
    background: #fde8e8;
    padding: 0.5rem 0.8rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* ── Results overlay ──────────────────────────────────────────────────────── */
.results-overlay {
    align-items: flex-start;
    padding: 2rem 1rem;
}

.results-panel {
    background: #fff;
    border-radius: 10px;
    width: min(860px, 98vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1.5px solid #eee;
    font-size: 1rem;
    color: #1a1a2e;
    flex-shrink: 0;
}

.results-ts {
    margin-left: 0.8rem;
    font-size: 0.85rem;
    color: #888;
    font-weight: normal;
}

.results-close-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #888;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}
.results-close-btn:hover { background: #f0f0f0; color: #333; }

.results-body {
    overflow-y: auto;
    padding: 1rem 1.5rem;
    flex: 1;
}

.result-question {
    padding: 1rem 0;
    border-bottom: 1px solid #eee;
}
.result-question:last-child { border-bottom: none; }

.result-q-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    flex-wrap: wrap;
    margin-bottom: 0.2rem;
}

.result-q-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1a1a2e;
}

.result-badge {
    padding: 0.15rem 0.55rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
}
.badge-correct   { background: #d8f5d8; color: #1a5c1a; }
.badge-incorrect { background: #fde8e8; color: #8a0000; }
.badge-null      { background: #f0f0f0; color: #888; }

.result-q-type {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #aaa;
    margin-bottom: 0.6rem;
}

.result-marks {
    font-size: 0.78rem;
    font-weight: 600;
    color: #2c5aa0;
    background: #e8f0fb;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
}

.result-table-wrap { overflow-x: auto; margin-top: 0.5rem; }

.result-trace-table {
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 0.88rem;
}

.result-trace-table th {
    background: #1a1a2e;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-style: italic;
    padding: 0.35rem 0.7rem;
    border: 1px solid #dde;
    white-space: nowrap;
}

.result-trace-table td {
    border: 1px solid #dde;
    padding: 0.3rem 0.65rem;
    text-align: center;
    font-family: 'Courier New', monospace;
    min-width: 60px;
}

.result-trace-table .result-cell-blank {
    background: repeating-linear-gradient(
        45deg,
        #e4e6ef,
        #e4e6ef 4px,
        #eef0f7 4px,
        #eef0f7 9px
    );
}

.result-trace-table .result-output-th,
.result-trace-table .result-output-td {
    border-left: 3px solid #4a5080;
}

.result-cell-ok    { background: #d8f5d8 !important; }
.result-cell-wrong { background: #fde8e8 !important; }

.result-empty {
    color: #aaa;
    font-style: italic;
    font-size: 0.9rem;
    margin-top: 0.3rem;
}
