:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-2: #24242c;
  --border: #2e2e38;
  --text: #f0f0f5;
  --text-muted: #9a9aa8;
  --accent: #e8a0bf;
  --accent-soft: rgba(232, 160, 191, 0.15);
  --primary: #d4789c;
  --primary-hover: #c46a8c;
  --success: #6bcf8e;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0,0,0,0.45);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  position: relative;
}

/* ========== HEADER ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 15, 18, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.logo svg {
  color: var(--accent);
}

.logo .accent {
  color: var(--accent);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.icon-btn.primary:hover {
  background: var(--primary-hover);
}

.icon-btn.small {
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  border-radius: 8px;
}

/* ========== STAGE ========== */
.stage {
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror by default */
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* when dragging we need pointer events */
#overlay.interactive {
  pointer-events: auto;
  cursor: grab;
}

#overlay.interactive:active {
  cursor: grabbing;
}

/* Guide / Start screen */
.guide-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 14, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  transition: opacity 0.4s ease;
}

.guide-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.guide-content {
  text-align: center;
  max-width: 360px;
  padding: 32px;
}

.guide-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.guide-content h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.guide-content p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 28px;
}

.btn-start {
  background: linear-gradient(135deg, var(--primary), #b85a82);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(212, 120, 156, 0.4);
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(212, 120, 156, 0.5);
}

/* Loading */
.loading {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 14, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 16;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== PANEL ========== */
.panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 340px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 25;
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
}

.panel.closed {
  transform: translateX(100%);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.panel-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.disclaimer {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Controls */
.control-group {
  margin-bottom: 22px;
}

.control-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.slider-row .value {
  min-width: 64px;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
}

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(212, 120, 156, 0.35);
}

.seg-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

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

.btn-secondary {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

/* FAB for mobile */
.fab {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  box-shadow: 0 6px 24px rgba(212, 120, 156, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: transform 0.2s;
}

.fab:hover {
  transform: scale(1.06);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}

.modal-content h3 {
  font-size: 1.1rem;
}

#capture-canvas {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  background: #000;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary {
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* Responsive */
@media (max-width: 900px) {
  .panel {
    width: 100%;
    max-width: 380px;
  }

  .fab {
    display: flex;
  }

  .panel.closed + .fab,
  .panel.closed ~ .fab {
    display: flex;
  }
}

@media (max-width: 600px) {
  .header {
    padding: 10px 14px;
  }

  .logo {
    font-size: 1rem;
  }

  .panel {
    max-width: 100%;
  }
}

/* Smooth scrollbar for panel */
.panel-body::-webkit-scrollbar {
  width: 5px;
}
.panel-body::-webkit-scrollbar-track {
  background: transparent;
}
.panel-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
