:root {
    color-scheme: dark;
    --esr-line: #555;
    --esr-panel: #292929;
    --esr-input: #222;
    --esr-muted: #909090;
    --esr-accent: #5ef;
    --esr-total: #5ef;
    --esr-resistance: #f4b860;
    --esr-capacitive: #72a7e8;
    --esr-inductive: #72c58b;
    --esr-phase: #c59df2;
}

button,
input {
    font: inherit;
}

button {
    color: var(--textcolor);
}

.esr-page {
    position: relative;
    display: block;
    min-height: 0;
    padding-bottom: 8em;
}

.tool-heading {
    display: flex;
    gap: 2em;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2em;
}

.tool-heading h2 {
    margin-bottom: 0.35em;
    color: #eee;
    font-size: 1.35em;
    font-weight: 600;
}

.tool-heading p {
    max-width: 42em;
    color: var(--esr-muted);
}

.reset-button {
    flex: none;
    padding: 0.35em 0.8em;
    border: 0;
    border-bottom: 1px solid var(--esr-line);
    border-radius: 4px;
    background: var(--esr-input);
    cursor: pointer;
}

.reset-button:hover,
.reset-button:focus-visible {
    color: #afe5;
    outline: 1px solid #afe5;
    outline-offset: 2px;
}

.input-sections {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.2em;
}

fieldset {
    min-width: 0;
    padding: 1em;
    border: 1px solid var(--esr-line);
}

legend {
    padding: 0 0.45em;
    color: var(--esr-accent);
    font-size: 0.88em;
}

.field {
    display: block;
    margin-bottom: 1em;
    color: #aaa;
    font-size: 0.82em;
}

.field:last-child {
    margin-bottom: 0;
}

.field > span:first-child {
    display: block;
    min-height: 2.5em;
    margin-bottom: 0.25em;
}

.field-label {
    display: flex !important;
    gap: 0.75em;
    align-items: baseline;
    justify-content: space-between;
}

.field-label output {
    color: var(--esr-accent);
    font-size: 0.88em;
    white-space: nowrap;
}

.input-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    width: 100%;
    border: 1px solid var(--esr-line);
    border-radius: 4px;
    background: var(--esr-input);
}

.input-shell:focus-within {
    border-color: var(--esr-accent);
}

.input-shell input {
    min-width: 0;
    width: 100%;
    padding: 0.55em 0.6em;
    border: 0;
    outline: 0;
    color: #eee;
    background: transparent;
}

.unit {
    padding: 0 0.65em;
    color: #888;
    font-size: 0.85em;
    white-space: nowrap;
}

.range {
    appearance: none;
    display: block;
    width: 100%;
    height: 1.2em;
    margin-top: 0.55em;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    cursor: pointer;
}

.range::-webkit-slider-runnable-track {
    height: 4px;
    border: 1px solid var(--esr-line);
    background: var(--esr-input);
}

.range::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -5px;
    border: 1px solid var(--esr-accent);
    border-radius: 50%;
    background: var(--bgcolor);
}

.range::-moz-range-track {
    height: 2px;
    border: 1px solid var(--esr-line);
    background: var(--esr-input);
}

.range::-moz-range-progress {
    height: 2px;
    background: var(--esr-accent);
}

.range::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border: 1px solid var(--esr-accent);
    border-radius: 50%;
    background: var(--bgcolor);
}

.range:focus-visible::-webkit-slider-thumb {
    outline: 1px solid #afe5;
    outline-offset: 2px;
}

.range:focus-visible::-moz-range-thumb {
    outline: 1px solid #afe5;
    outline-offset: 2px;
}

.form-error {
    margin-top: 1em;
    padding: 0.7em 0.9em;
    border-left: 2px solid #e87575;
    color: #f1b1b1;
    background: var(--esr-panel);
}

.results {
    margin-top: 2.5em;
}

.results h3 {
    margin-bottom: 0.75em;
    color: #ddd;
    font-size: 1em;
    font-weight: 500;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--esr-line);
    border-bottom: 1px solid var(--esr-line);
}

.result-item {
    min-width: 0;
    padding: 0.85em 1em 0.9em 0;
}

.result-item:nth-child(3n + 2),
.result-item:nth-child(3n + 3) {
    padding-left: 1em;
    border-left: 1px solid var(--esr-line);
}

.result-item:nth-child(n + 4) {
    border-top: 1px solid var(--esr-line);
}

.result-item span {
    display: block;
    overflow: hidden;
    margin-bottom: 0.25em;
    color: var(--esr-muted);
    font-size: 0.75em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-item strong {
    color: #eee;
    font-size: 1.15em;
    font-weight: 500;
}

.estimate {
    margin-top: 1em;
}

.estimate-heading {
    display: flex;
    gap: 1em;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.55em;
}

.estimate-heading > span {
    color: #ccc;
    font-size: 0.82em;
}

.estimate-heading small {
    margin-left: 0.45em;
    color: var(--esr-muted);
    font-size: 0.88em;
}

.estimate-heading strong {
    color: #ddd;
    font-size: 0.85em;
    font-weight: 500;
}

.estimate-track {
    position: relative;
    height: 8px;
    border: 1px solid var(--esr-line);
    background: var(--esr-input);
}

.estimate-track > span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--esr-accent);
}

.estimate-track > i {
    position: absolute;
    top: -4px;
    bottom: -4px;
    left: 66.666%;
    border-left: 1px solid #ccc;
}

.estimate-scale {
    position: relative;
    height: 1.6em;
    margin-top: 0.2em;
    color: #777;
    font-size: 0.65em;
}

.estimate-scale span {
    position: absolute;
    top: 0;
}

.estimate-scale span:first-child {
    left: 0;
}

.estimate-scale span:nth-child(2) {
    left: 66.666%;
    transform: translateX(-50%);
    white-space: nowrap;
}

.estimate-scale span:last-child {
    right: 0;
}

.operating-summary {
    margin: 0.35em 0 0;
    color: #aaa;
    font-size: 0.82em;
}

.estimate[data-state="invalid"] .operating-summary {
    color: #e9b0b0;
}

.formulas {
    margin-top: 2.5em;
    padding-top: 0.9em;
    border-top: 1px solid var(--esr-line);
}

.formulas summary {
    width: fit-content;
    color: var(--esr-accent);
    cursor: pointer;
}

.formulas summary:hover {
    color: #afe5;
}

.formulas summary:focus-visible {
    outline: 1px solid var(--esr-accent);
    outline-offset: 3px;
}

.formula-content {
    padding-top: 1em;
}

.formula-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    border: 1px solid var(--esr-line);
    background: var(--esr-line);
}

.formula-item {
    min-width: 0;
    padding: 0.8em;
    background: var(--bgcolor);
}

.formula-item > span {
    display: block;
    margin-bottom: 0.45em;
    color: var(--esr-muted);
    font-size: 0.72em;
}

.formula-item code {
    display: block;
    overflow-wrap: anywhere;
    color: #ccc;
    font-size: 0.76em;
    line-height: 1.55;
}

.formula-note,
.formula-links {
    max-width: 62em;
    color: #999;
    font-size: 0.76em;
    line-height: 1.5;
}

.formula-note {
    padding-top: 0.8em;
}

.plots {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 1.5em;
    margin-top: 3em;
}

.plot {
    min-width: 0;
    padding-top: 0.9em;
    border-top: 1px solid var(--esr-line);
}

.plot figcaption {
    display: flex;
    gap: 1em;
    align-items: flex-start;
    justify-content: space-between;
    min-height: 3.2em;
    margin-bottom: 0.7em;
}

.plot figcaption > span,
.plot figcaption strong,
.plot figcaption small {
    display: block;
}

.plot figcaption strong {
    color: #ddd;
    font-size: 0.92em;
    font-weight: 500;
}

.plot figcaption small,
.plot output {
    color: var(--esr-muted);
    font-size: 0.7em;
}

.plot output {
    max-width: 62%;
    text-align: right;
}

.plot-legend {
    display: flex;
    gap: 1em;
    min-height: 1.7em;
    color: #888;
    font-size: 0.68em;
}

.plot-legend span {
    display: inline-flex;
    gap: 0.35em;
    align-items: center;
}

.plot-legend i {
    display: inline-block;
    width: 1.2em;
    border-top: 2px solid;
}

.plot-legend .line-total {
    border-color: var(--esr-total);
}

.plot-legend .line-esr {
    border-color: var(--esr-resistance);
}

.plot-legend .line-xc {
    border-color: var(--esr-capacitive);
}

.plot-legend .line-xl {
    border-color: var(--esr-inductive);
}

canvas {
    display: block;
    width: 100%;
    height: 270px;
    border: 1px solid var(--esr-line);
    background: var(--esr-panel);
    cursor: crosshair;
}

canvas:focus-visible {
    outline: 1px solid var(--esr-accent);
    outline-offset: 2px;
}

@media (max-width: 760px) {
    .esr-page {
        padding-top: 7em;
    }

    .input-sections,
    .plots,
    .formula-grid {
        grid-template-columns: 1fr;
    }

    .input-sections {
        gap: 1.5em;
    }

    .field > span:first-child {
        min-height: 0;
    }
}

@media (max-width: 560px) {
    .esr-page {
        padding-right: 1em;
        padding-left: 1em;
    }

    .tool-heading {
        gap: 1em;
    }

    .tool-heading h2 {
        font-size: 1.15em;
    }

    .result-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .result-item,
    .result-item:nth-child(3n + 2),
    .result-item:nth-child(3n + 3) {
        padding: 0.8em 0.5em;
        border-top: 0;
        border-left: 0;
    }

    .result-item:nth-child(even) {
        padding-left: 0.8em;
        border-left: 1px solid var(--esr-line);
    }

    .result-item:nth-child(n + 3) {
        border-top: 1px solid var(--esr-line);
    }

    .result-item span {
        white-space: normal;
    }

    .plot figcaption {
        display: block;
    }

    .plot output {
        display: block;
        max-width: none;
        margin-top: 0.4em;
        text-align: left;
    }

    canvas {
        height: 240px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
    }
}
