:root {
    color-scheme: light;
    --ink: #1a2336;
    --muted: #55637a;
    --line: #d9e0ec;
    --accent: #4137ba;
    --navy: #171f37;
    --base: #f3f5fa;
    --surface: #fff;
    --soft: #edf0f8;
    --danger: #a32949;
    font: 14px/1.5 'Segoe UI',system-ui,sans-serif;
    color: var(--ink);
    background: var(--base);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1,h2,p {
    margin: 0;
}

h2 {
    font-weight: 650;
    font-size: 19px;
    line-height: 1.35;
    margin-bottom: 9px;
}

button,input,select,textarea {
    font: inherit;
    color: inherit;
}

button,.button-link {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--soft);
    padding: 7px 13px;
    min-height: 34px;
    cursor: pointer;
    font-weight: 600;
}

button:hover:enabled,.button-link:hover {
    filter: brightness(.95);
}

button:active:enabled,.button-link:active {
    filter: brightness(.87);
}

button:disabled {
    opacity: .45;
    cursor: default;
}

.button-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.full {
    display: block;
    width: 100%;
}

.soft {
    background: transparent;
    color: var(--accent);
}

:focus-visible {
    outline: 2px solid #7060df;
    outline-offset: 3px;
}

input:not([type=range],[type=checkbox],[type=file]),select,textarea {
    min-height: 33px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: white;
    padding: 6px 9px;
}

input[type=range] {
    width: 100%;
    margin: 4px 0;
    accent-color: var(--accent);
}

input[type=checkbox] {
    accent-color: var(--accent);
    margin: 0 5px 0 0;
    vertical-align: -2px;
}

label {
    font-weight: 500;
}

output {
    font-variant-numeric: tabular-nums;
}

.muted {
    color: var(--muted);
}

.row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
}

.control-row {
    margin: 10px 0;
}

.checks {
    margin: 6px 0 12px;
    gap: 12px;
}

.single-check {
    display: block;
    margin: 6px 0 10px;
}

.range-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.small {
    width: 60px;
}

.small.wide {
    width: 83px;
}

.masthead {
    background: var(--navy);
    padding: 17px max(24px,calc((100vw - 1140px)/2));
    color: #e1e7f5;
}

.topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    font-size: 27px;
    font-weight: 650;
    color: white;
}

.mark {
    width: 39px;
    height: 39px;
    flex: none;
    padding: 4px;
    border-radius: 9px;
    object-fit: contain;
    background: white;
}

.session {
    display: flex;
    gap: 9px;
    align-items: center;
    flex-wrap: wrap;
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a4aec4;
}

.indicator.online {
    background: #74dea3;
}

.session #battery {
    color: #caeccc;
}

.header-button {
    color: #e1e7f5;
    border-color: #586279;
}

.connection {
    margin-top: 13px;
    color: var(--ink);
}

.connection input {
    width: min(263px,100%);
}

.connection-status {
    margin-left: 5px;
    color: #d1d9ee;
    font-size: 13px;
}

.dashboard {
    width: min(100% - 48px,1140px);
    margin: 10px auto 15px;
    flex: 1;
}

.tabs {
    display: flex;
    overflow-x: auto;
    gap: 2px;
    margin-bottom: 14px;
}

.tabs button {
    border: 0;
    border-radius: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    padding: 9px 19px;
    color: var(--muted);
    white-space: nowrap;
}

.tabs button[aria-selected=true] {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tabs button:hover {
    background: #e8ebf6;
}

.columns {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 16px;
    align-items: start;
}

.columns[hidden] {
    display: none;
}

.drive-columns {
    grid-template-columns: 1.1fr 1fr;
}

.sequence-columns {
    grid-template-columns: 1.35fr 1fr;
}

.stack {
    display: grid;
    gap: 14px;
}

.card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    padding: 20px;
    min-width: 0;
}

.statusbar {
    padding: 11px max(24px,calc((100vw - 1140px)/2));
    background: #e8ecf6;
    min-height: 43px;
}

.statusbar.error {
    color: #841531;
}

.joystick {
    width: 244px;
    height: 244px;
    display: grid;
    place-items: center;
    margin: 13px auto 5px;
    touch-action: none;
    user-select: none;
    cursor: grab;
    max-width: 100%;
}

.joystick.dragging {
    cursor: grabbing;
}

.dial {
    width: 210px;
    height: 210px;
    position: relative;
    border: 1.5px solid #ddd8fc;
    border-radius: 50%;
    background: #f2f0ff;
    display: grid;
    place-items: center;
}

.axis,.inner-dial,.direction,.knob {
    position: absolute;
    pointer-events: none;
}

.axis-x {
    width: 96%;
    border-top: 1px solid #ddd8fc;
}

.axis-y {
    height: 96%;
    border-left: 1px solid #ddd8fc;
}

.inner-dial {
    width: 144px;
    height: 144px;
    border: 1px dashed #c8c0f5;
    border-radius: 50%;
}

.direction {
    color: #514396;
    font-size: 13px;
}

.north {
    top: 9px;
}

.south {
    bottom: 9px;
}

.east {
    right: 9px;
}

.west {
    left: 9px;
}

.knob {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: 3px solid white;
    background: var(--accent);
    transform: translate(var(--x,0px),var(--y,0px));
}

.readout {
    text-align: center;
    font-size: 15px;
    font-weight: 650;
    margin-bottom: 15px;
}

.channels {
    display: grid;
    grid-template-columns: 66px minmax(0,1fr) 45px;
    align-items: center;
    gap: 5px 8px;
    margin-bottom: 7px;
}

.channels output {
    text-align: right;
}

.swatch {
    background: var(--rgb,#764bff);
    border-radius: 5px;
    width: 35px;
    height: 24px;
    border: 1px solid var(--line);
}

.sensor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px 12px;
    margin: 8px 0;
}

.table-wrap,.events {
    border: 1px solid var(--line);
    border-radius: 5px;
    overflow: auto;
    min-height: 155px;
    max-height: 290px;
    margin: 8px 0 0;
}

table {
    border-collapse: collapse;
    width: 100%;
    text-align: left;
}

td,th {
    padding: 6px 10px;
    border-bottom: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}

th {
    background: var(--soft);
    position: sticky;
    top: 0;
}

.events {
    padding: 6px 10px;
    list-style: none;
}

.events li {
    padding: 4px 0;
}

.details {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

textarea {
    display: block;
    width: 100%;
    min-height: 300px;
    font: 14px/1.55 Consolas,'Cascadia Mono',monospace;
    resize: vertical;
}

.instructions p {
    margin-bottom: 11px;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 16px 0;
}

.auth-main {
    width: min(100% - 32px,410px);
    margin: 52px auto;
}

.auth-card {
    padding: 27px;
}

.auth-form {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.auth-form button {
    margin: 10px 0 12px;
}

.auth-card .muted {
    margin-bottom: 10px;
}

.auth-card h1 {
    font-size: 23px;
    line-height: 1.3;
}

.error {
    color: var(--danger);
    margin-top: 8px;
}

.notice {
    color: #176342;
    margin-top: 8px;
}

@media(max-width:760px) {
    .columns {
        grid-template-columns: 1fr;
    }
    .dashboard {
        width: calc(100% - 28px);
    }
    .masthead,.statusbar {
        padding-inline: 14px;
    }
    .card {
        padding: 16px;
    }
    .tabs button {
        padding-inline: 12px;
    }
    .joystick {
        margin-top: 6px;
    }
}

@media(max-width:390px) {
    .connection input {
        width: 200px;
    }
    .brand {
        font-size: 23px;
    }
    .session {
        font-size: 12px;
    }
    .sensor-grid {
        grid-template-columns: 1fr;
    }
}
