/* LEO Supercar web client - dark palette carried over from the WiFi version. */

:root {
    --bg: #0b0e13;
    --surface: #11151c;
    --surface-raised: #161b24;
    --border: #202630;
    --border-bright: #2a303b;
    --text: #f5f7fa;
    --text-dim: #707783;
    --text-faint: #4e555f;
    --accent: #3fb950;
    --accent-soft: #263b2d;
    --danger: #c93636;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overscroll-behavior: none;
}

body {
    display: flex;
    justify-content: center;
}

.app {
    width: 100%;
    max-width: 600px;
    padding: 24px 20px 32px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Everything but the connect button is inert until the link is up. */
.stack[aria-disabled="true"] {
    opacity: .45;
    pointer-events: none;
}

/* ---------------------------------------------------------------- */
/* Header                                                            */
/* ---------------------------------------------------------------- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
}

.subtitle {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.connect-button {
    display: flex;
    align-items: center;
    gap: 8px;

    padding: 12px 16px;
    border: 1px solid var(--border-bright);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);

    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: transform .1s, border-color .15s;
}

.connect-button:active {
    transform: scale(.96);
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background .2s, box-shadow .2s;
}

.status-dot.online {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.notice {
    margin: 0 0 16px;
    padding: 14px 16px;
    border: 1px solid var(--danger);
    border-radius: 14px;
    background: rgba(201, 54, 54, .12);
    font-size: 12px;
    line-height: 1.5;
}

/* ---------------------------------------------------------------- */
/* Cards                                                             */
/* ---------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 18px;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.card-title {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 2px;
}

.card-title.spaced {
    margin: 22px 0 10px;
}

.card-hint {
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: .5px;
}

/* ---------------------------------------------------------------- */
/* Mode selector                                                     */
/* ---------------------------------------------------------------- */

.modes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 8px;
}

.mode-button {
    display: flex;
    flex-direction: column;
    gap: 4px;

    padding: 14px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
}

.mode-button span {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.mode-button small {
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: .5px;
}

.mode-button:active {
    transform: scale(.97);
}

.mode-button.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.mode-button.active small {
    color: #8fd99a;
}

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

/* ---------------------------------------------------------------- */
/* Telemetry                                                         */
/* ---------------------------------------------------------------- */

.telemetry {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.telemetry-item {
    display: flex;
    flex-direction: column;
    gap: 6px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
}

.telemetry-item span {
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: 1px;
}

.telemetry-item strong {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- */
/* Joystick                                                          */
/* ---------------------------------------------------------------- */

.joystick-card.inactive .joystick-zone {
    opacity: .4;
}

.joystick-zone {
    position: relative;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1;
    margin: 0 auto;

    border-radius: 50%;
    border: 1px solid var(--border-bright);

    background: radial-gradient(circle,
        #1b2029 0%, #141922 45%, #10141b 70%, #0d1117 100%);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, .6);

    touch-action: none;
    overflow: hidden;
    transition: opacity .2s;
}

.joystick-cross {
    position: absolute;
    background: #242b35;
}

.joystick-cross.horizontal {
    width: 70%;
    height: 1px;
    left: 15%;
    top: 50%;
}

.joystick-cross.vertical {
    width: 1px;
    height: 70%;
    top: 15%;
    left: 50%;
}

.joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 84px;
    height: 84px;
    margin: -42px 0 0 -42px;

    border-radius: 50%;
    background: linear-gradient(135deg, #34d399, #10b981);
    box-shadow: 0 10px 30px rgba(16, 185, 129, .25);

    pointer-events: none;
    transition: transform .05s linear;
}

/* ---------------------------------------------------------------- */
/* Switches                                                          */
/* ---------------------------------------------------------------- */

.control-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 16px;
}

.control {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;

    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    cursor: pointer;
}

.control > span:first-child {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
}

.control small {
    grid-column: 1 / -1;
    margin-top: 6px;
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: 1px;
}

.switch {
    position: relative;
    display: block;
    width: 46px;
    height: 26px;
    flex: none;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.slider {
    position: absolute;
    inset: 0;
    border-radius: 20px;
    background: #252b34;
    transition: .2s;
    pointer-events: none;
}

.slider::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #858d99;
    transition: .2s;
}

.switch input:checked + .slider {
    background: var(--accent-soft);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
    background: #56d364;
}

/* ---------------------------------------------------------------- */
/* Buttons                                                           */
/* ---------------------------------------------------------------- */

.preset-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.preset-button {
    display: flex;
    flex-direction: column;
    gap: 4px;

    padding: 14px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
}

.preset-button span {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.preset-button small {
    font-size: 9px;
    color: var(--text-faint);
}

.preset-button:active {
    transform: scale(.97);
}

.preset-button.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.ghost-button {
    padding: 14px 10px;
    border: 1px solid var(--border-bright);
    border-radius: 16px;
    background: transparent;
    color: var(--text);

    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background .15s, transform .1s;
}

.ghost-button:active {
    transform: scale(.97);
    background: var(--surface-raised);
}

.ghost-button.danger {
    border-color: rgba(201, 54, 54, .6);
    color: #ff9c9c;
}

.stop-button {
    width: 100%;
    padding: 22px;

    border: none;
    border-radius: 18px;
    background: var(--danger);
    color: #fff;

    font-size: 14px;
    font-weight: 800;
    letter-spacing: 1.5px;
    cursor: pointer;

    box-shadow: 0 8px 30px rgba(201, 54, 54, .2);
    transition: transform .1s, background .15s;
}

.stop-button:active {
    transform: scale(.98);
}

/* ---------------------------------------------------------------- */
/* Settings                                                          */
/* ---------------------------------------------------------------- */

.settings summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    list-style: none;
}

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

.settings[open] summary {
    margin-bottom: 18px;
}

.settings-fields {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.setting-name {
    font-size: 13px;
    font-weight: 600;
}

.setting-hint {
    margin-top: 3px;
    font-size: 10px;
    color: var(--text-faint);
    line-height: 1.4;
}

.setting-value {
    flex: none;
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.setting-value .unit {
    margin-left: 3px;
    font-size: 10px;
    color: var(--text-dim);
}

input[type="range"] {
    width: 100%;
    height: 24px;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: #252b34;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    margin-top: -9px;
    border: none;
    border-radius: 50%;
    background: #56d364;
    box-shadow: 0 2px 10px rgba(86, 211, 100, .35);
}

input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: #252b34;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: #56d364;
}

/* ---------------------------------------------------------------- */
/* Footer and toast                                                  */
/* ---------------------------------------------------------------- */

.footer {
    margin-top: 24px;
    font-size: 10px;
    color: var(--text-faint);
    letter-spacing: .5px;
    text-align: center;
}

.footer code {
    color: var(--text-dim);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: 90vw;

    padding: 14px 18px;
    border: 1px solid var(--border-bright);
    border-radius: 14px;
    background: #1b2029;
    color: var(--text);

    font-size: 12px;
    letter-spacing: .5px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}

.toast-error {
    border-color: var(--danger);
    background: #2a1618;
}

/* ---------------------------------------------------------------- */
/* Narrow screens                                                    */
/* ---------------------------------------------------------------- */

@media (max-width: 420px) {
    .app {
        padding: 18px 14px 28px;
    }

    .telemetry {
        grid-template-columns: repeat(2, 1fr);
    }

    .card {
        padding: 14px;
        border-radius: 18px;
    }
}
