:root {
  --bg: #0d131c;
  --bg-soft: #121b26;
  --panel: #17222f;
  --panel-2: #1d2a3a;
  --line: #26374a;
  --text: #e8eef5;
  --muted: #8ba0b6;
  --accent: #21a1ff;
  --accent-2: #18c98b;
  --danger: #ff5a4e;
  --warn: #ffb020;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(33, 161, 255, .14), transparent 60%),
    radial-gradient(900px 420px at 110% 10%, rgba(24, 201, 139, .1), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: rgba(16, 24, 35, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-right: auto;
}

.brand h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: .5px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
}

.seg button.on {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.seg button:not(.on):hover {
  color: var(--text);
}

.connect-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 11px;
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
}

.connect-btn:hover {
  border-color: var(--accent);
}

.connect-btn .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #5c708a;
  box-shadow: 0 0 0 3px rgba(92, 112, 138, .18);
}

.connect-btn.connected .dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(24, 201, 139, .18);
}

.connect-btn.busy .dot {
  background: var(--warn);
  animation: pulse 1s infinite;
}

.connect-btn.flash {
  animation: flash 1.1s ease-in-out 2;
  border-color: var(--warn);
}

@keyframes flash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 176, 32, 0); }
  50% { box-shadow: 0 0 0 6px rgba(255, 176, 32, .35); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 18px;
  background: rgba(16, 24, 35, .6);
  border-bottom: 1px solid var(--line);
}

.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 11px 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tabs button.on {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
}

.stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #f4f7fa;
}

.stage iframe.hidden {
  visibility: hidden;
  pointer-events: none;
}

.banner {
  display: none;
  padding: 9px 18px;
  font-size: 13px;
  background: rgba(255, 176, 32, .12);
  border-bottom: 1px solid rgba(255, 176, 32, .3);
  color: #ffd27a;
}

.banner.show {
  display: block;
}

/* ---------- remote page ---------- */

.remote {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 16px 40px;
}

.page-head {
  width: min(760px, 100%);
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.page-head a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page-head a:hover {
  color: var(--text);
}

.page-head .spacer {
  margin-left: auto;
}

.remote-body {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 18px;
}

@media (max-width: 820px) {
  .remote-body {
    grid-template-columns: 1fr;
  }
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.card h2 {
  margin: 0 0 4px;
  font-size: 15px;
  letter-spacing: .3px;
}

.card .hint {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  grid-template-rows: repeat(3, 92px);
  gap: 10px;
  justify-content: center;
}

.pad button {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform .05s, background .12s;
}

.pad button:hover {
  background: #243447;
}

.pad button.active,
.pad button:active {
  background: var(--accent);
  transform: scale(.96);
}

.pad .stop {
  grid-column: 2;
  grid-row: 2;
  background: rgba(255, 90, 78, .14);
  border-color: rgba(255, 90, 78, .45);
  color: #ff8c82;
  font-size: 24px;
}

.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 3; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row + .row {
  margin-top: 14px;
}

.row .label {
  color: var(--muted);
  font-size: 13px;
  width: 52px;
}

.speed-seg button {
  width: 44px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chip i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, .25);
}

.chip:hover {
  border-color: var(--accent);
}

.big-stop {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 90, 78, .5);
  background: rgba(255, 90, 78, .16);
  color: #ff9d95;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}

.big-stop:hover {
  background: rgba(255, 90, 78, .26);
}

.log {
  margin-top: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
  word-break: break-all;
}

.status-line {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.status-line b {
  color: var(--accent-2);
  font-weight: 600;
}

.status-line.off b {
  color: var(--danger);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
}

.motor-test {
  display: flex;
  gap: 10px;
}

.motor-test button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 11px;
  padding: 12px 0;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.motor-test button:hover {
  background: #243447;
}

.motor-test button:active {
  background: var(--accent);
}

.note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  margin-top: 10px;
}

/* ---------- multi-mode remote ---------- */

.hidden {
  display: none !important;
}

.remote-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.remote-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.robot-card {
  padding: 14px 16px;
}

.robot-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.robot-line .status-line {
  margin-bottom: 0;
}

.series-badge {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}

.series-badge.detected {
  color: var(--accent-2);
  border-color: rgba(24, 201, 139, .5);
  background: rgba(24, 201, 139, .08);
}

.card-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.card-pick button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.card-pick button:hover {
  border-color: var(--accent);
}

.card-pick button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}

.mode-tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 4px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
}

.mode-tabs button:hover {
  color: var(--text);
}

.mode-tabs button.on {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.sticks {
  display: flex;
  gap: 22px;
  justify-content: center;
  flex-wrap: wrap;
}

.stick-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.stick {
  position: relative;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #223447, #16212e 70%);
  border: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stick.active {
  cursor: grabbing;
  border-color: rgba(33, 161, 255, .55);
}

.stick.small {
  width: 200px;
  height: 200px;
}

.ring {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px dashed rgba(139, 160, 182, .3);
  pointer-events: none;
}

.ring.r1 {
  width: 30%;
  height: 30%;
  border-style: solid;
  border-color: rgba(33, 161, 255, .3);
}

.ring.r2 {
  width: 70%;
  height: 70%;
}

.stick-label {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, #4aa6ff, #1668c9 72%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 0 0 2px rgba(255, 255, 255, .14);
  pointer-events: none;
}

.stick.active .knob {
  background: radial-gradient(circle at 40% 35%, #6fb9ff, #1d7ce0 72%);
}

.stick.small .knob {
  width: 56px;
  height: 56px;
}

.stick-toggles {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.mini-hint {
  color: var(--muted);
  font-size: 12px;
}

.cmd-line {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  min-height: 15px;
  text-align: center;
  word-break: break-all;
}

.throttles {
  display: flex;
  gap: 34px;
  justify-content: center;
  flex-wrap: wrap;
}

.throttle-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.throttle {
  position: relative;
  width: 96px;
  height: 240px;
  border-radius: 20px;
  background: linear-gradient(180deg, #1b2838, #14202d);
  border: 1px solid var(--line);
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.throttle.active {
  border-color: rgba(33, 161, 255, .55);
}

.center-line {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 1px;
  background: rgba(139, 160, 182, .4);
}

.thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, #4aa6ff, #1668c9 72%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 0 0 2px rgba(255, 255, 255, .14);
  pointer-events: none;
}

.gyro-meter {
  position: relative;
  margin-top: 14px;
  height: 160px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(139, 160, 182, .14), rgba(139, 160, 182, .14)) center / 1px 70% no-repeat,
    linear-gradient(rgba(139, 160, 182, .14), rgba(139, 160, 182, .14)) center / 70% 1px no-repeat,
    radial-gradient(circle at center, rgba(33, 161, 255, .07), transparent 70%);
}

.gyro-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-2);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 12px rgba(24, 201, 139, .7);
}

.pill {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
}

.pill:hover {
  border-color: var(--accent);
}

.pill.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.pill.ghost {
  background: transparent;
}

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

.wheel-grid button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 12px;
  padding: 22px 0;
  font-size: 14px;
  cursor: pointer;
}

.wheel-grid button:hover {
  background: #243447;
}

.wheel-grid button:active {
  background: var(--accent);
}

.adv {
  margin-top: 12px;
}

.adv summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

#path-canvas {
  display: block;
  width: 100%;
  height: 320px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #101a26;
  touch-action: none;
  cursor: crosshair;
}

@media (max-width: 560px) {
  .stick {
    width: 190px;
    height: 190px;
  }

  .stick.small {
    width: 170px;
    height: 170px;
  }

  .wheel-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---- Build guide entry & shell overlay ---- */

.build-entry {
  margin-top: 12px;
  width: 100%;
}

.build-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  background: #fff;
}

.build-overlay.show {
  display: block;
}

.build-overlay iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

@media (max-width: 560px) {
  .build-overlay {
    z-index: 120;
  }
}
