/* ======================================================================
   robocontrol — оформление в стиле versibionics.com

   Палитра (только она, без посторонних акцентов):
     --mist   #798D98   приглушённый текст, рамки, блик
     --steel  #3C5768   поверхности, кнопки
     --deep   #2C4B5E   наведение, вторичные поверхности
     --navy   #183245   основной фон
     --abyss  #00172C   самые тёмные панели
     --white  #FFFFFF   текст, акцент, активное состояние

   Смысл состояний передаётся яркостью, а не цветом: онлайн - белая
   светящаяся точка, офлайн - тусклая стальная; нажатая кнопка -
   белая с тёмным текстом.
   ====================================================================== */

:root {
  --mist:  #798D98;
  --steel: #3C5768;
  --deep:  #2C4B5E;
  --navy:  #183245;
  --abyss: #00172C;
  --white: #FFFFFF;

  --panel:  rgba(0, 23, 44, 0.42);
  --line:   rgba(121, 141, 152, 0.24);
  --line-2: rgba(121, 141, 152, 0.42);
  --btn:    rgba(60, 87, 104, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }

body {
  color: var(--white);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
  background-color: var(--navy);
  /* Градиент как на главной: светлее слева сверху, в глубокий тёмно-синий
     справа, и мягкий белёсый блик у верхнего края. */
  background-image:
    radial-gradient(ellipse 42% 38% at 66% -6%, rgba(255,255,255,.34), rgba(121,141,152,.20) 45%, transparent 75%),
    radial-gradient(ellipse 45% 70% at 90% 30%, rgba(0,23,44,.95), transparent 72%),
    linear-gradient(158deg, #4E6878 0%, var(--steel) 22%, var(--deep) 45%, var(--navy) 72%, #0E2A3F 100%);
  background-attachment: fixed;
}

/* Лёгкое зерно поверх градиента - как на скриншоте главной. */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
body > * { position: relative; z-index: 1; }

/* ---------- шапка ---------- */
header {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: rgba(0, 23, 44, .35); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { text-transform: lowercase; letter-spacing: .08em; font-size: 14px; white-space: nowrap; }
.brand .v { font-weight: 700; color: var(--white); }
.brand .b { color: var(--mist); }
.brand .sep { color: var(--steel); margin: 0 6px; }
.brand .app { color: var(--mist); font-weight: 400; }
header .name { font-weight: 600; letter-spacing: .02em; }
header .meta {
  color: var(--mist); font-size: 12px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
header a, header button {
  background: var(--btn); color: var(--white); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 13px;
  cursor: pointer; text-decoration: none; transition: background .15s;
}
header a:hover, header button:hover { background: var(--steel); }

.stage { max-width: 920px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.panel h2 {
  margin: 0 0 14px; font-size: 12px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--mist);
}
.note { color: var(--mist); font-size: 12px; margin-top: 10px; line-height: 1.6; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--steel); flex: none; display: inline-block; }
.dot.on  { background: var(--white); box-shadow: 0 0 8px rgba(255,255,255,.75); }
.dot.off { background: var(--steel); box-shadow: none; }

/* ---------- карточки устройств ---------- */
.devices {
  display: grid; gap: 16px; justify-content: center;
  grid-template-columns: repeat(auto-fill, minmax(280px, 320px));
}
.dev {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  text-decoration: none; color: inherit; cursor: pointer;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.dev:hover { transform: translateY(-3px); border-color: var(--line-2); box-shadow: 0 14px 30px rgba(0,23,44,.45); }

/* Рендер - главный герой карточки. Картинка 286x220 без @2x, поэтому
   показываем её не крупнее родного размера, иначе поплывёт. */
.dev-art {
  position: relative; height: 210px; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse 60% 55% at 50% 58%, rgba(121,141,152,.34), rgba(60,87,104,.14) 55%, transparent 78%),
    linear-gradient(180deg, rgba(60,87,104,.25), rgba(0,23,44,.1));
  border-bottom: 1px solid var(--line);
}
.dev-art img {
  width: 100%; max-width: 250px; height: auto;
  filter: drop-shadow(0 14px 16px rgba(0,23,44,.55));
  transition: transform .25s ease;
}
.dev:hover .dev-art img { transform: scale(1.04); }
.dev-art .noart { color: var(--mist); font-size: 13px; }

.dev-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 4px; }
.dev-title { display: flex; align-items: center; gap: 9px; font-size: 19px; font-weight: 600; letter-spacing: .02em; }
.dev-id { color: var(--mist); font-size: 11.5px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.dev-stats { color: var(--mist); font-size: 12.5px; margin-top: 8px; line-height: 1.7; }
.dev-cta {
  margin-top: 12px; align-self: stretch; text-align: center; padding: 10px;
  background: var(--white); color: var(--abyss); border-radius: 10px; font-weight: 600;
  transition: background .15s;
}
.dev:hover .dev-cta { background: #E6ECEF; }

.dev.busy { cursor: not-allowed; }
.dev.busy:hover { transform: none; box-shadow: none; }
.dev.busy .dev-art img { filter: grayscale(.9) brightness(.7) drop-shadow(0 14px 16px rgba(0,23,44,.55)); }
.dev.busy .dev-cta { background: transparent; color: var(--mist); border: 1px solid var(--line-2); }

.empty { color: var(--mist); text-align: center; padding: 56px 20px; line-height: 1.7; }

/* ---------- видео ---------- */
.video {
  position: relative; margin: 0 auto; width: 100%;
  background: var(--abyss); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; aspect-ratio: 4/3;
}
.video canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.video .off {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--mist); font-size: 14px; text-align: center; padding: 20px;
}
.video .badge {
  position: absolute; top: 8px; left: 8px; background: rgba(0,23,44,.7);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px;
  font-size: 11px; color: var(--white); font-variant-numeric: tabular-nums;
}
.vidbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.vidbar select, .vidbar button {
  background: var(--btn); color: var(--white); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.vidbar select option { background: var(--navy); }
.vidbar .flash { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 150px; }
.vidbar input[type=range] { flex: 1; accent-color: var(--white); }

/* ---------- джойстик ---------- */
.drive { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; }
.stick {
  position: relative; width: 210px; height: 210px; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, var(--deep), var(--abyss) 72%);
  border: 1px solid var(--line-2); touch-action: none;
  box-shadow: inset 0 0 24px rgba(0,23,44,.6);
}
.stick .arrow { position: absolute; color: var(--steel); font-size: 19px; pointer-events: none; transition: color .1s; }
.stick .arrow.u { top: 9px; left: 50%; transform: translateX(-50%); }
.stick .arrow.d { bottom: 9px; left: 50%; transform: translateX(-50%); }
.stick .arrow.l { left: 11px; top: 50%; transform: translateY(-50%); }
.stick .arrow.r { right: 11px; top: 50%; transform: translateY(-50%); }
.stick .arrow.hot { color: var(--white); text-shadow: 0 0 8px rgba(255,255,255,.7); }
.knob {
  position: absolute; width: 78px; height: 78px; border-radius: 50%; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(160deg, var(--steel), var(--navy));
  border: 1px solid var(--mist); box-shadow: 0 6px 18px rgba(0,23,44,.6);
  pointer-events: none; transition: transform .08s ease-out;
}
.knob.live {
  background: linear-gradient(160deg, var(--white), #C9D3D8);
  border-color: var(--white); box-shadow: 0 0 22px rgba(255,255,255,.45);
}
.stopbtn {
  width: 120px; height: 120px; border-radius: 50%;
  background: transparent; color: var(--white); border: 2px solid var(--white);
  font: inherit; font-weight: 700; font-size: 16px; letter-spacing: .08em; cursor: pointer;
  transition: background .12s, color .12s;
}
.stopbtn:active { background: var(--white); color: var(--abyss); }

/* ---------- пресеты ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 9px; }
.grid button {
  background: var(--btn); color: var(--white); border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 6px; font: inherit; font-size: 13px; cursor: pointer; line-height: 1.25;
  transition: background .12s, border-color .12s;
}
.grid button:hover { background: var(--steel); border-color: var(--line-2); }
.grid button:active { background: var(--white); color: var(--abyss); border-color: var(--white); }
.grid button .ic { display: block; font-size: 20px; margin-bottom: 3px; }

details.panel > summary {
  cursor: pointer; font-size: 12px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--mist);
}

/* ---------- форма входа ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 30px 24px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.login .brand { display: block; text-align: center; font-size: 17px; margin-bottom: 4px; }
.login .sub { text-align: center; color: var(--mist); font-size: 13px; margin-bottom: 26px; letter-spacing: .06em; }
.login label { display: block; font-size: 13px; color: var(--mist); margin: 14px 0 6px; }
.login input {
  width: 100%; padding: 13px 12px; font-size: 16px; color: var(--white);
  background: rgba(0,23,44,.55); border: 1px solid var(--line-2); border-radius: 10px; outline: none;
}
.login input:focus { border-color: var(--white); }
.login button {
  width: 100%; margin-top: 22px; padding: 14px; font: inherit; font-weight: 600; font-size: 16px;
  border: none; border-radius: 10px; background: var(--white); color: var(--abyss); cursor: pointer;
}
.login button:hover { background: #E6ECEF; }
.err {
  margin-top: 16px; padding: 11px; border-radius: 10px; font-size: 13px; text-align: center;
  background: rgba(0,23,44,.7); border: 1px solid var(--mist); color: var(--white);
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(140%);
  background: var(--abyss); border: 1px solid var(--line-2); border-radius: 10px; padding: 11px 16px;
  font-size: 14px; transition: transform .22s ease; z-index: 50; max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ======================================================================
   Пульт: три колонки - управление | видео | действия и эмоции
   ====================================================================== */
.console {
  display: grid; gap: 16px; max-width: 1500px; margin: 0 auto; padding: 16px;
  grid-template-columns: 270px auto 330px;
  grid-template-areas: "drive video side";
  justify-content: center; align-items: start;
}
.col-drive { grid-area: drive; }
.col-video { grid-area: video; display: flex; flex-direction: column; gap: 10px; width: min-content; }
.col-side  { grid-area: side; display: flex; flex-direction: column; gap: 14px; }

/* Видео подгоняется под высоту экрана, ширина следует из пропорций кадра
   (их выставляет скрипт после поворота) - поэтому ничего не растягивается. */
.col-video .video { height: clamp(360px, calc(100vh - 205px), 760px); width: auto; margin: 0; }
/* Альбомный кадр (робот без поворота) по высоте экрана вышел бы шире
   свободного места и вытолкнул боковые колонки. Ширину ограничиваем
   местом между ними (270 + 330 + отступы); кадр при этом не искажается -
   canvas вписан через object-fit: contain. */
@media (min-width: 1100px) {
  .col-video .video { max-width: calc(100vw - 680px); }
}
.col-video .vidbar { margin-top: 0; }

.drive-col { display: flex; flex-direction: column; align-items: center; gap: 18px; position: relative; }

/* Полоса анимации позы */
.anim { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; }
.anim-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 13px; }
.anim-name { color: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.anim-left { color: var(--white); font-variant-numeric: tabular-nums; font-weight: 600; }
.anim-track { margin-top: 7px; height: 6px; border-radius: 3px; background: rgba(0,23,44,.6); overflow: hidden; }
.anim-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--mist), var(--white)); border-radius: 3px; }
.anim.on .anim-name { color: var(--white); }
.anim.on { border-color: var(--line-2); }

/* На время позы ходьба заблокирована: робот всё равно доиграет позу
   до конца, а команды движения встанут в очередь. */
.console.animating .stick { opacity: .35; pointer-events: none; }
.lockmsg {
  display: none; position: absolute; top: 88px; left: 50%; transform: translateX(-50%);
  background: rgba(0,23,44,.85); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--white); white-space: nowrap; pointer-events: none;
}
.console.animating .lockmsg { display: block; }

/* Кнопки пресетов: компактнее, с длительностью */
.col-side .grid { grid-template-columns: repeat(3, 1fr); gap: 7px; }
/* Компактнее, чтобы 16 действий и 9 эмоций влезали в экран 900 px без прокрутки. */
.col-side .panel { padding: 12px 14px; }
.col-side .panel h2 { margin-bottom: 10px; }
.col-side .grid button { padding: 7px 4px 6px; font-size: 12px; line-height: 1.2; }
.col-side .grid button .ic { font-size: 18px; margin-bottom: 1px; }
.grid button .dur { display: block; font-size: 10.5px; color: var(--mist); margin-top: 2px; font-variant-numeric: tabular-nums; }
.grid button:disabled { opacity: .35; cursor: not-allowed; }
.grid button:disabled:hover { background: var(--btn); border-color: var(--line); }
.grid button.face.on { border-color: var(--white); box-shadow: inset 0 0 0 1px var(--white); }
.panel h2 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--steel); margin-left: 6px; }

.servos-wrap { max-width: 1500px; margin: 0 auto; padding: 0 16px 24px; }

/* Уже 1100 - видео сверху во всю ширину, под ним две колонки */
@media (max-width: 1099px) {
  .console { grid-template-columns: 1fr 1fr; grid-template-areas: "video video" "drive side"; }
  .col-video { width: auto; align-items: center; }
  .col-video .video { height: min(70vh, 640px); }
  .col-video .anim, .col-video .vidbar { width: 100%; max-width: 640px; }
}
/* Телефон - одна колонка, видео по ширине экрана */
@media (max-width: 699px) {
  .console { grid-template-columns: 1fr; grid-template-areas: "video" "drive" "side"; padding: 10px; }
  .col-video .video { width: 100%; height: auto; }
}

/* ----------------------------------------------------------------------
   Мини-панель ключей API в шапке. Кнопка стоит слева, сразу за логотипом,
   а всплывающая панель привязана к ней левым краем - иначе на узком экране
   она уезжает за границу окна.
   ---------------------------------------------------------------------- */
.keys-mini { position: relative; }
.keys-mini > button.open { background: var(--steel); }

.keys-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  width: 360px; max-width: calc(100vw - 32px);
  background: var(--navy); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 14px; box-shadow: 0 18px 40px rgba(0, 10, 20, .45);
  display: flex; flex-direction: column; gap: 10px;
}
.keys-pop[hidden] { display: none; }

.keys-hint { color: var(--mist); font-size: 12px; line-height: 1.35; }

.keys-list { display: flex; flex-direction: column; gap: 4px; }
.keys-empty { color: var(--mist); font-size: 12px; padding: 6px 0; }

.keys-row {
  display: grid; grid-template-columns: auto 1fr auto auto;
  align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 7px; background: rgba(0, 23, 44, .45);
  font-size: 12px;
}
.keys-row.dead { opacity: .45; }
.keys-id { font-family: ui-monospace, Consolas, monospace; color: var(--white); }
.keys-label { color: var(--mist); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keys-when { color: var(--mist); white-space: nowrap; }
.keys-del {
  background: transparent; border: 0; color: var(--mist); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 2px;
}
.keys-del:hover { color: var(--white); }

.keys-form { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.keys-form[hidden] { display: none; }
.keys-form input, .keys-form select {
  background: var(--abyss); color: var(--white); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 9px; font: inherit; font-size: 12px; min-width: 0;
}
.keys-form button {
  background: var(--btn); color: var(--white); border: 1px solid var(--line-2);
  border-radius: 7px; padding: 7px 11px; font: inherit; font-size: 12px; cursor: pointer;
}
.keys-form button:hover { background: var(--steel); }
.keys-form button:disabled { opacity: .5; cursor: default; }

.keys-fresh { display: flex; flex-direction: column; gap: 6px; }
.keys-fresh[hidden] { display: none; }
.keys-once { color: var(--white); font-size: 12px; }
.keys-token {
  font-family: ui-monospace, Consolas, monospace; font-size: 11px; word-break: break-all;
  background: var(--abyss); border: 1px dashed var(--mist); border-radius: 7px; padding: 8px;
  user-select: all;
}
.keys-copy {
  align-self: flex-start;
  background: transparent; color: var(--mist); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.keys-copy:hover { color: var(--white); }
