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

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2235;
  --bg-card-hover: #1f2a40;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.25);
  --red: #ef4444;
  --yellow: #eab308;
  --cyan: #06b6d4;
  --border: rgba(255, 255, 255, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────── */
.header {
  text-align: center;
  padding: 20px 0 28px;
}

.header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #6366f1 0%, #a78bfa 50%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 400;
}

/* ── Main Layout ─────────────────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  flex: 1;
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* ── Video Container ─────────────────────────────────────────────── */
.video-container {
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 4 / 3;
  box-shadow: 0 0 40px rgba(99, 102, 241, 0.08);
}

.video-container video,
.video-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-container video {
  transform: scaleX(-1);
}

.video-container canvas {
  z-index: 2;
  pointer-events: none;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: 16px;
  pointer-events: none;
}

.prediction {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--green);
  text-shadow: 0 2px 12px rgba(34, 197, 94, 0.5);
  transition: var(--transition);
}

.confidence {
  font-size: 1rem;
  font-weight: 500;
  color: var(--cyan);
  margin-top: 4px;
}

.fps {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--yellow);
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 10px;
  border-radius: 6px;
}

.flash {
  position: absolute;
  inset: 0;
  background: var(--green);
  opacity: 0;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.1s;
}

.flash.active {
  opacity: 0.2;
}

/* ── Controls Panel ──────────────────────────────────────────────── */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Mode Tabs ───────────────────────────────────────────────────── */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.tab:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 14px var(--accent-glow);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #4ade80);
  color: #052e16;
  box-shadow: 0 4px 16px var(--green-glow);
  flex: 1;
}

.btn-success:hover {
  transform: translateY(-1px);
}

.btn-success:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
  flex: 1;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* ── Panel ───────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}

.panel h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

/* ── Gesture Button Grid ─────────────────────────────────────────── */
.gesture-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.gesture-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  gap: 6px;
}

.gesture-btn:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.gesture-btn.active {
  border-color: var(--green);
  background: rgba(34, 197, 94, 0.1);
  box-shadow: 0 0 16px var(--green-glow);
}

.gesture-btn .count {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 28px;
  text-align: center;
}

.gesture-btn.active .count {
  background: rgba(34, 197, 94, 0.2);
  color: var(--green);
}

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

/* ── Model Status ────────────────────────────────────────────────── */
.model-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.red {
  background: var(--red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.status-dot.green {
  background: var(--green);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Sample Counts ───────────────────────────────────────────────── */
.sample-counts {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 20px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

.sample-counts .count-label {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Footer ──────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 24px 0 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ── Animations ──────────────────────────────────────────────────── */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  animation: slideIn 0.3s ease-out;
}

/* ── Mobile Responsive ──────────────────────────────────────────── */

/* Tablet & small laptops */
@media (max-width: 900px) {
  .app {
    padding: 16px 14px;
  }

  .header {
    padding: 14px 0 20px;
  }

  .header h1 {
    font-size: 1.7rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .main {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .video-container {
    aspect-ratio: 4 / 3;
    max-height: 55vh;
  }

  .prediction {
    font-size: 1.3rem;
  }

  .controls-panel {
    gap: 12px;
  }

  .panel {
    padding: 16px;
  }

  .footer {
    padding: 16px 0 8px;
  }
}

/* Phones */
@media (max-width: 600px) {
  .app {
    padding: 10px 10px;
    min-height: 100dvh;
  }

  .header {
    padding: 10px 0 14px;
  }

  .header h1 {
    font-size: 1.35rem;
    letter-spacing: -0.01em;
  }

  .subtitle {
    font-size: 0.78rem;
    margin-top: 4px;
  }

  .main {
    gap: 12px;
  }

  .video-container {
    aspect-ratio: 4 / 3;
    max-height: 45vh;
    border-radius: var(--radius-sm);
  }

  .overlay {
    padding: 10px;
  }

  .prediction {
    font-size: 1.1rem;
  }

  .confidence {
    font-size: 0.82rem;
    margin-top: 2px;
  }

  .fps {
    font-size: 0.72rem;
    top: 10px;
    right: 10px;
    padding: 3px 7px;
  }

  /* Mode Tabs */
  .mode-tabs {
    padding: 3px;
  }

  .tab {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  /* Buttons — larger touch targets */
  .btn {
    padding: 14px 16px;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    min-height: 48px;
  }

  .btn-primary:hover,
  .btn-success:hover {
    transform: none; /* disable hover lift on touch */
  }

  /* Panels */
  .panel {
    padding: 14px;
    border-radius: var(--radius-sm);
  }

  .panel h3 {
    font-size: 0.95rem;
  }

  .hint {
    font-size: 0.78rem;
    margin-bottom: 10px;
  }

  /* Gesture grid — single column on narrow phones */
  .gesture-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 10px;
  }

  .gesture-btn {
    padding: 10px 10px;
    font-size: 0.78rem;
    min-height: 44px;
    gap: 4px;
  }

  .gesture-btn .count {
    font-size: 0.7rem;
    padding: 2px 6px;
    min-width: 24px;
  }

  /* Action buttons row */
  .actions {
    flex-direction: column;
    gap: 8px;
  }

  .actions .btn {
    width: 100%;
  }

  /* Model Status */
  .model-status {
    padding: 12px 14px;
    font-size: 0.82rem;
  }

  /* Sample Counts */
  .sample-counts {
    padding: 12px 14px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
  }

  /* Footer */
  .footer {
    padding: 14px 0 6px;
    font-size: 0.75rem;
  }
}

/* Very small phones (iPhone SE, Galaxy Fold, etc.) */
@media (max-width: 400px) {
  .app {
    padding: 8px 8px;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    font-size: 0.72rem;
  }

  .video-container {
    max-height: 40vh;
  }

  .prediction {
    font-size: 0.95rem;
  }

  .confidence {
    font-size: 0.75rem;
  }

  .gesture-grid {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .gesture-btn {
    font-size: 0.75rem;
    padding: 9px 10px;
  }

  .tab {
    padding: 9px 8px;
    font-size: 0.8rem;
  }

  .btn {
    padding: 12px 14px;
    font-size: 0.85rem;
  }
}

/* Landscape phones — limit video height */
@media (max-height: 500px) and (orientation: landscape) {
  .video-container {
    max-height: 60vh;
    aspect-ratio: 16 / 9;
  }

  .header {
    padding: 6px 0 10px;
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .subtitle {
    display: none;
  }

  .main {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .app {
    padding: 8px 10px;
  }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
  .btn-primary:hover,
  .btn-success:hover,
  .btn-danger:hover,
  .gesture-btn:hover {
    transform: none;
  }

  .btn:active {
    transform: scale(0.97);
    transition: transform 0.1s;
  }

  .gesture-btn:active {
    transform: scale(0.97);
    transition: transform 0.1s;
  }

  .tab:active {
    transform: scale(0.97);
  }
}
