/* ==========================================================================
   Juicy Vector Forge — панель CEP
   Палитра и типографика по брендбуку Juicy:
     Lime #C6F23B — основная энергия, активные состояния
     Grape #A78BFA — фокус, акценты системы движения
     Orange #FF9A3C — прогресс, тёплые акценты
     Coral #FF6B6B — ошибки, вторичные акценты
     Ink #111111 / Milk #F8F8F6 — контраст
   Заголовки: Instrument Sans Bold · Текст: Inter
   ========================================================================== */

@font-face {
  font-family: "Inter";
  src: url("../assets/fonts/Inter-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: block;
}
@font-face {
  font-family: "Inter";
  src: url("../assets/fonts/Inter-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: block;
}
@font-face {
  font-family: "Inter";
  src: url("../assets/fonts/Inter-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: block;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../assets/fonts/InstrumentSans-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: block;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../assets/fonts/InstrumentSans-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: block;
}

:root {
  color-scheme: dark;

  /* бренд */
  --lime:   #C6F23B;
  --grape:  #A78BFA;
  --orange: #FF9A3C;
  --coral:  #FF6B6B;
  --milk:   #F8F8F6;

  /* поверхности — нейтральный ink, без мутного зелёного оттенка */
  --bg:          #0c0d0e;
  --panel:       #15171a;
  --panel-deep:  #101215;
  --button:      #1c1f23;
  --button-top:  #24282d;
  --button-hover:#2a2f35;
  --line:        #2c3238;
  --line-soft:   #1e2227;

  --text:  var(--milk);
  --muted: #a2a8ae;
  --dim:   #676d73;
  --shadow: rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background: linear-gradient(180deg, #08090a 0%, var(--bg) 38%, #0e1012 100%);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  line-height: 1.35;
}

button { font: inherit; }

.app-shell {
  /*
   * По умолчанию содержимое занимает всю ширину панели: её тянут как
   * угодно широко, и оставлять при этом полосу по центру с пустотой по
   * бокам — значит не пользоваться местом, которое человек сам и отдал.
   *
   * Кто хочет прежнюю узкую колонку — переключает, и тогда работает
   * потолок в 580: сетка 4×128 плюс отступы.
   */
  width: 100%;
  min-width: 280px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px;
}

.layout-centred .app-shell { width: min(100%, 580px); }

/* ---------------------------------------------------------------- шапка */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0)),
    var(--panel);
  box-shadow: 0 18px 34px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.05);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* Утверждённый app-mark из брендбука, светлая плитка на тёмной панели */
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 9px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.34);
}

.brand-copy { min-width: 0; }
.brand-copy p, .brand-copy h1 { margin: 0; }

.brand-copy p {
  color: var(--lime);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-copy h1 {
  overflow: hidden;
  max-width: 280px;
  color: var(--text);
  font-family: "Instrument Sans", "Inter", sans-serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-stack { display: grid; gap: 6px; justify-items: end; }
.top-controls { display: flex; align-items: center; gap: 7px; }

.host-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 214px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-deep);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.host-switch button {
  height: 29px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.host-switch button:last-child { border-right: 0; }
.host-switch button:hover { color: var(--text); }

.host-switch button.active {
  background:
    linear-gradient(135deg, rgba(198,242,59,0.20), rgba(167,139,250,0.18)),
    #1b2027;
  color: var(--text);
  font-weight: 700;
}

.refresh-button {
  position: relative;
  display: grid; place-items: center;
  width: 31px; height: 31px; min-width: 31px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0)),
    var(--panel-deep);
  color: var(--muted);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.refresh-button svg {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.refresh-button:hover {
  border-color: rgba(198,242,59,0.68);
  background: linear-gradient(135deg, rgba(198,242,59,0.14), rgba(167,139,250,0.14)), #191d22;
  color: var(--text);
}
.refresh-button:active { transform: translateY(1px); }

.license-button.licensed {
  border-color: rgba(198,242,59,0.72);
  color: var(--lime);
}

.license-button.blocked {
  border-color: rgba(255,107,107,0.58);
  color: var(--coral);
}

.connection-status {
  max-width: 214px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10.5px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.connection-status strong { color: var(--lime); font-weight: 600; }

/* --------------------------------------------------------- license */
.license-panel[hidden],
.license-details[hidden],
.license-actions button[hidden] { display: none; }

.license-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 58px 14px 14px;
  background: rgba(0, 0, 0, 0.52);
}

.license-card {
  width: min(430px, calc(100vw - 28px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 52px rgba(0,0,0,0.54);
}

.license-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.license-card-head h3,
.license-kicker { margin: 0; }
.license-card-head h3 { font: 700 18px/1.2 "Instrument Sans", "Inter", sans-serif; }
.license-kicker {
  margin-bottom: 3px;
  color: var(--lime);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.license-close {
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--muted);
  cursor: pointer;
}

.license-state {
  min-height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-deep);
  color: var(--muted);
  font-weight: 700;
}
.license-state.ok { border-color: rgba(198,242,59,0.50); color: var(--lime); }
.license-state.blocked { border-color: rgba(255,107,107,0.58); color: #ffc7c7; }

.license-details {
  display: grid;
  gap: 1px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}
.license-details div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--button);
}
.license-details span { color: var(--muted); font-size: 12px; font-weight: 700; }
.license-details strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.license-field { display: block; margin-top: 12px; color: var(--muted); }
.license-field input {
  width: 100%;
  min-width: 0;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #0b0d0f;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
}
.license-field input:focus { border-color: var(--grape); }

.license-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 12px; }
.license-actions button {
  min-width: 0;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  color: var(--text);
  cursor: pointer;
}
.license-actions button.primary { border-color: #9dc52b; background: var(--lime); color: #111; font-weight: 700; }
.license-actions button:disabled { opacity: 0.55; cursor: wait; }
.license-note { margin: 12px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

@media (max-width: 520px) {
  .license-panel { padding: 12px; }
  .license-card { width: 100%; }
  .license-actions { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ сетка тулов */
.tool-grid {
  position: relative;
  display: grid;
  /* Потолок в 128px держит плотность: без него на широкой панели плитки раздуваются. */
  grid-template-columns: repeat(4, minmax(84px, 128px));
  justify-content: center;
  gap: 7px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0)),
    #0f1114;
  box-shadow: 0 16px 36px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.035);
  overflow: visible;
}

.tool-button {
  position: relative;
  display: grid;
  grid-template-rows: minmax(34px, 1fr) minmax(24px, auto);
  align-items: center; justify-items: center;
  /* Без aspect-ratio: квадрат делал плитки высокими и тяжёлыми на широкой панели. */
  min-height: 82px;
  padding: 8px 6px 6px;
  border: 1px solid #303946;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--button-top), var(--button)), var(--button);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.055);
  isolation: isolate;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease,
              color 140ms ease, box-shadow 140ms ease;
}

.tool-button::before {
  position: absolute; inset: 0; z-index: -1;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(198,242,59,0.26), rgba(167,139,250,0.26));
  opacity: 0;
  content: "";
  transition: opacity 140ms ease;
}

/* подсказка */
.tool-button::after {
  position: absolute;
  left: 50%; bottom: calc(100% + 8px);
  z-index: 20;
  width: max-content; max-width: 205px;
  padding: 7px 9px;
  border: 1px solid rgba(198,242,59,0.30);
  border-radius: 6px;
  background: rgba(9,11,13,0.96);
  box-shadow: 0 14px 28px rgba(0,0,0,0.45);
  color: #e9efe0;
  content: attr(data-tip);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: normal;
}

.tool-button:hover:not([disabled]):not(.is-off) {
  border-color: rgba(198,242,59,0.70);
  background: linear-gradient(180deg, #2f343a, var(--button-hover)), var(--button-hover);
  color: #fff;
  box-shadow:
    0 16px 30px rgba(0,0,0,0.28),
    0 0 0 1px rgba(198,242,59,0.10),
    inset 0 1px 0 rgba(255,255,255,0.07);
}
.tool-button:hover::after { opacity: 1; transform: translate(-50%, 0); }
.tool-button:active:not([disabled]):not(.is-off) { transform: translateY(1px); }

/* основной инструмент текущего хоста */
.tool-button.primary {
  border-color: rgba(198,242,59,0.80);
  box-shadow:
    0 16px 32px rgba(0,0,0,0.3),
    0 0 0 1px rgba(198,242,59,0.18),
    inset 0 1px 0 rgba(255,255,255,0.075);
}
.tool-button.primary::before { opacity: 0.14; }
.tool-button.primary .tool-icon { color: var(--lime); }

/* Гашеная плитка держится на классе, а не на атрибуте disabled:
   такая кнопка не отдаёт события мыши, и подсказка «откройте панель
   в другом приложении» до пользователя бы не дошла — а именно здесь
   она нужнее всего. */
.tool-button[disabled],
.tool-button.is-off {
  color: var(--dim);
  cursor: not-allowed;
  opacity: 0.42;
}
.tool-button[disabled] .tool-icon,
.tool-button.is-off .tool-icon { color: var(--dim); }

.tool-button.is-busy {
  border-color: rgba(255,154,60,0.80);
  color: var(--orange);
  cursor: wait;
}
.tool-button.is-busy .tool-icon { color: var(--orange); }

.tool-icon {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  color: #eef2e6;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.32));
  transition: color 140ms ease;
}
.tool-icon svg { width: 28px; height: 28px; }

.tool-label {
  display: flex; align-items: center; justify-content: center;
  min-height: 24px; max-width: 100%;
  color: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}

/* --------------------------------------------------------------- опции */
/* Отступы те же, что у сетки инструментов сверху: блоки стоят друг под
   другом, и разный шаг между ними читался как сбой вёрстки */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel-deep);
}
.options:empty { display: none; }

.option {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.option label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.option select, .option input {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #0b0d0f;
  color: var(--text);
  font: inherit;
  font-size: 11px;
}
.option input { width: 62px; }

.option select:focus, .option input:focus {
  outline: none;
  border-color: var(--lime);
}

/* --------------------------------------------- превью пресетов анимации */
.anim-slot { flex: 1 1 100%; }

.anim-strip { display: flex; flex-wrap: wrap; gap: 6px; }

.anim-tile {
  width: auto; margin: 0;
  display: grid; justify-items: center; gap: 2px;
  padding: 6px 8px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.anim-tile:hover { border-color: rgba(198,242,59,0.5); background: var(--button-hover); }
.anim-tile.active { border-color: var(--lime); background: rgba(198,242,59,0.12); }

.anim-art { width: 50px; height: 34px; display: block; }

/* Бледный след — куда линия придёт в итоге */
.anim-track {
  fill: none; stroke: #2f353c; stroke-width: 2.4; stroke-linecap: round;
}

.anim-live {
  fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round;
  transition: stroke 140ms ease;
}
.anim-tile:hover .anim-live { stroke: var(--text); }
.anim-tile.active .anim-live { stroke: var(--lime); }

.anim-label {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.anim-tile.active .anim-label { color: var(--text); }

/* Trim Paths — это обрезка штриха, и в SVG ей отвечает stroke-dashoffset.
   Поэтому превью показывает ровно тот же механизм, что отработает в AE. */
.anim-none { stroke-dasharray: none; }

.anim-drawOn {
  stroke-dasharray: 100 100;
  animation: vf-draw-on 2.4s linear infinite;
}
@keyframes vf-draw-on {
  0%   { stroke-dashoffset: 100; }
  55%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; }
}

/* Сначала линия рисуется, затем стирается со своего начала — хвост */
.anim-drawTrail {
  stroke-dasharray: 100 100;
  animation: vf-trail 2.4s linear infinite;
}
@keyframes vf-trail {
  0%   { stroke-dashoffset: 100; }
  45%  { stroke-dashoffset: 0; }
  55%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -100; }
}

/* Видимый отрезок расширяется от середины в обе стороны */
.anim-fromMiddle {
  animation: vf-middle 2.4s linear infinite;
}
@keyframes vf-middle {
  0%   { stroke-dasharray: 0 100;   stroke-dashoffset: -50; }
  65%  { stroke-dasharray: 100 0;   stroke-dashoffset: 0; }
  100% { stroke-dasharray: 100 0;   stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .anim-live { animation: none !important; stroke-dasharray: none !important; }
}

/* ------------------------------------------------------- редактор easing */




/* При зажатом Shift видно, что ручки притягиваются к сетке */




/* Поля ввода: те же значения, что и ручки на графике, только числами.
   Связь двусторонняя — перетаскивание обновляет поля, ввод двигает ручки. */




/* --------------------------------------------------------------- статус */
.status-row {
  display: flex; align-items: flex-start; gap: 8px;
  min-height: 32px;
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.028), rgba(255,255,255,0)),
    #121417;
  color: var(--muted);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.035);
}

.status-dot {
  width: 9px; height: 9px; flex: none;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 12px rgba(198,242,59,0.45);
}
.status-row.busy  .status-dot { background: var(--orange); box-shadow: 0 0 12px rgba(255,154,60,0.46); }
.status-row.error .status-dot { background: var(--coral);  box-shadow: 0 0 12px rgba(255,107,107,0.46); }
.status-row.busy  #statusText { color: var(--orange); }
.status-row.error #statusText { color: var(--coral); }

/* Описание инструмента при наведении: длинный текст должен переноситься,
   а не обрезаться, поэтому строка тянется по высоте. */
.status-row.hint { border-color: rgba(198,242,59,0.32); }
.status-row.hint .status-dot { background: var(--grape); box-shadow: 0 0 12px rgba(167,139,250,0.45); }
.status-row.hint #statusText { color: var(--text); }

#statusText { flex: 1; min-width: 0; }
.status-dot { margin-top: 4px; }

/* Появляется после удачной отправки: фокус остаётся в Illustrator,
   но перейти в AE можно одним кликом, не ища настройку. */
.jump-btn {
  flex: none; width: auto; margin: 0;
  padding: 3px 9px;
  border: 1px solid rgba(198,242,59,0.55);
  border-radius: 4px;
  background: rgba(198,242,59,0.10);
  color: var(--lime);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.jump-btn:hover:not(:disabled) {
  background: rgba(198,242,59,0.20);
  border-color: var(--lime);
  color: var(--text);
}
.jump-btn[hidden] { display: none; }

/* ------------------------------------------------------------------ лог */








/* При зажатом Shift видно, что ручки притягиваются к сетке */




/* Поля ввода: те же значения, что и ручки на графике, только числами.
   Связь двусторонняя — перетаскивание обновляет поля, ввод двигает ручки. */




/* Молчащая строка состояния не занимает места: подтверждать каждое
   удачное нажатие незачем, результат виден в композиции */
.status-row.quiet { min-height: 0; padding-top: 0; padding-bottom: 0; }
.status-row.quiet .status-dot { display: none; }

/* -------------------------------------------------- сценки движения */
/*
 * Каждый пресет показывает своё движение маленьким квадратом внутри
 * кнопки. Двигается он только под курсором: пять непрерывно дёргающихся
 * плиток — это шум, от которого хочется отвернуться, а не объяснение.
 *
 * Ни файлов, ни загрузки: тот же квадрат, что и на кнопке, только он
 * ездит. Оттого и «весит» ровно ничего.
 */
/* --------------------------------------------------- порядок плиток */
/*
 * Плитку, которую тянут, надо отличать от тех, мимо которых её тянут:
 * иначе непонятно, что вообще происходит, и куда она встанет.
 */
/*
 * Поднятая плитка идёт над остальными и слегка увеличена — как берут
 * значок на телефоне. Тень даёт понять, что она «оторвалась» от сетки.
 */
.tool-button.is-lifted {
  z-index: 5;
  cursor: grabbing;
  transform-origin: center;
  border-color: var(--lime);
  box-shadow: 0 10px 24px rgba(0,0,0,0.45), 0 0 0 1px var(--lime) inset;
  transition: box-shadow 120ms ease;
}
.tool-button.is-lifted::before {
  /* Небольшой подъём поверх смещения от указателя: transform у плитки
     занят слежением за курсором, поэтому масштаб идёт отдельным слоем */
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  pointer-events: none;
}

/* ------------------------------------------------------------ адаптив */
/*
 * Раскладка идёт по признакам на корне, а не по медиазапросам.
 *
 * Панель CEP живёт внутри Adobe: ширина окна к её собственной ширине
 * отношения не имеет, и @media меряет не то. Признаки w-* и h-*
 * расставляет сама панель, измеряя себя; здесь только следствия.
 *
 * Ступени: до 300 — плитки в один столбец, до 420 — в два, до 640 —
 * четыре как раньше, дальше сколько поместится.
 */
.w-tight  .tool-grid { grid-template-columns: 1fr; }
.w-narrow .tool-grid { grid-template-columns: repeat(2, minmax(84px, 1fr)); }
.w-mid    .tool-grid { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.w-wide   .tool-grid { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
.w-huge   .tool-grid { grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); }

/* Растянутая сетка начинается слева, а не жмётся к середине: иначе
   широкая панель снова выглядит узкой полосой посередине */
.w-wide .tool-grid, .w-huge .tool-grid { justify-content: stretch; }
.layout-centred .tool-grid { justify-content: center; }

/* Узкой панели шапка нужна столбиком, иначе название теснит кнопки */
.w-tight .topbar,
.w-narrow .topbar { align-items: stretch; flex-direction: column; }
.w-tight .host-stack, .w-narrow .host-stack,
.w-tight .connection-status, .w-narrow .connection-status {
  justify-items: stretch; text-align: left;
}
.w-tight .host-switch, .w-narrow .host-switch,
.w-tight .top-controls, .w-narrow .top-controls { width: 100%; }
.w-tight .tool-button::after, .w-narrow .tool-button::after { display: none; }

/* Совсем узко — подписи под значками мельче, чтобы влезали целиком */
.w-tight .tool-button span { font-size: 10px; letter-spacing: 0.02em; }
.w-tight .options { gap: 6px; }
.w-tight .option { flex: 1 1 100%; }

/* Низкой панели журнал не нужен во весь рост: место дороже */
.h-short .log { max-height: 84px; }
.h-mid   .log { max-height: 200px; }

/*
 * Высокая узкая панель отдаёт остаток места журналу, низкая широкая —
 * плиткам. Это и есть та гибкость, ради которой всё затевалось: одна и
 * та же панель годится и колонкой сбоку, и полосой снизу.
 */
.shape-column .log { flex: 1 1 auto; max-height: none; }
.shape-column main { display: flex; flex-direction: column; }
.shape-row .options { flex-wrap: wrap; }

/* Прежний медиазапрос остаётся запасным: если признаки почему-то не
   встали, панель всё равно не должна разъезжаться */
@media (max-width: 500px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .host-stack, .connection-status { justify-items: stretch; text-align: left; }
  .host-switch, .top-controls { width: 100%; }
  .tool-button::after { display: none; }
}

/* --------------------------------------------------- точка привязки */
/*
 * Якорь, выравнивание и прореживание стоят в одном ряду: все три про то,
 * как объекты лежат.
 *
 * Шаг тот же, что у сетки инструментов, — 7px. Раньше здесь стояло 16px,
 * и на широкой панели ряд разъезжался на две строки, хотя места хватало.
 *
 * Перенос всё равно обязателен: панель CEP тянут за край как хотят, и в
 * узкой три кластера в строку не помещаются. Без переноса последний
 * уезжал за правый край и был недоступен вовсе.
 */
.layout-row {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 7px;
}

/* min-width: 0 — чтобы кластер мог сжиматься, а не распирать строку:
   по умолчанию flex-элемент не уже своего содержимого */
.tool-cluster {
  display: flex; flex-direction: column; gap: 6px;
  flex: 0 0 auto; min-width: 0;
}
.tool-cluster.grow { flex: 1 1 auto; }
.tool-cluster > label {
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.anchor-widget {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0d0f;
}

.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 20px);
  grid-template-rows: repeat(3, 20px);
  gap: 3px;
}

.anchor-cell {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: border-color .12s, background .12s;
}

/* точка в центре ячейки: сама ячейка — это место, куда встанет якорь */
.anchor-cell::after {
  content: "";
  position: absolute; inset: 0; margin: auto;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--milk); opacity: .35;
  transition: opacity .12s, background .12s;
}

.anchor-cell:hover { border-color: var(--grape); }
.anchor-cell:hover::after { opacity: .7; }

.anchor-cell.is-on { border-color: var(--lime); background: rgba(198, 242, 59, .1); }
.anchor-cell.is-on::after { background: var(--lime); opacity: 1; }



/* ------------------------------------------- выравнивание и распределение */
.align-widget {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0d0f;
}

.align-edges {
  display: grid;
  grid-template-columns: repeat(3, 26px);
  gap: 4px;
}

.align-side { display: flex; flex-direction: column; gap: 6px; }
.align-spread { display: flex; gap: 4px; }

.align-btn, .icon-btn {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--milk);
  padding: 0;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}

.align-btn svg, .icon-btn svg { width: 17px; height: 17px; }
.align-btn:hover, .icon-btn:hover { border-color: var(--lime); color: var(--lime); background: rgba(198, 242, 59, .08); }
.align-btn:active, .icon-btn:active { background: rgba(198, 242, 59, .18); }

.align-target {
  font: inherit; font-size: 11px;
  color: var(--milk);
  background: #0b0d0f;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
}

.align-gap-wrap {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted);
}

.align-gap {
  width: 56px;
  font: inherit; font-size: 11px;
  color: var(--milk);
  background: #0b0d0f;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
}

/* -------------------------------------- виджеты в строке опций */
/*
 * Разметка досталась в наследство от блока Motion, уехавшего в отдельный
 * плагин. Имена классов больше не говорят «motion»: на ней теперь живёт
 * только Select every, и название по бывшему соседу заставляло бы искать
 * несуществующий виджет.
 */
.cluster-widget {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0d0f;
}

.cluster-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.cluster-row { display: flex; align-items: center; gap: 8px; }

/* Чип — «нажал и получил», а не переключатель состояния */
.chip {
  width: auto; margin: 0;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--button);
  color: var(--text);
  font: inherit; font-size: 11px; font-weight: 500;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.chip:hover {
  border-color: var(--lime); color: var(--lime);
  background: rgba(198, 242, 59, .08);
}
.chip:active { background: rgba(198, 242, 59, .18); }

/* Прореживание выделения ничего не создаёт, а меняет уже выбранное —
   отсюда другой цвет наведения у его кнопок */
.cluster-actions { display: flex; gap: 4px; margin-left: auto; }
.cluster-actions .icon-btn:hover {
  border-color: var(--grape); color: var(--grape);
  background: rgba(167, 139, 250, .1);
}

.select-step { width: 44px; }

/* Выбранный шаг виден сразу: иначе не понять, что сделает кнопка */
.chip.is-on {
  border-color: var(--lime); color: var(--lime);
  background: rgba(198, 242, 59, .14);
}


/* ------------------------------------------------------ подсказки */
.tip-bubble {
  position: fixed;
  z-index: 999;
  max-width: 230px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #14181c;
  color: var(--milk);
  font-size: 11px;
  line-height: 1.4;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .55);
  pointer-events: none;          /* подсказка не должна перехватывать курсор */
  opacity: 0;
  transform: translateY(2px);
  transition: opacity .12s ease, transform .12s ease;
}

.tip-bubble.is-on { opacity: 1; transform: translateY(0); }

/* ----------------------------------------------------- shared Juicy theme */
.theme-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 66px;
  min-width: 66px;
  height: 31px;
  min-height: 31px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-deep);
  color: var(--muted);
  cursor: pointer;
  gap: 3px;
}

.theme-toggle:hover { border-color: rgba(198,242,59,0.72); }

.theme-toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 23px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--dim);
}

.theme-toggle-option svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle-night svg { fill: currentColor; stroke: none; }

.theme-toggle[data-theme="light"] .theme-toggle-day {
  border-color: rgba(98,124,5,0.42);
  background: var(--lime);
  color: #111;
}

.theme-toggle[data-theme="dark"] .theme-toggle-night {
  border-color: rgba(198,242,59,0.58);
  background: linear-gradient(135deg, #111 0%, #263117 100%);
  color: var(--lime);
  box-shadow: 0 0 14px rgba(198,242,59,0.18);
}

body.theme-dark {
  color-scheme: dark;
}

body.theme-light {
  color-scheme: light;
  --bg: #eef0ec;
  --panel: #fafbf8;
  --panel-deep: #f2f4ef;
  --button: #f6f7f3;
  --button-top: #ffffff;
  --button-hover: #edf1e6;
  --line: #cfd5cc;
  --line-soft: #dfe3dc;
  --text: #171a18;
  --muted: #626a65;
  --dim: #929993;
  --milk: #171a18;
  --shadow: rgba(23, 31, 25, 0.12);
  background: linear-gradient(180deg, #ffffff 0%, #f2f4ef 44%, #e8ebe6 100%);
}

body.theme-light .topbar,
body.theme-light .tool-grid,
body.theme-light .status-row,
body.theme-light .license-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.88), rgba(255,255,255,0.22)),
    var(--panel);
  box-shadow: 0 14px 30px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.9);
}

body.theme-light .tool-button {
  border-color: var(--line);
  background: linear-gradient(180deg, var(--button-top), var(--button));
  box-shadow: 0 8px 18px rgba(23,31,25,0.08), inset 0 1px 0 #fff;
}

body.theme-light .tool-button:hover:not([disabled]):not(.is-off) {
  border-color: rgba(98,124,5,0.62);
  background: linear-gradient(180deg, #fff, var(--button-hover));
  color: var(--text);
}

body.theme-light .tool-icon { color: #303631; filter: none; }
body.theme-light .tool-button.primary {
  border-color: rgba(98,124,5,0.62);
  background: linear-gradient(180deg, #ffffff, #f2f7e7);
  box-shadow: 0 8px 18px rgba(23,31,25,0.08), 0 0 0 1px rgba(98,124,5,0.08), inset 0 1px 0 #fff;
}
body.theme-light .tool-button.primary .tool-icon { color: #627c05; }
body.theme-light .tool-button::after,
body.theme-light .tip-bubble {
  border-color: rgba(98,124,5,0.32);
  background: rgba(250,251,248,0.98);
  color: var(--text);
  box-shadow: 0 12px 28px rgba(23,31,25,0.16);
}

body.theme-light .host-switch,
body.theme-light .refresh-button,
body.theme-light .theme-toggle,
body.theme-light .license-state,
body.theme-light .license-field input,
body.theme-light .option select,
body.theme-light .option input,
body.theme-light .anchor-widget,
body.theme-light .align-widget,
body.theme-light .align-target,
body.theme-light .align-gap,
body.theme-light .cluster-widget {
  background: var(--panel-deep);
}

body.theme-light .host-switch button.active {
  background: linear-gradient(135deg, rgba(198,242,59,0.45), rgba(167,139,250,0.15));
  color: var(--text);
}

body.theme-light .anim-track { stroke: #c3c9c2; }
body.theme-light .license-panel { background: rgba(28,34,29,0.28); }
body.theme-light .license-details { background: var(--line); }
body.theme-light .license-details div { background: var(--button); }
body.theme-light .align-btn,
body.theme-light .icon-btn { color: var(--text); }
body.theme-light .brand-mark { box-shadow: 0 6px 14px rgba(23,31,25,0.12); }
.brand-copy h1 { letter-spacing: 0; }

@media (max-width: 500px) {
  .top-controls { flex-wrap: wrap; justify-content: flex-start; }
  .host-switch { flex: 1 1 200px; width: auto; }
}
