/* ===== ROOT VARIABLES ===== */
:root {
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --blur: blur(14px);
  --cyan: #00f5ff;
  --purple: #b44cff;
  --green: #00ff88;
  --magenta: #ff00cc;
  --text: #f0f4ff;
  --text-dim: rgba(240, 244, 255, 0.65);
  --radius: 16px;
  --card-radius: 14px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Exo 2', sans-serif; color: var(--text); min-height: 100vh; overflow-x: hidden; background: #0a0f0a; }

/* ===== BACKGROUND SCENE ===== */
.bg-scene {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 60%, rgba(0,60,10,0.9) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 30%, rgba(5,40,10,0.8) 0%, transparent 50%),
    url('https://images.unsplash.com/photo-1448375240586-882707db888b?w=1600&q=80') center/cover no-repeat;
  background-blend-mode: multiply, multiply, normal;
}
.bg-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.45) 0%, rgba(0,20,5,0.6) 100%);
}

/* Light Rays */
.light-ray {
  position: absolute; top: -10%; width: 3px; height: 120vh;
  background: linear-gradient(to bottom, rgba(180,255,160,0.18), transparent);
  transform-origin: top center;
  animation: swayRay 8s ease-in-out infinite alternate;
  filter: blur(6px);
}
.ray1 { left: 20%; transform: rotate(-8deg); animation-delay: 0s; }
.ray2 { left: 50%; transform: rotate(3deg); animation-delay: 2s; opacity: 0.6; }
.ray3 { left: 75%; transform: rotate(-5deg); animation-delay: 4s; opacity: 0.4; }

@keyframes swayRay {
  from { opacity: 0.2; transform: rotate(-10deg); }
  to   { opacity: 0.5; transform: rotate(5deg); }
}

/* Particles */
.particles { position: absolute; inset: 0; overflow: hidden; }
.particle {
  position: absolute; border-radius: 50%;
  background: rgba(0, 255, 136, 0.6);
  animation: floatUp linear infinite;
  pointer-events: none;
}
@keyframes floatUp {
  0%   { transform: translateY(100vh) scale(0); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.5; }
  100% { transform: translateY(-10vh) scale(1.2); opacity: 0; }
}

/* ===== HUB CONTAINER ===== */
.hub-container {
  position: relative; z-index: 1;
  max-width: 1600px; margin: 0 auto;
  padding: 28px 24px 40px;
  display: flex; flex-direction: column; gap: 20px;
}

/* ===== TITLE ===== */
.hub-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(22px, 3.5vw, 38px);
  font-weight: 700;
  text-align: center;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.4), 0 0 60px rgba(180, 76, 255, 0.2);
  margin-bottom: 4px;
}
.hub-title .v1 { color: var(--cyan); }

/* ===== GLASS CARD ===== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.1);
  padding: 20px 22px;
  transition: border-color 0.3s;
}
.glass-card:hover { border-color: rgba(0, 245, 255, 0.3); }

.card-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 15px; font-weight: 700;
  letter-spacing: 1px; margin-bottom: 14px;
  color: #fff;
}

/* ===== TOP ROW: 4 cards ===== */
.top-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 18px;
}

/* Image Detection */
.card-image-detect { display: flex; flex-direction: column; gap: 12px; }

.file-input-wrapper { width: 100%; }
.file-label {
  display: flex; align-items: center;
  background: rgba(0,0,0,0.35);
  border: 1.5px solid var(--cyan);
  border-radius: 8px; padding: 10px 14px;
  cursor: pointer; width: 100%;
  font-family: 'Exo 2', sans-serif; font-size: 13px;
  color: var(--text-dim);
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.15), inset 0 0 8px rgba(0, 245, 255, 0.05);
  transition: box-shadow 0.3s, border-color 0.3s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-label:hover { box-shadow: 0 0 20px rgba(0, 245, 255, 0.35); border-color: var(--cyan); }

/* Audio Detection */
.card-audio-detect { display: flex; flex-direction: column; }
.audio-player-row  {
  display: flex; align-items: center; gap: 14px; margin-bottom: 0;
}
.audio-player { flex: 1; }
.audio-placeholder {
  background: rgba(255,255,255,0.08);
  border-radius: 30px; padding: 8px 16px;
  font-size: 12px; color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
  white-space: nowrap; overflow: hidden;
}
audio { width: 100%; border-radius: 30px; display: none; }
.btn-detect-audio { white-space: nowrap; flex-shrink: 0; }

/* ===== BUTTON ===== */
.btn {
  font-family: 'Orbitron', sans-serif;
  font-size: 12px; font-weight: 700;
  letter-spacing: 1px;
  padding: 10px 28px;
  border: none; border-radius: 30px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.3s;
  position: relative; overflow: hidden;
  align-self: center;
}
.btn-gradient {
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  color: #fff;
  box-shadow: 0 4px 20px rgba(180, 76, 255, 0.45);
}
.btn-gradient:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 30px rgba(0, 245, 255, 0.5);
}
.btn-gradient:active { transform: scale(0.97); }
.btn-gradient::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  opacity: 0; transition: opacity 0.3s;
  border-radius: inherit;
}
.btn-gradient:hover::after { opacity: 0.25; }

/* Camera & Mic cards */
.card-camera, .card-mic { display: flex; flex-direction: column; gap: 10px; }
.camera-select-row { display: flex; align-items: center; gap: 10px; }
.select-label { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.glass-select {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: 8px; padding: 6px 10px;
  color: var(--text); font-family: 'Exo 2', sans-serif;
  font-size: 13px; cursor: pointer; flex: 1;
}
.glass-select option { background: #1a2a1a; }

.camera-preview-wrapper {
  position: relative; width: 100%; height: 110px;
  border-radius: 10px; overflow: hidden;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--glass-border);
}
#cameraFeed    { width: 100%; height: 100%; object-fit: cover; display: none; }
#micVisualizer { width: 100%; height: 100%; display: none; }
.camera-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; font-size: 12px; color: var(--text-dim);
}
.camera-icon { font-size: 28px; }

.card-mic.mic-active {
  border-color: var(--cyan);
  box-shadow: var(--glass-shadow), 0 0 20px rgba(0, 245, 255, 0.25);
}

/* ===== ANALYTICS ROW ===== */
.analytics-row { display: flex; }
.card-analytics {
  display: flex; flex-direction: row;
  align-items: center; gap: 20px;
  flex: 1;
}
.card-analytics .card-title { margin-bottom: 0; white-space: nowrap; }
.charts-row { display: flex; gap: 12px; flex: 1; min-width: 0; }
.chart-wrap { flex: 1; min-width: 0; }
.chart-legend {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--text-dim);
  margin-bottom: 6px; flex-wrap: wrap;
}
.dot        { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-purple { background: var(--purple); }
.dot-cyan   { background: var(--cyan); }
.dot-green  { background: var(--green); }

/* Chart canvases — JS controls pixel dims via setupHiDPICanvas();
   CSS height is fixed so the logical size is predictable.
   Do NOT use the global canvas override here. */
.chart-canvas {
  display: block;
  width: 100% !important;
  height: 160px !important;
  border-radius: 6px;
}

/* ===== RESULTS ROW — stacked: Static on top, Live below ===== */
.results-row {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.results-section { display: flex; flex-direction: column; gap: 12px; }
.section-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 15px; font-weight: 700;
  letter-spacing: 1px; color: #fff;
}

/* Result Cards Row */
.results-cards { display: flex; gap: 12px; height: 100%; }
.result-card {
  flex: 1;
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--card-radius);
  padding: 14px 14px 12px;
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
  transition: border-color 0.3s, transform 0.2s;
  min-width: 0;
  overflow: visible;
}
.result-card:hover { border-color: rgba(0, 245, 255, 0.3); transform: translateY(-2px); }

.result-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px; font-weight: 700;
  color: var(--text-dim); letter-spacing: 1px;
  align-self: flex-start;
}

/* ── All result image wrappers: unified tall height ── */
/* Both Static and Live rows are now full-width, so use a generous height */
.result-img-wrap {
  width: 100%;
  height: 420px;
  border-radius: 10px; overflow: hidden;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}

/* Image fills wrapper */
.result-img-wrap img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
}

.result-placeholder { font-size: 36px; opacity: 0.4; position: relative; z-index: 1; }
.result-caption {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  font-family: 'Exo 2', sans-serif;
  width: 100%;
  min-height: 20px;
  padding: 4px 6px;
  background: rgba(0,0,0,0.35);
  border-radius: 6px;
  word-break: break-word;
  flex-shrink: 0;
}

/* Audio Wave */
.audio-wave {
  display: flex; align-items: center;
  gap: 4px; height: 70px;
}
.audio-wave span {
  display: block; width: 6px; border-radius: 3px;
  background: linear-gradient(to top, var(--purple), var(--cyan));
  animation: waveAnim 1s ease-in-out infinite alternate;
  height: 20px;
}
.audio-wave span:nth-child(1) { animation-delay: 0s; }
.audio-wave span:nth-child(2) { animation-delay: 0.15s; }
.audio-wave span:nth-child(3) { animation-delay: 0.3s; }
.audio-wave span:nth-child(4) { animation-delay: 0.15s; }
.audio-wave span:nth-child(5) { animation-delay: 0s; }
@keyframes waveAnim {
  from { height: 10px; opacity: 0.5; }
  to   { height: 60px; opacity: 1; }
}
.audio-wave.active span       { animation-play-state: running; }
.audio-wave:not(.active) span { animation-play-state: paused; height: 20px; opacity: 0.4; }

/* Live video — native browser rendering, no canvas copy, truly smooth */
#liveVideo {
  display: none;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  border-radius: 10px;
}

/* Live Canvas — transparent overlay for bbox drawing only, never the video frame */
#liveCanvas {
  display: none;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border-radius: 10px;
  pointer-events: none;
  background: transparent;
}

/* Mic Result Canvas */
#micResultCanvas {
  position: absolute; inset: 0;
  width: 100% !important;
  height: 100% !important;
  border-radius: 10px;
}

/* Mic Result */
.mic-result { flex-direction: column; }
.no-activity {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; height: 100%; width: 100%;
  position: relative; z-index: 1;
}
.na-icon { font-size: 32px; }
.na-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px; font-weight: 700;
  color: var(--text-dim);
}
.na-sub { font-size: 11px; color: rgba(240,244,255,0.4); }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  color: #fff; padding: 12px 28px;
  border-radius: 30px; font-family: 'Orbitron', sans-serif;
  font-size: 12px; letter-spacing: 1px;
  box-shadow: 0 8px 30px rgba(180,76,255,0.5);
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), opacity 0.4s;
  opacity: 0; pointer-events: none; z-index: 999;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ===== DETECTING ANIMATION ===== */
.detecting {
  animation: detectGlow 1s ease-in-out infinite alternate;
}
@keyframes detectGlow {
  from { border-color: rgba(180, 76, 255, 0.4); box-shadow: var(--glass-shadow); }
  to   { border-color: var(--cyan);              box-shadow: 0 0 30px rgba(0, 245, 255, 0.3); }
}

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: var(--purple); border-radius: 3px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1300px) {
  .top-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .top-row { grid-template-columns: 1fr 1fr; }
  .results-row { grid-template-columns: 1fr; }
  .card-analytics { flex-direction: column; align-items: flex-start; }
  .charts-row { width: 100%; }
}

/* ===== MOBILE ===== */
@media (max-width: 640px) {
  .hub-container { padding: 14px 10px 30px; gap: 14px; }
  .hub-title { font-size: 16px; letter-spacing: 1px; }

  /* One card per row, comfortable spacing */
  .top-row { grid-template-columns: 1fr; gap: 12px; }
  .glass-card { padding: 16px 14px; }
  .card-title { font-size: 13px; margin-bottom: 10px; }

  /* Full-width tap targets */
  .btn { width: 100%; align-self: stretch; padding: 12px 16px; font-size: 12px; }
  .file-label { padding: 12px 14px; }

  /* Audio card: stack player above its button */
  .audio-player-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .audio-placeholder { text-align: center; }

  /* Camera / mic preview smaller on phones */
  .camera-preview-wrapper { height: 130px; }
  .camera-select-row { flex-wrap: wrap; }

  /* Charts stack vertically */
  .charts-row { flex-direction: column; gap: 16px; }
  .chart-canvas { height: 140px !important; }
  .card-analytics { gap: 12px; }

  /* Results: one card per row, phone-sized panels */
  .results-cards { flex-direction: column; gap: 12px; }
  .result-img-wrap { height: 62vw; min-height: 200px; max-height: 320px; }
  .result-caption { font-size: 12px; }
  .section-title { font-size: 13px; }

  /* Lighter background work on phones */
  .light-ray { display: none; }
}

/* Very small phones */
@media (max-width: 380px) {
  .hub-title { font-size: 14px; }
  .glass-card { padding: 12px 10px; }
}
