.bgtool,
.bgtool-hub {
    --bgtool-ink: #18312b;
    --bgtool-muted: #5e6f69;
    --bgtool-line: #d9e3df;
    --bgtool-soft: #f2f7f4;
    --bgtool-surface: #ffffff;
    --bgtool-accent: #0b7a53;
    --bgtool-accent-dark: #075c40;
    --bgtool-warm: #f4efe3;
    color: var(--bgtool-ink);
    font-family: "Aptos", "Segoe UI", sans-serif;
}

.bgtool {
    border: 1px solid var(--bgtool-line);
    border-radius: 24px;
    background: linear-gradient(145deg, #fff 0%, #f9fcfa 75%);
    box-shadow: 0 18px 45px rgba(25, 54, 46, .08);
    overflow: hidden;
    margin: 28px 0;
}

.bgtool__heading,
.bgtool__form,
.bgtool__results,
.bgtool__trust,
.bgtool__history {
    padding-inline: clamp(18px, 4vw, 40px);
}

.bgtool__heading {
    padding-top: clamp(24px, 4vw, 42px);
    padding-bottom: 22px;
    background:
        radial-gradient(circle at 95% 5%, rgba(11, 122, 83, .12), transparent 32%),
        linear-gradient(130deg, #f9fcfa, #f2f7f4);
}

.bgtool__eyebrow {
    margin: 0 0 8px;
    color: var(--bgtool-accent-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.bgtool__heading h2 {
    margin: 0 0 8px;
    color: var(--bgtool-ink);
    font: 750 clamp(25px, 4vw, 38px)/1.08 "Aptos Display", "Segoe UI", sans-serif;
    letter-spacing: -.035em;
}

.bgtool__heading > p:last-child {
    max-width: 70ch;
    margin: 0;
    color: var(--bgtool-muted);
    line-height: 1.6;
}

.bgtool__form {
    padding-top: 26px;
    padding-bottom: 30px;
}

.bgtool__advanced {
    margin-top: 18px;
    border: 1px solid var(--bgtool-line);
    border-radius: 14px;
    background: var(--bgtool-soft);
}

.bgtool__advanced > summary {
    min-height: 46px;
    padding: 13px 15px;
    color: var(--bgtool-accent-dark);
    font-weight: 800;
    cursor: pointer;
}

.bgtool__fields--advanced {
    padding: 2px 15px 16px;
}

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

.bgtool__field {
    min-width: 0;
}

.bgtool__field[hidden] {
    display: none;
}

.bgtool__field label {
    display: block;
    margin: 0 0 7px;
    color: var(--bgtool-ink);
    font-size: 14px;
    font-weight: 700;
}

.bgtool__field input:not([type="checkbox"]),
.bgtool__field select {
    width: 100%;
    min-height: 50px;
    box-sizing: border-box;
    border: 1px solid #bccbc5;
    border-radius: 12px;
    background: var(--bgtool-surface);
    color: var(--bgtool-ink);
    padding: 11px 13px;
    font: inherit;
}

.bgtool__field input:focus,
.bgtool__field select:focus,
.bgtool button:focus-visible,
.bgtool-hub button:focus-visible,
.bgtool-hub input:focus {
    outline: 3px solid rgba(11, 122, 83, .22);
    outline-offset: 2px;
    border-color: var(--bgtool-accent);
}

.bgtool__field input[aria-invalid="true"] {
    border-color: #b42318;
}

.bgtool__field small {
    display: block;
    margin-top: 6px;
    color: var(--bgtool-muted);
    font-size: 12px;
    line-height: 1.45;
}

.bgtool__field--checkbox {
    align-self: end;
    border: 1px solid var(--bgtool-line);
    border-radius: 12px;
    background: var(--bgtool-soft);
    padding: 13px;
}

.bgtool__field--checkbox label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.bgtool__field--checkbox input {
    width: 20px;
    height: 20px;
    accent-color: var(--bgtool-accent);
}

.bgtool__submit,
.bgtool__share button,
.bgtool__history button {
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    padding: 11px 18px;
    font: 750 15px/1.2 inherit;
    cursor: pointer;
}

.bgtool__submit {
    min-width: 180px;
    margin-top: 22px;
    background: var(--bgtool-accent);
    color: #fff;
    box-shadow: 0 8px 22px rgba(11, 122, 83, .2);
}

.bgtool__submit:hover {
    background: var(--bgtool-accent-dark);
}

.bgtool__submit:disabled {
    opacity: .6;
    cursor: wait;
}

.bgtool__error {
    border-left: 4px solid #b42318;
    background: #fff1f0;
    color: #7a271a;
    padding: 12px 14px;
    margin: 18px 0 0;
}

.bgtool__results {
    border-top: 1px solid var(--bgtool-line);
    background: #f7faf8;
    padding-top: 28px;
    padding-bottom: 30px;
}

.bgtool__results h3,
.bgtool__history h3 {
    margin: 0 0 16px;
    font: 750 21px/1.2 "Aptos Display", "Segoe UI", sans-serif;
}

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

.bgtool__result {
    min-width: 0;
    border: 1px solid var(--bgtool-line);
    border-radius: 14px;
    background: var(--bgtool-surface);
    padding: 15px;
}

.bgtool__result--primary {
    border-color: rgba(11, 122, 83, .35);
    background: #eaf6f0;
}

.bgtool__result span,
.bgtool__result small {
    display: block;
    color: var(--bgtool-muted);
    font-size: 12px;
    line-height: 1.35;
}

.bgtool__result strong {
    display: block;
    overflow-wrap: anywhere;
    margin: 6px 0 3px;
    color: var(--bgtool-ink);
    font-size: clamp(20px, 3vw, 28px);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.bgtool[data-tool="night-work"] [data-result-card="legal_status"] {
    grid-column: 1 / -1;
    border-color: #d6a94a;
    background: #fff9e8;
}

.bgtool[data-tool="night-work"] [data-result="legal_status"] {
    font-size: 16px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.bgtool__details {
    margin-top: 16px;
    border: 1px solid var(--bgtool-line);
    border-radius: 12px;
    background: var(--bgtool-surface);
    padding: 11px 14px;
}

.bgtool__details summary {
    color: var(--bgtool-accent-dark);
    font-weight: 750;
    cursor: pointer;
}

.bgtool__details ol {
    margin: 12px 0 0;
    padding-left: 22px;
    color: var(--bgtool-muted);
    font-size: 13px;
    line-height: 1.55;
}

.bgtool__insights {
    margin-top: 16px;
    border-left: 4px solid var(--bgtool-accent);
    border-radius: 12px;
    background: var(--bgtool-surface);
    padding: 14px 16px;
}

.bgtool__insights h4 {
    margin: 0 0 8px;
    color: var(--bgtool-ink);
    font-size: 15px;
}

.bgtool__insights ul {
    margin: 0;
    padding-left: 20px;
    color: var(--bgtool-muted);
    font-size: 13px;
    line-height: 1.55;
}

.bgtool__share {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    margin-top: 18px;
}

.bgtool__share input {
    min-height: 44px;
    min-width: 0;
    border: 1px solid var(--bgtool-line);
    border-radius: 10px;
    padding: 8px 11px;
    color: var(--bgtool-muted);
}

.bgtool__share button,
.bgtool__history button {
    min-height: 44px;
    background: #e3eee9;
    color: var(--bgtool-accent-dark);
}

.bgtool__share .bgtool__share-primary {
    background: var(--bgtool-accent);
    color: #fff;
}

.bgtool__share .bgtool__share-primary:hover {
    background: var(--bgtool-accent-dark);
}

.bgtool__share [data-bgtool-copy-status] {
    grid-column: 1 / -1;
    min-height: 18px;
    color: var(--bgtool-muted);
    font-size: 12px;
}

.bgtool__trust {
    margin: 0;
    border-top: 1px solid var(--bgtool-line);
    background: var(--bgtool-warm);
    padding-top: 17px;
    padding-bottom: 17px;
    color: #5d5544;
    font-size: 13px;
    line-height: 1.55;
}

.bgtool__trust a {
    color: var(--bgtool-accent-dark);
    font-weight: 750;
}

.bgtool__history {
    border-top: 1px solid var(--bgtool-line);
    padding-top: 20px;
    padding-bottom: 22px;
}

.bgtool__history-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.bgtool__history-heading h3 {
    margin: 0;
}

.bgtool__history ol {
    margin: 14px 0 0;
    padding-left: 22px;
    color: var(--bgtool-muted);
    font-size: 13px;
    line-height: 1.6;
}

.bgtool__history-empty {
    margin: 12px 0 0;
    color: var(--bgtool-muted);
    font-size: 13px;
}

.bgtool.is-loading .bgtool__results {
    opacity: .68;
}

.bgtool-hub__controls {
    padding: clamp(18px, 3vw, 30px);
    border: 1px solid var(--bgtool-line);
    border-radius: 20px;
    background: linear-gradient(145deg, #fff, var(--bgtool-soft));
}

.bgtool-hub__controls > label {
    display: block;
    margin-bottom: 8px;
    font-weight: 800;
}

.bgtool-hub__controls > input {
    width: 100%;
    min-height: 52px;
    box-sizing: border-box;
    border: 1px solid #b9cac3;
    border-radius: 13px;
    background: #fff;
    padding: 12px 15px;
    color: var(--bgtool-ink);
    font: inherit;
}

.bgtool-hub__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.bgtool-hub__filters button {
    min-height: 40px;
    border: 1px solid var(--bgtool-line);
    border-radius: 999px;
    background: #fff;
    color: var(--bgtool-ink);
    padding: 8px 14px;
    font: 700 13px/1 inherit;
    cursor: pointer;
}

.bgtool-hub__filters button.is-active {
    border-color: #0f6b50;
    background: #0f6b50;
    color: #fff;
}

.bgtool-hub__count {
    margin: 16px 0 8px;
    color: var(--bgtool-muted);
    font-size: 13px;
}

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

.bgtool-card {
    min-width: 0;
    border: 1px solid var(--bgtool-line);
    border-radius: 18px;
    background: var(--bgtool-surface);
    padding: 20px;
    box-shadow: 0 10px 30px rgba(25, 54, 46, .06);
}

.bgtool-card[hidden] {
    display: none;
}

.bgtool-card > span {
    color: var(--bgtool-accent-dark);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.bgtool-card h2 {
    margin: 10px 0 9px;
    font-size: 21px;
    line-height: 1.15;
}

.bgtool-card h2 a {
    color: var(--bgtool-ink);
    text-decoration: none;
}

.bgtool-card p {
    color: var(--bgtool-muted);
    font-size: 14px;
    line-height: 1.55;
}

.bgtool-card__cta {
    color: var(--bgtool-accent-dark);
    font-weight: 800;
}

.bgtool-hub__empty {
    border: 1px dashed var(--bgtool-line);
    border-radius: 14px;
    padding: 20px;
    color: var(--bgtool-muted);
    text-align: center;
}

@media (max-width: 820px) {
    .bgtool__result-grid,
    .bgtool-hub__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .bgtool {
        border-radius: 18px;
        margin: 20px 0;
    }

    .bgtool__heading,
    .bgtool__form,
    .bgtool__results,
    .bgtool__trust,
    .bgtool__history {
        padding-inline: 16px;
    }

    .bgtool__heading {
        padding-top: 22px;
        padding-bottom: 18px;
    }

    .bgtool__fields,
    .bgtool__result-grid,
    .bgtool-hub__grid {
        grid-template-columns: 1fr;
    }

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

    .bgtool__share input {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .bgtool__submit {
        width: 100%;
    }

    .bgtool__result strong {
        font-size: 24px;
    }
}

/* Gross/net clarity and local-history disclosure (staging package 2026-10-09). */
.bgtool__field-label-row{display:flex;align-items:center;flex-wrap:wrap;gap:.4rem .6rem;margin-bottom:7px;min-width:0}
.bgtool__field-label-row>label{margin:0}
.bgsc-terms{position:relative;display:inline-block;max-width:100%;font:inherit;color:var(--bgtool-ink,#102a22)}
.bgsc-terms>summary{display:inline-flex;align-items:center;gap:.42rem;max-width:100%;min-height:30px;box-sizing:border-box;padding:.18rem .55rem .18rem .28rem;border:1px solid var(--bgtool-line,#d7e5df);border-radius:999px;background:var(--bgtool-soft,#f3f8f5);color:inherit;font-size:.76rem;line-height:1.2;cursor:pointer;list-style:none;-webkit-tap-highlight-color:transparent;transition:border-color .2s ease,background-color .2s ease}
.bgsc-terms>summary::-webkit-details-marker{display:none}
.bgsc-terms>summary:hover{border-color:var(--bgtool-accent,#0f7a5a);background:var(--bgtool-surface,#fff)}
.bgsc-terms>summary:focus-visible{outline:3px solid var(--bgtool-accent,#0f7a5a);outline-offset:2px}
.bgsc-terms__icon{display:inline-grid;place-items:center;flex:none;width:20px;height:20px;border-radius:50%;background:var(--bgtool-accent,#0f7a5a);color:#fff;font:italic 700 .72rem/1 Georgia,serif}
.bgsc-terms__short{flex:none;font-weight:750}
.bgsc-terms__swap{display:grid;min-width:0;width:min(15.5rem,42vw);color:var(--bgtool-muted,#526860);font-weight:500}
.bgsc-terms__swap>span{grid-area:1/1;min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.bgsc-terms__swap>span:first-child{animation:bgsc-terms-gross 18s ease-in-out 2}
.bgsc-terms__swap>span:last-child{opacity:0;animation:bgsc-terms-net 18s ease-in-out 2}
.bgsc-terms__panel{position:absolute;z-index:30;top:calc(100% + .35rem);left:0;width:min(20rem,calc(100vw - 48px));box-sizing:border-box;padding:.75rem .85rem;border:1px solid var(--bgtool-line,#d7e5df);border-radius:12px;background:var(--bgtool-surface,#fff);box-shadow:0 14px 34px rgba(13,45,36,.16)}
.bgsc-terms:not([open])>.bgsc-terms__panel{display:none}
.bgsc-terms__panel dl{display:grid;grid-template-columns:auto 1fr;gap:.32rem .6rem;margin:0;font-size:.82rem;line-height:1.4}
.bgsc-terms__panel dt{font-weight:800;color:var(--bgtool-accent-dark,#0b5f48)}
.bgsc-terms__panel dd{margin:0;color:var(--bgtool-ink,#102a22)}
@media (hover:hover) and (pointer:fine){.bgsc-terms:hover>.bgsc-terms__panel{display:block}}
@keyframes bgsc-terms-gross{0%,42%{opacity:1}48%,92%{opacity:0}98%,100%{opacity:1}}
@keyframes bgsc-terms-net{0%,42%{opacity:0}48%,92%{opacity:1}98%,100%{opacity:0}}
.bgsc-history-note{margin:.65rem 0 0;color:var(--bgtool-muted,#526860);font-size:.82rem;line-height:1.45}
.bgtool__history [data-bgtool-clear-history]{display:inline-flex;align-items:center;gap:.38rem;min-height:36px;padding:.36rem .72rem;border:1px solid var(--bgtool-line,#d7e5df);border-radius:999px;background:var(--bgtool-surface,#fff);color:var(--bgtool-ink,#102a22);font:inherit;font-size:.84rem;font-weight:750;cursor:pointer}
.bgtool__history [data-bgtool-clear-history]::before{content:"";width:14px;height:14px;flex:none;background:currentColor;-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 3h6l1 2h4v2H4V5h4l1-2zm-3 6h12l-1 12H7L6 9z'/%3E%3C/svg%3E") center/contain no-repeat;mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 3h6l1 2h4v2H4V5h4l1-2zm-3 6h12l-1 12H7L6 9z'/%3E%3C/svg%3E") center/contain no-repeat}
.bgtool__history [data-bgtool-clear-history]:hover{border-color:#b42318;color:#b42318;background:#fff5f4}
.bgtool__history [data-bgtool-clear-history]:focus-visible{outline:3px solid var(--bgtool-accent,#0f7a5a);outline-offset:2px}
@media (max-width:520px){.bgsc-terms__short{display:none}.bgsc-terms__swap{width:min(15rem,calc(100vw - 100px))}.bgsc-terms>summary{font-size:.73rem}}
@media (pointer:coarse){.bgsc-terms>summary{min-height:44px}.bgtool__history [data-bgtool-clear-history]{min-height:44px}}
@media (prefers-reduced-motion:reduce){.bgsc-terms>summary{transition:none}.bgsc-terms__swap{width:auto;display:flex;flex-wrap:wrap;gap:.2rem .55rem}.bgsc-terms__swap>span{animation:none!important;opacity:1!important;white-space:normal}.bgsc-terms__swap>span+span::before{content:"· ";font-weight:700}}

@media (prefers-reduced-motion: reduce) {
    .bgtool *,
    .bgtool-hub * {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}

body.bgk-dark .bgtool,
body.bgk-dark .bgtool-hub {
    --bgtool-ink: #edf7f2;
    --bgtool-muted: #b6c7c0;
    --bgtool-line: #39544a;
    --bgtool-soft: #1d3029;
    --bgtool-surface: #14261f;
    --bgtool-accent: #58c997;
    --bgtool-accent-dark: #7de0b4;
    --bgtool-warm: #322f25;
}

body.bgk-dark .bgtool,
body.bgk-dark .bgtool__heading,
body.bgk-dark .bgtool__results,
body.bgk-dark .bgtool-hub__controls {
    background: #14261f;
}

body.bgk-dark .bgtool__field input:not([type="checkbox"]),
body.bgk-dark .bgtool__field select,
body.bgk-dark .bgtool__share input,
body.bgk-dark .bgtool-card {
    background: #102019;
    color: var(--bgtool-ink);
}

:root[data-theme="dark"] .bgtool,
:root[data-theme="dark"] .bgtool-hub {
    --bgtool-ink: #f1f5f9;
    --bgtool-muted: #cbd5e1;
    --bgtool-line: #475569;
    --bgtool-soft: #18251f;
    --bgtool-surface: #101b17;
    --bgtool-accent: #34b388;
    --bgtool-accent-dark: #8ef0cf;
    --bgtool-warm: #28271f;
}

:root[data-theme="dark"] .bgtool,
:root[data-theme="dark"] .bgtool__heading,
:root[data-theme="dark"] .bgtool__results,
:root[data-theme="dark"] .bgtool-hub__controls {
    background: #101b17;
}

:root[data-theme="dark"] .bgtool__field input:not([type="checkbox"]),
:root[data-theme="dark"] .bgtool__field select,
:root[data-theme="dark"] .bgtool__share input,
:root[data-theme="dark"] .bgtool-card,
:root[data-theme="dark"] .bgtool__details,
:root[data-theme="dark"] .bgtool__insights {
    border-color: #475569;
    background: #0f172a;
    color: var(--bgtool-ink);
}

:root[data-theme="dark"] .bgtool__result--primary {
    border-color: #34b388;
    background: #17362b;
}

:root[data-theme="dark"] .bgtool__submit {
    color: #04140f;
}

:root[data-theme="dark"] .bgtool__share button,
:root[data-theme="dark"] .bgtool__history button {
    border: 1px solid #64748b;
    background: #1e293b;
    color: #f8fafc;
}

:root[data-theme="dark"] .bgtool__share .bgtool__share-primary {
    border-color: #34b388;
    background: #0f7a5a;
    color: #fff;
}

:root[data-theme="dark"] .bgtool-hub__filters button {
    border-color: #64748b;
    background: #1e293b;
    color: #f8fafc;
}

:root[data-theme="dark"] .bgtool-hub__filters button.is-active {
    border-color: #8ef0cf;
    background: #0f6b50;
    color: #ffffff;
}

/* Phase 3: catalog task navigator + flagship card (uses existing tokens, follows dark mode) */
.bgtool-tasks {
    margin: 0 0 18px;
    padding: clamp(16px, 3vw, 24px);
    border: 1px solid var(--bgtool-line);
    border-radius: 20px;
    background: var(--bgtool-soft);
}

.bgtool-tasks__title {
    margin: 0 0 12px;
    font-size: 20px;
    line-height: 1.2;
}

.bgtool-tasks__list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.bgtool-tasks__list a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    box-sizing: border-box;
    border: 1px solid var(--bgtool-line);
    border-radius: 999px;
    background: var(--bgtool-surface);
    color: var(--bgtool-ink);
    padding: 10px 16px;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
    text-decoration: none;
}

.bgtool-tasks__list a:hover,
.bgtool-tasks__list a:focus-visible {
    border-color: var(--bgtool-accent);
    color: var(--bgtool-accent-dark);
}

.bgtool-tasks__list a:focus-visible {
    outline: 3px solid var(--bgtool-accent);
    outline-offset: 2px;
}

.bgtool-card--flagship {
    grid-column: span 2;
    border-color: var(--bgtool-accent);
    box-shadow: 0 14px 36px rgba(11, 122, 83, .14);
}

@media (max-width: 600px) {
    .bgtool-card--flagship {
        grid-column: auto;
    }

    .bgtool-tasks__list a {
        flex: 1 1 100%;
    }
}
