/* ==========================================================================
   Components
   ========================================================================== */

/* Page head --------------------------------------------------------------- */

.page-head {
    padding-block: 1.75rem 1.5rem;
    background: var(--surface-50);
    border-bottom: 1px solid var(--border-200);
}

.page-head--home {
    padding-block: 2.25rem 1.75rem;
}

.page-head__title {
    max-width: 40ch;
}

.page-head__lead {
    max-width: 62ch;
    margin-top: 0.6rem;
    color: var(--ink-500);
    font-size: 1.1rem;
}

.eyebrow {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.eyebrow a {
    color: var(--accent-600);
    text-decoration: none;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    color: var(--ink-500);
    font-size: 0.9rem;
}

/* Rank Math breadcrumbs */
.rank-math-breadcrumb {
    margin-bottom: 0.75rem;
    color: var(--ink-500);
    font-size: 0.875rem;
}

.rank-math-breadcrumb p {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.rank-math-breadcrumb a {
    color: var(--ink-700);
}

/* Sections ---------------------------------------------------------------- */

.section {
    padding-block: 2.5rem;
}

.section--tight {
    padding-block: 2rem 3rem;
}

.section--alt {
    background: var(--surface-50);
    border-top: 1px solid var(--border-200);
}

.section__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: 1.25rem;
}

.section__title {
    margin-bottom: 1.25rem;
}

.section__head .section__title {
    margin-bottom: 0;
}

.section__link {
    font-weight: 600;
}

/* Buttons ----------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.75rem;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
}

.btn--sm {
    min-height: 2.5rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.92rem;
}

.btn--ghost {
    border-color: var(--border-300);
    background: var(--surface-0);
    color: var(--primary-800);
}

.btn--ghost:hover {
    border-color: var(--primary-700);
    color: var(--primary-900);
}

.btn--on-dark {
    border-color: rgb(255 255 255 / 0.35);
    color: var(--on-dark);
}

.btn--on-dark:hover {
    border-color: #ffffff;
    color: #ffffff;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid var(--border-200);
    border-radius: var(--radius);
    background: var(--surface-0);
    color: var(--ink-500);
    cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
    border-color: var(--error-600);
    color: var(--error-600);
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Calculator panel -------------------------------------------------------- */

.tool-wrap {
    padding-block: 1.5rem 2.5rem;
}

.tool-stack {
    display: grid;
    gap: 1.5rem;
}

.tool {
    display: grid;
    gap: 1.25rem;
    padding: 1.25rem;
    border: 1px solid var(--border-200);
    border-radius: var(--radius-lg);
    background: var(--surface-0);
    box-shadow: var(--shadow-md);
}

.tool__title {
    font-size: 1.2rem;
}

.tool__help,
.tool__note {
    color: var(--ink-500);
    font-size: 0.92rem;
}

.tool__note {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--tan-100);
    color: var(--ink-700);
}

.tool__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.tool__split {
    display: grid;
    gap: 1.25rem;
    align-items: center;
}

@media (min-width: 48rem) {
    .tool {
        padding: 1.75rem;
    }

    .tool__split {
        grid-template-columns: auto minmax(0, 1fr);
        gap: 2rem;
    }
}

/* Fields ------------------------------------------------------------------ */

.field {
    display: grid;
    gap: 0.35rem;
    align-content: start;
    min-width: 0;
}

.field[hidden] {
    display: none;
}

.field--short {
    max-width: 16rem;
}

.field__label {
    color: var(--ink-900);
    font-size: 0.92rem;
    font-weight: 700;
}

.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr));
    gap: 1rem;
}

@media (min-width: 40rem) {
    .field-row--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.tool input[type="number"],
.tool input[type="text"],
.tool select {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border-300);
    border-radius: var(--radius);
    background: var(--surface-0);
    color: var(--ink-900);
    font-size: 1rem;
}

.tool input[type="number"],
.tool input[type="text"] {
    font-family: var(--font-mono);
}

.tool input:hover,
.tool select:hover {
    border-color: var(--ink-500);
}

.field__control {
    display: flex;
    min-width: 0;
}

.field__control input {
    flex: 1 1 auto;
    min-width: 0;
    border-start-end-radius: 0;
    border-end-end-radius: 0;
}

.tool .field__control .field__unit {
    flex: 0 0 auto;
    width: auto;
    min-width: 4.25rem;
    margin-inline-start: -1px;
    border-start-start-radius: 0;
    border-end-start-radius: 0;
    background: var(--surface-50);
}

.field__suffix {
    display: inline-flex;
    flex: none;
    align-items: center;
    min-width: 2.75rem;
    justify-content: center;
    margin-inline-start: -1px;
    padding-inline: 0.6rem;
    border: 1px solid var(--border-300);
    border-start-end-radius: var(--radius);
    border-end-end-radius: var(--radius);
    background: var(--surface-50);
    color: var(--ink-700);
    font-weight: 600;
}

/* Segmented radio group */
.segmented {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.segmented legend {
    float: left;
    margin-inline-end: 0.5rem;
}

.segmented__option {
    position: relative;
}

.segmented__option input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.segmented__option span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.5rem;
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--border-300);
    border-radius: var(--radius);
    background: var(--surface-0);
    font-weight: 700;
}

.segmented__option input:checked + span {
    border-color: var(--primary-800);
    background: var(--primary-800);
    color: #ffffff;
}

.segmented__option input:focus-visible + span {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

/* Results ----------------------------------------------------------------- */

.result {
    display: grid;
    gap: 0.35rem;
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--accent-500);
    border-radius: var(--radius);
    background: var(--accent-100);
}

.result[data-state="error"] {
    border-left-color: var(--error-600);
    background: var(--error-100);
}

.result__label {
    color: var(--ink-700);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.result__value {
    color: var(--ink-900);
    font-family: var(--font-mono);
    font-size: clamp(1.6rem, 1.3rem + 1.4vw, 2.25rem);
    font-weight: 700;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.result__detail {
    color: var(--ink-700);
    font-size: 0.95rem;
}

.result[data-state="error"] .result__detail {
    color: var(--error-600);
    font-weight: 600;
}

.result-list {
    display: grid;
    gap: 0.35rem 1.5rem;
    margin-top: 0.5rem;
}

.result-list:empty {
    display: none;
}

.result-list div {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgb(var(--primary-900-rgb) / 0.1);
}

.result-list dt {
    color: var(--ink-700);
}

.result-list dd {
    color: var(--ink-900);
    font-family: var(--font-mono);
    font-weight: 700;
}

@media (min-width: 40rem) {
    .result-list--grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.table-wrap {
    margin-top: 0.5rem;
    overflow-x: auto;
}

.result-table,
.rich-text table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.result-table th,
.result-table td,
.rich-text th,
.rich-text td {
    padding: 0.45rem 0.4rem;
    border-bottom: 1px solid rgb(var(--primary-900-rgb) / 0.12);
    text-align: left;
    white-space: nowrap;
}

.result-table {
    font-size: 0.85rem;
}

@media (min-width: 40rem) {
    .result-table {
        font-size: 0.95rem;
    }

    .result-table th,
    .result-table td {
        padding-inline: 0.6rem;
    }
}

.result-table td {
    font-family: var(--font-mono);
}

.result-table thead th,
.rich-text thead th {
    color: var(--ink-900);
    font-size: 0.85rem;
}

/* Color code ---------------------------------------------------------------- */

.resistor {
    display: flex;
    justify-content: center;
    padding: 0.75rem;
    border-radius: var(--radius);
    background: var(--surface-50);
}

.resistor svg {
    width: min(100%, 26rem);
    height: auto;
}

.resistor__lead {
    fill: none;
    stroke: #9aa3ad;
    stroke-width: 6;
    stroke-linecap: round;
}

.resistor__body {
    fill: var(--tan-300);
    stroke: rgb(0 0 0 / 0.15);
    stroke-width: 1.5;
}

.resistor__band[data-color="white"] {
    stroke: rgb(0 0 0 / 0.25);
    stroke-width: 1;
}

.band-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr));
    gap: 1rem;
}

.band-field__control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.band-field__control select {
    flex: 1 1 auto;
    min-width: 0;
}

.swatch {
    flex: none;
    width: 1.75rem;
    height: 2.75rem;
    border: 1px solid rgb(0 0 0 / 0.25);
    border-radius: 0.25rem;
    background: var(--swatch, transparent);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.7rem 0.3rem 0.35rem;
    border: 1px solid var(--border-300);
    border-radius: 999px;
    background: var(--surface-0);
    color: var(--ink-900);
    font-weight: 700;
}

.chip::before {
    content: "";
    width: 1.35rem;
    height: 1.35rem;
    border: 1px solid rgb(0 0 0 / 0.25);
    border-radius: 50%;
    background: var(--swatch, transparent);
}

/* Resistor list ------------------------------------------------------------ */

.rlist {
    display: grid;
    gap: 0.75rem;
    justify-items: start;
}

.rlist__rows {
    display: grid;
    gap: 0.6rem;
    width: 100%;
    counter-reset: none;
}

.rlist__row {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 22rem) auto;
    gap: 0.5rem;
    align-items: center;
}

.rlist__label {
    color: var(--ink-900);
    font-family: var(--font-mono);
    font-weight: 700;
}

/* Schematics, SMD chip, E-series table -------------------------------------- */

.schematic {
    justify-self: center;
    color: var(--ink-900);
}

.schematic svg {
    width: 11rem;
    height: auto;
}

.schematic__text {
    fill: currentColor;
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
}

.smd-chip {
    display: flex;
    justify-self: center;
    align-items: center;
    justify-content: center;
    width: 9rem;
    height: 5rem;
    border-inline: 1.1rem solid #c9ced6;
    border-radius: 0.2rem;
    background: #1f2328;
    color: #f2f2f2;
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.series-table summary {
    color: var(--primary-700);
    font-weight: 600;
    cursor: pointer;
}

.series-table__values {
    margin-top: 0.5rem;
    color: var(--ink-700);
    font-family: var(--font-mono);
    font-size: 0.92rem;
    line-height: 1.8;
}

/* Calculator cards ----------------------------------------------------------- */

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: 1rem;
}

.tool-card {
    position: relative;
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    align-content: start;
    gap: 0.25rem 0.85rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border-200);
    border-radius: var(--radius-lg);
    background: var(--surface-0);
    box-shadow: var(--shadow-sm);
}

.tool-card:hover {
    border-color: var(--primary-700);
}

.tool-card:focus-within {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.tool-card__icon {
    grid-row: span 2;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius);
    background: var(--primary-100);
    color: var(--primary-700);
    font-family: var(--font-mono);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.tool-card__icon--color-code { background: linear-gradient(90deg, var(--tan-300) 0 20%, #d32f2f 20% 35%, var(--tan-300) 35% 45%, #7b1fa2 45% 60%, var(--tan-300) 60% 70%, #7b4a26 70% 85%, var(--tan-300) 85%); }
.tool-card__icon--parallel::before { content: "∥"; font-size: 1.3rem; }
.tool-card__icon--series::before { content: "+"; font-size: 1.3rem; }
.tool-card__icon--led::before { content: "LED"; }
.tool-card__icon--ohms-law::before { content: "V=IR"; font-size: 0.6rem; }
.tool-card__icon--voltage-divider::before { content: "÷"; font-size: 1.3rem; }
.tool-card__icon--voltage-drop::before { content: "ΔV"; }
.tool-card__icon--power::before { content: "W"; font-size: 1.1rem; }
.tool-card__icon--smd::before { content: "472"; }
.tool-card__icon--standard-values::before { content: "E24"; }

.tool-card__title {
    font-size: 1.02rem;
}

.tool-card__title a {
    color: var(--ink-900);
    text-decoration: none;
}

.tool-card__title a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.tool-card__title a:focus-visible {
    outline: none;
}

.tool-card__text {
    color: var(--ink-500);
    font-size: 0.92rem;
    line-height: 1.5;
}

/* Post cards -------------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    gap: 1.25rem;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-200);
    border-radius: var(--radius-lg);
    background: var(--surface-0);
    box-shadow: var(--shadow-sm);
}

.card:hover {
    border-color: var(--primary-700);
}

.card:focus-within {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.card__img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.card__body {
    display: grid;
    gap: 0.4rem;
    padding: 1rem 1.1rem 1.25rem;
}

.card__title {
    font-size: 1.08rem;
}

.card__title a {
    color: var(--ink-900);
    text-decoration: none;
}

.card__title a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.card__title a:focus-visible {
    outline: none;
}

.card__text {
    color: var(--ink-500);
    font-size: 0.94rem;
    line-height: 1.55;
}

/* Rich text --------------------------------------------------------------- */

.page-body {
    padding-block: 2rem 3rem;
}

.rich-text > * + * {
    margin-top: 1rem;
}

.rich-text > :first-child {
    margin-top: 0;
}

.rich-text h2 {
    margin-top: 2.5rem;
}

.rich-text h3 {
    margin-top: 1.75rem;
}

.rich-text h2 + *,
.rich-text h3 + * {
    margin-top: 0.6rem;
}

.rich-text ul,
.rich-text ol {
    padding-inline-start: 1.4rem;
}

.rich-text li + li {
    margin-top: 0.35rem;
}

.rich-text strong {
    color: var(--ink-900);
}

.rich-text blockquote {
    padding: 0.9rem 1.1rem;
    border-left: 4px solid var(--primary-700);
    border-radius: var(--radius);
    background: var(--primary-100);
    color: var(--ink-900);
}

.rich-text pre,
.rich-text .formula {
    overflow-x: auto;
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius);
    background: var(--surface-100);
    color: var(--ink-900);
    font-family: var(--font-mono);
    font-size: 1rem;
    white-space: pre-wrap;
}

.rich-text table {
    display: block;
    overflow-x: auto;
}

.rich-text img {
    border-radius: var(--radius);
}

.rich-text figure img {
    margin-inline: auto;
}

.rich-text figcaption,
.rich-text .wp-caption-text {
    margin-top: 0.5rem;
    color: var(--ink-500);
    font-size: 0.88rem;
    text-align: center;
}

.rich-text .aligncenter {
    margin-inline: auto;
}

/* Post hero and credit ------------------------------------------------------- */

.post-hero {
    margin-top: 1.75rem;
}

.post-hero img {
    width: 100%;
    border-radius: var(--radius-lg);
}

.credit {
    margin-top: 0.45rem;
    color: var(--ink-500);
    font-size: 0.8rem;
}

.credit a {
    color: inherit;
}

/* Pagination ----------------------------------------------------------------- */

.pagination {
    margin-top: 2.25rem;
}

.pagination .nav-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-300);
    border-radius: var(--radius);
    text-decoration: none;
}

.pagination .page-numbers.current {
    border-color: var(--primary-800);
    background: var(--primary-800);
    color: #ffffff;
}

.result__detail:empty {
    display: none;
}
