* {
    box-sizing: border-box;
}

[hidden] {
    display: none;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: #10110f;
    color: #f5f7f8;
    font-family: "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

button {
    min-height: 44px;
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #202327;
    color: #f5f7f8;
    cursor: pointer;
    font-weight: 700;
}

button:hover {
    border-color: #2fd38d;
    background: #292d32;
}

button:focus,
input:focus,
select:focus,
summary:focus {
    outline: 2px solid rgba(47, 211, 141, 0.55);
    outline-offset: 2px;
}

button:active,
button.is-active {
    transform: translateY(1px);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.05;
}

h2 {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.2;
    text-transform: uppercase;
}

.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
    padding: 18px;
    gap: 18px;
}

.camera-panel {
    flex: 1 1 auto;
    min-width: 0;
}

.control-panel {
    flex: 0 0 390px;
    min-width: 0;
}

.control-panel {
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #181a1d;
}

.room-text {
    color: #a8b0b8;
    font-size: 13px;
    font-weight: 700;
}

.room-footer {
    margin-top: 0;
    text-align: center;
}

.metrics {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    color: #a8b0b8;
    font-size: 12px;
}

.preview-metrics {
    position: absolute;
    z-index: 4;
    bottom: 12px;
    right: 66px;
    left: 12px;
    max-width: calc(100% - 78px);
    opacity: 0.5;
}

.metrics span {
    border: 1px solid #373d43;
    border-radius: 8px;
    padding: 6px 7px;
    background: #202327;
    color: #f5f7f8;
    font-weight: 700;
    white-space: nowrap;
}

.distance-readout {
    position: absolute;
    z-index: 5;
    top: 50%;
    display: grid;
    min-width: 92px;
    max-width: 34%;
    gap: 2px;
    padding: 8px 10px;
    transform: translateY(-50%);
    opacity: 0.72;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.75);
}

.distance-left {
    left: 12px;
}

.distance-center {
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.distance-right {
    right: 12px;
    text-align: right;
}

.distance-readout span {
    color: #a8b0b8;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}

.distance-readout strong {
    color: #f5f7f8;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
    font-weight: 900;
    line-height: 1.1;
    white-space: nowrap;
}

.distance-readout[data-state="waiting"] strong,
.distance-readout[data-state="error"] strong {
    color: #a8b0b8;
}

.distance-readout[data-alert="true"] strong {
    animation: distance-alert 650ms ease-in-out infinite;
}

@keyframes distance-alert {
    0%,
    100% {
        color: #ff3b3b;
    }

    50% {
        color: rgba(255, 59, 59, 0.25);
    }
}

.metrics .wifi-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.signal-icon {
    display: inline-flex;
    align-items: flex-end;
    width: 15px;
    height: 12px;
    gap: 1px;
    font-style: normal;
}

.signal-icon b {
    display: block;
    width: 3px;
    border-radius: 2px 2px 0 0;
    background: currentColor;
    opacity: 0.25;
}

.signal-icon b:nth-child(1) {
    height: 4px;
}

.signal-icon b:nth-child(2) {
    height: 6px;
}

.signal-icon b:nth-child(3) {
    height: 9px;
}

.signal-icon b:nth-child(4) {
    height: 12px;
}

.wifi-badge[data-strength="1"] .signal-icon b:nth-child(-n+1),
.wifi-badge[data-strength="2"] .signal-icon b:nth-child(-n+2),
.wifi-badge[data-strength="3"] .signal-icon b:nth-child(-n+3),
.wifi-badge[data-strength="4"] .signal-icon b:nth-child(-n+4) {
    opacity: 1;
}

.wifi-badge[data-alert="true"] {
    border-color: #ff3b3b;
    background: rgba(255, 59, 59, 0.16);
    color: #fff4f4;
    animation: wifi-alert 650ms ease-in-out infinite;
}

@keyframes wifi-alert {
    0%,
    100% {
        border-color: #ff3b3b;
        background: rgba(255, 59, 59, 0.26);
        color: #fff;
    }

    50% {
        border-color: rgba(255, 59, 59, 0.35);
        background: rgba(255, 59, 59, 0.06);
        color: rgba(255, 244, 244, 0.55);
    }
}

#connectionText[data-connected="true"],
#robotText[data-connected="true"] {
    border-color: #2fd38d;
    background: #173526;
    color: #effff7;
}

#connectionText[data-connected="false"],
#robotText[data-connected="false"] {
    border-color: #f5b84b;
    background: #352b18;
    color: #fff8e8;
}

.camera-frame {
    position: relative;
    width: 100%;
    height: 0;
    min-height: 360px;
    max-height: calc(100vh - 36px);
    padding-bottom: 80%;
    overflow: hidden;
    border: 1px solid #4a535c;
    border-radius: 8px;
    background: #080908;
}

.camera-frame img,
.camera-placeholder,
.camera-frame:before {
    position: absolute;
}

.camera-frame:before {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: block;
    background: #0c1511;
    content: "";
}

.camera-frame img {
    z-index: 1;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center center;
    opacity: 1;
}

.fullscreen-drive-surface {
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: none;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}

.camera-frame[data-fullscreen="true"] .fullscreen-drive-surface {
    display: block;
}

.fullscreen-drive-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    display: none;
    width: 96px;
    height: 96px;
    margin: -48px 0 0 -48px;
    border: 1px solid rgba(255, 255, 255, 0.54);
    border-radius: 50%;
    background: rgba(8, 9, 8, 0.28);
    box-shadow: 0 0 0 4px rgba(8, 9, 8, 0.14);
    pointer-events: none;
}

.fullscreen-drive-surface.is-active .fullscreen-drive-guide {
    display: block;
}

.gesture-direction {
    position: absolute;
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.92);
    opacity: 1;
    transition: opacity 90ms ease;
}

.gesture-direction:before {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    content: "";
}

.gesture-direction.forward {
    top: 6px;
    left: 50%;
    margin-left: -9px;
}

.gesture-direction.forward:before {
    transform: rotate(-45deg);
}

.gesture-direction.reverse {
    bottom: 6px;
    left: 50%;
    margin-left: -9px;
}

.gesture-direction.reverse:before {
    transform: rotate(135deg);
}

.gesture-direction.left {
    top: 50%;
    left: 6px;
    margin-top: -9px;
}

.gesture-direction.left:before {
    transform: rotate(-135deg);
}

.gesture-direction.right {
    top: 50%;
    right: 6px;
    margin-top: -9px;
}

.gesture-direction.right:before {
    transform: rotate(45deg);
}

.fullscreen-drive-guide[data-motion*="forward"] .gesture-direction.forward,
.fullscreen-drive-guide[data-motion*="reverse"] .gesture-direction.reverse,
.fullscreen-drive-guide[data-motion*="left"] .gesture-direction.left,
.fullscreen-drive-guide[data-motion*="right"] .gesture-direction.right {
    opacity: 0;
}

.gesture-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid rgba(255, 255, 255, 0.88);
    border-radius: 50%;
    background: #2fd38d;
    box-shadow: 0 0 0 4px rgba(47, 211, 141, 0.2);
}

.camera-frame[data-fullscreen="true"] .preview-title,
.camera-frame[data-fullscreen="true"] .preview-metrics,
.camera-frame[data-fullscreen="true"] .camera-state {
    pointer-events: none;
}

.camera-frame[data-camera-state="waiting"] img {
    opacity: 0;
}

.camera-frame[data-camera-state="stale"] img {
    opacity: 0.58;
}

.preview-title {
    position: absolute;
    z-index: 3;
    top: 12px;
    left: 14px;
    color: rgba(245, 247, 248, 0.62);
    font-size: 16px;
    font-weight: 800;
}

.camera-placeholder {
    z-index: 2;
    top: 50%;
    left: 50%;
    width: 220px;
    margin-left: -110px;
    margin-top: -44px;
    color: #a8b0b8;
    font-weight: 700;
    text-align: center;
    pointer-events: none;
}

.camera-frame[data-camera-state="ready"] .camera-placeholder,
.camera-frame[data-camera-state="stale"] .camera-placeholder {
    display: none;
}

.camera-glyph {
    display: block;
    width: 64px;
    height: 44px;
    margin: 0 auto 10px;
    border: 2px solid #4a535c;
    border-radius: 8px;
    background:
        radial-gradient(circle at 50% 50%, rgba(47, 211, 141, 0.22) 0 24%, transparent 25%),
        #202327;
    box-shadow: inset 0 0 0 8px rgba(0, 0, 0, 0.18);
}

.camera-glyph:before {
    display: block;
    width: 18px;
    height: 8px;
    margin: -10px auto 0;
    border: 2px solid #4a535c;
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
    content: "";
}

.camera-state {
    position: absolute;
    z-index: 3;
    bottom: 52px;
    left: 12px;
    display: inline-flex;
    align-items: center;
    max-width: calc(100% - 24px);
    min-height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 6px 9px;
    gap: 7px;
    background: #10110f;
    color: #a8b0b8;
    font-size: 12px;
    font-weight: 800;
    opacity: 0.5;
}

.camera-frame[data-camera-state="ready"] .camera-state {
    opacity: 0;
}

.camera-frame[data-camera-state="ready"]:hover .camera-state {
    opacity: 0.5;
}

.camera-state-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #f5b84b;
}

.camera-frame[data-camera-state="ready"] .camera-state-dot {
    background: #2fd38d;
}

.camera-fullscreen-button {
    position: absolute;
    z-index: 4;
    right: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-color: rgba(255, 255, 255, 0.16);
    background: #10110f;
}

.fullscreen-icon {
    display: block;
    width: 20px;
    height: 20px;
    background:
        linear-gradient(currentColor, currentColor) left top / 8px 2px no-repeat,
        linear-gradient(currentColor, currentColor) left top / 2px 8px no-repeat,
        linear-gradient(currentColor, currentColor) right top / 8px 2px no-repeat,
        linear-gradient(currentColor, currentColor) right top / 2px 8px no-repeat,
        linear-gradient(currentColor, currentColor) left bottom / 8px 2px no-repeat,
        linear-gradient(currentColor, currentColor) left bottom / 2px 8px no-repeat,
        linear-gradient(currentColor, currentColor) right bottom / 8px 2px no-repeat,
        linear-gradient(currentColor, currentColor) right bottom / 2px 8px no-repeat;
}

.camera-frame:fullscreen,
.camera-frame:-webkit-full-screen,
.camera-frame[data-fullscreen="true"] {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0 !important;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: #000;
}

.camera-frame:fullscreen:before,
.camera-frame:-webkit-full-screen:before,
.camera-frame[data-fullscreen="true"]:before {
    display: none;
}

.camera-frame:fullscreen img,
.camera-frame:-webkit-full-screen img,
.camera-frame[data-fullscreen="true"] img {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    object-fit: contain;
    object-position: center center;
}

.camera-frame[data-fullscreen="true"] .preview-title {
    top: calc(12px + env(safe-area-inset-top));
    left: calc(14px + env(safe-area-inset-left));
}

.camera-frame[data-fullscreen="true"] .preview-metrics {
    right: calc(66px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: calc(12px + env(safe-area-inset-left));
    max-width: none;
}

.camera-frame[data-fullscreen="true"] .distance-readout {
    min-width: 116px;
    padding: 10px 12px;
}

.camera-frame[data-fullscreen="true"] .distance-left {
    left: calc(14px + env(safe-area-inset-left));
}

.camera-frame[data-fullscreen="true"] .distance-center {
    top: calc(12px + env(safe-area-inset-top));
}

.camera-frame[data-fullscreen="true"] .distance-right {
    right: calc(14px + env(safe-area-inset-right));
}

.camera-frame[data-fullscreen="true"] .camera-state {
    bottom: calc(52px + env(safe-area-inset-bottom));
    left: calc(12px + env(safe-area-inset-left));
}

.camera-frame[data-fullscreen="true"] .camera-fullscreen-button {
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.danger-button {
    border-color: rgba(239, 68, 68, 0.75);
    background: #3a1717;
    color: #fff2f2;
}

.danger-button:hover {
    border-color: #ef4444;
    background: #571f1f;
}

.drive-pad {
    position: relative;
    width: 100%;
    height: 330px;
    overflow: hidden;
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #202327;
    touch-action: none;
    user-select: none;
}

.drive-pad.is-active {
    border-color: #2fd38d;
    background: #173526;
}

.drive-axis {
    position: absolute;
    background: rgba(245, 247, 248, 0.16);
    pointer-events: none;
}

.drive-axis.vertical {
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
}

.drive-axis.horizontal {
    top: 50%;
    right: 0;
    left: 0;
    height: 2px;
    margin-top: -1px;
}

.drive-zone-label {
    position: absolute;
    color: rgba(245, 247, 248, 0.58);
    font-size: 12px;
    font-weight: 800;
    pointer-events: none;
    text-transform: uppercase;
}

.drive-zone-label.forward {
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
}

.drive-zone-label.reverse {
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
}

.drive-zone-label.left {
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
}

.drive-zone-label.right {
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
}

.drive-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 58px;
    height: 58px;
    border: 3px solid rgba(255, 255, 255, 0.86);
    border-radius: 50%;
    background: #2fd38d;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.drive-readout {
    display: flex;
    gap: 8px;
}

.drive-readout span {
    flex: 1 1 0;
    border: 1px solid #373d43;
    border-radius: 8px;
    padding: 9px;
    background: #202327;
    color: #f5f7f8;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
}

.slider-row,
.tb-grid label,
.settings-grid label {
    display: block;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row span {
    flex: 0 0 82px;
}

.slider-row input {
    flex: 1 1 auto;
}

.slider-row output {
    flex: 0 0 50px;
    text-align: right;
}

.slider-row span,
.tb-grid span,
.settings-grid span {
    color: #a8b0b8;
    font-size: 13px;
    font-weight: 700;
}

input[type="range"] {
    width: 100%;
    accent-color: #2fd38d;
}

input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: #2fd38d;
}

.settings-panel {
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #202327;
}

.settings-panel summary {
    min-height: 46px;
    cursor: pointer;
    padding: 13px 12px;
    color: #f5f7f8;
    font-weight: 800;
}

.config-slider-row {
    padding: 0 12px 12px;
}

.settings-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 0 12px 12px;
}

.settings-grid label {
    flex: 1 1 150px;
    min-width: 0;
}

.settings-grid span,
.tb-grid span {
    display: block;
    margin-bottom: 8px;
}

.settings-grid input[type="number"] {
    width: 100%;
    min-height: 42px;
    border: 1px solid #373d43;
    border-radius: 8px;
    padding: 7px 9px;
    background: #111314;
    color: #f5f7f8;
}

.settings-grid select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #373d43;
    border-radius: 8px;
    padding: 7px 9px;
    background: #111314;
    color: #f5f7f8;
}

.settings-grid .camera-select-row {
    flex-basis: 100%;
}

.settings-grid .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-basis: 100%;
    min-height: 42px;
    border: 1px solid #373d43;
    border-radius: 8px;
    padding: 7px 9px;
    gap: 12px;
    background: #111314;
}

.settings-grid .toggle-row input[type="checkbox"] {
    flex: 0 0 auto;
    margin: 0;
    cursor: pointer;
}

.settings-grid .toggle-row span {
    margin-bottom: 0;
}

#saveSettingsButton {
    width: 100%;
    border-color: rgba(47, 211, 141, 0.7);
    background: #123022;
    color: #e9fff5;
}

#saveSettingsButton:hover {
    background: #16432e;
}

.tb-grid {
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #202327;
    padding: 12px;
}

input[type="color"] {
    width: 100%;
    height: 44px;
    border: 1px solid #373d43;
    border-radius: 8px;
    background: #202327;
}

@media (max-width: 920px) {
    .app-shell {
        display: block;
    }

    .camera-panel,
    .control-panel {
        width: 100%;
    }

    .control-panel {
        margin-top: 12px;
    }

    .camera-frame {
        max-height: none;
    }
}

@media (max-width: 520px) {
    html,
    body {
        overflow-x: hidden;
    }

    .app-shell {
        padding: 10px;
    }

    .metrics {
        gap: 5px;
        font-size: 11px;
    }

    .metrics span {
        padding: 5px 6px;
    }

    .camera-frame {
        min-height: 220px;
    }

    .distance-readout {
        min-width: 76px;
        max-width: 36%;
        padding: 7px 8px;
    }

    .distance-left {
        left: 8px;
    }

    .distance-center {
        top: 8px;
    }

    .distance-right {
        right: 8px;
    }

    .distance-readout span {
        font-size: 10px;
    }

    .distance-readout strong {
        font-size: 15px;
    }

    .drive-pad {
        height: 320px;
    }

    .slider-row {
        display: block;
    }

    .slider-row span,
    .slider-row input,
    .slider-row output {
        display: block;
        width: 100%;
        text-align: left;
    }

    .slider-row input {
        margin: 8px 0;
    }

    .settings-grid label {
        flex-basis: 100%;
    }
}
