:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #0d1117;
  color: #edf2f7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.sim-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  min-height: 100vh;
}

.viewport {
  position: relative;
  min-height: 100vh;
  background: #0d1117;
}

#simCanvas {
  display: block;
  width: 100%;
  height: 100vh;
}

.hud {
  position: absolute;
  top: 18px;
  left: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, auto));
  gap: 8px;
  pointer-events: none;
}

.hud div,
.status {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(13, 17, 23, 0.78);
  backdrop-filter: blur(14px);
}

.hud div {
  padding: 8px 10px;
}

.hud span {
  display: block;
  margin-bottom: 2px;
  color: #93a4b7;
  font-size: 11px;
  letter-spacing: 0;
}

.hud strong {
  display: block;
  min-width: 72px;
  font-size: 16px;
}

.status {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-width: 132px;
  padding: 9px 12px;
  text-align: center;
  color: #cfe2ff;
}

.touch-controls {
  display: none;
}

.mobile-panel-toggle {
  display: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100vh;
  padding: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  background: #121820;
  overflow-y: auto;
}

.panel-head {
  display: grid;
  gap: 6px;
}

.brand {
  width: max-content;
  color: #7fc7ff;
  text-decoration: none;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.1;
}

.build-source {
  color: #9fb0c5;
  font-size: 12px;
  line-height: 1.35;
}

h2 {
  color: #d9e6f5;
  font-size: 14px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: #1f6feb;
  color: white;
  cursor: pointer;
  font-weight: 700;
}

button + button {
  background: #243242;
}

.group {
  display: grid;
  gap: 9px;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: #151d27;
}

label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  color: #bccadd;
  font-size: 13px;
}

input[type="range"] {
  grid-column: 1 / 3;
  width: 100%;
  accent-color: #7fc7ff;
}

select {
  grid-column: 1 / 3;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: #0f151d;
  color: #edf2f7;
}

.is-hidden {
  display: none;
}

output {
  min-width: 62px;
  text-align: right;
  color: #edf2f7;
  font-variant-numeric: tabular-nums;
}

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

.battery-line {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 8px;
  align-items: center;
}

.battery-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  color: #aebed0;
  font-size: 12px;
}

.battery-stats strong {
  display: block;
  color: #edf2f7;
  font-variant-numeric: tabular-nums;
}

meter {
  width: 100%;
  height: 20px;
}

.keys {
  color: #aebed0;
  font-size: 12px;
  line-height: 1.38;
}

kbd {
  display: inline-grid;
  min-width: 23px;
  min-height: 21px;
  margin: 0 2px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: #0f151d;
  color: #f4f8ff;
  font-size: 11px;
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .sim-shell {
    display: block;
    min-height: 100dvh;
  }

  .viewport,
  #simCanvas {
    min-height: 100dvh;
    height: 100dvh;
  }

  .panel {
    position: fixed;
    right: 10px;
    bottom: 10px;
    z-index: 8;
    width: min(300px, calc(100vw - 20px));
    max-height: 38dvh;
    min-height: auto;
    padding: 10px;
    gap: 8px;
    border-left: 0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: rgba(18, 24, 32, 0.88);
    backdrop-filter: blur(14px);
    overflow-y: auto;
  }

  .panel.is-collapsed {
    display: none;
  }

  .mobile-panel-toggle {
    position: fixed;
    right: 12px;
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 9;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 999px;
    padding: 9px 13px;
    background: rgba(31, 111, 235, 0.88);
    color: #ffffff;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    font-size: 13px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(92px, auto));
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  .hud div {
    padding: 6px 8px;
  }

  .status {
    right: 10px;
    top: 10px;
    bottom: auto;
    min-width: 96px;
    padding: 7px 9px;
    font-size: 12px;
  }

  .panel-head,
  .keys {
    display: none;
  }

  .group {
    padding: 9px;
  }

  .touch-controls {
    position: fixed;
    inset: 0;
    z-index: 7;
    display: block;
    pointer-events: none;
  }

  .touch-cluster {
    position: absolute;
    bottom: 18px;
    display: grid;
    gap: 10px;
    justify-items: center;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }

  .touch-cluster-left {
    left: 14px;
  }

  .touch-cluster-right {
    right: 14px;
    bottom: 76px;
  }

  .touch-cluster div {
    display: flex;
    gap: 10px;
  }

  .touch-cluster button {
    width: 54px;
    height: 54px;
    min-height: 54px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(15, 21, 29, 0.68);
    color: #ffffff;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    font-size: 24px;
    line-height: 1;
  }

  .touch-cluster button:active {
    background: rgba(31, 111, 235, 0.82);
    transform: scale(0.96);
  }
}

@media (max-width: 620px) {
  .panel {
    left: 10px;
    right: 10px;
    width: auto;
    max-height: 30dvh;
  }

  .mobile-panel-toggle {
    right: 50%;
    transform: translateX(50%);
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .control-row,
  .telemetry,
  .group:nth-of-type(2) label:nth-of-type(n + 3) {
    display: none;
  }

  .touch-cluster {
    bottom: max(64px, env(safe-area-inset-bottom));
  }

  .touch-cluster button {
    width: 50px;
    height: 50px;
    min-height: 50px;
  }
}
