.hk {
    --hk-bg: #121212;
    --hk-card: #1c2024;
    --hk-card-2: #232a30;
    --hk-line: #323b43;
    --hk-text: #e8ecef;
    --hk-muted: #9aa6b0;
    --hk-teal: #45adb9;
    --hk-teal-dark: #1f5c64;
    --hk-amber: #e0a940;
    --hk-error: #f2867e;

    /* Height of everything above the calculator (navbar + spacing).
       Adjust this if the page still scrolls a little, or leaves a gap at the bottom. */
    --hk-offset: 90px;

    /* Use the full browser width, even inside the layout's centered .container */
    width: calc(100vw - 2rem);
    margin: 1rem 0 1rem calc(50% - 50vw + 1rem);
    color: var(--hk-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

.hk *,
.hk *::before,
.hk *::after { box-sizing: border-box; }

/* ---------- Header ---------- */
.hk-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--hk-teal);
    color: #fff;
    padding: 0.9rem 1.25rem;
    border-radius: 8px 8px 0 0;
}

.hk-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    font-family: inherit;
}

.hk-formula-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}

.hk-formula-btn:hover { background: rgba(255, 255, 255, 0.25); }

.hk-formula-btn .hk-sigma {
    font-size: 1.2rem;
    line-height: 1;
}

/* ---------- Layout: inputs | results | drawing, buttons below ---------- */
.hk-body {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-areas:
        "inputs  results diagram"
        "footer  footer  diagram";
    background: var(--hk-card);
    border: 1px solid var(--hk-line);
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.hk-inputs  { grid-area: inputs; }
.hk-results { grid-area: results; }
.hk-diagram { grid-area: diagram; }
.hk-footer  { grid-area: footer; }

.hk-inputs {
    padding: 1.25rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.9rem;
    align-content: start;
}

.hk-field {
    width: 16rem;
    max-width: 100%;
}

.hk-field label {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

.hk-sym {
    color: var(--hk-amber);
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-size: 1.05rem;
}

.hk-input-group {
    display: flex;
    border: 1px solid var(--hk-line);
    border-radius: 6px;
    background: var(--hk-bg);
    overflow: hidden;
}

/* Resozes the Width of the placeholder bar 
. hk-inputs.hk-input-group {
    max-width: 16rem; 
} */


/* Resizing on dropdown bar on placeholder text */
.hk-inputs select {
    width: 6.5rem;
    flex-shrink: 0;
}

.hk-input-group:focus-within {
    border-color: var(--hk-teal);
    box-shadow: 0 0 0 2px rgba(69, 173, 185, 0.35);
}

.hk-input-group input {
    flex: 1;
    width: 0; /* lets the field shrink on narrow screens */
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--hk-text);
    font: inherit;
    font-size: 1.05rem;
    padding: 0.5rem 0.7rem;
    outline: none;
    font-variant-numeric: tabular-nums;
}

.hk-input-group input::placeholder { color: #5f6a73; }

.hk select {
    border: none;
    border-left: 1px solid var(--hk-line);
    background: var(--hk-card-2);
    color: var(--hk-text);
    font: inherit;
    font-size: 0.95rem;
    padding: 0 0.6rem;
    cursor: pointer;
}

.hk select:focus-visible {
    outline: 2px solid var(--hk-teal);
    outline-offset: -2px;
}

.hk-diagram {
    border-left: 1px solid var(--hk-line);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hk-diagram svg {
    width: 100%;
    height: auto;
}

.hk-diagram text {
    fill: var(--hk-muted);
    font-family: system-ui, sans-serif;
    font-size: 13px;
}

.hk-diagram .hk-dim-label {
    fill: var(--hk-amber);
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-size: 15px;
}

#hk-rod { transition: height 0.2s ease, y 0.2s ease; }

/* ---------- Results table ---------- */
.hk-results {
    border-left: 1px solid var(--hk-line);
}

.hk-row {
    display: grid;
    /* Adds value and controls the size of colums such as...
    1. Labels: Minmax
    2. Stempelside: 1.25fr
    3. Stangside: 1fr
    4. Unit dropdowns: 5.5rem
    */
    grid-template-columns: minmax(7.5rem, 1.2fr) 1.65fr 0.8fr 5.5rem;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border-top: 1px solid var(--hk-line);
}

.hk-row-head {
    background: var(--hk-card-2);
    border-top: none;
    color: var(--hk-muted);
    font-size: 0.95rem;
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
}

.hk-row-head span:nth-child(2),
.hk-row-head span:nth-child(3) { text-align: right; }

.hk-label {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 1.05rem;
}

.hk-label svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    stroke: var(--hk-teal);
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hk-value {
    text-align: right;
    font-size: 1.2rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.hk-value.is-empty {
    color: #5f6a73;
    font-weight: 400;
    font-size: 1rem;
}

.hk-value-wide { grid-column: 2 / 4; }

.hk-value-input {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--hk-line);
    border-radius: 6px;
    background: var(--hk-bg);
    color: var(--hk-text);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    padding: 0.3rem 0.6rem;
    outline: none;
}

.hk-value-input:focus {
    border-color: var(--hk-teal);
    box-shadow: 0 0 0 2px rgba(69, 173, 185, 0.35);
}

.hk-value-input::placeholder {
    color: #5f6a73;
    font-weight: 400;
    font-size: 1rem;
}

.hk-results select {
    border: 1px solid var(--hk-line);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
}

.hk-unitless {
    color: var(--hk-muted);
    font-size: 0.95rem;
    padding-left: 0.5rem;
    grid-column: 4;
}

/* ---------- Error + buttons ---------- */
.hk-footer {
    border-top: 1px solid var(--hk-line);
    padding: 0.25rem 1.25rem 0.6rem;
}

.hk-error {
    color: var(--hk-error);
    min-height: 1.2rem;
    margin: 0 0 0.25rem;
}

.hk-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* The field that covers nullstill and kopierer resultater */
.hk-actions button {
    background: var(--hk-teal-dark);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.6rem 1.5rem;
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.hk-actions button:hover { background: #26707a; }

.hk button:focus-visible {
    outline: 2px solid var(--hk-amber);
    outline-offset: 2px;
}

/* ---------- Formula dialog ---------- */
.hk-dialog {
    width: min(680px, calc(100% - 2rem));
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--hk-card);
    color: var(--hk-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hk-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.hk-dialog header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--hk-teal);
    color: #fff;
    padding: 0.8rem 1.25rem;
}

.hk-dialog h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    font-family: inherit;
}

.hk-dialog-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
}

.hk-formulas {
    width: 100%;
    border-collapse: collapse;
}

.hk-formulas th,
.hk-formulas td {
    padding: 0.7rem 1rem;
    border-top: 1px solid var(--hk-line);
    text-align: left;
    vertical-align: top;
}

.hk-formulas thead th {
    background: var(--hk-card-2);
    color: var(--hk-muted);
    font-weight: 500;
    border-top: none;
}

.hk-formulas .hk-math {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.15rem;
    white-space: nowrap;
}

.hk-formulas .hk-legend {
    color: var(--hk-muted);
    font-size: 0.85rem;
    padding-top: 0;
    border-top: none;
}

.hk-formulas tr:has(.hk-legend) td { border-top: none; }

.hk-formula-scroll { overflow-x: auto; }

.hk-formulas .hk-legend b {
    color: var(--hk-amber);
    font-weight: 500;
}

/* ---------- Small screens ---------- */
/* Medium screens: drawing on top, inputs and results side by side */
@media (max-width: 1100px) {
    .hk-body {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
        grid-template-areas:
            "diagram diagram"
            "inputs  results"
            "footer  footer";
    }
    .hk-diagram {
        border-left: none;
        border-bottom: 1px solid var(--hk-line);
    }
    .hk-diagram svg { max-height: 240px; }
}

@media (max-width: 720px) {
    .hk-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "diagram" "inputs" "results" "footer";
    }
    .hk-results {
        border-left: none;
        border-top: 1px solid var(--hk-line);
    }
    .hk-row {
        grid-template-columns: 1fr 1fr 5.5rem;
        gap: 0.25rem 0.75rem;
        padding: 0.7rem 1rem;
    }
    .hk-row-head span:first-child { display: none; }
    .hk-label { grid-column: 1 / -1; font-size: 1rem; }
    .hk-value-wide { grid-column: 1 / 3; }
    .hk-value,
    .hk-value-input { text-align: left; }
    .hk-row-head span:nth-child(2),
    .hk-row-head span:nth-child(3) { text-align: left; }
}

@media (max-width: 560px) {
    .hk-formulas th,
    .hk-formulas td { padding: 0.6rem 0.5rem; }
    .hk-formulas .hk-math {
        white-space: normal;
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #hk-rod { transition: none; }
}

/* ---------- Desktop: fit the screen height, no scrolling ----------
   Kept at the end of the file so it overrides the rules above. */
@media (min-width: 1101px) and (min-height: 700px) {
    .hk {
        height: calc(100dvh - var(--hk-offset));
        display: flex;
        flex-direction: column;
    }
    .hk-body {
        flex: 1;
        min-height: 0;
        grid-template-rows: minmax(0, 1fr) auto;
    }
    /* Spread the inputs and result rows over the available height */
    .hk-inputs { align-content: space-evenly; }
    .hk-results {
        display: flex;
        flex-direction: column;
    }
    .hk-results .hk-row:not(.hk-row-head) { flex: 1; }
    .hk-diagram svg { max-height: 100%; }
}
