:root { color-scheme: light; --nav-h: 48px; --font-scale: 1; }
html { font-size: 16px; font-size: calc(16px * var(--font-scale)); }
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
/* Ensure hidden attribute always hides elements even if other display rules apply */
[hidden] { display: none !important; }
/* Collapse layout cleanly when map is hidden via toggle */
.map-hidden #mapwrapper { display: none !important; }
.map-hidden .map-toggle { margin: 0 0 6px; }
.joystick-hidden #joystick-section { display: none !important; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 0; background: #ffffff; color: #111111; }
body.admin-mode { background: #fff5f5; }
.container { max-width: 920px; margin: 0 auto; padding: 1rem; }
/* Robot view app layout */
.robot-app { max-width: none; padding: 0; min-height: 100vh; display: grid; grid-template-rows: auto auto 1fr; }
.topbar { padding: 0.5rem 1rem; border-bottom: 1px solid rgba(127,127,127,0.25); }
.topbar .title { font-size: 1.1rem; margin: 0; }
.topbar .map-switcher { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.topbar .map-switcher .map-label { opacity: 0.8; font-size: 0.95rem; }
.topbar .map-switcher select { max-width: 40vw; }
.topbar .map-switcher button { padding: 0.2rem 0.5rem; min-width: 2rem; }
.content { padding: 0.5rem 1rem; }
.bottom-nav { position: sticky; top: 0; display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: stretch; height: var(--nav-h); border-bottom: 1px solid rgba(127,127,127,0.25); background: rgba(255,255,255,0.9); backdrop-filter: blur(3px); z-index: 10; }
.bottom-nav button { margin: 0; padding: 0 0.75rem; border: 0; background: transparent; font-weight: 600; height: 100%; display: flex; align-items: center; justify-content: center; }
.bottom-nav button.active { background: rgba(127,127,127,0.15); }
.fab { position: fixed; right: 16px; bottom: 70px; padding: 0.9rem 1.2rem; border-radius: 24px; border: 0; color: white; background: #007aff; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
label { display: block; margin: 0.5rem 0; }
input { padding: 0.5rem; width: 100%; max-width: 420px; }
button { padding: 0.6rem 1rem; margin: 0.25rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.list { list-style: none; padding: 0; }
.list li { padding: 0.5rem 0; }
.vendor-group { padding: 0.6rem 0; }
.group-header { display: block; font-weight: 600; margin: 0.4rem 0 0.2rem; }
.group-header.vendor { font-size: 1.05rem; }
.group-header.user { font-weight: 500; font-size: 0.95rem; margin-left: 0.75rem; }
.user-group .robot-sublist { margin-left: 1.25rem; }
.user-group .robot-sublist li { padding: 0.35rem 0; }
.error { color: #c00; }
.note { background: rgba(127,127,127,0.15); padding: 0.75rem; border-radius: 6px; }
.note.telemetry-offline { color: #888; }
.hint { opacity: 0.7; font-size: 0.9rem; }
.admin-badge { color: #b45309; background: #FEF3C7; border: 1px solid #F59E0B; padding: 2px 6px; border-radius: 4px; font-weight: 700; }
.map { height: 300px; background: rgba(127,127,127,0.12); display: flex; align-items: center; justify-content: center; border: 1px solid rgba(127,127,127,0.25); }
.zoom-controls { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: calc(16px + env(safe-area-inset-left, 0px)); display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,0.85); box-shadow: 0 2px 8px rgba(0,0,0,0.15); z-index: 2000; backdrop-filter: blur(6px); font-size: 0.9rem; }
.zoom-controls button { padding: 0.3rem 0.6rem; min-width: 2.1rem; }
.zoom-controls span { min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.zoom-spacer { height: 80px; }
@media (max-width: 600px) {
  .zoom-controls { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: calc(12px + env(safe-area-inset-left, 0px)); font-size: 0.85rem; gap: 4px; }
  .zoom-controls button { padding: 0.25rem 0.5rem; min-width: 2rem; }
  .zoom-spacer { height: 110px; }
}

/* Map editor layout (legacy-compatible) */
#mapwrapper { position: relative; height: 420px; border: 1px solid rgba(127,127,127,0.25); margin-bottom: 16px; }
#mapwrapper canvas#map { width: 100%; height: 100%; display: block; background: #ffffff; }
#mapbuttonwrapper { position: absolute; top: 80px; right: 8px; left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#mapbuttonwrapper .sqbutton {
  min-width: 50px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
  touch-action: manipulation;
}
#mapbuttonwrapper .sqbutton:not(#mapstatic) {
  font-size: 1.2rem;
}
.sqbutton { padding: 0.2rem 0.5rem; }
.button-icon { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.button-icon .icon { font-size: 1.1em; font-weight: 600; line-height: 1; }
.map-toolbar, .plan-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.plan-toolbar label { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.plan-toolbar label span { font-weight: 700; }
.plan-toolbar input[type="range"] { min-width: 140px; width: 180px; }
.pattern-label { padding: 2px 8px; border: 1px solid rgba(127,127,127,0.25); border-radius: 999px; font-size: 0.9rem; background: rgba(0,0,0,0.03); }
.sqbutton.active { background: rgba(127,127,127,0.15); }
.mode-label { padding: 2px 8px; border: 1px solid rgba(127,127,127,0.25); border-radius: 999px; font-size: 0.9rem; background: rgba(0,0,0,0.03); }
.action-bar, .record-bar, .plan-bar { position: sticky; top: var(--nav-h); z-index: 9; padding: 6px; background: rgba(255,255,255,0.95); border-bottom: 1px solid rgba(127,127,127,0.25); display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.record-bar .button-icon { width: 100%; }
.map-toggle { display: flex; justify-content: flex-end; margin: 6px 0; }
.map-name-bar { margin: 6px 0; font-weight: 600; }
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px 18px;
  align-items: center;
}
.controls-grid label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}
.controls-grid label span { font-weight: 700; }
.controls-grid input[type="range"] {
  flex: 1;
  min-width: 140px;
}
.controls-grid .sqbutton { justify-self: start; }
.controls-checkbox {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  grid-column: span 2;
}
.controls-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.controls-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
}
.controls-checkbox .hint {
  font-weight: 400;
}
.dev-toolbar { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.kb-toggle { margin-left: auto; font-size: 0.9rem; opacity: 0.8; }
.status-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0; }
.status-bar { margin: 8px 0 10px; }
.status-bar.offline { color: #777; }
.status-bar.offline strong { color: #555; }
.op-sched { margin-left: 6px; }
.op-sched.active { color: #007aff; opacity: 1; }
.conn { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: #c00; box-shadow: 0 0 0 2px rgba(0,0,0,0.05) inset; }
.conn.online { background: #0a0; }
.conn.offline { background: #c00; }
.conn-text { margin-left: 6px; font-size: 0.9rem; opacity: 0.85; }

/* Joystick */
.joystick-section { margin: 10px 0 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.joypad { width: 160px; height: 160px; border-radius: 50%; border: 2px solid rgba(0,0,0,0.2); background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0.05), rgba(0,0,0,0.02)); position: relative; touch-action: none; }
.joypad::after { content: ''; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin-left: -3px; margin-top: -3px; background: rgba(0,0,0,0.35); border-radius: 50%; }
.joy-thumb { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin-left: -22px; margin-top: -22px; border-radius: 50%; background: rgba(0,0,0,0.08); border: 2px solid rgba(0,0,0,0.25); box-shadow: 0 2px 8px rgba(0,0,0,0.15); transition: transform 80ms ease-out; }
.joy-hint { opacity: 0.7; font-size: 0.9rem; }
.joy-readout { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; opacity: 0.9; }

/* Give iOS users larger interactive targets without affecting map controls */
@supports (-webkit-touch-callout: none) and (-webkit-overflow-scrolling: touch) {
  button:not(.sqbutton) {
    font-size: 1.05rem;
    padding: 0.75rem 1.25rem;
    min-height: 44px;
  }

  .topbar .map-switcher button {
    padding: 0.4rem 0.75rem;
    min-height: 40px;
  }

  .bottom-nav {
    --nav-h: 60px;
  }

  .bottom-nav button {
    font-size: 1.05rem;
  }

  .fab {
    padding: 1rem 1.4rem;
  }
}

/* Small screens */
/* Always use slightly taller tabs on small screens */
@media (max-width: 600px) {
  :root { --nav-h: 56px; }
  #mapwrapper { height: 55vh; margin-bottom: 80px; }
  #mapbuttonwrapper { top: 96px; }
  .controls-checkbox { grid-column: span 1; }
  .sqbutton { padding: 0.3rem 0.6rem; font-size: 0.9rem; }
  /* Add a small scroll gutter on right side of map to allow page scroll on touch devices */
  #mapwrapper::after {
    content: '';
    position: absolute;
    right: 0;
    top: 140px; /* leave map controls tappable */
    bottom: 0;
    width: 28px; /* scroll handle width */
    background: transparent; /* invisible gutter */
    touch-action: pan-y; /* allow vertical scroll */
  }
}

/* Hide duplicate controls in toolbars since we have top bars */
.operate-controls { display: none; }
#add-point, #remove-last, #rec-stop { display: none; }
#calc-map { display: none; }
.plan-bar { grid-template-columns: 1fr; }
