/* ==========================================================================
   Team14 Mecanum BLE Controller — Stylesheet
   ========================================================================== */

:root {
  --bg: #000000;
  --panel: #111111;
  --border: #3a3a3a;
  --text: #ffffff;
  --muted: #888888;
  --status-connected: #22c55e;
  --status-connecting: #f59e0b;
  --status-disconnected: #ef4444;
  --thumb-size: clamp(40px, 12dvh, 52px);
}

/* ==================== Reset & Base Layout ==================== */
* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  touch-action: none;
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding: max(8px, env(safe-area-inset-top))
           max(10px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom))
           max(10px, env(safe-area-inset-left));
  gap: 6px;
}

/* ==================== Top Telemetry & Mode Bar ==================== */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar::-webkit-scrollbar {
  display: none;
}

.group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

button {
  background: #000000;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  outline: none;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.08s ease;
}

button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

button.primary,
button.active {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
}

button.danger {
  background: #000000;
  color: #ffffff;
  border: 1px solid #ffffff;
}

button:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ==================== Dynamic PWM Ceiling Control ==================== */
.pwm-ctrl {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: #000000;
}

.pwm-ctrl button {
  border: none;
  border-radius: 0;
  padding: 6px 8px;
}

.pwm-step {
  min-width: 26px;
  font-size: 13px;
  line-height: 1;
}

.pwm-val {
  border-left: 1px solid var(--border) !important;
  border-right: 1px solid var(--border) !important;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
}

.pwm-val.pwm-low {
  color: var(--muted);
}

.pwm-val.pwm-high {
  color: var(--status-connecting);
}

/* ==================== Connection Status Pill ==================== */
.control-area {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.conn-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px 0 4px;
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--status-disconnected);
  color: var(--status-disconnected);
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.conn-status.connected {
  color: var(--status-connected);
  border-color: var(--status-connected);
}

.conn-status.disconnected {
  color: var(--status-disconnected);
  border-color: var(--status-disconnected);
}

.conn-status.connecting {
  color: var(--status-connecting);
  border-color: var(--status-connecting);
}

/* ==================== Control Zones, Sliders & Joystick ==================== */
.main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
  min-width: 0;
}

.label {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  line-height: 1;
}

.track {
  position: relative;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  touch-action: none;
  transition: opacity 0.2s ease;
}

.track-v {
  width: clamp(54px, 14dvh, 70px);
  height: clamp(130px, 50dvh, 200px);
}

.track-h {
  width: clamp(130px, 32vw, 210px);
  height: clamp(50px, 14dvh, 66px);
}

.joy-pad {
  position: relative;
  width: clamp(140px, 50dvh, 200px);
  height: clamp(140px, 50dvh, 200px);
  background: radial-gradient(circle, #181818 60%, #050505 100%);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  touch-action: none;
  transition: opacity 0.2s ease;
}

.thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--thumb-size);
  height: var(--thumb-size);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
  will-change: transform;
}

.disabled {
  opacity: 0.28;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

/* ==================== Center Action Buttons ==================== */
.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.act-btn {
  width: clamp(82px, 15vw, 108px);
  height: clamp(38px, 14dvh, 52px);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: var(--panel);
  color: #ffffff;
  border: 1.5px solid var(--border);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.act-btn.pressed {
  background: #ffffff;
  color: #000000;
  border-color: #ffffff;
  transform: scale(0.96);
}

.estop-btn {
  background: #1a0505;
  color: var(--status-disconnected);
  border-color: var(--status-disconnected);
}

.estop-btn.pressed,
.estop-btn:active {
  background: var(--status-disconnected);
  color: #ffffff;
  border-color: var(--status-disconnected);
  transform: scale(0.96);
}

.right-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3dvh, 18px);
}
