/* SPDX-License-Identifier: GPL-3.0-or-later */
:root {
    --ink: #242723;
    --muted: #51564d;
    --panel: #e6e5df;
    --shell: #d5d5ce;
    --line: #93968e;
    --display: #202a25;
    --phosphor: #d5e6bd;
    --accent: #e39756;
    --accent-ink: #242723;
    --danger: #8f321e;
    --focus: #00636e;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font: 16px/1.5 Arial, Helvetica, sans-serif;
    background: #c4cacb;
    color: var(--ink);
    color-scheme: light;
}

body {
    margin: 0;
}

main {
    max-width: 76rem;
    margin: clamp(.5rem, 2vw, 2rem) auto;
    padding: clamp(1rem, 4vw, 3rem);
    background: linear-gradient(145deg, #e5e4de, var(--shell));
    border: 1px solid #8e938d;
    border-radius: .8rem;
    box-shadow: inset 0 1px #fffc, 0 8px 24px #26383226;
}

h1 {
    font-size: clamp(1.6rem, 3vw, 2.3rem);
    font-weight: 750;
    letter-spacing: -.025em;
    text-transform: uppercase;
    line-height: 1.2;
    margin: .3rem 0;
}

h2 {
    font-size: 1.25rem;
    letter-spacing: -.02em;
    margin: 0 0 .5rem;
}

h3 {
    font-size: .95rem;
    font-weight: 600;
    margin: 0 0 .75rem;
}

p {
    margin: .5rem 0 1rem;
}

a {
    color: #365a50;
    text-underline-offset: .2em;
}

code {
    font-size: .9em;
    overflow-wrap: anywhere;
}

section {
    scroll-margin-top: 5rem;
}

.eyebrow {
    color: var(--ink);
    font-family: var(--mono);
    letter-spacing: .1em;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: .5rem;
}

.hint, #release {
    color: var(--muted);
}

.hint {
    font-size: .9rem;
}

.error {
    color: var(--danger);
}

[hidden] {
    display: none !important;
}

.page-header, .section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
}

.page-header {
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}

.release-info {
    text-align: right;
    flex-shrink: 0;
    padding-top: .5rem;
}

.theme-control {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: .75rem;
    font-size: .9rem;
}

.release-info a, .section-heading > a {
    font-size: .9rem;
}

.section-heading > a {
    flex-shrink: 0;
    padding-top: .4rem;
}

.task-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--shell);
    padding: .25rem;
    margin-top: 1rem;
    border: 1px solid var(--line);
    border-radius: .45rem;
    box-shadow: inset 0 1px 2px #0002;
}

.task-nav button {
    flex: 1;
    background: transparent;
    box-shadow: none;
    color: var(--ink);
    text-decoration: none;
    padding: .55rem 1rem;
    border: 1px solid transparent;
    border-radius: .3rem;
}

.task-nav button:hover {
    border-color: var(--ink);
    background: var(--panel);
}

.task-nav button[aria-selected=true] {
    background: var(--accent);
    border-color: #a86a3c;
    color: var(--accent-ink);
    box-shadow: inset 0 1px #fff6;
}

[role=tabpanel]:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
}

.skip-link {
    position: fixed;
    top: -5rem;
    left: 1rem;
    z-index: 5;
    background: var(--panel);
    padding: .75rem;
}

.skip-link:focus {
    top: 1rem;
}

main > section {
    margin-top: 1.25rem;
    padding: 1.25rem;
    border: 1px solid #aeb1a7;
    border-radius: .45rem;
    background: #eeeee73d;
}

.connection {
    display: grid;
    padding: 1rem;
    grid-template-columns: 1fr auto;
    gap: 2rem;
}

.connection h2 {
    font-size: 1.1rem;
}

.connection p {
    margin-bottom: .5rem;
}

.connection p:last-child {
    margin-bottom: 0;
}

.connection-controls {
    min-width: 18rem;
}

#status {
    margin-top: .85rem;
    padding: .45rem .65rem;
    font: .85rem/1.5 var(--mono);
    background: var(--display);
    color: var(--phosphor);
    border: 1px solid #101a15;
    border-radius: .15rem;
    overflow-wrap: anywhere;
}

#status.error {
    color: #ffc8a3;
}

.matching-links {
    display: grid;
    gap: .5rem;
}

.summary {
    color: var(--muted);
    white-space: nowrap;
    font-size: .9rem;
}

.actions {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: center;
}

button {
    font: 500 .95rem/1.4 Arial, Helvetica, sans-serif;
    border: 1px solid #a86a3c;
    border-radius: .3rem;
    padding: .55rem 1rem;
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: inset 0 1px #fff6;
    cursor: pointer;
}

button.secondary, button[aria-pressed=false] {
    background: var(--panel);
    color: var(--ink);
    border-color: var(--line);
}

button:hover:not(:disabled), .file-button:hover {
    filter: brightness(1.06);
}

button:active:not(:disabled) {
    box-shadow: inset 0 1px 2px #0002;
}

button:disabled {
    background: #d7d8d1;
    color: #68685e;
    border-color: #a2a69c;
    box-shadow: none;
    cursor: default;
}

button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
}

input, select, textarea {
    font: .95rem/1.5 var(--mono);
    color: var(--phosphor);
    background: var(--display);
    color-scheme: dark;
    border: 1px solid var(--line);
    border-radius: .3rem;
    padding: .5rem;
    box-sizing: border-box;
    max-width: 100%;
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

input[type=checkbox] {
    width: 1.4rem;
    height: 1.4rem;
    accent-color: var(--danger);
}

.file-button {
    background: var(--panel);
    box-shadow: inset 0 1px #fff6;
    font-weight: 500;
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: .55rem 1rem;
    border: 1px solid var(--line);
    border-radius: .3rem;
    cursor: pointer;
    color: var(--ink);
    font-size: .95rem;
    line-height: 1.4;
}

.file-button input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    cursor: pointer;
}

.file-button:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
}

.tool-bar {
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 1.5rem;
    padding: 1.25rem 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.tool-group {
    min-width: 0;
}

.tool-group p {
    font-size: .9rem;
    color: var(--muted);
    margin-bottom: 0;
}

.tool-group p.error {
    color: var(--danger);
}

.cps-tabs {
    margin: 1.5rem 0;
}

.cps-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.cps-editor {
    flex: 1;
    min-width: 0;
}

.cps-editor h3 {
    margin-top: 0;
}

.cps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.cps-field {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin: .75rem 0;
}

.cps-records {
    width: 16rem;
    flex-shrink: 0;
}

.cps-records ul {
    list-style: none;
    padding: 0;
    max-height: 28rem;
    overflow: auto;
}

.cps-records li {
    margin-bottom: .5rem;
}

.cps-records button {
    width: 100%;
    text-align: left;
    overflow-wrap: anywhere;
}

.cps-members {
    padding-left: 1.5rem;
}

.cps-members li {
    margin: .5rem 0;
}

.cps-members span {
    display: inline-block;
    min-width: 12rem;
}

.cps-members button {
    padding: .3rem .6rem;
    margin-right: .3rem;
}

.cps-editor > fieldset {
    margin-bottom: 1rem;
}

fieldset {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: .35rem;
    padding: 1rem;
}

#cps-preview {
    margin-top: 1.5rem;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
}

#cps-json, #cps-before, #cps-after {
    width: 100%;
    font: .85rem/1.5 monospace;
}

#cps-status {
    color: var(--muted);
}

#cps-status.error {
    color: var(--danger);
}

.remote-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    margin-top: 1.5rem;
}

.radio-screen, #radio-keypad {
    min-width: 0;
}

#radio-keypad {
    padding-left: 1.5rem;
    border-left: 1px solid var(--line);
}

#live-ui canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    background: var(--display);
    border: 6px solid #343c36;
    border-radius: .65rem;
    box-shadow: 0 0 0 1px #879084, inset 0 1px 3px #0007;
    margin-bottom: 1rem;
    box-sizing: border-box;
}

#live-ui.stale canvas {
    border-color: #535d54;
}

.radio-screen p, #radio-keypad p {
    font-size: .9rem;
    color: var(--muted);
}

#radio-keypad:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 4px;
}

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

.keypad-grid button {
    touch-action: none;
    user-select: none;
    padding: .8rem .4rem;
    min-height: 3.25rem;
    font-size: 1.1rem;
}

.radio-screen > button {
    width: 100%;
}

.keypad-grid button[data-key="4"]:not(:disabled) {
    background: var(--accent);
    color: var(--accent-ink);
}

.keypad-grid button[aria-pressed=true] {
    background: var(--accent);
    border-color: var(--ink);
    color: var(--accent-ink);
    box-shadow: inset 0 1px 2px #0002;
}

.warning {
    padding: 1rem 1.25rem;
    background: #e397561c;
    color: var(--danger);
    border-left: 5px solid var(--danger);
    border-radius: .25rem;
}

.boot-connection {
    margin: 1.5rem 0;
}

[data-firmware-status] {
    margin: 1rem 0 .5rem;
    color: var(--muted);
    overflow-wrap: anywhere;
}

[data-firmware-status].error {
    color: var(--danger);
}

progress {
    width: 100%;
    height: .5rem;
    accent-color: var(--danger);
}

.connection-notes {
    margin-top: .75rem;
    font-size: .9rem;
    color: var(--muted);
}

summary {
    cursor: pointer;
}

details[open] > summary {
    margin-bottom: 1rem;
}

.firmware-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 1rem;
}

.tool-card {
    min-width: 0;
    padding: 1.25rem;
    background: #d5d5ce55;
    border: 1px solid var(--line);
    border-radius: .25rem;
}

.tool-card p {
    font-size: .92rem;
}

.tool-card p:last-child {
    margin-bottom: 0;
}

.calibration-card {
    grid-column: 1 / -1;
}

.recovery-tools {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}

.recovery-tools > summary {
    color: var(--danger);
}

[data-flash-preview], [data-bundle-status], [data-backup-status] {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

[data-flash-preview] {
    font: .85rem/1.5 monospace;
}

[data-flash-review] {
    max-width: min(52rem, 85vw);
}

.flash-ack {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    margin: 1rem 0;
}

.flash-ack input {
    flex-shrink: 0;
}

dialog {
    box-shadow: 0 12px 40px #0005;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 6px solid var(--accent);
    border-radius: .3rem;
    max-width: min(35rem, 85vw);
    max-height: 85vh;
    overflow: auto;
}

dialog::backdrop {
    background: #0009;
}

[data-calibration] {
    overflow-wrap: anywhere;
}

[data-calibration] details {
    margin: 1rem 0;
}

[data-calibration] pre {
    white-space: pre-wrap;
    font: .85rem/1.5 monospace;
}

.calibration-scroll {
    overflow-x: auto;
}

.calibration-scroll table {
    border-collapse: collapse;
    width: 100%;
    min-width: 48rem;
    overflow-wrap: normal;
}

.calibration-scroll caption {
    text-align: left;
    padding: .5rem 0;
}

.calibration-scroll th, .calibration-scroll td {
    padding: .5rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 1.5rem;
    color: var(--muted);
    font-size: .85rem;
}

:root[data-theme=dark] {
    color-scheme: dark;
    --ink: #e4e7e1;
    --muted: #b1b8af;
    --panel: #303632;
    --shell: #262c29;
    --line: #657067;
    --display: #131e18;
    --danger: #ffad91;
    --focus: #7dd3cf;
    background: #171c1a;
}

:root[data-theme=dark] main {
    background: linear-gradient(145deg, #343b36, var(--shell));
    border-color: var(--line);
    box-shadow: inset 0 1px #ffffff14, 0 8px 24px #0005;
}

:root[data-theme=dark] a {
    color: #aed5c6;
}

:root[data-theme=dark] main > section {
    background: #ffffff04;
    border-color: #535e56;
}

:root[data-theme=dark] button:disabled {
    background: #303630;
    color: #969e93;
    border-color: #535e56;
    box-shadow: none;
}

:root[data-theme=dark] .tool-card {
    background: #22292455;
}

@media (max-width: 800px) {
    .page-header, .section-heading {
        flex-direction: column;
        gap: .5rem;
    }

    .release-info {
        text-align: left;
        padding: 0;
    }

    .theme-control {
        justify-content: flex-start;
    }

    .release-info p {
        margin: 0 0 .5rem;
    }

    .connection, .tool-bar, .firmware-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .connection-controls {
        min-width: 0;
    }

    .remote-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 1rem;
    }

    #radio-keypad {
        padding-left: 0;
        border-left: 0;
    }

    .cps-layout {
        flex-direction: column;
    }

    .cps-records, .cps-editor {
        width: 100%;
    }

    .cps-records ul {
        max-height: 12rem;
    }

    main > section {
        padding: 1rem;
    }

    footer {
        flex-direction: column;
        gap: 0;
    }

}

@media (max-width: 480px) {
    .task-nav button {
        padding: .5rem;
        font-size: .83rem;
    }

    section {
        scroll-margin-top: 7rem;
    }

}

#modem fieldset { margin-block: 1rem; }
#modem pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0.75rem; border-bottom: 1px solid var(--border); }

#modem-map {
    height: clamp(18rem, 48vh, 30rem);
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--line);
    z-index: 0;
}

#modem-map:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

#modem-map .leaflet-popup-content-wrapper,
#modem-map .leaflet-popup-tip,
#modem-map .leaflet-bar a,
#modem-map .leaflet-control-attribution {
    background: var(--panel);
    color: var(--ink);
}

#modem-map .leaflet-control-attribution a {
    color: var(--ink);
}

.station-details {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#modem-stations {
    max-height: 20rem;
    overflow: auto;
    padding-left: 1.5rem;
}

#modem-stations li {
    margin: .75rem 0;
}

.packet-map {
    display: block;
    margin-top: .5rem;
}
