@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Lato:wght@300;400;600;700&display=swap');

:root {
    --navy: #0F2E3D;
    --navy-hover: #1a4a5e;
    --navy-soft: #e8eef1;
    --gold: #CA981A;
    --gold-dark: #9e7410;
    --gold-light: rgba(202, 152, 26, 0.08);
    --gold-medium: rgba(202, 152, 26, 0.35);
    --white: #FFFFFF;
    --light-gray: #f1f3f5;
    --mid-gray: #dce1e4;
    --green: #25835b;
    --green-light: #e3f4ec;
    --red: #b34444;
    --red-light: #f9e8e8;
    --amber: #a96f00;
    --amber-light: #fff4d8;
    --text-primary: rgba(0, 0, 0, 1);
    --text-secondary: rgba(0, 0, 0, 0.8);
    --text-muted: rgba(0, 0, 0, 0.6);
    --text-light: rgba(255, 255, 255, 0.8);
    --border-radius: 4px;
    --shadow: 0 8px 24px rgba(15, 46, 61, 0.08);
    --transition: 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
    overflow-x: clip;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--white);
    color: var(--text-secondary);
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 1.06rem;
    line-height: 1.6;
    overflow-x: hidden;
    overflow-x: clip;
}

button,
input,
select {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--gold-medium);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Header — deliberately follows the existing tool header treatment. */
.site-header {
    position: relative;
    overflow: hidden;
    background: var(--navy);
    padding: 14px 20px;
}

.header-content {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
    align-items: center;
    gap: 16px;
}

.header-art {
    position: absolute;
    inset: 0 0 0 auto;
    z-index: 0;
    width: min(70%, 1100px);
    background:
        linear-gradient(90deg, var(--navy) 0%, rgba(15, 46, 61, 0.72) 24%, rgba(15, 46, 61, 0.18) 100%),
        url('header-art.webp') center right / cover no-repeat;
    opacity: 0.42;
    pointer-events: none;
}

.back-link {
    justify-self: start;
    color: var(--gold);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--white);
}

.header-title {
    text-align: center;
}

.header-title h1 {
    color: var(--white);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.25;
}

.header-title .subtitle {
    margin-top: 2px;
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 300;
}

.header-summary {
    justify-self: end;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-light);
    font-size: 0.88rem;
}

.connection-dot {
    width: 9px;
    height: 9px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.38);
}

.connection-dot.partial {
    background: var(--gold);
    box-shadow: 0 0 0 4px rgba(202, 152, 26, 0.14);
}

.connection-dot.connected {
    background: #4ade80;
    box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.14);
}

.compatibility-banner {
    max-width: 1200px;
    width: calc(100% - 40px);
    margin: 24px auto 0;
    padding: 13px 18px;
    color: var(--text-secondary);
    background: var(--amber-light);
    border: 1px solid rgba(169, 111, 0, 0.35);
    border-left: 4px solid var(--gold);
    border-radius: var(--border-radius);
    font-size: 0.92rem;
}

.compatibility-banner strong {
    color: var(--navy);
    margin-right: 4px;
}

main {
    flex: 1;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 36px 20px 52px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

h2 {
    color: var(--navy);
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.3;
}

.eyebrow {
    margin-bottom: 2px;
    color: var(--gold-dark);
    font-family: 'Fira Code', monospace;
    font-size: 0.69rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.section-copy {
    max-width: 680px;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.intro-row,
.section-heading,
.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 24px;
}

.connection-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 18px;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.1;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
}

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

.button-primary:hover:not(:disabled) {
    background: var(--navy-hover);
}

.button-secondary {
    background: var(--white);
    color: var(--navy);
    border-color: var(--gold);
}

.button-secondary:hover:not(:disabled) {
    background: var(--gold);
}

.button-quiet {
    background: var(--light-gray);
    color: var(--text-secondary);
}

.button-quiet:hover:not(:disabled) {
    background: var(--mid-gray);
}

.button-large {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
}

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

.control-panel,
.timeline-panel {
    min-width: 0;
    padding: 24px;
    background: var(--light-gray);
    border-radius: var(--border-radius);
}

.scope-control {
    display: inline-flex;
    align-items: center;
    padding: 3px;
    background: var(--white);
    border-radius: var(--border-radius);
}

.scope-label {
    padding: 0 10px 0 8px;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
}

.scope-button {
    min-height: 34px;
    padding: 6px 12px;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 600;
    transition: background var(--transition), color var(--transition);
}

.scope-button:hover {
    color: var(--navy);
    background: var(--gold-light);
}

.scope-button.active {
    color: var(--white);
    background: var(--navy);
}

.live-control-grid {
    margin-top: 22px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 32px;
    align-items: end;
}

.control-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
}

.control-mode-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 600;
    user-select: none;
}

.checkbox-control input {
    width: 15px;
    height: 15px;
    accent-color: var(--gold);
    cursor: pointer;
}

.control-label-row > label {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

.target-slider-stack {
    margin-top: 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.target-slider-row {
    padding: 14px 16px 9px;
    background: var(--white);
    border-left: 4px solid var(--mid-gray);
    border-radius: var(--border-radius);
    transition: border-color var(--transition), background var(--transition);
}

.target-slider-row.is-average {
    background: linear-gradient(90deg, var(--navy-soft), var(--white) 32%);
    border-left-color: var(--navy);
}

.target-slider-row.has-staged-change {
    border-left-color: var(--gold);
}

.target-slider-row.is-offline {
    background: #f5f6f7;
    border-left-color: #c4ccd0;
}

.target-slider-row.is-offline .target-row-name,
.target-slider-row.is-offline .target-row-secondary,
.target-slider-row.is-offline .range-scale,
.target-slider-row.is-offline .target-unit {
    color: #7f898e;
}

.target-row-meta {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 140px 150px;
    align-items: center;
    gap: 12px;
}

.target-row-title {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.target-row-name {
    color: var(--navy);
    font-size: 0.94rem;
}

.target-row-secondary {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.target-row-value {
    position: relative;
    display: block;
}

.target-value-input {
    width: 100%;
    height: 38px;
    padding: 7px 43px 7px 10px;
    color: var(--navy);
    background: var(--white);
    border: 2px solid var(--mid-gray);
    border-radius: var(--border-radius);
    font-family: 'Fira Code', monospace;
    font-size: 0.96rem;
    font-weight: 600;
    -moz-appearance: textfield;
}

.target-value-input::-webkit-inner-spin-button,
.target-value-input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.target-value-input:focus {
    border-color: var(--gold);
    outline: none;
}

.target-slider-row.has-staged-change:not(.is-offline) .target-value-input {
    border-color: var(--gold-medium);
}

.target-slider-row.is-offline .target-value-input {
    color: #7f898e;
    background: #edf0f2;
    border-color: #d1d7da;
}

.target-unit {
    position: absolute;
    top: 50%;
    right: 10px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    transform: translateY(-50%);
    pointer-events: none;
}

.target-slider-row .slider-shell {
    margin-top: 7px;
}

.target-slider-row .range-scale {
    margin-top: -5px;
}

.slider-footnotes {
    margin-top: 3px;
}

.target-slider-row input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.setpoint-entry {
    display: grid;
    grid-template-columns: 46px minmax(160px, 230px) 46px;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.nudge-button {
    width: 46px;
    height: 46px;
    color: var(--navy);
    background: var(--white);
    border: 2px solid var(--mid-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    transition: border-color var(--transition), background var(--transition);
}

.nudge-button:hover {
    border-color: var(--gold);
    background: var(--gold-light);
}

.number-with-unit {
    position: relative;
}

.number-with-unit input {
    width: 100%;
    height: 46px;
    padding: 8px 58px 8px 14px;
    color: var(--navy);
    background: var(--white);
    border: 2px solid var(--mid-gray);
    border-radius: var(--border-radius);
    font-family: 'Fira Code', monospace;
    font-size: 1.2rem;
    font-weight: 600;
}

.number-with-unit input:focus {
    border-color: var(--gold);
    outline: none;
}

.number-with-unit span {
    position: absolute;
    top: 50%;
    right: 13px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    transform: translateY(-50%);
}

.setpoint-range {
    width: 100%;
    height: 22px;
    background: transparent;
    cursor: pointer;
    accent-color: var(--navy);
    appearance: none;
    -webkit-appearance: none;
}

.setpoint-range::-webkit-slider-runnable-track {
    height: 5px;
    background: var(--track-gradient, linear-gradient(90deg, var(--gold), var(--navy)));
    border-radius: 3px;
}

.setpoint-range::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    margin-top: -7px;
    background: var(--white);
    border: 3px solid var(--navy);
    border-radius: 50%;
    -webkit-appearance: none;
}

.setpoint-range::-moz-range-track {
    height: 5px;
    background: var(--track-gradient, linear-gradient(90deg, var(--gold), var(--navy)));
    border-radius: 3px;
}

.setpoint-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--white);
    border: 3px solid var(--navy);
    border-radius: 50%;
}

.target-slider-row.has-staged-change:not(.is-offline) .setpoint-range::-webkit-slider-thumb {
    background: var(--gold);
    border-color: var(--gold-dark);
}

.target-slider-row.has-staged-change:not(.is-offline) .setpoint-range::-moz-range-thumb {
    background: var(--gold);
    border-color: var(--gold-dark);
}

.target-slider-row.is-offline .setpoint-range::-webkit-slider-runnable-track {
    background: #c4ccd0;
}

.target-slider-row.is-offline .setpoint-range::-moz-range-track {
    background: #c4ccd0;
}

.target-slider-row.is-offline .setpoint-range::-webkit-slider-thumb {
    background: #dce1e4;
    border-color: #98a4aa;
}

.target-slider-row.is-offline .setpoint-range::-moz-range-thumb {
    background: #dce1e4;
    border-color: #98a4aa;
}

.target-slider-row.is-offline .range-marker {
    background: #aab3b8;
}

.target-slider-row.is-offline input:disabled {
    opacity: 1;
}

.slider-shell {
    position: relative;
}

.slider-shell.with-markers {
    padding-bottom: 22px;
}

.slider-shell .setpoint-range {
    position: relative;
    z-index: 2;
    display: block;
}

.range-markers {
    position: absolute;
    inset: 0 10px auto;
    z-index: 1;
    height: 36px;
    pointer-events: none;
}

.range-marker {
    position: absolute;
    top: 10px;
    width: 1px;
    height: 11px;
    background: rgba(15, 46, 61, 0.48);
    transform: translateX(-50%);
}

.range-marker > span {
    position: absolute;
    top: 13px;
    left: 50%;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.57rem;
    line-height: 1;
    transform: translateX(-50%);
    white-space: nowrap;
}

.range-markers.full-scale .range-marker > span {
    display: none;
}

.marker-legend {
    margin-top: 4px;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.61rem;
    line-height: 1.45;
}

.range-scale {
    display: flex;
    justify-content: space-between;
    margin-top: -4px;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.67rem;
}

.field-note {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.apply-block {
    padding: 18px;
    background: var(--white);
    border-left: 4px solid var(--gold);
    border-radius: var(--border-radius);
}

.apply-summary {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 13px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.apply-summary strong {
    color: var(--navy);
    font-size: 0.88rem;
    text-align: right;
}

.shortcut-row {
    margin-top: 22px;
    padding-top: 18px;
    display: flex;
    align-items: center;
    gap: 9px;
    border-top: 1px solid var(--mid-gray);
}

.shortcut-label {
    margin-right: 3px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.shortcut-list {
    min-width: 0;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.shortcut-item {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
}

.shortcut-button {
    min-height: 34px;
    padding: 6px 12px;
    color: var(--navy);
    background: var(--white);
    border: 1px solid var(--mid-gray);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: border-color var(--transition), background var(--transition);
}

.shortcut-button:hover {
    border-color: var(--gold);
    background: var(--gold-light);
}

.shortcut-button.user-preset {
    padding-right: 28px;
    border-left: 3px solid var(--gold);
}

.shortcut-delete {
    position: absolute;
    top: 50%;
    right: 5px;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: 2px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    transform: translateY(-50%);
}

.shortcut-delete:hover {
    color: var(--red);
    background: var(--red-light);
}

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

.shortcut-add {
    margin-left: auto;
    border-style: dashed;
    color: var(--text-muted);
}

.cell-grid {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.cell-card {
    min-width: 0;
    overflow: hidden;
    background: var(--light-gray);
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.cell-card.is-connected {
    border-color: rgba(15, 46, 61, 0.15);
    box-shadow: var(--shadow);
}

.cell-card.is-selected {
    border-color: var(--gold);
    box-shadow: 0 8px 24px rgba(202, 152, 26, 0.12);
}

.cell-card.is-busy {
    opacity: 0.82;
}

.cell-card-top {
    min-height: 78px;
    padding: 16px 16px 12px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.cell-title-row {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cell-number {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--navy);
    background: var(--gold);
    border-radius: 50%;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    font-weight: 700;
}

.cell-name {
    overflow: hidden;
    color: var(--navy);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-id {
    overflow: hidden;
    max-width: 180px;
    margin-top: 2px;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.63rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-status {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 7px;
    border-radius: 10px;
    font-size: 0.66rem;
    font-weight: 600;
}

.cell-status i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-online {
    color: var(--green);
    background: var(--green-light);
}

.status-connecting {
    color: var(--amber);
    background: var(--amber-light);
}

.status-offline {
    color: var(--text-muted);
    background: var(--white);
}

.status-error {
    color: var(--red);
    background: var(--red-light);
}

.cell-output {
    padding: 17px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    color: var(--white);
    background: var(--navy);
}

.metric-label {
    display: block;
    margin-bottom: -2px;
    color: var(--text-light);
    font-size: 0.69rem;
}

.cell-mv {
    font-family: 'Fira Code', monospace;
    font-size: 1.75rem;
    font-weight: 500;
    letter-spacing: -0.05em;
}

.metric-unit {
    margin-left: 3px;
    color: var(--text-light);
    font-size: 0.72rem;
}

.target-readout {
    text-align: right;
}

.target-readout span {
    display: block;
    color: var(--text-light);
    font-size: 0.67rem;
}

.target-readout strong {
    color: var(--gold);
    font-family: 'Fira Code', monospace;
    font-size: 0.78rem;
    font-weight: 500;
}

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1px;
    background: var(--mid-gray);
}

.channel-control-row {
    padding: 9px 12px;
    background: var(--white);
    border-bottom: 1px solid var(--mid-gray);
}

.channel-output-control {
    min-height: 28px;
    display: grid;
    grid-template-columns: 1fr auto 66px;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    user-select: none;
}

.channel-output-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.channel-control-label {
    color: var(--navy);
    font-size: 0.72rem;
    font-weight: 600;
}

.cell-output-state {
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.64rem;
    font-weight: 500;
}

.channel-output-control input:checked + .toggle-track {
    background: var(--navy);
}

.channel-output-control input:checked + .toggle-track::after {
    transform: translateX(15px);
}

.channel-output-control input:focus-visible + .toggle-track {
    outline: 3px solid var(--gold-medium);
    outline-offset: 2px;
}

.channel-output-control input:disabled ~ * {
    opacity: 0.55;
}

.telemetry-grid > div {
    min-width: 0;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    background: var(--white);
}

.telemetry-grid span {
    color: var(--text-muted);
    font-size: 0.69rem;
}

.telemetry-grid strong {
    overflow: hidden;
    color: var(--navy);
    font-family: 'Fira Code', monospace;
    font-size: 0.69rem;
    font-weight: 500;
    text-overflow: ellipsis;
}

.flag-list {
    min-height: 34px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.status-flag {
    padding: 2px 6px;
    color: var(--text-muted);
    background: var(--white);
    border-radius: 2px;
    font-family: 'Fira Code', monospace;
    font-size: 0.57rem;
    line-height: 1.4;
    text-transform: uppercase;
}

.status-flag.good {
    color: var(--green);
    background: var(--green-light);
}

.status-flag.warning {
    color: var(--amber);
    background: var(--amber-light);
}

.status-flag.error {
    color: var(--red);
    background: var(--red-light);
}

.cell-actions {
    padding: 4px 12px 12px;
    display: flex;
    gap: 7px;
}

.cell-actions .button {
    min-height: 36px;
    flex: 1 1 auto;
    padding: 7px 10px;
    font-size: 0.72rem;
}

.advanced-settings {
    border-top: 1px solid var(--mid-gray);
}

.advanced-settings > summary {
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--navy);
    background: var(--white);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    list-style: none;
}

.advanced-settings > summary::-webkit-details-marker {
    display: none;
}

.advanced-settings[open] > summary span {
    transform: rotate(45deg);
}

.advanced-settings > summary span {
    color: var(--gold-dark);
    font-size: 1rem;
    transition: transform var(--transition);
}

.advanced-form {
    padding: 16px;
    background: var(--white);
    border-top: 1px solid var(--mid-gray);
}

.advanced-section + .advanced-section {
    margin-top: 19px;
    padding-top: 16px;
    border-top: 1px solid var(--light-gray);
}

.advanced-section h4 {
    margin-bottom: 10px;
    color: var(--navy);
    font-size: 0.78rem;
    font-weight: 600;
}

.advanced-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.advanced-title-row > span {
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 0.57rem;
    text-transform: uppercase;
}

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

.field,
.toggle-field {
    min-width: 0;
}

.field > span,
.toggle-field > span:first-child {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.67rem;
    font-weight: 600;
}

.field small {
    font-size: inherit;
    font-weight: 400;
}

.field input,
.field select {
    width: 100%;
    min-width: 0;
    height: 36px;
    padding: 6px 8px;
    color: var(--text-primary);
    background: var(--white);
    border: 2px solid var(--light-gray);
    border-radius: var(--border-radius);
    font-family: 'Fira Code', monospace;
    font-size: 0.72rem;
}

.field input:focus,
.field select:focus {
    border-color: var(--gold);
    outline: none;
}

.toggle-field {
    min-height: 36px;
    align-self: end;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
}

.toggle-field > span:first-child {
    grid-row: 1 / 3;
    margin: 0;
}

.toggle-label,
.toggle-field {
    cursor: pointer;
    user-select: none;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--navy);
    font-size: 0.84rem;
    font-weight: 600;
}

.toggle-label input,
.toggle-field input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-track {
    position: relative;
    width: 34px;
    height: 19px;
    display: inline-block;
    background: #adb5bd;
    border-radius: 10px;
    transition: background var(--transition);
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 13px;
    height: 13px;
    background: var(--white);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition);
}

.toggle-label input:checked + .toggle-track,
.toggle-field input:checked + .toggle-track {
    background: var(--navy);
}

.toggle-label input:checked + .toggle-track::after,
.toggle-field input:checked + .toggle-track::after {
    transform: translateX(15px);
}

.toggle-label input:focus-visible + .toggle-track,
.toggle-field input:focus-visible + .toggle-track {
    outline: 3px solid var(--gold-medium);
    outline-offset: 2px;
}

.raw-field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.device-info-row {
    margin-top: 18px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    color: var(--text-muted);
    background: var(--light-gray);
    border-radius: var(--border-radius);
    font-size: 0.6rem;
}

.device-info-row .wide {
    grid-column: 1 / -1;
}

.device-info-row strong {
    color: var(--navy);
    font-family: 'Fira Code', monospace;
    font-weight: 500;
}

.advanced-actions {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.advanced-actions .field-note {
    margin: 0;
}

.advanced-actions .button {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 13px;
    font-size: 0.74rem;
}

.timeline-heading {
    align-items: center;
}

.timeline-progress {
    margin-top: 20px;
    padding: 14px 16px;
    background: var(--white);
    border-left: 4px solid var(--gold);
    border-radius: var(--border-radius);
}

.timeline-progress-copy {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: baseline;
    margin-bottom: 8px;
}

.timeline-state {
    color: var(--green);
    font-family: 'Fira Code', monospace;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
}

.timeline-progress-copy strong {
    color: var(--navy);
    font-size: 0.9rem;
}

#timeline-countdown {
    color: var(--navy);
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
}

.progress-track {
    height: 5px;
    overflow: hidden;
    background: var(--mid-gray);
    border-radius: 3px;
}

.progress-track span {
    width: 0;
    height: 100%;
    display: block;
    background: var(--gold);
    transition: width 0.15s linear;
}

.timeline-table-wrap {
    min-width: 0;
    max-width: 100%;
    margin-top: 20px;
    overflow-x: auto;
    background: var(--white);
    border-radius: var(--border-radius);
}

.timeline-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
}

.timeline-table th {
    padding: 9px 10px;
    color: var(--text-muted);
    background: var(--navy-soft);
    font-size: 0.68rem;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
}

.timeline-table td {
    padding: 8px 10px;
    border-top: 1px solid var(--light-gray);
    vertical-align: middle;
}

.timeline-table tr:first-child td {
    border-top: 0;
}

.timeline-table tr.active-step td {
    background: var(--gold-light);
}

.step-index {
    width: 32px;
    color: var(--navy);
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    font-weight: 600;
}

.timeline-table select,
.timeline-table input {
    width: 100%;
    height: 34px;
    padding: 5px 8px;
    color: var(--text-primary);
    background: var(--white);
    border: 1px solid var(--mid-gray);
    border-radius: var(--border-radius);
    font-size: 0.75rem;
}

.duration-field {
    width: 90px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 5px;
}

.duration-field span {
    color: var(--text-muted);
    font-size: 0.66rem;
}

.step-actions {
    display: flex;
    justify-content: flex-end;
    gap: 3px;
}

.icon-button {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.82rem;
}

.icon-button:hover:not(:disabled) {
    color: var(--navy);
    background: var(--light-gray);
}

.icon-button.delete:hover {
    color: var(--red);
    background: var(--red-light);
}

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

.timeline-actions {
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.timeline-run-actions {
    display: flex;
    gap: 8px;
}

footer {
    margin-top: 30px;
    padding: 20px;
    color: var(--text-light);
    background: var(--navy);
    text-align: center;
}

footer p {
    font-size: 0.82rem;
    font-weight: 300;
}

footer p + p {
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.58);
}

.preset-dialog {
    width: min(520px, calc(100% - 32px));
    padding: 0;
    color: var(--text-secondary);
    background: var(--white);
    border: 0;
    border-radius: var(--border-radius);
    box-shadow: 0 24px 80px rgba(15, 46, 61, 0.32);
}

.preset-dialog::backdrop {
    background: rgba(15, 46, 61, 0.68);
}

.preset-dialog form {
    padding: 24px;
}

.dialog-heading {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.dialog-close {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    color: var(--text-muted);
    background: var(--light-gray);
    border: 0;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
}

.preset-dialog .field {
    display: block;
    margin-top: 20px;
}

.preset-dialog .field input {
    height: 44px;
    padding: 8px 12px;
    font-family: 'Lato', sans-serif;
    font-size: 0.9rem;
}

.dialog-actions {
    margin-top: 22px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.toast-region {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 20;
    width: min(360px, calc(100% - 36px));
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 14px;
    color: var(--white);
    background: var(--navy);
    border-left: 4px solid var(--gold);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 28px rgba(15, 46, 61, 0.25);
    font-size: 0.82rem;
    animation: toast-in 0.22s ease-out;
}

.toast.error {
    border-left-color: #ef7777;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1020px) {
    .cell-grid {
        grid-template-columns: 1fr;
    }

    .cell-card {
        display: grid;
        grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
    }

    .cell-card-top,
    .cell-output,
    .channel-control-row,
    .telemetry-grid,
    .flag-list,
    .cell-actions {
        grid-column: 1;
    }

    .advanced-settings {
        grid-column: 2;
        grid-row: 1 / span 6;
        border-top: 0;
        border-left: 1px solid var(--mid-gray);
    }

    .advanced-settings > summary {
        min-height: 61px;
    }

    .advanced-settings:not([open]) {
        align-self: start;
    }
}

@media (max-width: 760px) {
    .site-header {
        padding: 12px 16px;
    }

    .header-content {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 7px;
        text-align: center;
    }

    .back-link,
    .header-summary {
        justify-self: center;
    }

    .back-link {
        order: -1;
    }

    .header-title h1 {
        font-size: 1.25rem;
    }

    .header-art {
        width: 100%;
        opacity: 0.25;
    }

    .compatibility-banner {
        width: calc(100% - 32px);
        margin-top: 16px;
    }

    main {
        padding: 24px 16px 38px;
        gap: 24px;
    }

    .intro-row,
    .section-heading,
    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    .connection-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .connection-actions .button {
        flex: 1 1 auto;
    }

    .control-panel,
    .timeline-panel {
        padding: 18px 14px;
    }

    .scope-control {
        width: 100%;
        overflow-x: auto;
    }

    .scope-label {
        display: none;
    }

    .scope-button {
        flex: 1 0 auto;
    }

    .live-control-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .setpoint-entry {
        grid-template-columns: 42px minmax(0, 1fr) 42px;
    }

    .nudge-button {
        width: 42px;
    }

    .target-row-meta {
        grid-template-columns: minmax(92px, 1fr) 110px 120px;
        gap: 8px;
    }

    .target-slider-row {
        padding-right: 11px;
        padding-left: 11px;
    }

    .target-row-secondary {
        font-size: 0.66rem;
    }

    .target-value-input {
        padding-right: 38px;
        font-size: 0.84rem;
    }

    .target-unit {
        right: 8px;
    }

    .shortcut-row {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .shortcut-label {
        width: 100%;
    }

    .shortcut-list {
        width: 100%;
        padding-bottom: 2px;
    }

    .shortcut-add {
        width: 100%;
        margin-left: 0;
    }

    .cell-card {
        display: block;
    }

    .advanced-settings {
        border-top: 1px solid var(--mid-gray);
        border-left: 0;
    }

    .cell-output {
        padding: 15px 16px;
    }

    .timeline-heading {
        flex-direction: row;
        align-items: flex-start;
    }

    .timeline-table-wrap {
        margin-right: -14px;
        margin-left: -14px;
        border-radius: 0;
    }

    .timeline-actions {
        flex-direction: column;
    }

    .timeline-run-actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .timeline-actions > .button,
    .timeline-run-actions .button {
        width: 100%;
        padding-right: 10px;
        padding-left: 10px;
    }

}

@media (max-width: 420px) {
    .control-label-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 7px;
    }

    .control-mode-actions {
        width: 100%;
        justify-content: space-between;
    }

    .target-row-meta {
        grid-template-columns: minmax(55px, 1fr) 90px 104px;
        gap: 6px;
    }

    .target-row-name {
        font-size: 0.84rem;
    }

    .target-row-secondary {
        display: none;
    }

    .target-value-input {
        padding-right: 29px;
        padding-left: 6px;
        font-size: 0.72rem;
    }

    .target-unit {
        right: 6px;
        font-size: 0.6rem;
    }

    .telemetry-grid > div {
        align-items: flex-start;
        flex-direction: column;
        gap: 1px;
    }

    .cell-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .cell-pair-button {
        grid-column: 1 / -1;
    }

    .field-grid,
    .raw-field-grid {
        grid-template-columns: 1fr;
    }

    .advanced-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .timeline-heading {
        flex-direction: column;
    }
}

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