/* ── 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;
}

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

#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); }

.notation-switcher {
    display: flex;
    gap: 0.3rem;
}

.notation-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;
}

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

main {
    max-width: 960px;
    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;
}

.port-eg {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.6rem;
    line-height: 16px;
    text-align: center;
    vertical-align: middle;
}
.port-eg.out { background: #c8ffc8; border: 1.5px solid #4a4; }
.port-eg.in  { background: #ffc8c8; border: 1.5px solid #a44; }

/* ── Question display ─────────────────────────────────────────────────────── */
.prompt-description {
    font-size: 1.05rem;
    line-height: 1.6;
}

.prompt-text {
    font-size: 0.95rem;
    color: #555;
    margin-top: 0.7rem;
}

.prompt-algebra {
    font-size: 1.2rem;
    font-family: 'Georgia', serif;
    padding: 0.5rem 0;
}

/* ── Boolean expression display ───────────────────────────────────────────── */
.bool-var   { font-style: italic; font-weight: 600; }
.bool-const { font-weight: 600; color: #555; }
.bool-op    { color: #c00; font-weight: 700; }
.bool-kw    { color: #0055aa; font-weight: 700; }
.bool-not   { color: #c00; font-weight: 700; }
.overbar {
    display: inline-block;
    border-top: 1.5px solid currentColor;
    padding-top: 3px;
    vertical-align: bottom;
    line-height: inherit;
}

/* ── Truth tables ─────────────────────────────────────────────────────────── */
.truth-table {
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    margin: 0.5rem 0;
}

.truth-table th,
.truth-table td {
    border: 1px solid #dde;
    padding: 0.45rem 0.9rem;
    text-align: center;
}

.truth-table th {
    background: #1a1a2e;
    color: #fff;
    font-weight: 600;
    font-style: italic;
}

.truth-table tbody tr:nth-child(even) { background: #f7f8fc; }

.truth-table .output-divider {
    border-left: 3px solid #667;
}

/* Interactive answer table */
.answer-table .answer-cell { padding: 0.2rem; }

.toggle-cell {
    width: 38px;
    height: 32px;
    border: 2px solid #bbb;
    border-radius: 5px;
    background: #f0f0f0;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

.toggle-cell:hover  { border-color: #888; }
.toggle-cell.val-0  { background: #eef; border-color: #aac; }
.toggle-cell.val-1  { background: #efe; border-color: #6a6; color: #363; }

.cell-correct .toggle-cell { background: #c8f0c8 !important; border-color: #4a4 !important; }
.cell-wrong   .toggle-cell { background: #fcc !important;    border-color: #c44 !important; }

/* ── Algebra input ────────────────────────────────────────────────────────── */
.algebra-toolbar {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}

.sym-btn {
    padding: 0.35rem 0.75rem;
    border: 1.5px solid #c8cfe8;
    border-radius: 5px;
    background: #f0f3ff;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.1s;
}

.sym-btn:hover { background: #dde6ff; }

.algebra-input-field {
    width: 100%;
    padding: 0.55rem 0.8rem;
    font-size: 1rem;
    border: 2px solid #c8cfe8;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    outline: none;
}

.algebra-input-field:focus { border-color: #6680dd; }

.working-section, .final-answer-section { margin-top: 0.8rem; }

.working-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #888;
    margin-bottom: 0.4rem;
}

.working-row {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.working-row .algebra-input-field { flex: 1; min-width: 200px; }

.remove-line-btn {
    padding: 0.4rem 0.6rem;
    border: 1.5px solid #e8c0c0;
    background: #fff0f0;
    color: #a00;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.remove-line-btn:hover { background: #ffd8d8; }

.add-line-btn {
    padding: 0.35rem 0.9rem;
    border: 1.5px dashed #c8cfe8;
    background: transparent;
    color: #557;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

.add-line-btn:hover { background: #f0f3ff; }

.equiv-badge {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-right: 0.4rem;
    vertical-align: middle;
}

.equiv-yes { background: #d8f5d8; color: #1a5c1a; }
.equiv-no  { background: #fde8e8; color: #8a0000; }

.algebra-preview {
    margin-top: 0.5rem;
    padding: 0.4rem 0.7rem;
    border-radius: 5px;
    font-size: 1rem;
    min-height: 1.6rem;
}

.preview-ok  { background: #f0fff0; color: #2a5a2a; }
.preview-err { background: #fff0f0; color: #8a0000; font-size: 0.85rem; }
.preview-label { color: #777; font-size: 0.8rem; }

/* ── Circuit diagrams ─────────────────────────────────────────────────────── */
.circuit-diagram {
    display: block;
    max-width: 100%;
    overflow: visible;
}

.gate-body {
    fill: #fff;
    stroke: #1a1a2e;
    stroke-width: 2;
}

.gate-extra {
    fill: none;
    stroke: #1a1a2e;
    stroke-width: 2;
}

.gate-bubble {
    fill: #fff;
    stroke: #1a1a2e;
    stroke-width: 2;
}

.gate-label {
    font-size: 8px;
    fill: #666;
    pointer-events: none;
    font-family: 'Segoe UI', sans-serif;
}

.port-stub {
    stroke: #1a1a2e;
    stroke-width: 1.5;
}

.wire {
    fill: none;
    stroke: #1a1a2e;
    stroke-width: 1.5;
}

.io-node {
    fill: #e8eeff;
    stroke: #1a1a2e;
    stroke-width: 1.5;
}

.output-node {
    fill: #ffeaea;
}

.io-label {
    font-size: 11px;
    font-weight: 700;
    font-family: 'Segoe UI', sans-serif;
    fill: #1a1a2e;
    pointer-events: none;
    font-style: italic;
}

/* ── Diagram builder ──────────────────────────────────────────────────────── */
.diagram-builder {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
}

.gate-palette {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 80px;
}

.palette-label {
    font-size: 0.72rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
}

.palette-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.4rem 0.3rem;
    border: 1.5px solid #c8cfe8;
    border-radius: 6px;
    background: #f0f3ff;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    color: #1a1a2e;
    transition: background 0.1s;
}

.palette-btn:hover { background: #dde6ff; }

.clear-btn {
    margin-top: 0.6rem;
    background: #fff0f0;
    border-color: #e8c0c0;
    color: #a00;
}

.clear-btn:hover { background: #ffd8d8; }

.mini-gate .gate-body  { fill: #fff; stroke: #1a1a2e; stroke-width: 2; }
.mini-gate .gate-extra { fill: none; stroke: #1a1a2e; stroke-width: 2; }
.mini-gate .gate-bubble { fill: #fff; stroke: #1a1a2e; stroke-width: 2; }

.diagram-canvas {
    border: 1.5px solid #dde;
    border-radius: 8px;
    background: #fafbff;
    cursor: default;
    flex: 1;
}

.draggable-gate { cursor: grab; }
.draggable-gate:active { cursor: grabbing; }

.port {
    fill: #ccd;
    stroke: #556;
    stroke-width: 1.5;
    cursor: crosshair;
    transition: fill 0.1s;
}

.port:hover { fill: #88aaff; stroke: #446; r: 7; }
.out-port   { fill: #c8ffc8; stroke: #4a4; }
.in-port    { fill: #ffc8c8; stroke: #a44; }

.interactive-wire {
    fill: none;
    stroke: #446;
    stroke-width: 2;
    cursor: pointer;
    transition: stroke 0.1s;
}

.interactive-wire:hover { stroke: #c00; stroke-width: 3; }

.temp-wire {
    fill: none;
    stroke: #88aaff;
    stroke-width: 2;
    stroke-dasharray: 5,3;
    pointer-events: none;
}

.diagram-hint {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.5rem;
    line-height: 1.5;
}

/* ── 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;
}

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