:root {
  --bg: #0b0c10;
  --card: #111218;
  --muted: #b8becc; /* slightly brighter for better contrast */
  --text: #e6e8ee;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ring: rgba(59,130,246,0.35);

  /* Detective theme colors */
  --detective-amber: #d97706;
  --detective-gold: #fbbf24;
  --detective-shadow: rgba(0,0,0,0.6);
  --case-paper: #f9fafb;
  --evidence-red: #dc2626;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  background: linear-gradient(180deg, #0b0c10, #11121a);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.app {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
}

.pane {
  background: var(--card);
  border: 1px solid #1a1c24;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

/* Enhanced video container with recording states */
.video-wrap {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  transition: box-shadow 0.3s ease;
}

.video-wrap.recording {
  box-shadow: 0 0 0 2px var(--evidence-red), 0 0 20px rgba(220, 38, 38, 0.3);
  animation: recordingPulse 2s ease-in-out infinite;
}

@keyframes recordingPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--evidence-red), 0 0 20px rgba(220, 38, 38, 0.3); }
  50% { box-shadow: 0 0 0 2px var(--evidence-red), 0 0 30px rgba(220, 38, 38, 0.5); }
}

/* Mirror BOTH layers so overlay aligns with selfie view */
.video-wrap video,
#overlay {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
  transform-origin: center;
}

/* Overlay sits on top and doesn't catch clicks */
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Enhanced status with visual indicator */
.status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 6px 10px;
  background: rgba(17, 18, 24, 0.85);
  border: 1px solid #272938;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Default indicator dot */
.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  transition: background-color 0.3s ease;
}

/* Recording/pulsing */
.status.listening::before {
  background: var(--evidence-red);
  animation: statusPulse 1s ease-in-out infinite;
}

/* Processing spinner (now an actual spinner) */
.status.processing::before {
  content: '';
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--detective-amber);
  background: transparent;
  animation: spin 0.8s linear infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

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

/* Enhanced countdown with animation */
.countdown {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 2px solid var(--evidence-red);
  background: rgba(17,18,24,0.85);
  font-weight: 700;
  color: var(--evidence-red);
  backdrop-filter: blur(8px);
  animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Enhanced controls */
.controls {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.btn {
  appearance: none;
  border: 1px solid #26324a;
  background: linear-gradient(180deg, #1b2232, #151b28);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  transition: left 0.5s ease;
}

.btn:hover:not(:disabled)::before {
  left: 100%;
}

.btn:hover:not(:disabled) {
  box-shadow: 0 0 0 3px var(--ring);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .6;
  cursor: not-allowed;
  background: #161a24;
  border-color: #1f2431;
  box-shadow: none;
  transform: none;
}

/* Focus visibility (keyboard users) */
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}
a:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Variants */
.btn.primary {
  border-color: #2a4e9a;
  background: linear-gradient(180deg, #1e3a8a, #1e40af);
}
.btn.danger {
  border-color: #7a2a2a;
  background: linear-gradient(180deg, #7f1d1d, #991b1b);
}

/* Button icons */
.btn-icon {
  font-size: 14px;
}

/* Loading state */
.btn.loading {
  pointer-events: none;
}
.btn.loading .btn-icon {
  animation: spin 1s linear infinite;
}

.privacy {
  margin: 12px 2px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* Enhanced error styling */
#ui-error {
  margin: 8px 2px 0;
  font-size: 12px;
  color: #fca5a5;
  display: none;
  padding: 8px 12px;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: 8px;
  text-align: center;
}

/* Detective-themed narrative panel */
.pane-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 240px;
}

/* Case file styling */
.narrative-card {
  background: linear-gradient(180deg, #131624, #11131c);
  border: 1px solid #1e2030;
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.narrative-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--detective-amber);
}

.case-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.case-number {
  background: var(--detective-amber);
  color: #000;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.narrative-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--detective-gold);
  font-family: 'Courier New', monospace;
}

.narrative-body {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.case-closed {
  margin-top: 16px;
  padding: 8px 12px;
  background: rgba(217, 119, 6, 0.1);
  border: 1px solid rgba(217, 119, 6, 0.2);
  border-radius: 6px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--detective-amber);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Typewriter effect for story reveal (keep lightweight) */
.narrative-body.typewriter {
  overflow: hidden;
  white-space: pre-wrap;
  animation: typewriter 2s steps(100) forwards;
}

@keyframes typewriter {
  from { width: 0; }
  to { width: 100%; }
}

/* Progress bar */
.progress-container {
  margin-top: 8px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--evidence-red), var(--detective-amber));
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 2px;
  will-change: width; /* perf hint */
}

/* Two-view toggle helper */
.pane-left > section[hidden] { display: none !important; }

/* Analysis reading view */
.analysis-reading {
  max-width: 640px;
  padding: 16px;
  margin: 0 auto;
  background: var(--card, #111218);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.analysis-title {
  font-size: 18px;
  color: var(--detective-gold, #e0b94a);
  margin: 0 0 8px;
  font-weight: 700;
}
.analysis-body {
  white-space: pre-wrap;
  color: var(--muted, #a3a8b3);
  line-height: 1.5;
  margin: 0;
}
.analysis-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Optional compact mode to hide right pane via JS toggle */
.app.compact .pane-right { display: none; }

/* Mobile responsiveness */
@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    gap: 12px;
    margin: 16px auto;
  }
  .video-wrap {
    aspect-ratio: 4 / 3;
  }
  .btn {
    padding: 14px 20px;
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .controls {
    flex-direction: column;
  }
  .controls { gap: 10px; margin-top: 14px; }
  .btn { justify-content: center; padding: 16px 20px; font-size: 16px; }
}

/* Reduce motion niceties */
@media (prefers-reduced-motion: reduce) {
  .btn, .video-wrap, .countdown, .status::before {
    transition: none;
  }
  .video-wrap.recording { animation: none; }
  .countdown { animation: none; }
  .narrative-body.typewriter { animation: none; }
}
