:root {
  --ink: #12191f;
  --muted: #62717d;
  --soft: #8996a0;
  --line: #d7e0e6;
  --line-strong: #bac7d1;
  --surface: #ffffff;
  --surface-soft: #f7fafb;
  --page: #eef4f6;
  --stage: #101820;
  --accent: #21718b;
  --accent-strong: #11546c;
  --accent-soft: #e4f3f7;
  --ok: #21835d;
  --ok-soft: #e4f4ed;
  --warn: #a96615;
  --warn-soft: #fff0d9;
  --danger: #b42318;
  --shadow: 0 22px 60px rgba(18, 25, 31, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(33, 113, 139, 0.11), transparent 34%),
    linear-gradient(315deg, rgba(33, 131, 93, 0.08), transparent 30%),
    var(--page);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1240px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
}

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.04;
  letter-spacing: 0;
}

.subtitle {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.header-tools {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.language-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.lang-button {
  min-width: 54px;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.lang-button.active {
  color: #ffffff;
  background: var(--accent);
}

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

.pill {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.ok {
  color: var(--ok);
  border-color: rgba(33, 131, 93, 0.34);
  background: var(--ok-soft);
}

.pill.warn {
  color: var(--warn);
  border-color: rgba(169, 102, 21, 0.34);
  background: var(--warn-soft);
}

.pill.idle {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
}

.stage-panel,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.stage-panel {
  padding: 12px;
  min-width: 0;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 4px 12px;
}

.stage-toolbar strong {
  font-size: 15px;
}

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

.stage-meta span,
.stage-link {
  min-height: 30px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
}

.stage-link {
  text-decoration: none;
}

.stage-link:focus-visible {
  outline: 3px solid rgba(33, 113, 139, 0.24);
  outline-offset: 2px;
}

.viewport {
  position: relative;
  min-height: 540px;
  height: calc(100vh - 186px);
  overflow: hidden;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 42%, rgba(79, 150, 172, 0.28), transparent 23%),
    linear-gradient(180deg, #172431 0%, #0d151d 56%, #091016 100%);
}

.frame-stream {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
  background: #000000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}

.frame-stream.online {
  opacity: 1;
}

.webrtc-frame {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000000;
  pointer-events: none;
}

.horizon {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 34%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02), transparent 30%, rgba(255, 255, 255, 0.025) 70%, transparent);
}

.terrain-grid {
  position: absolute;
  inset: 52% -20% -32%;
  background:
    linear-gradient(rgba(142, 164, 175, 0.17) 1px, transparent 1px),
    linear-gradient(90deg, rgba(142, 164, 175, 0.17) 1px, transparent 1px);
  background-size: 54px 54px;
  transform: perspective(600px) rotateX(64deg);
  transform-origin: top;
}

.robot-visual {
  position: absolute;
  left: 50%;
  top: 48%;
  width: min(300px, 52vw);
  height: 156px;
  transform: translate(-50%, -50%);
}

.robot-visual .body,
.robot-visual .head,
.robot-visual .leg {
  position: absolute;
  display: block;
  background: #e5eff3;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.robot-visual .body {
  left: 54px;
  top: 42px;
  width: 184px;
  height: 56px;
  border-radius: 8px;
}

.robot-visual .head {
  right: 18px;
  top: 52px;
  width: 50px;
  height: 36px;
  border-radius: 7px;
  background: #bdd6de;
}

.robot-visual .leg {
  width: 18px;
  height: 84px;
  border-radius: 6px;
  transform-origin: top center;
  background: #f6f9fa;
}

.robot-visual .front-left {
  left: 196px;
  top: 90px;
  transform: rotate(-13deg);
}

.robot-visual .front-right {
  left: 160px;
  top: 90px;
  transform: rotate(12deg);
  background: #c8dce2;
}

.robot-visual .rear-left {
  left: 88px;
  top: 90px;
  transform: rotate(12deg);
}

.robot-visual .rear-right {
  left: 56px;
  top: 90px;
  transform: rotate(-12deg);
  background: #c8dce2;
}

.stream-placeholder {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%);
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  color: #dce9ed;
  background: rgba(6, 12, 17, 0.72);
  text-align: center;
}

.stream-placeholder.hidden {
  display: none;
}

.stream-placeholder strong {
  font-size: 13px;
  letter-spacing: 0;
}

.viewport-readout {
  position: absolute;
  z-index: 5;
  left: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  color: #dce9ed;
  background: rgba(6, 12, 17, 0.76);
}

.viewport-readout span {
  color: #91a8b2;
  font-size: 12px;
  font-weight: 800;
}

.viewport-readout strong {
  font-size: 13px;
  letter-spacing: 0;
}

.control-panel {
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.panel-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.command-card {
  background: linear-gradient(180deg, #ffffff, #f8fbfc);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title span,
.metrics span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.section-title strong,
.metrics strong {
  font-size: 15px;
  line-height: 1.2;
  text-align: right;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  grid-template-rows: repeat(2, 70px);
  gap: 10px;
}

.key {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.key:focus-visible,
.lang-button:focus-visible {
  outline: 3px solid rgba(33, 113, 139, 0.24);
  outline-offset: 2px;
}

.key.active {
  color: #ffffff;
  border-color: var(--accent-strong);
  background: var(--accent);
  transform: translateY(1px);
}

.key-w {
  grid-column: 2;
  grid-row: 1;
}

.key-a {
  grid-column: 1;
  grid-row: 2;
}

.key-s {
  grid-column: 2;
  grid-row: 2;
}

.key-d {
  grid-column: 3;
  grid-row: 2;
}

.metrics {
  display: grid;
  gap: 10px;
}

.metrics div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
}

.checklist {
  display: grid;
  gap: 10px;
}

.check {
  display: grid;
  grid-template-columns: 12px 1fr;
  align-items: center;
  gap: 10px;
}

.check span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--soft);
}

.check.ok span {
  background: var(--ok);
}

.check.warn span {
  background: var(--warn);
}

.check.fail span {
  background: var(--danger);
}

.check p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

@media (max-width: 960px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding: 14px 0;
  }

  .app-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .header-tools {
    justify-items: start;
    width: 100%;
  }

  .status-row {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .viewport {
    min-height: 360px;
    height: 50vh;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 12px, 430px);
  }

  h1 {
    font-size: 28px;
  }

  .subtitle {
    font-size: 14px;
  }

  .status-row {
    gap: 6px;
  }

  .pill {
    min-height: 32px;
    padding: 7px 10px;
    font-size: 12px;
  }

  .stage-panel,
  .control-panel {
    padding: 8px;
  }

  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-meta {
    justify-content: flex-start;
  }

  .viewport {
    min-height: 320px;
  }

  .keypad {
    grid-template-columns: repeat(3, minmax(54px, 1fr));
    grid-template-rows: repeat(2, 58px);
    gap: 8px;
  }

  .key {
    font-size: 22px;
  }
}
