:root {
    color-scheme: light;
    --navy: #0f2e3d;
    --navy-soft: #183f52;
    --amber: #ca981a;
    --amber-dark: #9e7210;
    --amber-pale: #fff8e5;
    --ink: #17242b;
    --muted: #5d6a70;
    --line: #d8dfe2;
    --panel: #ffffff;
    --background: #f3f6f7;
    --success: #19734a;
    --success-pale: #eaf7f0;
    --danger: #a4382e;
    --danger-pale: #fff0ed;
    --shadow: 0 14px 34px rgba(15, 46, 61, 0.09);
}

* {
    box-sizing: border-box;
}

html {
    font-family: "Lato", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--background);
    color: var(--ink);
}

body {
    min-width: 320px;
    margin: 0;
    line-height: 1.55;
}

button,
input {
    font: inherit;
}

button,
label,
summary {
    -webkit-tap-highlight-color: transparent;
}

.site-header {
    padding: 28px 24px 32px;
    color: #fff;
    background:
        radial-gradient(circle at 88% 8%, rgba(202, 152, 26, 0.34), transparent 28rem),
        linear-gradient(145deg, var(--navy), #0a222d);
}

.header-content,
main {
    width: min(880px, 100%);
    margin: 0 auto;
}

.back-link {
    display: inline-block;
    margin-bottom: 28px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.92rem;
    text-decoration: none;
}

.back-link:hover,
.back-link:focus-visible {
    color: #fff;
    text-decoration: underline;
}

.eyebrow {
    margin: 0 0 5px;
    color: #f0c55a;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1 {
    max-width: 700px;
    margin: 0;
    font-size: clamp(2rem, 6vw, 3.35rem);
    line-height: 1.08;
    letter-spacing: -0.035em;
}

.subtitle {
    max-width: 680px;
    margin: 13px 0 0;
    color: rgba(255, 255, 255, 0.77);
    font-size: clamp(1rem, 2.5vw, 1.15rem);
}

main {
    padding: 32px 24px 54px;
}

.notice,
.step-card,
.log-card,
.privacy-note {
    margin-bottom: 22px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.notice {
    display: flex;
    gap: 16px;
    padding: 18px 20px;
}

.notice[hidden],
[hidden] {
    display: none !important;
}

.notice h2,
.notice p {
    margin: 0;
}

.notice h2 {
    font-size: 1rem;
}

.notice p {
    margin-top: 3px;
    color: #614c14;
    font-size: 0.94rem;
}

.notice-safety {
    border-color: #e9c76d;
    background: var(--amber-pale);
    box-shadow: none;
}

.notice-error {
    display: block;
    border-color: #e8aaa3;
    color: var(--danger);
    background: var(--danger-pale);
    box-shadow: none;
}

.notice-icon {
    display: grid;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--amber-dark);
    font-weight: 900;
}

.step-card {
    padding: clamp(20px, 4vw, 30px);
}

.step-heading {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 22px;
}

.step-number {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--navy);
    font-weight: 800;
}

.step-heading h2,
.log-heading h2,
.privacy-note h2 {
    margin: 0;
    color: var(--navy);
    font-size: 1.23rem;
    line-height: 1.3;
}

.step-heading p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.94rem;
}

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

.firmware-option {
    display: flex;
    min-height: 132px;
    gap: 12px;
    padding: 18px;
    border: 2px solid var(--line);
    border-radius: 11px;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.firmware-option:hover {
    border-color: #a8b5bb;
    transform: translateY(-1px);
}

.firmware-option.is-selected {
    border-color: var(--amber);
    background: var(--amber-pale);
}

.firmware-option input {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin: 3px 0 0;
    accent-color: var(--amber-dark);
}

.option-body,
.option-title-row {
    display: flex;
}

.option-body {
    min-width: 0;
    flex-direction: column;
    gap: 7px;
}

.option-title-row {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.badge {
    padding: 2px 8px;
    border-radius: 100px;
    color: #fff;
    background: var(--amber-dark);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.option-description,
.file-detail,
.help-text {
    color: var(--muted);
    font-size: 0.86rem;
}

.file-detail {
    overflow-wrap: anywhere;
}

code {
    padding: 0.08em 0.3em;
    border-radius: 4px;
    color: #26383f;
    background: #e8edef;
    font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
    font-size: 0.88em;
}

.custom-panel {
    margin-top: 16px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8fafb;
}

.file-picker {
    display: flex;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: 1px dashed #8c9da5;
    border-radius: 8px;
    color: var(--navy);
    background: #fff;
    cursor: pointer;
    font-weight: 700;
    text-align: center;
}

.file-picker:hover,
.file-picker:focus-within {
    border-color: var(--amber-dark);
    background: var(--amber-pale);
}

.file-picker input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    clip-path: inset(50%);
}

.address-row {
    display: grid;
    grid-template-columns: 130px minmax(0, 210px);
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.address-row label {
    color: var(--navy);
    font-weight: 700;
}

.address-row input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #a8b5bb;
    border-radius: 7px;
    font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
}

.address-row input:focus {
    border-color: var(--amber-dark);
    outline: 3px solid rgba(202, 152, 26, 0.2);
}

.help-text,
.custom-panel .file-detail {
    margin: 10px 0 0;
}

.connection-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.button {
    min-height: 46px;
    padding: 10px 19px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 100ms ease, filter 100ms ease, opacity 100ms ease;
}

.button:hover:not(:disabled) {
    filter: brightness(1.07);
    transform: translateY(-1px);
}

.button:focus-visible,
.text-button:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(202, 152, 26, 0.4);
    outline-offset: 2px;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.button-primary {
    color: #fff;
    background: var(--navy);
}

.button-secondary {
    color: var(--navy);
    background: #e4ebee;
}

.button-flash {
    width: 100%;
    margin-top: 18px;
    color: #fff;
    background: var(--amber-dark);
}

.status-pill {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 100px;
    color: var(--muted);
    background: #edf1f2;
    font-size: 0.88rem;
    font-weight: 700;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #819198;
}

.status-busy .status-dot {
    background: var(--amber);
    box-shadow: 0 0 0 4px rgba(202, 152, 26, 0.17);
}

.status-connected {
    color: var(--success);
    background: var(--success-pale);
}

.status-connected .status-dot {
    background: var(--success);
}

.boot-help {
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.9rem;
}

.boot-help summary {
    width: fit-content;
    color: var(--navy);
    cursor: pointer;
    font-weight: 700;
}

.boot-help ol {
    margin: 10px 0 6px;
    padding-left: 1.4rem;
}

.boot-help p {
    margin: 6px 0 0;
}

.confirmation-row {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #f8fafb;
    cursor: pointer;
    font-size: 0.9rem;
}

.confirmation-row input {
    flex: 0 0 auto;
    width: 19px;
    height: 19px;
    margin: 2px 0 0;
    accent-color: var(--amber-dark);
}

.progress-panel {
    margin-top: 20px;
    padding: 17px;
    border-radius: 9px;
    background: #f1f5f6;
}

.progress-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--navy);
    font-size: 0.9rem;
}

.progress-track {
    height: 11px;
    margin-top: 10px;
    overflow: hidden;
    border-radius: 100px;
    background: #d6e0e4;
}

.progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--amber-dark), #e1b13c);
    transition: width 100ms linear;
}

.progress-detail {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.83rem;
}

.result-message {
    margin-top: 18px;
    padding: 15px 17px;
    border: 1px solid;
    border-radius: 9px;
    font-size: 0.92rem;
}

.result-success {
    border-color: #9ed0b7;
    color: #105d3a;
    background: var(--success-pale);
}

.result-error {
    border-color: #e8aaa3;
    color: var(--danger);
    background: var(--danger-pale);
}

.log-card {
    overflow: hidden;
    background: #0b202a;
}

.log-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.log-heading h2 {
    color: #fff;
    font-size: 1rem;
}

.text-button {
    padding: 4px 7px;
    border: 0;
    color: #e9c66d;
    background: transparent;
    cursor: pointer;
    font-weight: 700;
}

#terminal-log {
    min-height: 190px;
    max-height: 340px;
    margin: 0;
    padding: 17px 18px;
    overflow: auto;
    color: #d7e4e9;
    background: transparent;
    font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.privacy-note {
    padding: 21px 23px;
    box-shadow: none;
}

.privacy-note h2 {
    font-size: 1rem;
}

.privacy-note p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

footer {
    padding: 24px;
    color: rgba(255, 255, 255, 0.72);
    background: var(--navy);
    font-size: 0.82rem;
    text-align: center;
}

footer p {
    margin: 0;
}

.serial-send-form {
    margin: 0;
    padding: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.035);
}

.serial-send-form > label {
    display: block;
    color: #f1f6f8;
    font-size: 0.88rem;
    font-weight: 700;
}

.serial-send-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 165px auto;
    align-items: stretch;
    gap: 10px;
    margin-top: 9px;
}

.serial-send-row input,
.serial-send-row select {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid #42606e;
    border-radius: 8px;
    color: #eef5f8;
    background: #153441;
    font: inherit;
    font-size: 0.9rem;
    color-scheme: dark;
}

.serial-send-row input {
    font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
}

.serial-send-row input::placeholder { color: #9db3bf; }

.serial-send-row input:focus-visible,
.serial-send-row select:focus-visible {
    outline: 3px solid rgba(202, 152, 26, 0.4);
    outline-offset: 2px;
    border-color: var(--amber);
}

.serial-send-row .button {
    min-width: 88px;
    color: #fff;
    background: var(--amber-dark);
}

.serial-send-form .help-text {
    margin: 10px 0 0;
    color: #adbec7;
    font-size: 0.8rem;
}

.serial-send-form .file-detail {
    margin: 7px 0 0;
    color: #e9c66d;
    font-size: 0.8rem;
}

.serial-send-form .file-detail:empty { display: none; }
.serial-send-row :disabled { opacity: 0.55; cursor: not-allowed; }

@media (max-width: 650px) {
    .serial-send-row { grid-template-columns: minmax(0, 1fr) auto; }
    .serial-send-row input { grid-column: 1 / -1; }
}

@media (max-width: 650px) {
    .site-header {
        padding: 22px 18px 28px;
    }

    .back-link {
        margin-bottom: 22px;
    }

    main {
        padding: 22px 14px 42px;
    }

    .firmware-options {
        grid-template-columns: 1fr;
    }

    .firmware-option {
        min-height: auto;
    }

    .address-row {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .connection-row .button {
        flex: 1 1 140px;
    }

    .status-pill {
        width: 100%;
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
