:root {
  --bg: #0d1014;
  --card: #161b22;
  --line: #262d37;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4ee08a;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: .04em; }

.health { color: var(--muted); font-size: 13px; }
.health.ok { color: var(--accent); }
.health.bad { color: var(--bad); }

main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.card.wide { grid-column: 1 / -1; }

h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.devices { display: flex; flex-direction: column; gap: 8px; }

.dev {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.dev.active { border-color: var(--accent); }
.dev-id { font-weight: 600; }
.dev-meta { color: var(--muted); font-size: 12px; }

.pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.9;
  max-height: 420px;
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 25% 25%,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 25% 25%,
    #0a0d11;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: crosshair;
  overflow: hidden;
}

.pad-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 6px rgba(78, 224, 138, .18);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}

.pad:active .pad-dot, .pad-dot.on { opacity: 1; }

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

input, button {
  font: inherit;
  background: #0a0d11;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

input[type="number"] { width: 90px; }
input[type="text"] { flex: 1; min-width: 160px; }

button {
  cursor: pointer;
  background: #1d2530;
}

button:hover { border-color: var(--accent); }

.log {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  color: var(--muted);
  white-space: pre-wrap;
}

/* ---------- экран, агент, шаги (добавлено) ---------- */

.pad .screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;          /* картинка = поле тапа, проценты совпадают */
  pointer-events: none;
  user-select: none;
}

.pad .screen:not([src]) { display: none; }

.pad.has-screen {
  /* ширина от высоты и пропорции кадра (--ar ставит app.js); высота — из aspect-ratio,
     так картинка не растягивается ни на узком экране, ни у горизонтального кадра */
  width: min(100%, calc(min(600px, 72vh) * var(--ar, 0.46)));
  height: auto;
  max-height: none;
  max-width: 100%;
  margin: 0 auto;
  background: #000;
}

.dev.offline { opacity: .6; border-style: dashed; }

/* калибровка AssistiveTouch: клик по картинке уходит в /at/calibrate, не на телефон */
.pad.calibrating { outline: 3px dashed #f5c451; outline-offset: 3px; cursor: cell; }
.at-hint { color: #f5c451; margin: 8px 0 0; }

select { max-width: calc(100% - 6px); }
.row > label { max-width: 100%; }

.frame-info { margin: 8px 0 0; }

textarea, select {
  font: inherit;
  background: #0a0d11;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
}

label { color: var(--muted); font-size: 13px; }
label select, label input { margin-left: 6px; }

button.primary { border-color: var(--accent); color: var(--accent); }
button.danger:not(:disabled):hover { border-color: var(--bad); color: var(--bad); }
button:disabled, button:disabled:hover { opacity: .45; cursor: default; border-color: var(--line); }

.status { margin: 12px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.status.live { color: #f5c451; }
.status.ok { color: var(--accent); }
.status.bad { color: var(--bad); }

.steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 420px;
  overflow: auto;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
}

.steps:empty::before { content: 'шагов пока нет'; color: var(--muted); }

.step {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.step .n, .step .t, .step .ms { color: var(--muted); }
.step .act { color: var(--accent); font-weight: 600; }
.step .strategy { color: #f5c451; }
.step .why { flex-basis: 100%; color: var(--muted); }
.step.runner { border-style: dashed; }
.step.bad { border-color: var(--bad); }
.step.bad .res { color: var(--bad); }

@media (max-width: 480px) {
  header { padding: 12px 16px; }
  main { padding: 16px; }
}