/* ─── Reset & Variables ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #07070f;
  --surface:     rgba(255,255,255,0.04);
  --surface-2:   rgba(255,255,255,0.07);
  --border:      rgba(255,255,255,0.08);
  --border-hi:   rgba(255,255,255,0.18);
  --accent:      #8b5cf6;
  --accent-2:    #22d3ee;
  --text:        #f1f5f9;
  --text-dim:    #64748b;
  --radius:      12px;
  --header-h:    58px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── App Shell ──────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 50% at 20% 0%, rgba(139,92,246,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 40% 40% at 80% 100%, rgba(34,211,238,0.08) 0%, transparent 60%),
    var(--bg);
}

/* ─── Header ─────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(7,7,15,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon { width: 28px; height: 28px; }
.logo-text  { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.logo-accent{ background: linear-gradient(135deg, #a78bfa, #22d3ee);
              -webkit-background-clip: text; -webkit-text-fill-color: transparent;
              background-clip: text; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #64748b;
  transition: background 0.4s, box-shadow 0.4s;
}
.status-dot.ready   { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.status-dot.tracking{ background: var(--accent-2); box-shadow: 0 0 6px var(--accent-2); }
.status-dot.error   { background: #f87171; box-shadow: 0 0 6px #f87171; }

/* Buttons */
.cam-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s;
}
.cam-btn svg { width: 15px; height: 15px; }
.cam-btn:hover { background: var(--surface); border-color: var(--border-hi); }
.cam-btn.off  { color: var(--text-dim); }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { color: var(--text); border-color: var(--border-hi); background: var(--surface-2); }
.icon-btn.danger:hover { color: #f87171; border-color: rgba(248,113,113,0.3); }

/* ─── Main ───────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Stage (camera + guide) ─────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  gap: 10px;
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}

#video {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#drawCanvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* Gesture chip overlay */
.gesture-chip {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 7px;
  padding: 6px 16px;
  border-radius: 20px;
  background: rgba(7,7,15,0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-hi);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
}
#chipIcon { font-size: 16px; }

/* Cursor dot */
.cursor {
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 0 12px 4px rgba(255,255,255,0.5);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: width 0.15s, height 0.15s, opacity 0.2s, background 0.2s, box-shadow 0.2s;
  display: none;
}
.cursor.draw  { background: var(--accent-2); box-shadow: 0 0 14px 5px rgba(34,211,238,0.6); }
.cursor.erase { background: #f87171;         box-shadow: 0 0 14px 5px rgba(248,113,113,0.5);
                width: 40px; height: 40px; opacity: 0.4; }
.cursor.pinch { background: #facc15;         box-shadow: 0 0 14px 5px rgba(250,204,21,0.5); }
.cursor.rest  { opacity: 0; }

/* No camera overlay */
.no-cam {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  background: rgba(7,7,15,0.85);
  color: var(--text-dim);
}
.no-cam svg { width: 48px; height: 48px; }
.no-cam p   { font-size: 15px; }

/* ─── Gesture Guide ───────────────────────────────────────────────── */
.gesture-guide {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.gesture-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.25s, background 0.25s;
}
.gesture-item.active {
  border-color: var(--border-hi);
  background: var(--surface-2);
}

.g-icon {
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.g-icon svg { width: 28px; height: 28px; }

.draw-icon  { background: rgba(34,211,238,0.12);  color: #22d3ee; }
.erase-icon { background: rgba(248,113,113,0.12); color: #f87171; }
.move-icon  { background: rgba(250,204,21,0.12);  color: #facc15; }
.rest-icon  { background: rgba(148,163,184,0.12); color: #94a3b8; }

.g-text { display: flex; flex-direction: column; }
.g-name { font-size: 13px; font-weight: 600; }
.g-hint { font-size: 11px; color: var(--text-dim); }

/* ─── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  padding: 12px 12px 12px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ctrl-section {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.ctrl-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ctrl-label-row .ctrl-label { margin-bottom: 0; }
.ctrl-val {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

/* Color grid */
.color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.color-btn {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--c);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  outline: none;
}
.color-btn:hover  { transform: scale(1.12); }
.color-btn.active { border-color: white; box-shadow: 0 0 0 1px rgba(255,255,255,0.3); }

.custom-color-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  transition: color 0.2s;
}
.custom-color-label:hover { color: var(--text); }
.custom-color-label input[type="color"] {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-hi);
  background: none;
  cursor: pointer;
  padding: 2px;
  -webkit-appearance: none;
}
.custom-color-label input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-label input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

/* Sliders */
.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* Gallery */
.gallery-section { flex: 1; min-height: 0; }
.gallery {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.gallery-empty {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 16px 0;
}
.gallery-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s;
}
.gallery-item:hover { border-color: var(--border-hi); }
.gallery-thumb {
  width: 36px; height: 36px;
  border-radius: 5px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}
.gallery-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.gallery-name {
  font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gallery-date { font-size: 10px; color: var(--text-dim); }
.gallery-del {
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px;
  background: none; border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}
.gallery-del:hover { color: #f87171; background: rgba(248,113,113,0.1); }
.gallery-del svg { width: 12px; height: 12px; }

/* ─── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 10px 20px;
  border-radius: 20px;
  background: rgba(15,15,30,0.95);
  border: 1px solid var(--border-hi);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(12px);
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  opacity: 0;
  z-index: 100;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
