:root {
    color-scheme: light;
    --bg: #f7f4ed;
    --ink: #16201b;
    --muted: #5e6a63;
    --line: #d7d0c1;
    --panel: #ffffff;
    --accent: #0f5559;
    --accent-strong: #083f42;
    --danger: #a83232;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

.shell {
    width: min(1080px, calc(100% - 32px));
    margin: 0 auto;
    padding: 48px 0;
}

.site-header {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    padding: 12px 16px;
    box-shadow: 0 8px 24px rgba(22, 32, 27, 0.08);
}

.brand-row {
    display: flex;
    align-items: center;
    min-height: 44px;
}

.brand {
    color: var(--ink);
    font-size: 1.1rem;
    font-weight: 900;
    text-decoration: none;
}

.converter {
    scroll-margin-top: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(24px, 4vw, 44px);
}

.contact-page {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(24px, 4vw, 44px);
}

.contact-page p {
    max-width: 680px;
    color: var(--muted);
}

.contact-reveal {
    width: auto;
    min-height: 44px;
    margin-top: 8px;
}

.contact-output {
    min-height: 30px;
    margin: 16px 0 0;
    font-weight: 800;
}

.contact-output a {
    color: var(--accent-strong);
}

.eyebrow,
.label {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1 {
    max-width: 720px;
    margin: 0 0 28px;
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 1.05;
}

.smart-form,
.convert-form {
    display: grid;
    gap: 14px;
    align-items: end;
}

.smart-form {
    grid-template-columns: 1fr auto auto;
    margin-bottom: 10px;
}

.convert-form {
    grid-template-columns: 1fr 1fr auto 1fr auto auto;
    margin-top: 22px;
}

.examples {
    margin: 0;
    color: var(--muted);
    font-size: 0.94rem;
}

.examples a {
    color: var(--accent-strong);
    font-weight: 700;
}

.auto-toggle {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    margin-top: 14px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.auto-toggle input {
    width: auto;
    min-height: 0;
    margin: 0;
    accent-color: var(--accent);
}

.quick-converters {
    margin-top: 18px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.quick-converters h2 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.quick-links li {
    display: flex;
}

.quick-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 8px 10px;
    font-size: 0.92rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
}

.quick-links a:hover,
.quick-links a:focus {
    background: #e8efe9;
}

.recent-conversions {
    margin-top: 18px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.favorite-conversions {
    margin-top: 18px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.recent-heading {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.recent-heading h2 {
    margin: 0;
    font-size: 1rem;
}

.text-button {
    width: auto;
    min-height: 34px;
    border: 1px solid var(--line);
    background: #f8faf8;
    color: var(--muted);
    padding: 6px 10px;
    font-size: 0.86rem;
}

.text-button:hover,
.text-button:focus {
    background: #e8efe9;
    color: var(--ink);
}

.recent-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.recent-links li {
    display: flex;
}

.recent-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #eef5f2;
    color: var(--accent-strong);
    padding: 8px 10px;
    font-size: 0.9rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
}

.recent-links a:hover,
.recent-links a:focus {
    background: #e1eee8;
}

.favorite-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.favorite-links li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
}

.favorite-links a,
.favorite-links button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #eef5f2;
    color: var(--accent-strong);
    padding: 8px 10px;
    font-size: 0.9rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
}

.favorite-links button {
    width: auto;
    background: #f8faf8;
    color: var(--muted);
    font-size: 0.82rem;
}

.favorite-links a:hover,
.favorite-links a:focus,
.favorite-links button:hover,
.favorite-links button:focus {
    background: #e1eee8;
    color: var(--ink);
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

input,
button,
.button {
    width: 100%;
    min-height: 46px;
    border-radius: 6px;
    font: inherit;
}

input {
    border: 1px solid var(--line);
    padding: 10px 12px;
}

.input-wrap {
    position: relative;
    display: block;
}

.input-wrap input {
    padding-right: 44px;
}

.input-wrap input[type="number"] {
    appearance: textfield;
}

.input-wrap input[type="number"]::-webkit-outer-spin-button,
.input-wrap input[type="number"]::-webkit-inner-spin-button {
    appearance: none;
    margin: 0;
}

.field-clear {
    position: absolute;
    top: 50%;
    right: 9px;
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-height: 28px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8faf8;
    color: var(--muted);
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
    transform: translateY(-50%);
}

.field-clear:hover,
.field-clear:focus {
    background: #e8efe9;
    color: var(--ink);
}

.js-ready .input-wrap.has-value .field-clear {
    display: inline-flex;
}

.js-ready .clear-link {
    display: none;
}

button,
.button {
    border: 0;
    background: var(--accent);
    color: #fff;
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
}

button:hover,
button:focus,
.button:hover,
.button:focus {
    background: var(--accent-strong);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.button.secondary {
    border: 1px solid var(--line);
    background: #f8faf8;
    color: var(--ink);
}

.button.secondary:hover,
.button.secondary:focus {
    background: #e8efe9;
}

.auto-convert-ready .convert-submit {
    display: none;
}

.swap-fields {
    width: auto;
    min-width: 72px;
    border: 1px solid var(--line);
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 8px 12px;
    font-size: 0.9rem;
}

.swap-fields:hover,
.swap-fields:focus {
    background: #e8efe9;
    color: var(--ink);
}

.result {
    scroll-margin-top: 110px;
    margin-top: 24px;
    border-top: 1px solid var(--line);
    padding-top: 22px;
}

.result.error {
    color: var(--danger);
    font-weight: 700;
}

.result h2 {
    margin: 0 0 18px;
    font-size: clamp(1.4rem, 3vw, 2.4rem);
}

.category-context {
    display: inline-flex;
    margin: 0 0 12px;
    color: var(--accent-strong);
    font-size: 0.92rem;
    font-weight: 800;
}

.category-context:hover,
.category-context:focus {
    color: var(--ink);
}

.precision-control {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 16px;
}

.precision-control > span {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.precision-options {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.precision-options button {
    width: auto;
    min-height: 34px;
    border: 1px solid var(--line);
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 6px 10px;
    font-size: 0.86rem;
}

.precision-options button:hover,
.precision-options button:focus,
.precision-options button.is-active {
    background: var(--accent);
    color: #fff;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 20px;
}

.copy-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 38px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.copy-button:hover,
.copy-button:focus {
    background: #e8efe9;
}

.copy-button.is-saved {
    background: #e1eee8;
    color: var(--ink);
}

.copy-status {
    min-height: 24px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.unit-notes {
    margin: 0 0 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf8;
    padding: 14px;
}

.unit-notes h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.unit-notes ul {
    display: grid;
    gap: 8px;
    margin: 0;
    padding-left: 18px;
}

.unit-notes li {
    color: var(--muted);
}

.notes {
    display: grid;
    gap: 8px;
    margin: 0 0 20px;
}

.notes p {
    margin: 0;
    border-left: 3px solid var(--accent);
    background: #eef5f2;
    padding: 10px 12px;
    color: var(--muted);
}

.matrix {
    margin: 0 0 22px;
}

.matrix h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.matrix-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.matrix-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(92px, auto);
    gap: 10px;
    align-items: center;
    min-height: 46px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.matrix-row:nth-child(odd) {
    border-right: 1px solid var(--line);
}

.matrix-row:nth-last-child(-n+2) {
    border-bottom: 0;
}

.matrix-value {
    overflow-wrap: anywhere;
    font-weight: 700;
}

.matrix-unit {
    color: var(--muted);
    text-align: right;
}

.nearby-values {
    margin: 0 0 22px;
}

.nearby-values h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.nearby-table {
    display: grid;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.nearby-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    min-height: 44px;
    border-bottom: 1px solid var(--line);
    background: #f8faf8;
    padding: 10px 12px;
}

.nearby-row:last-child {
    border-bottom: 0;
}

.nearby-row span,
.nearby-row strong {
    overflow-wrap: anywhere;
}

.nearby-row span {
    color: var(--muted);
}

.nearby-row strong {
    text-align: right;
}

dl {
    display: grid;
    gap: 10px;
    margin: 0;
}

dl div {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 16px;
}

dt {
    color: var(--muted);
    font-weight: 700;
}

dd {
    margin: 0;
}

.related {
    margin-top: 22px;
}

.related h3,
.link-panel h3,
.unit-list h3 {
    margin: 0 0 10px;
    font-size: 1rem;
}

.related-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.related-links a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 8px 12px;
    font-weight: 700;
    text-decoration: none;
}

.related-links a:hover,
.related-links a:focus {
    background: #e8efe9;
}

.category-page {
    scroll-margin-top: 110px;
    display: grid;
    gap: 22px;
    margin-top: 22px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(22px, 3vw, 34px);
}

.category-copy h2 {
    margin: 0 0 10px;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.category-copy p:last-child {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
}

.unit-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.unit-grid.compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.unit-grid article {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf8;
    padding: 14px;
}

.unit-card {
    color: inherit;
    text-decoration: none;
}

.unit-card article {
    height: 100%;
}

.unit-card:hover article,
.unit-card:focus article {
    background: #e8efe9;
    border-color: #cadbd0;
}

.unit-grid h4 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.unit-grid p {
    margin: 0;
    color: var(--muted);
}

.unit-details {
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.unit-details summary {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8faf8;
    color: var(--accent-strong);
    padding: 8px 12px;
    font-weight: 700;
    cursor: pointer;
}

.unit-details summary:hover,
.unit-details summary:focus {
    background: #e8efe9;
}

.unit-details .unit-grid {
    margin-top: 14px;
}

.category-faq {
    display: grid;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.category-faq h3 {
    margin: 0;
    font-size: 1rem;
}

.category-faq details {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf8;
    padding: 0;
}

.category-faq summary {
    min-height: 42px;
    padding: 10px 12px;
    color: var(--accent-strong);
    font-weight: 800;
    cursor: pointer;
}

.category-faq p {
    margin: 0;
    border-top: 1px solid var(--line);
    padding: 10px 12px 12px;
    color: var(--muted);
}

.categories {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 18px;
}

.categories a {
    color: inherit;
    text-decoration: none;
}

.categories article {
    background: #e8efe9;
    border: 1px solid #cadbd0;
    border-radius: 8px;
    padding: 16px;
}

.categories h2 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.categories p {
    margin: 0;
    color: var(--muted);
}

.site-footer {
    display: flex;
    justify-content: center;
    margin-top: 22px;
    color: var(--muted);
    font-size: 0.92rem;
}

.site-footer a {
    color: var(--accent-strong);
    font-weight: 800;
}

.site-footer a:hover,
.site-footer a:focus {
    color: var(--ink);
}

.back-to-top {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 800;
    opacity: 0;
    pointer-events: none;
    text-decoration: none;
    transform: translateY(8px);
    box-shadow: 0 8px 24px rgba(22, 32, 27, 0.18);
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.back-to-top.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top:hover,
.back-to-top:focus {
    background: var(--accent-strong);
}

@media (max-width: 760px) {
    .smart-form,
    .convert-form,
    .categories,
    .quick-links,
    .unit-grid.compact,
    .unit-grid {
        grid-template-columns: 1fr;
    }

    dl div {
        grid-template-columns: 1fr;
        gap: 2px;
    }

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

    .nearby-row {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .nearby-row strong {
        text-align: left;
    }

    .matrix-row,
    .matrix-row:nth-child(odd) {
        border-right: 0;
    }

    .matrix-row:nth-last-child(2) {
        border-bottom: 1px solid var(--line);
    }

    .shell {
        width: min(100% - 20px, 1080px);
        padding: 18px 0 72px;
    }

    .back-to-top {
        right: 10px;
        bottom: 10px;
    }
}
