@media (orientation: landscape) {
    body { flex-direction: column; height: 100vh; }
    #title {
        flex-direction: column !important;
        max-height: 30vh;
        flex-shrink: 0;
        padding: 0.5em;
        gap: 0.2em;
        width: 100%;
    }
    #nav_elements_main {
        display: flex !important;
        flex-direction: row !important; /* All buttons in ONE horizontal line */
        justify-content: space-evenly !important; /* Even spread: Driving | Arm | Settings | Bluetooth */
        align-items: center !important;
        width: 100% !important;
        flex: 0 0 auto;
        gap: 0.5em; /* Button spacing */
    }
    #nav_elements_main > div { /* Each page/connect div */
        flex: 1; /* Equal width */
        display: flex !important;
        justify-content: center !important;
    }
    #connectBle { /* Bluetooth special: right-align text */
        justify-content: flex-end !important;
        gap: 0.5em;
    }
    #main { flex: 1 !important; width: 100%; }
    #orientation_frame {
        flex: 1 !important;
        width: 100% !important;
        border-top: 5px solid !important;
        border-left: none !important;
    }
}




.info {
	color:rgb(10, 100, 10);
}

.error {
	color:rgb(120, 10, 10);	
}

html {
	height: 100%;
}

body {
	color: white;
	font-family:sans-serif;
	background-color: rgb(50,50,50);
	min-width:23em;
	margin: 0;
	height:100%;
    display:flex;
}

#main {
    display:flex;
    height:100%;
    width:100%;
}

#title {
	display:flex; 
    justify-content:space-between;
	background-color: rgb(0,0,0);
	color: lightskyblue;
    align-items: center;
}

#title > div {
    padding: 0.5em;
}

#title button {
  background-color: unset;
  border: none;
  padding-left:1em;
  padding-right:1em;
  color: lightskyblue;
  font-size:110%;
  height: 2.2em;
}

h1 {
	font-size:1.3rem;
}

#orientation_frame {
    position: relative;
    padding:0.2em;
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 100%;
}

.running {
	border-color: rgb(50,200,50);
}

.stopped {
	border-color: rgb(194, 59, 51);
}


#status{
  padding:1em;
  font-size:90%;
  font-weight: bold;
    font-family: "Courier New", serif;
  background-color: rgba(200,200,200,0.9);
    margin: 1.5em 0.5em 0.5em;
    height:90%;
    width: 70%;
  flex-direction: column;
}

#status td {
	padding-right: 1em;
	padding-bottom: 0.2em;
}

#status_scroll{
  margin-top:1em;
  flex: 1 1 auto;
}

#status p {
    margin: 0 0 0.5em;
}
.sensor-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5em; /* space between blocks */
    justify-content: center;
}

.sensor-block {
    flex: 1 1 calc(33.33% - 1em); /* 3 per row, with gap compensation */
    box-sizing: border-box;
    margin-bottom: 1.5em;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #000;
    border-radius: 12px;
    padding: 1em 0;
    min-width: 220px; /* optional: prevents blocks from getting too small */
    max-width: 300px; /* optional: for better scaling on large screens */
}

.sensor-icon {
    font-size: 2.5em;
    margin-bottom: 0.3em;
    color: #3498db;
}

.sensor-block-value {
    display: inline-block;
    min-width: 2.5em;
    padding: 0.5em 0.8em;
    background: #3498db;
    color: #fff;
    border-radius: 12px;
    font-weight: bold;
    box-shadow: 0 2px 6px #0002;
    transition: background 0.2s;
}

.iaq-disconnected {
    color: #3498db;
}

.iaq-good {
    color: #4caf50;
}
.iaq-moderate {
    color: #ffc107;
}
.iaq-bad {
    color: #f44336;
}




/* Update the sliderContainer to be positioned absolutely */
#sliderContainer {
    display: flex;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 0; /* Ensure it's above other elements */
}

#armController {
    position: absolute;
    visibility: hidden;
    display: flex;
    flex-direction: column; /* Change to column layout */
    justify-content: flex-end; /* Align to bottom */
    align-items: center; /* Center horizontally */
    z-index: 5;
    width: 100%; /* Full width */
    height: 100%; /* Full height of container */
    bottom: 0; /* Anchor to bottom */
}

.arm-controls {
    order: 2; /* Controls below the arm view */
    width: 100% !important; /* Full width */
    height: 150px; /* Reduced height */
    display: flex;
    justify-content: space-around; /* Evenly space the dot containers */
    align-items: center;
    margin-bottom: 20px; /* Space from bottom */
}

.arm-view {
    order: 1; /* Arm view above controls */
    width: 90% !important;
    height: 600px !important;
    margin-bottom: 20px; /* Space between arm view and controls */
}

#settings {
    visibility: hidden;
    width: 100%;
}

.settings-container {
    display: flex;
    flex-direction: column;
    gap: 1.5em;
}

/* Group wheel settings in a row */
.head-safe-wheel0,
.head-safe-wheel1,
.safe-wheel0,
.safe-wheel1 {
    display: inline-block;
    vertical-align: top;
    width: 48%;
    box-sizing: border-box;
}


/* Place wheels in a flex row */
.head-safe-wheel0,
.safe-wheel0 {
    margin-right: 2%;
}
.head-safe-wheel1,
.safe-wheel1 {
    margin-left: 2%;
}

/* Use a wrapper to create a row for wheels */
.safe-wheel0,
.safe-wheel1 {
    margin-bottom: 1em;
}

/* Arms: two rows, two columns */
.safe-arm0, .safe-arm1, .safe-arm2 {
    display: inline-block;
    vertical-align: top;
    width: 48%;
    box-sizing: border-box;
    margin-bottom: 1em;
}

/* Add spacing between columns */
.safe-arm0, .safe-arm2 {
    margin-right: 2%;
}
.safe-arm1, .safe-arm3 {
    margin-left: 2%;
}


.wheel-container {
    order: 1;
    width: 100%;
    justify-content: space-around;
    display: flex;
    align-items: center;
}

/* Adjust the speedController to be centered better */
#speedController {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    pointer-events: none;
    z-index: 15; /* Ensure sliders are on top */
}

input[type="range"][orient="vertical"] {
    writing-mode: vertical-lr;   /* Modern browsers */
    direction: rtl;              /* Ensures low value at the bottom, high at the top */
    width: 8vw;       /* Adjust as needed */
    height: 70vh; /* Reduced from 90vh */
    margin: 20vh 0; /* Increased from 5vh to center vertically */
    position: absolute;
    background: transparent;
    top: 0;
    pointer-events: auto;
    appearance: none;
}

input[type="range"][orient="vertical"]::-webkit-slider-runnable-track {
    height: 8px;
    background: #595959;
    border-radius: 20px;
}

input[type="range"][orient="vertical"]::-moz-range-track {
    height: 8px;
    background: #595959;
    border-radius: 20px;
}

input[type="range"][orient="vertical"]::-ms-fill-lower,
input[type="range"][orient="vertical"]::-ms-fill-upper {
    background: #595959;
    border-radius: 20px;
}

input[type="range"][orient="vertical"]::-webkit-slider-thumb {
    appearance: none;
    width: 64px;
    height: 64px;
    background: #222;
    border: 3px solid #3498db;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: border 0.2s;
}

input[type="range"][orient="vertical"]:focus::-webkit-slider-thumb {
    border: 3px solid #4caf50;
}

#speedDial0 {
    left: 10px;
}

#speedDial1 {
    right: 10px;
}


.arm {
    position: relative;
    left: 0;

    width: 100%;
}
.arm0 {
    z-index: 1;

    transform: rotate(-6deg);
}

.arm0-rotate {
    position: relative;

    height: 300px;
    width: 300px;

    top: 250px;

    bottom: auto;
    transform-origin: 270px 82px;
    transform: rotate(0deg);
}

.arm1 {
    z-index: 3;
}

.arm1-rotate {
    position: relative;
    z-index: 2;
    top: -105px;

    transform-origin: 26px 22px;
    transform: rotate(-6deg);
}

.arm2-rotate {
    position: relative;
    z-index: 2;
    left: 255px;
    top: -52px;
    transform-origin: 22px 22px;
    transform: rotate(-90deg);
}

.arm2 {
    z-index: 2;

    height: 50px !important;
    width: auto !important;
}

.dot-container {
    position: relative;
    width: 120px;
    height: 120px;
    border: 1px dashed #ccc;
    border-radius: 50%;
    pointer-events: none;
    display: inline-block;
    margin: 0 10px;
}

.draggable-dot {
    position: absolute;
    width: 50px;
    height: 50px;
    background-color: #3887be;
    border-radius: 50%;
    cursor: move;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
}


.arm0-dot-container, .arm1-dot-container, .arm2-dot-container, .arm3-dot-container {
    top: auto;
}


.status_history {
    display: flex;
}


.entry {
    width: 90%;
    background-color: black;
    padding: 1px 5px 5px 20px;
    border-radius: 15px;
    margin-bottom: 15px;
    margin-top: 10px
}


#wheel0, #wheel1 {
    pointer-events: auto;
}

.joystick {
    position: absolute;
    bottom: 3em;
    left: 3em;
    width: 140px;
    height: 140px;
    z-index: 20;
}

.joystick-base {
    position: relative;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 60%, #555 0%, #333 40%, #222 70%);
    border: 6px solid #666;
    border-radius: 50%;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5);
}

.joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 50px;
    background: linear-gradient(to top, #888, #ccc);
    border-radius: 3px 3px 10px 10px;
    transform-origin: center bottom;
    transform:
            translate(-50%, 0)
            rotate(var(--angle, 0deg));
}

.joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    background: radial-gradient(circle, #5aaaff 0%, #1e88e5 70%);
    border: 4px solid #fff;
    border-radius: 50%;
    box-shadow:
            0 6px 16px rgba(0,0,0,0.6),
            inset 0 2px 4px rgba(255,255,255,0.3);
    transform:
            translate(-50%, -50%)
            translate(
                    calc(var(--magnitude, 0) * 35px * cos(var(--angle, 0deg))),
                    calc(var(--magnitude, 0) * 35px * sin(var(--angle, 0deg)))
            );
    transition: transform 0.08s ease-out;
}

.joystick.active .joystick-knob { transition: none; }

/* Responsive */
@media (orientation: landscape) {
    .joystick { left: 2vw; bottom: 2vw; width: clamp(120px, 18vw, 160px); height: 140px; }
}
@media (orientation: portrait) {
    .joystick { right: 2vw; left: auto; bottom: 2vw; }
}


.throttle-slider {
    position: absolute;
    top: 50%;
    right: 2em;
    height: 200px;
    width: 50px;
    z-index: 20;
    transform: translateY(-50%);
}

.slider-track {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #444 0%, #222 100%);
    border: 4px solid #666;
    border-radius: 25px;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5);
}

.slider-thumb {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    width: 42px;
    height: 42px;
    margin: 0 auto;
    background: radial-gradient(circle, #ff6b35 0%, #e55a2b 70%);
    border: 4px solid #fff;
    border-radius: 50%;
    box-shadow: 0 6px 16px rgba(0,0,0,0.6);
    cursor: ns-resize;
    transition: top 0.1s ease-out;
}

.throttle-slider.active .slider-thumb {
    transition: none;
}

/* Responsive */
@media (orientation: landscape) {
    .throttle-slider { right: 2vw; height: clamp(160px, 25vh, 220px); }
}
@media (orientation: portrait) {
    .throttle-slider { right: 2vw; left: auto; }
}
