/* Computer System Components + Embedded Systems learning lab.
   All selectors are scoped to .csx-widget to minimise interference with site styles. */

.csx-widget {
    --csx-ink: #172033;
    --csx-muted: #5d687c;
    --csx-line: #d9e1ec;
    --csx-panel: #ffffff;
    --csx-soft: #f5f8fc;
    --csx-accent: #4657b8;
    --csx-accent-soft: #edf0ff;
    --csx-green: #147d64;
    --csx-green-soft: #e8f7f1;
    --csx-amber: #9a4e10;
    --csx-amber-soft: #fff4e6;
    margin: 1.5rem 0;
    color: var(--csx-ink);
    background: linear-gradient(145deg, #f7f9ff 0%, #f0f5fb 100%);
    border: 1px solid #dce4f2;
    border-radius: 26px;
    padding: clamp(0.8rem, 2.5vw, 1.5rem);
    box-shadow: 0 16px 42px rgba(25, 40, 75, 0.09);
    box-sizing: border-box;
}

.csx-widget *,
.csx-widget *::before,
.csx-widget *::after {
    box-sizing: border-box;
}

.csx-widget h3,
.csx-widget h4,
.csx-widget p {
    margin-top: 0;
}

.csx-widget h3,
.csx-widget h4 {
    color: var(--csx-ink);
    line-height: 1.25;
}

.csx-widget p {
    line-height: 1.6;
}

.csx-widget button,
.csx-widget select,
.csx-widget input {
    font: inherit;
}

.csx-widget button {
    touch-action: manipulation;
}

.csx-widget button:focus-visible,
.csx-widget select:focus-visible,
.csx-widget input:focus-visible,
.csx-widget summary:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 3px;
}

.csx-widget-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.25rem;
    margin-bottom: 1.2rem;
}

.csx-widget-header h3 {
    margin-bottom: 0.35rem;
    font-size: clamp(1.35rem, 2.5vw, 1.9rem);
}

.csx-eyebrow {
    margin-bottom: 0.45rem !important;
    color: var(--csx-accent) !important;
    font-size: 0.72rem !important;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.csx-intro {
    max-width: 54rem;
    margin-bottom: 0;
    color: var(--csx-muted);
}

.csx-scenario-control {
    display: grid;
    gap: 0.45rem;
    min-width: min(100%, 230px);
    color: var(--csx-ink);
    font-size: 0.9rem;
    font-weight: 750;
}

.csx-scenario-control select {
    width: 100%;
    min-height: 44px;
    border: 1px solid #bfc9db;
    border-radius: 13px;
    padding: 0.65rem 0.8rem;
    color: var(--csx-ink);
    background: #fff;
}

.csx-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding: 0.35rem;
    margin-bottom: 1rem;
    background: #e7ecf6;
    border-radius: 16px;
}

.csx-tab,
.csx-aspect,
.csx-control-button {
    min-height: 42px;
    border: 1px solid #c9d3e2;
    border-radius: 12px;
    padding: 0.65rem 0.9rem;
    color: #26334b;
    background: #fff;
    font-weight: 750;
    cursor: pointer;
    transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease;
}

.csx-tab:hover,
.csx-aspect:hover,
.csx-control-button:hover {
    transform: translateY(-1px);
    border-color: #8796b8;
}

.csx-tab.is-active,
.csx-aspect.is-active {
    color: #fff;
    background: var(--csx-ink);
    border-color: var(--csx-ink);
}

.csx-panel[hidden] {
    display: none !important;
}

.csx-panel-intro {
    color: var(--csx-muted);
    margin-bottom: 1rem;
}

.csx-flow-map {
    padding: clamp(0.7rem, 2vw, 1.2rem);
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--csx-line);
    border-radius: 20px;
}

.csx-flow-row {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 0.5rem;
}

.csx-node {
    position: relative;
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 0;
    min-height: 108px;
    padding: 0.75rem 0.8rem;
    border: 1px solid #ccd6e6;
    border-radius: 16px;
    background: #fff;
    color: var(--csx-ink);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.csx-node:hover {
    transform: translateY(-2px);
    border-color: #8797bd;
}

.csx-node.is-active {
    background: var(--csx-accent-soft);
    border: 2px solid var(--csx-accent);
    padding: calc(0.75rem - 1px) calc(0.8rem - 1px);
    box-shadow: 0 8px 20px rgba(70, 87, 184, 0.13);
}

.csx-node-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.5rem;
    margin-bottom: 0.45rem;
    border-radius: 7px;
    background: #edf1f7;
    color: #59667e;
    font-size: 0.72rem;
    font-weight: 850;
}

.csx-node.is-active .csx-node-index {
    background: var(--csx-accent);
    color: #fff;
}

.csx-node strong {
    font-size: 0.95rem;
    line-height: 1.25;
}

.csx-node small {
    display: block;
    margin-top: 0.3rem;
    color: var(--csx-muted);
    font-size: 0.77rem;
    line-height: 1.35;
}

.csx-arrow {
    align-self: center;
    flex: 0 0 auto;
    color: #8190aa;
    font-size: 1.5rem;
    font-weight: 800;
}

.csx-flow-support {
    display: grid;
    grid-template-columns: minmax(160px, 0.75fr) minmax(0, 1.25fr);
    align-items: center;
    gap: 0.8rem 1rem;
    max-width: 680px;
    margin: 0.85rem auto;
    padding: 0.85rem;
    border: 1px dashed #aab7cf;
    border-radius: 17px;
    background: #f8faff;
}

.csx-flow-support .csx-branch-label {
    grid-column: 1 / -1;
}

.csx-flow-support p {
    margin: 0;
    color: var(--csx-muted);
    font-size: 0.9rem;
}

.csx-node-memory {
    min-height: 82px;
}

.csx-branch-label {
    display: block;
    color: #64718a;
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.csx-flow-branches {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    padding-top: 0.8rem;
    border-top: 1px dashed #bdc8da;
}

.csx-flow-branches .csx-branch-label {
    grid-column: 1 / -1;
}

.csx-diagram-note {
    margin: 0.8rem 0 0;
    color: #66738a;
    font-size: 0.8rem;
}

.csx-step-area {
    margin-top: 1rem;
}

.csx-step-controls,
.csx-quiz-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-bottom: 0.8rem;
}

.csx-control-primary {
    color: #fff !important;
    background: var(--csx-accent) !important;
    border-color: var(--csx-accent) !important;
}

.csx-control-quiet {
    background: transparent !important;
}

.csx-control-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.csx-step-card {
    padding: clamp(1rem, 2.5vw, 1.35rem);
    background: #fff;
    border: 1px solid var(--csx-line);
    border-left: 5px solid var(--csx-accent);
    border-radius: 17px;
    box-shadow: 0 8px 24px rgba(20, 35, 65, 0.05);
}

.csx-step-card h4 {
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.csx-step-card p:last-child {
    margin-bottom: 0;
}

.csx-exam-link {
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    color: #29418c;
    background: #eef2ff;
    font-size: 0.92rem;
}

.csx-status {
    margin: 0.7rem 0 0;
    color: var(--csx-muted);
    font-size: 0.86rem;
}

.csx-aspect-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.csx-aspect {
    border-radius: 999px;
    min-height: 39px;
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
}

.csx-comparison-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
}

.csx-comparison-card {
    padding: 1.1rem;
    border: 1px solid var(--csx-line);
    border-radius: 18px;
    background: #fff;
}

.csx-comparison-card h4 {
    margin-bottom: 0.55rem;
    font-size: 1.1rem;
}

.csx-comparison-card p:last-child {
    margin-bottom: 0;
}

.csx-comparison-embedded {
    border-color: #c6d2ff;
    background: #f8f9ff;
}

.csx-feedback-card {
    margin-top: 0.9rem;
    padding: 1rem 1.1rem;
    border: 1px solid #f3d1a9;
    border-radius: 16px;
    background: var(--csx-amber-soft);
}

.csx-feedback-card h4 {
    margin-bottom: 0.4rem;
    color: var(--csx-amber);
}

.csx-feedback-card p {
    margin-bottom: 0;
    color: #6e3c15;
}

.csx-quiz-topline {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}

.csx-quiz-score {
    margin-bottom: 0.45rem;
    color: var(--csx-green);
    font-weight: 850;
}

.csx-panel > h4 {
    font-size: 1.2rem;
    margin-bottom: 0.9rem;
}

.csx-quiz-options {
    display: grid;
    gap: 0.6rem;
    margin: 0 0 1rem;
}

.csx-quiz-option {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid var(--csx-line);
    border-radius: 14px;
    background: #fff;
    cursor: pointer;
    line-height: 1.45;
}

.csx-quiz-option:hover {
    border-color: #98a7c4;
}

.csx-quiz-option input {
    flex: 0 0 auto;
    margin-top: 0.2rem;
    accent-color: var(--csx-accent);
}

.csx-quiz-option.is-correct {
    border-color: #4ca98d;
    background: var(--csx-green-soft);
}

.csx-quiz-option.is-incorrect {
    border-color: #e6a5a5;
    background: #fff0f0;
}

.csx-quiz-option.is-disabled {
    cursor: default;
}

.csx-quiz-feedback {
    min-height: 1.2rem;
    padding: 0;
    color: var(--csx-muted);
    line-height: 1.55;
}

.csx-quiz-feedback.is-correct,
.csx-quiz-feedback.is-incorrect,
.csx-quiz-feedback.is-prompt {
    margin-top: 0.7rem;
    padding: 0.8rem 0.9rem;
    border-radius: 13px;
}

.csx-quiz-feedback.is-correct {
    color: #105d49;
    background: var(--csx-green-soft);
    border: 1px solid #b6e4d3;
}

.csx-quiz-feedback.is-incorrect {
    color: #842c2c;
    background: #fff0f0;
    border: 1px solid #f0c2c2;
}

.csx-quiz-feedback.is-prompt {
    color: #78400f;
    background: var(--csx-amber-soft);
    border: 1px solid #f3d1a9;
}

.csx-widget details {
    margin-top: 0.9rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--csx-line);
    border-radius: 14px;
    background: #fff;
}

.csx-widget summary {
    color: var(--csx-ink);
    font-weight: 750;
    cursor: pointer;
}

@media (max-width: 760px) {
    .csx-widget-header {
        flex-direction: column;
    }

    .csx-scenario-control {
        width: 100%;
    }

    .csx-flow-row {
        flex-direction: column;
    }

    .csx-arrow {
        align-self: center;
        transform: rotate(90deg);
        line-height: 1;
    }

    .csx-node {
        flex-basis: auto;
        width: 100%;
        min-height: 80px;
    }

    .csx-flow-support {
        grid-template-columns: 1fr;
    }

    .csx-flow-support .csx-branch-label {
        grid-column: auto;
    }

    .csx-flow-branches,
    .csx-comparison-grid {
        grid-template-columns: 1fr;
    }

    .csx-flow-branches .csx-branch-label {
        grid-column: auto;
    }

    .csx-tabs {
        display: grid;
        grid-template-columns: 1fr;
    }

    .csx-tab {
        width: 100%;
        text-align: left;
    }

    .csx-quiz-topline {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .csx-widget *,
    .csx-widget *::before,
    .csx-widget *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
