* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fff;
  color: #222;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* --- Connection Panel --- */

.connection-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #ddd;
  flex-wrap: wrap;
  justify-content: center;
}

.connection-panel label {
  font-size: 14px;
  color: #555;
}

.connection-panel input {
  border: 1px solid #ccc;
  color: #222;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  width: 140px;
  background: #fff;
}

.connection-panel input:focus {
  outline: none;
  border-color: #222;
}

.connection-panel button {
  padding: 6px 14px;
  border: 1px solid #222;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  background: #fff;
  color: #222;
  transition: background 0.15s;
}

.connection-panel button:hover {
  background: #f0f0f0;
}

.connection-panel button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Status --- */

.status {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
}

.status.connected {
  background: #222;
  color: #fff;
}

.status.disconnected {
  background: #eee;
  color: #999;
}

/* --- Mode Toggle --- */

.mode-bar {
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 6px 12px;
  border-bottom: 1px solid #ddd;
}

.mode-btn {
  padding: 6px 20px;
  border: 1px solid #ccc;
  background: #fff;
  color: #555;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.mode-btn:first-child {
  border-radius: 4px 0 0 4px;
}

.mode-btn:last-child {
  border-radius: 0 4px 4px 0;
  border-left: none;
}

.mode-btn.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

/* --- Main Controller Area --- */

.controller-area {
  display: flex;
  height: calc(100vh - 90px);
  align-items: center;
  justify-content: space-around;
  padding: 16px;
  gap: 16px;
}

/* --- Joystick --- */

.joystick-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.joystick-label {
  font-size: 13px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.joystick {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: #f5f5f5;
  border: 2px solid #ccc;
  position: relative;
  touch-action: none;
}

.joystick-knob {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #222;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -30px;
  margin-left: -30px;
  transition: transform 0.05s ease-out;
  pointer-events: none;
}

/* --- Center Panel --- */

.center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 160px;
}

.values-display {
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 13px;
  line-height: 1.8;
  text-align: left;
  width: 100%;
}

.values-display .label {
  color: #888;
}

.values-display .value {
  color: #222;
  font-weight: 700;
  font-family: "Courier New", monospace;
}

.packet-display {
  background: #f5f5f5;
  padding: 8px 12px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: #222;
  word-break: break-all;
  width: 100%;
  text-align: center;
  border: 1px solid #ddd;
}

/* --- Emergency Stop --- */

#stop-btn {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #d00;
  color: #d00;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.1s;
  line-height: 1.2;
}

#stop-btn:active {
  background: #d00;
  color: #fff;
}

/* --- Accelerometer Mode --- */

.accel-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 90px);
  padding: 16px;
  gap: 16px;
}

.accel-visual {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background: #f5f5f5;
  position: relative;
}

.accel-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #222;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -15px;
  margin-left: -15px;
  transition: transform 0.08s ease-out;
  pointer-events: none;
}

.accel-crosshair-h,
.accel-crosshair-v {
  position: absolute;
  background: #ddd;
}

.accel-crosshair-h {
  width: 100%;
  height: 1px;
  top: 50%;
  left: 0;
}

.accel-crosshair-v {
  width: 1px;
  height: 100%;
  top: 0;
  left: 50%;
}

.accel-info {
  font-size: 13px;
  color: #888;
  text-align: center;
  line-height: 1.6;
}

#accel-enable-btn {
  padding: 10px 24px;
  border: 1px solid #222;
  border-radius: 4px;
  background: #fff;
  color: #222;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#accel-enable-btn:hover {
  background: #f0f0f0;
}

.hidden {
  display: none !important;
}

/* --- Responsive --- */

@media (max-width: 700px) {
  .controller-area {
    padding: 8px;
    gap: 8px;
  }

  .joystick {
    width: 140px;
    height: 140px;
  }

  .joystick-knob {
    width: 50px;
    height: 50px;
    margin-top: -25px;
    margin-left: -25px;
  }

  .center-panel {
    min-width: 100px;
  }

  #stop-btn {
    width: 75px;
    height: 75px;
    font-size: 12px;
  }

  .values-display {
    font-size: 11px;
    padding: 8px;
  }

  .packet-display {
    font-size: 10px;
  }

  .accel-visual {
    width: 160px;
    height: 160px;
  }
}

@media (max-width: 480px) {
  .connection-panel {
    padding: 6px 8px;
    gap: 4px;
  }

  .connection-panel input {
    width: 100px;
    font-size: 12px;
  }

  .connection-panel button {
    padding: 4px 10px;
    font-size: 12px;
  }

  .joystick {
    width: 110px;
    height: 110px;
  }

  .joystick-knob {
    width: 40px;
    height: 40px;
    margin-top: -20px;
    margin-left: -20px;
  }

  #stop-btn {
    width: 65px;
    height: 65px;
    font-size: 10px;
  }

  .accel-visual {
    width: 130px;
    height: 130px;
  }

  .accel-dot {
    width: 24px;
    height: 24px;
    margin-top: -12px;
    margin-left: -12px;
  }
}
