:root {
  --bg: #000;
  --panel: #151a24;
  --panel-2: #1c2330;
  --line: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #4f8ef7;
  --good: #3ecf8e;
  --warn: #f7b64f;
  --bad: #f75f5f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

/* ---------- centered card (code gate, admin login) ---------- */

.center-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.card h1 {
  margin: 0 0 26px;
  font-size: 26px;
  letter-spacing: 0.3px;
}

.card .sub {
  color: var(--muted);
  margin: 0 0 26px;
  font-size: 15px;
}

.code-input {
  width: 100%;
  text-align: center;
  font-size: 42px;
  letter-spacing: 18px;
  text-transform: uppercase;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 14px 0 14px 18px;
  border-radius: 12px;
}

.error {
  color: var(--bad);
  min-height: 22px;
  margin-top: 14px;
  font-size: 14px;
}

/* Preview mirrors the robot's screen: portrait 3:4, center-cropped. */
#previewWrap {
  position: relative;
  width: 240px;
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

/* Knocking state on the join button, and the dissolve on acceptance. */
.primary.knocking-btn {
  background: #8b5e34;
  cursor: default;
}

.primary.knocking-btn:disabled {
  opacity: 1;
}

#preflight .card > *,
.preflight-cols > * {
  transition: opacity 0.35s;
}

#preflight.dissolve .card > *:not(.preflight-cols),
#preflight.dissolve .preflight-cols > *:not(#previewWrap) {
  opacity: 0;
}

#preflightVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#micMeter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 34px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
}

.primary {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 12px 22px;
  font-weight: 600;
  width: 100%;
  margin-top: 16px;
}

.primary:disabled {
  opacity: 0.4;
  cursor: default;
}

/* The knock button is green (the brown knocking state still wins). */
#joinBtn:not(.knocking-btn) {
  background: var(--good);
}

/* Stacked (mobile) join screen: breathing room under the preview. */
.preflight-right > .field:first-child {
  margin-top: 14px;
}

/* Desktop join screen: preview on the left, controls on the right. */
@media (min-width: 760px) {
  #preflight .card {
    max-width: 780px;
  }

  .preflight-cols {
    display: flex;
    gap: 24px;
    text-align: left;
  }

  /* The preview spans the full column: top level with "Your name", bottom
     level with the last button. */
  .preflight-cols #previewWrap {
    width: 300px;
    flex: 0 0 auto;
    align-self: stretch;
    aspect-ratio: auto;
    margin: 0;
  }

  .preflight-right {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  /* The preview's top edge lines up with the top of "Your name". */
  .preflight-right > .field:first-child {
    margin-top: 0;
  }

  /* Knock rides the bottom edge, level with the preview. */
  .preflight-right #joinBtn {
    margin-top: auto;
  }

  .preflight-right #robotRow {
    margin-bottom: 16px;
  }
}

/* ---------- driver cockpit ---------- */

#cockpit {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#remoteVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

#remoteVideo.downview {
  transform: rotate(180deg);
}

/* Down-camera floor apron (multicam iPads): the floor feed lies down into
   the bottom of the view, fading out toward its far edge. */
#floorWrap {
  position: absolute;
  left: 50%;
  bottom: -3vh;
  width: min(58vw, 66vh);
  aspect-ratio: 4 / 5;
  transform: translateX(-50%);
  perspective: 750px;
  pointer-events: none;
  z-index: 3;
  -webkit-mask-image: linear-gradient(to bottom, transparent 4%, #000 46%);
  mask-image: linear-gradient(to bottom, transparent 4%, #000 46%);
}

#floorTilt {
  width: 100%;
  height: 100%;
  transform-origin: 50% 100%;
  transform: rotateX(52deg);
}

#downVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Robot mirrors the down camera at the source; this vertical flip makes
     the top of the frame point forward — same as the single-cam downview. */
  transform: rotate(180deg);
  border-radius: 10px;
}

/* Self-view: a 3:4 portrait crop matching what the robot's iPad displays. */
#selfView {
  position: absolute;
  top: 68px;
  right: 16px;
  width: 210px;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  overflow: hidden;
  z-index: 5;
}

#localVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#selfResize {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 26px;
  height: 26px;
  cursor: nesw-resize;
  z-index: 6;
}

#selfResize::after {
  content: "";
  position: absolute;
  left: 5px;
  bottom: 5px;
  width: 10px;
  height: 10px;
  border-left: 2px solid rgba(255, 255, 255, 0.65);
  border-bottom: 2px solid rgba(255, 255, 255, 0.65);
  border-bottom-left-radius: 3px;
}

@media (max-width: 900px) {
  #selfView {
    width: 110px;
  }
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(rgba(0, 0, 0, 0.65), transparent);
  z-index: 6;
  font-size: 14px;
}

.hud .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

.hud .spacer {
  flex: 1;
}

.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.pill.good { color: var(--good); }

#joystick {
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  z-index: 7;
}

#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transform: translate(-50%, -50%);
  transition: transform 0.08s;
}

#turboBtn {
  position: absolute;
  left: 190px;
  bottom: 72px;
  z-index: 7;
}

.controls {
  position: absolute;
  right: 20px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 7;
}

/* Collapsible button groups: the flyout slides out sideways from its
   group button — left on desktop, right on mobile. */
.ctl-group {
  position: relative;
  display: flex;
}

.group-flyout {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(10px);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
}

.ctl-group.open .group-flyout {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}

/* Saved soundboard buttons: emoji chips, horizontally scrollable. */
#soundButtons {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(46vw, 430px);
  overflow-x: auto;
  scrollbar-width: thin;
}

#soundButtons .ctl {
  flex: 0 0 auto;
  font-size: 26px;
}

.ctl {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctl:active {
  background: rgba(79, 142, 247, 0.6);
}

.ctl .icon {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Line icons inline with text (battery, bolt, door, bell…). */
.icon-inline {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  vertical-align: -0.12em;
}

.icon-inline.filled {
  fill: currentColor;
  stroke: none;
}

.ctl .icon.filled,
.ctl .icon.filled use {
  fill: currentColor;
  stroke: none;
}

.ctl.danger {
  background: rgba(220, 60, 60, 0.75);
}

.ctl.toggled {
  background: rgba(79, 142, 247, 0.55);
  border-color: var(--accent);
}

.ctl.muted {
  background: rgba(220, 60, 60, 0.8);
  border-color: var(--bad);
}

/* Spinner ring around a control while the robot works (park/unpark). */
.ctl {
  position: relative;
}

.ctl.busy {
  pointer-events: none;
}

.ctl.busy::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  animation: ctl-spin 0.8s linear infinite;
}

@keyframes ctl-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Knock: shown while waiting for accept at the robot. The self-view stays
   visible so the knocker sees what the robot side sees of them. */
#knockOverlay {
  display: none;
}

#cockpit.knocking #knockOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.75);
  z-index: 4;
  font-size: 26px;
  text-align: center;
}

#cockpit.knocking .controls,
#cockpit.knocking #joystick,
#cockpit.knocking #turboBtn,
#cockpit.knocking .keys-hint,
#cockpit.knocking .hud {
  display: none;
}

.knock-emoji {
  font-size: 64px;
  animation: knock-pulse 1.2s ease-in-out infinite;
}

.knock-sub {
  font-size: 15px;
  color: var(--muted);
}

@keyframes knock-pulse {
  0%, 100% { transform: rotate(0deg) scale(1); }
  12% { transform: rotate(-8deg) scale(1.08); }
  24% { transform: rotate(6deg) scale(1.04); }
  36% { transform: rotate(0deg) scale(1); }
}

#overlayMsg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(0, 0, 0, 0.82);
  z-index: 20;
  font-size: 22px;
  text-align: center;
  padding: 30px;
}

#overlayMsg button {
  width: auto;
}

/* Punch: a fist scales up out of the screen at the tap point, with impact shake. */
.punch-fist {
  position: fixed;
  transform: translate(-50%, -50%) scale(0.15) rotate(-25deg);
  font-size: 110px;
  z-index: 50;
  pointer-events: none;
  animation: punch-in 0.6s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

@keyframes punch-in {
  0% { transform: translate(-50%, -50%) scale(0.15) rotate(-25deg); opacity: 0; }
  40% { transform: translate(-50%, -50%) scale(3.4) rotate(6deg); opacity: 1; }
  65% { transform: translate(-50%, -50%) scale(3.0) rotate(0deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(3.6) rotate(2deg); opacity: 0; }
}

#cockpit.shake {
  animation: cockpit-shake 0.4s;
}

@keyframes cockpit-shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-14px, 7px); }
  40% { transform: translate(11px, -9px); }
  60% { transform: translate(-8px, -5px); }
  80% { transform: translate(6px, 4px); }
}

/* Big session countdown, top center — twice the pill scale. */
#bigTimer {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 12px 26px;
  z-index: 6;
  transition: opacity 0.45s, transform 0.55s cubic-bezier(0.34, 1.3, 0.64, 1);
}

/* Entrance: drops in from above the viewport at 4X... */
#bigTimer.enter-start {
  transition: none;
  transform: translateX(-50%) translateY(-60vh) scale(4);
}

/* ...lands big in the upper middle, holds, then the base transition
   shrinks it home to the pill spot. */
#bigTimer.enter-big {
  transition: transform 0.7s cubic-bezier(0.34, 1.4, 0.64, 1);
  transform: translateX(-50%) translateY(24vh) scale(4);
}

#bigTimer.warn {
  color: var(--warn);
}

#bigTimer.crit {
  color: #f75f5f;
}

#cockpit.intro #bigTimer {
  opacity: 0;
}

/* Pole-motion hints at the video edges (debounced, fade in/out). */
.pole-hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 24px;
  line-height: 0.9;
  text-align: center;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 9;
}

.pole-hint.top {
  top: 54px;
}

.pole-hint.bottom {
  bottom: 8px;
}

.pole-hint.show {
  opacity: 0.95;
}

#speedViz {
  position: absolute;
  bottom: 58px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 6;
}

#attitudeViz {
  position: absolute;
  top: 64px;
  left: 16px;
  width: 264px;   /* rendered at 3x internally for crispness when scaled */
  height: 262px;
  pointer-events: none;
  z-index: 6;
  transform-origin: top left;
}

/* Entry animation: the flying driver preview, and hidden controls that
   fade in once the model settles into its corner. */
#introVideo {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 240px;
  aspect-ratio: 3 / 4;
  transform: translate(-50%, -50%) scaleX(-1);
  object-fit: cover;
  border-radius: 12px;
  background: #000;
  z-index: 40;
}

.controls,
#joystick,
#turboBtn,
.hud,
.keys-hint,
#speedViz,
#floorWrap,
#selfView {
  transition: opacity 0.45s;
}

#remoteVideo {
  transition: opacity 0.6s;
}

#cockpit.intro .controls,
#cockpit.intro #joystick,
#cockpit.intro #turboBtn,
#cockpit.intro .hud,
#cockpit.intro .keys-hint,
#cockpit.intro #speedViz,
#cockpit.intro #selfView,
#cockpit.intro #remoteVideo,
#cockpit.intro #floorWrap,
#cockpit.intro #soundboard {
  opacity: 0;
  pointer-events: none;
}

.keys-hint {
  position: absolute;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
  z-index: 6;
}

/* ---------- admin ---------- */

.admin-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.admin-header h1 {
  font-size: 24px;
  margin: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 22px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 17px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

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

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bad);
  margin-right: 8px;
}

.dot.on {
  background: var(--good);
}

.battery-bar {
  width: 120px;
  height: 10px;
  border-radius: 5px;
  background: var(--panel-2);
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.battery-bar span {
  display: block;
  height: 100%;
  background: var(--good);
}

.stat {
  color: var(--muted);
  font-size: 14px;
}

.stat b {
  color: var(--text);
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: end;
}

.field label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
}

.checks {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.btn {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
}

.btn.subtle {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}

.btn.danger {
  background: var(--bad);
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.code-cell {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 17px;
  letter-spacing: 2px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}

.badge.active { background: rgba(62, 207, 142, 0.15); color: var(--good); }
.badge.idle { background: rgba(139, 149, 168, 0.15); color: var(--muted); }
.badge.dead { background: rgba(247, 95, 95, 0.15); color: var(--bad); }
.badge.live { background: rgba(79, 142, 247, 0.2); color: var(--accent); }

/* ---------- instant-apply settings ---------- */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-label .stat {
  margin-top: 2px;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.inline-controls input[type="number"] {
  width: 64px;
  padding: 7px 8px;
}

.inline-controls input.dimmed {
  opacity: 0.35;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch .track {
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}

.switch input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .track::after {
  transform: translateX(18px);
  background: #fff;
}

.switch.small .track {
  width: 36px;
  height: 22px;
}

.switch.small .track::after {
  width: 16px;
  height: 16px;
}

.switch.small input:checked + .track::after {
  transform: translateX(14px);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

.segmented button {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel-2);
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

#newCodeBanner {
  background: rgba(62, 207, 142, 0.1);
  border: 1px solid rgba(62, 207, 142, 0.4);
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

#newCodeBanner .big-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 30px;
  letter-spacing: 8px;
  font-weight: 700;
  color: var(--good);
}

.locked {
  opacity: 0.35;
  pointer-events: none;
}

/* Soundboard flyout */
#soundboard {
  position: absolute;
  right: 90px;
  bottom: 24px;
  width: 280px;
  max-height: 50vh;
  background: rgba(10, 13, 20, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#soundSearch {
  width: 100%;
}

/* ---------- join-screen robot picker ---------- */

.field-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.field-row .field {
  flex: 1;
  min-width: 0;
}

#robotRow {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}

.robot-tile {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 8px 7px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.robot-tile.selected {
  border-color: var(--good);
  background: rgba(62, 207, 142, 0.14);
}

.robot-tile.unavailable {
  cursor: default;
  opacity: 0.72;
}

.tile-model {
  position: relative;
}

.tile-model canvas {
  display: block;
  width: 100%;
  height: auto;
}

.tile-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  padding: 3px 8px;
}

.tile-name {
  text-align: center;
  font-weight: 600;
  margin-top: 4px;
}

.tile-sub {
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  min-height: 15px;
}

.primary:disabled {
  opacity: 0.45;
  cursor: default;
}

#soundSearchView,
#soundEmojiView {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#soundResults {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sound-row {
  display: flex;
  gap: 6px;
}

.sound-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
}

/* The + on each search result adds it to the saved soundboard. */
.sound-add {
  flex: 0 0 34px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.sound-add:active {
  background: rgba(79, 142, 247, 0.4);
}

#emojiGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#emojiGrid button {
  width: 46px;
  height: 46px;
  font-size: 24px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 10px;
}

#emojiGrid button:active {
  background: rgba(79, 142, 247, 0.4);
}

.emoji-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.sound-item:active {
  background: rgba(79, 142, 247, 0.4);
}

/* Time critical: under 10 seconds the screen pulses red — one pulse per
   tick, restarted from JS so it lands exactly on each second. */
#cockpit.time-critical::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

#cockpit.time-critical.pulse::after {
  animation: red-alert 0.7s ease-in-out;
}

@keyframes red-alert {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(247, 95, 95, 0); }
  50% { box-shadow: inset 0 0 90px 24px rgba(247, 95, 95, 0.65); }
}

/* ---------- multi-robot ---------- */

.robot-card {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.robot-card:last-child {
  border-bottom: none;
}


/* ---------- mobile cockpit ----------
   Late in the file so these win order ties against the base rules above. */

@media (max-width: 900px) {
  /* Tuck the 3D model into the top-left corner, a bit smaller. The drawing
     has internal margin, so pull it past the edge to sit visually flush. */
  #attitudeViz {
    top: 44px;
    left: -24px;
    width: 190px;
    height: 189px;
  }

  /* No keyboard on a phone — the hint is noise. */
  .keys-hint {
    display: none;
  }

  /* Sides swapped on mobile: joystick (+turbo) right, buttons left. */
  #joystick {
    left: auto;
    right: 10px;
    bottom: 10px;
  }

  #turboBtn {
    left: auto;
    right: 172px;
    bottom: 54px;
  }

  .controls {
    right: auto;
    left: 10px;
    bottom: 10px;
  }

  /* Group flyouts expand to the RIGHT of the (left-side) button column. */
  .group-flyout {
    right: auto;
    left: calc(100% + 10px);
    transform: translateY(-50%) translateX(-10px);
  }

  .ctl-group.open .group-flyout {
    transform: translateY(-50%) translateX(0);
  }

  #soundButtons {
    max-width: calc(100vw - 190px);
  }

  /* The soundboard opens beside its (now left-side) button. */
  #soundboard {
    right: auto;
    left: 76px;
    bottom: 10px;
  }
}

/* ---------- visibility toggle ----------
   Kept LAST so it wins order ties, with ID+class variants to out-rank the
   bare-ID display rules (#cockpit, #newCodeBanner) and compound selectors
   (.hud .pill). Anything the JS hides via classList must stay hidden. */

.hidden,
.pill.hidden,
.ctl.hidden,
.ctl-group.hidden,
#gate.hidden,
#cockpit.hidden,
#login.hidden,
#dash.hidden,
#overlayMsg.hidden,
#sessionRow.hidden,
#soundboard.hidden,
#soundSearchView.hidden,
#soundEmojiView.hidden,
#newCodeBanner.hidden {
  display: none;
}
