/* The maths tools (Views/Shared/Tools/_Math.cshtml, js/math-tools.js): the scientific calculator and the graphing
   calculator. Built on the .jt look of css/tools.css; nothing here needs a style attribute. */

.jm .jt-title { margin-bottom: .75rem; }
.jm-spacer { flex: 1; }

/* ---- scientific ---- */
.jm-calc {
    display: grid;
    gap: .75rem;
}

@media (min-width: 860px) {
    .jm-calc { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); grid-template-areas: "screen history" "modes history" "keys history"; align-items: start; }
    .jm-screen { grid-area: screen; }
    .jm-modes { grid-area: modes; }
    .jm-keys { grid-area: keys; }
    .jm-history-wrap { grid-area: history; }
}

.jm-screen {
    background: #0f253d;
    color: #fff;
    border-radius: 8px;
    padding: .9rem 1rem .8rem;
    display: grid;
    gap: .2rem;
}

.jm-expr {
    width: 100%;
    background: transparent;
    border: 0;
    color: #fff;
    font: 500 1.35rem/1.3 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    padding: 0;
    outline: none;
    caret-color: var(--jt-teal);
}
.jm-expr::placeholder { color: rgba(255, 255, 255, .45); font-size: 1rem; }
.jm-screen:focus-within { box-shadow: 0 0 0 3px rgba(31, 184, 190, .55); }

.jm-result {
    display: block;
    min-height: 1.9rem;
    text-align: right;
    font: 700 1.6rem/1.2 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    color: #8be3e7;
    overflow-wrap: anywhere;
}
.jm-result.is-error { color: #fecaca; font: 500 .95rem/1.4 var(--nr-sans, system-ui, sans-serif); text-align: left; }

.jm-modes { display: flex; gap: .35rem; align-items: center; }
.jm-mode {
    border: 1px solid var(--jt-rule);
    background: #fff;
    color: var(--jt-muted);
    border-radius: 999px;
    padding: .2rem .7rem;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .04em;
}
.jm-mode[aria-pressed="true"] { background: var(--jt-ink); border-color: var(--jt-ink); color: #fff; }

.jm-keys {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: .35rem;
}

.jm-key {
    border: 1px solid var(--jt-rule);
    background: #fff;
    color: var(--jt-ink);
    border-radius: 8px;
    min-height: 2.75rem;
    font-size: 1.05rem;
    font-weight: 600;
    padding: .2rem;
    transition: background .1s, border-color .1s;
    touch-action: manipulation;
}
.jm-key:hover { border-color: var(--jt-teal); }
.jm-key:active { background: var(--jt-wash); }
.jm-key:focus-visible, .jm-mode:focus-visible { outline: 2px solid var(--jt-teal); outline-offset: 2px; }
.jm-key--fn { background: var(--jt-wash); font-size: .9rem; color: var(--jt-teal-ink); }
.jm-key--op { background: #e6f7f8; color: var(--jt-teal-ink); font-size: 1.2rem; }
.jm-key--clear { min-height: 2rem; padding: .2rem .8rem; font-size: .85rem; color: #b91c1c; }
.jm-key--equals {
    grid-column: span 3;
    background: var(--jt-teal);
    border-color: var(--jt-teal);
    color: var(--jt-ink);
    font-size: 1.4rem;
}
.jm-key--equals:hover { background: #18a5ab; }

.jm-history-title {
    margin: 0 0 .4rem;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--jt-muted);
}
.jm-history { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; max-height: 22rem; overflow-y: auto; }
.jm-history-item {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    border: 1px solid var(--jt-rule);
    background: #fff;
    border-radius: 6px;
    padding: .45rem .6rem;
    font: .9rem/1.3 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    text-align: left;
    color: var(--jt-text);
}
.jm-history-item span { overflow-wrap: anywhere; color: var(--jt-muted); }
.jm-history-item strong { color: var(--jt-ink); white-space: nowrap; }
.jm-history-item:hover, .jm-history-item:focus-visible { border-color: var(--jt-teal); outline: none; }

/* ---- graphing ---- */
.jm-graph { display: grid; gap: 1rem; }

@media (min-width: 900px) {
    .jm-graph { grid-template-columns: minmax(16rem, 1fr) minmax(0, 2.2fr); grid-template-rows: auto 1fr; grid-template-areas: "fns plot" "points plot"; align-items: start; }
    .jm-fns { grid-area: fns; }
    .jm-plot { grid-area: plot; }
    .jm-points { grid-area: points; }
}

.jm-fns { display: grid; gap: .5rem; }
.jm-fn {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .45rem;
}
.jm-fn[hidden] { display: none; }
.jm-fn label { font-weight: 700; color: var(--jt-ink); font-style: italic; }
.jm-fn input {
    border: 1px solid var(--jt-rule);
    border-radius: 6px;
    padding: .5rem .6rem;
    font: 1rem ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    min-width: 0;
}
.jm-fn input:focus { outline: 2px solid var(--jt-teal); outline-offset: 1px; }
.jm-fn input[aria-invalid="true"] { border-color: #b91c1c; }
.jm-fn-remove { border: 0; background: none; color: var(--jt-muted); padding: .3rem; border-radius: 4px; }
.jm-fn-remove:hover { color: #b91c1c; background: var(--jt-wash); }
.jm-fn-problem { grid-column: 3 / 5; margin: 0; font-size: .8rem; color: #b91c1c; }
.jm-fn-problem:empty { display: none; }

.jm-swatch { display: inline-block; width: .9rem; height: .9rem; border-radius: 50%; flex: none; }
.jm-c0 { background: #0b8f96; }
.jm-c1 { background: #c2410c; }
.jm-c2 { background: #1f3a68; }
.jm-c3 { background: #7e3a8a; }
.jm-cmeet { background: conic-gradient(#0b8f96 0 50%, #c2410c 0); }

.jm-add {
    justify-self: start;
    border: 1px dashed var(--jt-teal);
    background: #fff;
    color: var(--jt-teal-ink);
    border-radius: 999px;
    padding: .3rem .9rem;
    font-weight: 600;
    font-size: .9rem;
}
.jm-add[hidden] { display: none; }

.jm-plot { margin: 0; }
.jm-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--jt-rule);
    border-radius: 8px;
    cursor: crosshair;
    touch-action: none;
    background: #fff;
}
.jm-trace { margin: .4rem 0 0; font: .85rem ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; color: var(--jt-text); min-height: 1.3em; }
.jm-view { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .4rem; }
.jm-view button {
    border: 1px solid var(--jt-rule);
    background: #fff;
    border-radius: 6px;
    padding: .25rem .6rem;
    color: var(--jt-ink);
    font-size: .85rem;
}
.jm-view button:hover { border-color: var(--jt-teal); }
.jm-window { font-size: .78rem; color: var(--jt-muted); }

.jm-point-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; max-height: 20rem; overflow-y: auto; }
.jm-point-list li { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; font-size: .88rem; }
.jm-point-list strong { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-weight: 600; color: var(--jt-ink); }
.jm-point-list .jm-point-none { display: block; color: var(--jt-muted); }

/* ---- calculus ---- */
.jm-calculus { display: grid; gap: .9rem; }

.jm-tabs { display: flex; gap: .35rem; flex-wrap: wrap; }
.jm-tab {
    border: 1px solid var(--jt-rule);
    background: #fff;
    color: var(--jt-ink);
    border-radius: 999px;
    padding: .35rem 1rem;
    font-weight: 600;
}
.jm-tab[aria-pressed="true"] { background: var(--jt-ink); border-color: var(--jt-ink); color: #fff; }
.jm-tab:focus-visible, .jm-solve:focus-visible, .jm-examples button:focus-visible { outline: 2px solid var(--jt-teal); outline-offset: 2px; }

.jm-cform { display: grid; gap: .6rem; }
.jm-crow {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #0f253d;
    border-radius: 8px;
    padding: .6rem .9rem;
}
.jm-crow:focus-within { box-shadow: 0 0 0 3px rgba(31, 184, 190, .55); }
.jm-lead, .jm-dx { color: #8be3e7; font: 600 1.2rem/1 'Cambria Math', 'STIX Two Math', Georgia, serif; white-space: nowrap; }
.jm-dx[hidden] { display: none; }
.jm-cinput {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    color: #fff;
    font: 500 1.2rem/1.3 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    outline: none;
    caret-color: var(--jt-teal);
}
.jm-cinput::placeholder { color: rgba(255, 255, 255, .45); }

.jm-copts { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.jm-copts[hidden] { display: none; }
.jm-copts label { display: flex; gap: .4rem; align-items: center; font-weight: 600; color: var(--jt-ink); font-size: .9rem; }
.jm-copts input, .jm-copts select {
    border: 1px solid var(--jt-rule);
    border-radius: 6px;
    padding: .35rem .5rem;
    font: .95rem ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    width: 7rem;
}
.jm-copts select { font-family: inherit; width: auto; }

.jm-solve {
    justify-self: start;
    border: 0;
    border-radius: 8px;
    background: var(--jt-teal);
    color: var(--jt-ink);
    font-weight: 700;
    padding: .5rem 1.2rem;
}
.jm-solve:hover { background: #18a5ab; }

.jm-examples { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.jm-examples-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--jt-muted); margin-right: .2rem; }
.jm-examples button {
    border: 1px solid var(--jt-rule);
    background: var(--jt-wash);
    color: var(--jt-teal-ink);
    border-radius: 999px;
    padding: .2rem .7rem;
    font-size: .85rem;
}
.jm-examples button:hover { border-color: var(--jt-teal); }

.jm-answer { border: 1px solid var(--jt-rule); border-left: 4px solid var(--jt-teal); border-radius: 8px; padding: .9rem 1rem; background: #fff; }
.jm-answer.is-error { border-left-color: #b91c1c; }
.jm-answer.is-none { border-left-color: #c2410c; }
.jm-answer-math {
    margin: 0;
    font: 600 1.25rem/1.4 'Cambria Math', 'STIX Two Math', Georgia, serif;
    color: var(--jt-ink);
    overflow-wrap: anywhere;
}
.jm-answer.is-error .jm-answer-math { font: 500 .95rem/1.4 var(--nr-sans, system-ui, sans-serif); color: #b91c1c; }
.jm-answer-note { margin: .35rem 0 0; font-size: .9rem; color: var(--jt-text); }
.jm-answer-note:empty, .jm-check:empty, .jm-steps:empty { display: none; }

.jm-steps { margin: .9rem 0 0; padding-left: 1.4rem; display: grid; gap: .55rem; }
.jm-steps li { padding-left: .2rem; }
.jm-steps li::marker { color: var(--jt-teal-ink); font-weight: 700; }
.jm-step-rule { display: block; font-weight: 700; color: var(--jt-ink); font-size: .9rem; }
.jm-step-work { display: block; font: 1rem/1.45 'Cambria Math', 'STIX Two Math', Georgia, serif; color: var(--jt-text); overflow-wrap: anywhere; }
.jm-steps .jm-step-head { list-style: none; margin-left: -1.4rem; margin-top: .4rem; }
.jm-steps .jm-step-head .jm-step-rule { text-transform: uppercase; letter-spacing: .05em; font-size: .75rem; color: var(--jt-teal-ink); }
.jm-check { margin: .8rem 0 0; font-size: .82rem; color: var(--jt-muted); }
.jm-check::before { content: "✓ "; color: var(--jt-teal-ink); font-weight: 700; }

/* ---- equations ---- */
.jm-solver { display: grid; gap: .7rem; }
.jm-elabel { font-weight: 700; color: var(--jt-ink); }
.jm-etext {
    box-sizing: border-box;
    width: 100%;
    background: #0f253d;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: .7rem .9rem;
    font: 500 1.15rem/1.5 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    resize: vertical;
    caret-color: var(--jt-teal);
}
.jm-etext:focus { outline: none; box-shadow: 0 0 0 3px rgba(31, 184, 190, .55); }

/* ---- matrices ---- */
.jm-matrix-tool { display: grid; gap: .8rem; }
.jm-ops { display: flex; flex-wrap: wrap; gap: .35rem; }
.jm-grids { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-start; }
.jm-grid-box { border: 1px solid var(--jt-rule); border-radius: 8px; padding: .5rem .8rem .8rem; margin: 0; min-width: 0; }
.jm-grid-box[hidden] { display: none; }
.jm-grid-box legend { font: 700 1.1rem/1 'Cambria Math', 'STIX Two Math', Georgia, serif; font-style: italic; color: var(--jt-ink); padding: 0 .3rem; width: auto; float: none; margin: 0; }
.jm-size { display: flex; gap: .4rem; align-items: center; margin-bottom: .6rem; font-size: .85rem; color: var(--jt-muted); }
.jm-size label { display: flex; gap: .3rem; align-items: center; }
.jm-size select { border: 1px solid var(--jt-rule); border-radius: 6px; padding: .15rem .3rem; }
.jm-size select:disabled { background: var(--jt-wash); color: var(--jt-muted); }
.jm-grid {
    display: grid;
    width: max-content;
    max-width: 100%;
    box-sizing: border-box;
    gap: .3rem;
    padding: .2rem .55rem;
    border-left: 2px solid var(--jt-ink);
    border-right: 2px solid var(--jt-ink);
    border-radius: 6px;
    overflow-x: auto;
}
.jm-grid-row { display: grid; gap: .3rem; }
.jm-grid-row input {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    border: 1px solid var(--jt-rule);
    border-radius: 5px;
    padding: .35rem .3rem;
    text-align: center;
    font: .95rem ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
.jm-grid-row input:focus { outline: 2px solid var(--jt-teal); outline-offset: 0; }

.jm-matrix {
    border-collapse: separate;
    border-spacing: 0;
    margin: .5rem 0 .2rem;
    border-left: 2px solid var(--jt-ink);
    border-right: 2px solid var(--jt-ink);
    border-radius: 6px;
    font: 1rem/1.35 'Cambria Math', 'STIX Two Math', Georgia, serif;
    color: var(--jt-ink);
    display: inline-table;
}
.jm-matrix td, .jm-matrix th { padding: .15rem .7rem; text-align: center; white-space: nowrap; }
.jm-matrix th { font-weight: 600; font-size: .8rem; color: var(--jt-muted); font-style: italic; }
.jm-matrix .jm-split { border-left: 1.5px solid var(--jt-muted); }
.jm-steps .jm-matrix { display: table; }
.jm-eigen { margin: .2rem 0 0; padding-left: 1.2rem; font: 1rem/1.5 'Cambria Math', 'STIX Two Math', Georgia, serif; }
