:root {
    color-scheme: dark;

    --background: #07110d;
    --background-secondary: #0b1913;
    --surface: #10231b;
    --surface-hover: #142b22;
    --border: #284538;
    --primary: #68f0a8;
    --primary-soft: rgba(104, 240, 168, 0.12);
    --text: #eefcf4;
    --text-muted: #9db7a8;
    --danger: #ff8b8b;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background:
        radial-gradient(
            circle at top,
            rgba(104, 240, 168, 0.08),
            transparent 35rem
        ),
        var(--background);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input,
select {
    font: inherit;
}

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

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

.app-container {
    width: min(100% - 2rem, 760px);
    margin-inline: auto;
    padding-block: 2rem 3rem;
}

.app-header {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.5rem;
    text-align: center;
}

.author-link {
    align-self: flex-end;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition:
        color 150ms ease,
        transform 150ms ease;
}

.author-link:hover {
    color: var(--primary);
    transform: translateY(-1px);
}

.author-link:focus-visible {
    border-radius: 0.25rem;
    outline: 2px solid var(--primary);
    outline-offset: 4px;
}

.eyebrow {
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.app-header h1 {
    margin: 0.25rem 0;
    color: var(--primary);
    font-size: clamp(2.6rem, 15vw, 4rem);
    letter-spacing: 0.07em;
    line-height: 1;
    text-transform: uppercase;
}

.app-header p {
    max-width: 34rem;
    margin: 1rem auto 0;
    color: var(--text-muted);
    line-height: 1.5;
}

.calculator-card,
.results-section {
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    background: rgba(16, 35, 27, 0.9);
}

.calculator-card {
    position: relative;
    z-index: 2;
    overflow: visible;
    padding: 1.4rem 1.5rem 0.75rem;
}

.input-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field {
    display: grid;
    gap: 0.5rem;
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.input-with-unit {
    display: flex;
    align-items: center;
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: var(--background-secondary);
}

.input-with-unit:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.input-with-unit input {
    width: 100%;
    min-width: 0;
    border: 0;
    border-radius: 0.85rem 0 0 0.85rem;
    outline: 0;
    background: transparent;
    color: var(--text);
    padding: 0.9rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
}

.unit-selector-wrapper {
    position: relative;
    z-index: 20;
    display: flex;
    align-self: stretch;
    min-width: 76px;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 0 0.85rem 0.85rem 0;
}

.unit-selector-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    border: 0;
    border-radius: 0 0.85rem 0.85rem 0;
    padding: 0 0.85rem;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    transition: background-color 150ms ease;
}

.unit-selector-button:hover,
.unit-selector-button[aria-expanded="true"] {
    background: var(--primary-soft);
}

.unit-selector-button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -3px;
}

.unit-selector-chevron {
    flex-shrink: 0;
    transition: transform 150ms ease;
}

.unit-selector-button[aria-expanded="true"] .unit-selector-chevron {
    transform: rotate(180deg);
}

.unit-selector-menu {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    z-index: 1000;
    min-width: 90px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--surface);
    box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    pointer-events: none;
    transition:
        opacity 150ms ease,
        transform 150ms ease,
        visibility 150ms ease;
}

.unit-selector-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.unit-selector-option {
    width: 100%;
    border: 0;
    padding: 0.7rem 0.9rem;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
}

.unit-selector-option:hover,
.unit-selector-option:focus-visible {
    background: var(--surface-hover);
    color: var(--text);
    outline: none;
}

.unit-selector-option.is-selected {
    background: var(--primary-soft);
    color: var(--primary);
}

.bar-weight-field {
    margin: 0;
    padding: 0;
    border: 0;
}

.bar-weight-field legend {
    margin-bottom: 0.5rem;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.bar-weight-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.bar-weight-option {
    position: relative;
    cursor: pointer;
}

.bar-weight-option input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
}

.bar-weight-option span {
    display: grid;
    min-height: 3.25rem;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: var(--background-secondary);
    color: var(--text-muted);
    font-size: 1.05rem;
    font-weight: 700;
    transition:
        border-color 150ms ease,
        background-color 150ms ease,
        color 150ms ease;
}

.bar-weight-option:hover span {
    border-color: var(--primary);
}

.bar-weight-option input:checked + span {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.bar-weight-option input:focus-visible + span {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.validation-message {
    min-height: 1.1rem;
    margin: 0.65rem 0 0;
    color: var(--danger);
    font-size: 0.85rem;
}

.validation-message:empty {
    min-height: 0;
    margin-top: 0.25rem;
}

.results-section {
    position: relative;
    z-index: 1;

    margin-top: 1rem;
    overflow: hidden;
}

.results-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.results-heading h2 {
    margin: 0;
    font-size: 1.15rem;
}

.live-indicator {
    flex-shrink: 0;
    border: 1px solid rgba(104, 240, 168, 0.35);
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.results-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem 1.5rem;
    text-align: right;
    white-space: nowrap;
}

th:first-child,
td:first-child {
    text-align: left;
}

th {
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

tbody tr {
    border-top: 1px solid rgba(40, 69, 56, 0.7);
}

tbody tr:hover {
    background: var(--surface-hover);
}

td {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.primary-column {
    background: var(--primary-soft);
}

td.primary-column strong {
    color: var(--primary);
    font-size: 1.05rem;
}

.percentage {
    display: inline-grid;
    min-width: 3.25rem;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.55rem;
    color: var(--text);
    font-weight: 700;
}

.empty-state {
    padding: 2rem;
    color: var(--text-muted);
    text-align: center;
}

.mobile-label {
    display: none;
}

@media (max-width: 560px) {
    .app-container {
        width: min(100% - 1rem, 760px);
        padding-block: 1rem 2rem;
    }

    .app-header {
        margin-bottom: 1.25rem;
    }

    .author-link {
        margin-bottom: 0.4rem;
        font-size: 0.8rem;
    }

    .eyebrow {
        font-size: 0.7rem;
        letter-spacing: 0.16em;
    }

    .app-header h1 {
        font-size: clamp(2.6rem, 17vw, 4rem);
        letter-spacing: 0.08em;
    }

    .app-header p {
        margin-top: 0.75rem;
        font-size: 0.95rem;
    }

    .calculator-card {
        padding: 1.1rem 1rem 0.65rem;
    }

    .input-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .results-heading {
        padding: 1rem;
    }

    .results-heading h2 {
        font-size: 1.05rem;
    }

    table {
        table-layout: fixed;
    }

    th,
    td {
        padding: 0.85rem 0.55rem;
    }

    th:nth-child(1),
    td:nth-child(1) {
        width: 27%;
    }

    th:nth-child(2),
    td:nth-child(2) {
        width: 38%;
    }

    th:nth-child(3),
    td:nth-child(3) {
        width: 35%;
    }

    th {
        font-size: 0.67rem;
        letter-spacing: 0.05em;
    }

    td {
        font-size: 0.9rem;
    }

    td.primary-column strong {
        font-size: 0.95rem;
    }

    .percentage {
        min-width: 2.8rem;
        padding: 0.25rem 0.4rem;
    }

    .desktop-label {
        display: none;
    }

    .mobile-label {
        display: inline;
    }
}

@media (max-width: 390px) {
    .app-header h1 {
        font-size: 2.7rem;
    }

    .app-header p {
        font-size: 0.9rem;
    }

    .results-heading h2 {
        font-size: 0.98rem;
    }

    .live-indicator {
        padding-inline: 0.5rem;
        font-size: 0.68rem;
    }

    th,
    td {
        padding-inline: 0.45rem;
    }

    th {
        font-size: 0.64rem;
    }

    td {
        font-size: 0.84rem;
    }

    td.primary-column strong {
        font-size: 0.9rem;
    }

    .percentage {
        min-width: 2.6rem;
        font-size: 0.88rem;
    }
}