.algebra-page {
    padding-top: 0;
    --algebra-blue: #123f66;
    --algebra-muted: #536775;
    color: #1f2b35;
    font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
    line-height: 1.6;
    padding-bottom: 30px;
}

    .algebra-page [hidden] {
        display: none !important;
    }

.algebra-header {
    padding: 0 0 20px;
    max-width: 850px;
}

.algebra-page .back-link {
    color: var(--algebra-muted);
    text-decoration: none;
    font-size: .9rem;
}

.algebra-page .eyebrow {
    color: var(--algebra-blue);
    font-size: .73rem;
    letter-spacing: .14em;
    font-weight: 750;
    margin: 15px 0 10px;
}

.algebra-page .lead {
    color: var(--algebra-muted);
    font-size: 1.1rem;
    max-width: 740px;
    margin: 16px 0 0;
}

.algebra-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 26px;
    border-bottom: 1px solid #d7e1e7;
    padding-bottom: 15px;
}

    .algebra-nav a {
        color: var(--algebra-blue);
        padding: 8px 18px;
        border-radius: 6px;
        text-decoration: none;
        font-weight: 650;
    }

        .algebra-nav a[aria-current] {
            color: white;
            background: var(--algebra-blue);
        }

        .algebra-nav a:hover {
            background: #e7eff4;
            color: var(--algebra-blue);
        }

.solver-layout {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(0,1.15fr);
    align-items: start;
    gap: 24px;
}

.equation-card {
    background: #f6f9fb;
    border: 1px solid #d7e1e7;
    border-radius: 12px;
    padding: 26px;
    min-width: 0;
}

    .equation-card h2 {
        font-size: 1.25rem;
    }

.algebra-page .formula {
    font-family: Georgia,serif;
    font-size: 1.55rem;
    background: white;
    border: 1px solid #e2e9ee;
    padding: 16px;
    border-radius: 6px;
    color: var(--algebra-blue);
}

.coefficient-grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 4px 15px;
}

.algebra-page label {
    font-size: .85rem;
}

.algebra-page input, .algebra-page select, .algebra-page textarea {
    font: inherit;
    background: white;
    width: 100%;
    min-width: 0;
    border: 1px solid #aebfc9;
    padding: 11px;
    border-radius: 5px;
    color: #1f2b35;
}

.algebra-page textarea {
    resize: vertical;
}

.algebra-page :is(input,select,textarea,button,a):focus-visible {
    outline: 3px solid #89b8df;
    outline-offset: 3px;
}

.algebra-page .field-note {
    font-size: .82rem;
    color: var(--algebra-muted);
    margin: 14px 0;
}

.equation-actions {
    display: flex;
    gap: 10px;
}

    .equation-actions button {
        margin-top: 8px;
        min-height: 46px;
        border-radius: 6px;
    }

    .equation-actions .secondary {
        width: auto;
        background: white;
        border: 1px solid #aebfc9;
        color: var(--algebra-blue);
        padding-inline: 20px;
    }

.equation-status {
    font-size: .85rem;
    margin: 14px 0 0;
}

.result-card {
    background: white;
    border-top: 4px solid var(--algebra-blue);
}

    .result-card .eyebrow {
        margin-top: 0;
    }

.equation-preview {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: ui-monospace,monospace;
    font-size: .93rem;
    padding-bottom: 15px;
    border-bottom: 1px solid #d7e1e7;
}

#solution h3 {
    font-size: 1.65rem;
    line-height: 1.25;
    color: var(--algebra-blue);
    margin: 18px 0;
}

#solution strong {
    display: block;
    margin: 10px 0;
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.verification {
    background: #edf6f0;
    color: #28583d;
    border-left: 3px solid #428262;
    border-radius: 4px;
    padding: 1px 14px;
    margin: 20px 0;
    font-size: .88rem;
    overflow-wrap: anywhere;
}

    .verification:empty {
        display: none;
    }

.equation-steps {
    padding-left: 23px;
    margin-bottom: 0;
}

    .equation-steps li {
        margin: 12px 0;
        padding-left: 4px;
        overflow-wrap: anywhere;
    }

.equation-matrix {
    margin: 12px 0;
    font-family: ui-monospace,monospace;
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: .82rem;
}

    .equation-matrix caption {
        text-align: left;
        caption-side: top;
        font: .75rem system-ui;
        color: var(--algebra-muted);
    }

    .equation-matrix td {
        padding: 6px;
        text-align: center;
        background: #f5f8fa;
        overflow-wrap: anywhere;
    }

    .equation-matrix .constant {
        border-left: 2px solid #aebfc9;
    }

.system-row {
    border: 0;
    padding: 0;
    margin: 20px 0;
    min-width: 0;
}

.system-coefficients {
    display: flex;
    gap: 9px;
}

.system-row legend {
    float: none;
    width: auto;
    color: var(--algebra-blue);
    font-size: .85rem;
    font-weight: 650;
}

.system-row label {
    flex: 1;
    min-width: 0;
    margin-top: 3px;
}

.system-row input {
    padding: 9px 6px;
}

.graph-panel {
    margin-top: 24px;
    background: white;
}

#equation-plot {
    width: 100%;
    height: auto;
    overflow: visible;
}

    #equation-plot text {
        font: 10px system-ui;
        fill: #536775;
    }

.plot-grid {
    stroke: #e5ecf0;
    stroke-width: 1;
}

.plot-axis {
    stroke: #9aabb8;
    stroke-width: 1.2;
}

.plot-line {
    fill: none;
    stroke: #123f66;
    stroke-width: 2.5;
}

.plot-1 {
    stroke: #c68116;
}

.algebra-guide {
    margin-top: 40px;
    max-width: 960px;
}

    .algebra-guide h2 {
        margin-top: 30px;
    }

    .algebra-guide p {
        color: #536775;
    }

    .algebra-guide details {
        border-bottom: 1px solid #d7e1e7;
        padding: 16px 0;
    }

    .algebra-guide summary {
        cursor: pointer;
        font-weight: 650;
        color: var(--algebra-blue);
    }

.algebra-tools {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 22px;
}

.algebra-tool {
    border: 1px solid #d7e1e7;
    border-radius: 12px;
    padding: 28px;
    text-decoration: none;
    color: #1f2b35;
    background: #f6f9fb;
    transition: box-shadow .15s,border-color .15s;
}

    .algebra-tool:hover {
        border-color: #7a9bb4;
        box-shadow: 0 5px 20px #123f6610;
    }

.tool-number {
    font-size: .72rem;
    font-weight: 750;
    letter-spacing: .12em;
    color: #536775;
}

.tool-formula {
    display: block;
    font-family: Georgia,serif;
    font-size: clamp(1.2rem,3vw,1.8rem);
    margin: 25px 0;
    color: var(--algebra-blue);
}

.algebra-tool p {
    color: #536775;
    font-size: .94rem;
}

.tool-open {
    font-weight: 750;
    display: block;
    margin-top: 20px;
    color: var(--algebra-blue);
}

.table-scroll {
    overflow-x: auto;
}

.solver-comparison {
    width: 100%;
    text-align: left;
    border-collapse: collapse;
    font-size: .92rem;
}

    .solver-comparison th, .solver-comparison td {
        padding: 14px;
        border-bottom: 1px solid #d7e1e7;
    }

    .solver-comparison th {
        color: var(--algebra-blue);
        background: #f3f7f9;
    }

.matrix-size-controls {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 14px;
    margin: 18px 0;
}

    .matrix-size-controls fieldset {
        border: 1px solid #d7e1e7;
        border-radius: 7px;
        padding: 10px 12px 13px;
        min-width: 0;
    }

    .matrix-size-controls legend {
        color: var(--algebra-blue);
        font-size: .82rem;
        font-weight: 700;
        padding: 0 5px;
    }

    .matrix-size-controls label {
        display: grid;
        grid-template-columns: 1fr 64px;
        align-items: center;
        gap: 8px;
        margin-top: 6px;
    }

    .matrix-size-controls select {
        padding: 7px;
    }

.matrix-input-group {
    margin-top: 20px;
}

    .matrix-input-group h3 {
        color: var(--algebra-blue);
        font-size: .92rem;
        margin-bottom: 8px;
    }

.matrix-entry {
    --matrix-cols: 2;
    display: grid;
    grid-template-columns: repeat(var(--matrix-cols),minmax(48px,1fr));
    gap: 7px;
    padding: 9px;
    border-left: 3px solid #8da5b6;
    border-right: 3px solid #8da5b6;
    border-radius: 5px;
    overflow-x: auto;
}

    .matrix-entry input {
        padding: 8px 5px;
        text-align: center;
        font-family: ui-monospace,monospace;
    }

.matrix-output {
    width: auto;
    min-width: min(100%,320px);
    table-layout: auto;
    border-left: 3px solid #8da5b6;
    border-right: 3px solid #8da5b6;
}

    .matrix-output td {
        min-width: 54px;
    }

#matrix-answer h3 {
    color: var(--algebra-blue);
    font-size: 1.45rem;
}

#matrix-check .equation-matrix {
    margin-top: 10px;
}

.coefficient-set {
    border: 1px solid #d7e1e7;
    border-radius: 7px;
    padding: 12px 14px 16px;
    margin: 18px 0;
}

    .coefficient-set legend {
        color: var(--algebra-blue);
        font-weight: 700;
        padding: 0 5px;
    }

.rational-result {
    display: inline-grid;
    text-align: center;
    font-family: Georgia,serif;
    font-size: 1.15rem;
    margin: 8px 0 18px;
}

    .rational-result span:first-child {
        border-bottom: 1px solid currentColor;
        padding: 3px 10px;
    }

    .rational-result span:last-child {
        padding: 3px 10px;
    }

.function-table {
    background: white;
    margin-top: 12px;
}

#function-answer {
    max-height: 520px;
    overflow: auto;
}

@media(max-width:780px) {
    .solver-layout, .algebra-tools {
        grid-template-columns: 1fr;
    }

    .algebra-page.wrap {
        width: 100%;
        padding:0 16px 16px;
    }

    .equation-card, .algebra-tool {
        padding: 20px;
    }

    .algebra-header {
        padding-top: 12px;
    }

    .algebra-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: thin;
        padding-bottom: 10px;
    }

    .algebra-nav a {
        flex: 0 0 auto;
        padding: 8px 12px;
        font-size: .9rem;
    }

    .matrix-size-controls {
        grid-template-columns: 1fr;
    }
}

@media print {
    .algebra-nav, .equation-actions, .back-link {
        display: none;
    }

    .solver-layout {
        display: block;
    }

    .equation-card {
        margin: 12px 0;
    }
}
