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

:root {
  --bg:        #0d0f14;
  --surface:   #161b25;
  --border:    #252d3d;
  --accent:    #00e5ff;
  --accent2:   #7c3aed;
  --text:      #e2e8f0;
  --text-muted:#6b7280;
  --green:     #22c55e;
  --orange:    #f97316;
  --red:       #ef4444;
  --radius:    12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
header {
  text-align: center;
  padding: 2rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

/* ─── Main layout ───────────────────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 1.5rem;
  align-items: flex-start;
  justify-content: center;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Video / canvas ────────────────────────────────────────────────────── */
.video-wrapper {
  position: relative;
  width: min(640px, 100%);
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

#webcam, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay { pointer-events: none; }

/* Status badge */
.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
  transition: background 0.3s, color 0.3s;
}

.badge--idle    { background: rgba(107,114,128,.7); color: #fff; }
.badge--ready   { background: rgba(34,197,94,.8);  color: #fff; }
.badge--active  { background: rgba(0,229,255,.85); color: #000; }

/* ─── Loading overlay ───────────────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 15, 20, 0.92);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
  transition: opacity 0.4s ease;
}

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

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

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-step {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.loading-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

/* ─── Hold countdown ring ───────────────────────────────────────────────── */
.hold-countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 5;
}

.hold-countdown.visible { opacity: 1; }

.hold-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* arc starts from the top */
}

.hold-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 7;
}

.hold-ring-arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 251.3;
  stroke-dashoffset: 251.3;
  filter: drop-shadow(0 0 6px var(--accent));
}

.hold-seconds {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.9);
  position: relative;
  z-index: 1;
}

/* ─── Right panel ───────────────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  flex: 1;
  min-width: 260px;
  max-width: 360px;
}

.gesture-display,
.av-action-display,
.audio-player,
.gesture-legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* Gesture display */
.gesture-icon {
  font-size: 3.5rem;
  text-align: center;
  line-height: 1.2;
}

.gesture-label {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 0.4rem;
  color: var(--accent);
}

.confidence-wrap {
  background: var(--border);
  border-radius: 999px;
  height: 8px;
  margin-top: 0.75rem;
  overflow: hidden;
}

.confidence-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 999px;
  transition: width 0.2s ease;
}

.confidence-text {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* AV action display */
.av-action-display h2,
.audio-player h2,
.gesture-legend h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.av-action {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--green);
  min-height: 2rem;
}

/* Flash animation for AV action text */
@keyframes flash-in {
  0%   { opacity: 0; transform: translateY(-4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.av-action.flash {
  animation: flash-in 0.25s ease forwards;
}

/* Volume bar */
.volume-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.volume-bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.volume-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--green));
  border-radius: 999px;
  transition: width 0.25s ease;
}

#volume-value {
  min-width: 2.5ch;
  font-weight: 600;
  color: var(--text);
}

/* ─── Audio player ──────────────────────────────────────────────────────── */
.audio-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

/* Override native audio element to match dark theme */
#demo-audio {
  width: 100%;
  border-radius: 8px;
  accent-color: var(--accent);
  filter: invert(1) hue-rotate(180deg) brightness(0.9);
}

/* ─── Gesture legend table ──────────────────────────────────────────────── */
.gesture-legend table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.gesture-legend td {
  padding: 0.4rem 0.5rem;
  vertical-align: middle;
}

.gesture-legend tr:not(:last-child) td {
  border-bottom: 1px solid var(--border);
}

.gesture-legend td:first-child { font-size: 1.4rem; }

/* ─── Photo modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: min(480px, 92vw);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  transform: translateY(12px);
  transition: transform 0.25s ease;
}

.modal-overlay.visible .modal-card {
  transform: translateY(0);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: var(--text);
  background: var(--border);
}

.photo-preview {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
}

.btn-download {
  display: block;
  text-align: center;
  padding: 0.65rem 1.25rem;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #000;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 8px;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn-download:hover { opacity: 0.85; }

/* ─── Footer ────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  header h1  { font-size: 1.4rem; }
  .panel     { max-width: 100%; }
  main       { padding: 1rem; gap: 1rem; }
}
