*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f4f6fb;
  --surface:  #ffffff;
  --surface2: #f0f2f8;
  --border:   #e2e6f0;
  --accent:   #5b5ef4;
  --accent-h: #4345d4;
  --text:     #1a1a2e;
  --muted:    #7b82a0;
  --ok:       #17a86a;
  --warn:     #e07b20;
  --err:      #d63a5a;
  --shadow:   0 2px 12px rgba(80,90,140,0.08);
  --shadow-lg:0 4px 24px rgba(80,90,140,0.13);
  --radius:   14px;
  --radius-sm:8px;

  /* жест-цвета */
  --c0: #e8445a;
  --c1: #5b5ef4;
  --c2: #17a86a;
  --c3: #e07b20;
  --c4: #0ea5c9;
  --c5: #9b59b6;
  --c6: #27ae60;
  --c7: #c0392b;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 14px 48px;
  gap: 16px;
}

/* ── Header ── */
header { text-align: center; }
header h1 {
  font-size: 1.5rem; font-weight: 800;
  letter-spacing: -0.03em; color: var(--text);
}
header p { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }

/* ── Steps ── */
.steps {
  display: flex; gap: 6px; align-items: center;
  font-size: 0.75rem; color: var(--muted);
  flex-wrap: wrap; justify-content: center;
}
.step-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--border); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700;
  transition: background 0.25s, color 0.25s;
}
.step-dot.active { background: var(--accent); color: #fff; }
.step-dot.done   { background: var(--ok); color: #fff; }
.step-sep { color: var(--border); }

/* ── Video ── */
.video-wrap {
  position: relative;
  width: 100%; max-width: 480px;
  aspect-ratio: 4/3;
  background: #1a1a2e;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
#video  {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform: scaleX(-1);
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.badge {
  position: absolute; top: 10px; left: 12px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 99px;
  padding: 6px 16px;
  font-size: 0.88rem; font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  transition: color 0.2s;
}

/* ── Confidence bars ── */
#conf-wrap {
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 7px;
  min-height: 16px;
}
.conf-row  { display: flex; align-items: center; gap: 10px; }
.conf-label {
  width: 96px; font-size: 0.78rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conf-bg {
  flex: 1; height: 7px;
  background: var(--border); border-radius: 99px; overflow: hidden;
}
.conf-bar  {
  height: 100%; border-radius: 99px;
  transition: width 0.15s ease; width: 0%;
  opacity: 0.85;
}
.conf-pct  {
  width: 36px; text-align: right;
  font-size: 0.74rem; color: var(--muted); font-variant-numeric: tabular-nums;
}

/* ── Layout ── */
.main { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 12px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); margin-bottom: 12px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 14px; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #fff;
  font-size: 0.85rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  width: 100%; box-shadow: 0 2px 8px rgba(91,94,244,0.18);
}
.btn:hover    { background: var(--accent-h); box-shadow: 0 4px 14px rgba(91,94,244,0.28); }
.btn:active   { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.btn.secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); box-shadow: none;
}
.btn.secondary:hover { background: var(--border); }

.btn.danger {
  background: #fff0f3; color: var(--err);
  border: 1px solid #ffd6df; box-shadow: none;
}
.btn.danger:hover { background: #ffe0e6; }

.btn.warn {
  background: #fff7ed; color: var(--warn);
  border: 1px solid #fde8c8; box-shadow: none;
}
.btn.warn:hover { background: #feecd4; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.82rem;
  padding: 3px 7px; border-radius: 6px;
  transition: color 0.15s, background 0.15s; line-height: 1;
}
.btn-icon:hover { color: var(--err); background: #fff0f3; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ── Gesture cards ── */
#gesture-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 320px; overflow-y: auto;
  padding-right: 4px;
}
#gesture-list::-webkit-scrollbar { width: 4px; }
#gesture-list::-webkit-scrollbar-track { background: transparent; }
#gesture-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.gesture-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow 0.15s;
}
.gesture-card:hover { box-shadow: var(--shadow); }

.gesture-card-header {
  display: flex; align-items: center; gap: 9px;
}
.gesture-emoji { font-size: 1.35rem; line-height: 1; }
.gesture-name  { font-size: 0.9rem; font-weight: 600; flex: 1; color: var(--text); }
.gesture-count {
  font-size: 0.72rem; font-weight: 700;
  border-radius: 99px; padding: 3px 10px;
}
.gesture-card-actions { display: flex; gap: 6px; }
.gesture-card-actions .btn {
  font-size: 0.78rem; padding: 7px 10px;
  box-shadow: none;
}
.btn-capture { background: var(--accent); color: #fff; }
.btn-capture:hover { background: var(--accent-h); }
.btn-undo {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); flex: 0 0 auto; width: auto;
}
.btn-undo:hover { color: var(--warn); border-color: #fde8c8; background: #fff7ed; }

.gesture-samples { font-size: 0.72rem; }
.sample-info { color: var(--muted); }
.sample-info.muted { opacity: 0.5; }

/* ── Log ── */
.log {
  font-size: 0.74rem; line-height: 1.75;
  min-height: 80px; color: var(--muted);
}
.log span   { display: block; }
.log .ok    { color: var(--ok); }
.log .warn  { color: var(--warn); }
.log .err   { color: var(--err); }

/* ── Dialog ── */
.dialog-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(26,26,46,0.35);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-lg);
  width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 14px;
}
.dialog h2 { font-size: 1rem; font-weight: 700; }
.dialog label {
  font-size: 0.78rem; color: var(--muted);
  display: block; margin-bottom: 5px; font-weight: 500;
}
.dialog input {
  width: 100%; background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px; color: var(--text);
  font-size: 0.9rem; font-family: inherit; outline: none;
  transition: border-color 0.15s;
}
.dialog input:focus { border-color: var(--accent); }
.dialog-buttons { display: flex; gap: 8px; }

/* ── Desktop 2-column ── */
@media (min-width: 900px) {
  body { padding: 28px 24px 48px; }

  .desktop-wrap {
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 24px;
    width: 100%;
    max-width: 980px;
    align-items: start;
  }

  .col-left  { display: flex; flex-direction: column; gap: 14px; }
  .col-right { display: flex; flex-direction: column; gap: 12px; }

  .video-wrap { max-width: 100%; }
  #conf-wrap  { max-width: 100%; }
  .main       { max-width: 100%; }
}

/* ── Save/Load menu ── */
.save-menu-wrap { position: relative; }

.save-menu-btn {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; width: 100%;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 0.85rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.save-menu-btn:hover { border-color: var(--accent); background: var(--surface2); }
.save-menu-btn .arrow { transition: transform 0.2s; font-size: 0.7rem; color: var(--muted); }
.save-menu-btn.open .arrow { transform: rotate(180deg); }

.save-menu-dropdown {
  display: none;
  flex-direction: column; gap: 6px;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  box-shadow: var(--shadow-lg);
}
.save-menu-dropdown.open { display: flex; }

.save-menu-dropdown .btn { font-size: 0.82rem; padding: 9px 12px; }

.save-note {
  font-size: 0.72rem; color: var(--muted); line-height: 1.5;
  padding: 6px 2px 2px;
}
