/* ==========================================================================
   Spot the Scam — Main Design System
   ========================================================================== */

:root {
  --primary: #0F172A;
  --secondary: #2563EB;
  --accent: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --background: #E2E8F0;
  --surface: #FFFFFF;
  --text: #1E293B;
  --text-muted: #64748B;
  --border: #CBD5E1;
  --border-focus: #2563EB;
  --safe: #22C55E;
  --suspicious: #EF4444;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.1);
  --header-height: 52px;
  --footer-height: 60px;
  --narration-height: 52px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition-fast: 150ms ease;
  --transition-base: 220ms ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.skip-link {
  position: absolute; top: -100%; left: var(--space-md); z-index: 10000;
  padding: var(--space-sm) var(--space-md); background: var(--secondary); color: white;
  border-radius: var(--radius-sm); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: var(--space-md); }

/* Loading */
.loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: white;
}
.loading-content { text-align: center; }
.loading-shield { font-size: 3rem; margin-bottom: var(--space-md); color: var(--accent); }
.loading-text { font-size: 0.9rem; opacity: 0.85; margin-bottom: var(--space-md); }
.loading-bar { width: 200px; height: 3px; background: rgba(255,255,255,0.2); border-radius: 2px; overflow: hidden; margin: 0 auto; }
.loading-bar-fill { height: 100%; background: var(--accent); animation: loadProgress 1.4s ease forwards; }
@keyframes loadProgress { to { width: 100%; } }

/* App shell: full viewport course player */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* Header */
.course-header {
  flex-shrink: 0;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px var(--space-md);
  background: var(--primary);
  color: white;
  gap: var(--space-sm);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.header-brand { flex-shrink: 1; min-width: 0; }
.brand-title {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  line-height: 1.3;
}

.header-center { flex: 1; min-width: 80px; max-width: 240px; margin: 0 var(--space-sm); }
.progress-track { height: 4px; background: rgba(255,255,255,0.15); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.4s ease; }
.progress-label { font-size: 0.65rem; opacity: 0.7; margin-top: 2px; display: block; text-align: center; white-space: nowrap; }

.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.score-badge {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.1); padding: 4px 8px;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600;
  white-space: nowrap;
}
.score-label { opacity: 0.85; font-weight: 500; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none;
  background: rgba(255,255,255,0.1); color: white;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition-fast);
}
.btn-icon:hover { background: rgba(255,255,255,0.2); }
.btn-icon:focus-visible { outline: 2px solid white; outline-offset: 1px; }
.btn-icon[aria-pressed="true"] { background: var(--secondary); }

/* Course menu */
.course-menu {
  position: fixed; top: 0; right: 0; width: 300px; max-width: 88vw;
  height: 100vh; height: 100dvh; background: var(--surface);
  box-shadow: var(--shadow-lg); z-index: 200;
  transform: translateX(100%); transition: transform 0.3s ease;
  overflow-y: auto;
}
.course-menu.open { transform: translateX(0); }
.menu-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-md); background: var(--primary); color: white;
  position: sticky; top: 0; z-index: 1;
}
.menu-header h2 { font-size: 1rem; margin: 0; }
.menu-subtitle { font-size: 0.7rem; opacity: 0.75; margin-top: 2px; font-weight: 400; }
.menu-close { background: rgba(255,255,255,0.1); }
.menu-list { list-style: none; padding: var(--space-sm); }
.menu-list li { margin-bottom: 2px; }
.menu-item {
  display: flex; align-items: center; gap: var(--space-sm);
  width: 100%; padding: 10px var(--space-md); border: none; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem;
  text-align: left; color: var(--text); transition: background var(--transition-fast);
}
.menu-item:hover { background: #F1F5F9; }
.menu-item.active { background: #EFF6FF; color: var(--secondary); font-weight: 600; }
.menu-item.completed { color: #15803D; }
.menu-item:disabled { opacity: 0.4; cursor: not-allowed; }
.menu-item .menu-icon { width: 18px; text-align: center; color: var(--text-muted); font-size: 0.8rem; }
.menu-settings {
  padding: var(--space-md);
  border-top: 1px solid var(--border);
  background: #F8FAFC;
}
.menu-settings h3 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: var(--space-sm);
}
.menu-field { margin-bottom: var(--space-md); }
.menu-field:last-child { margin-bottom: 0; }
.menu-field label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text); margin-bottom: 4px;
}
.menu-field-row { display: flex; gap: 6px; }
.menu-input { font-size: 0.8rem; padding: 8px 10px; width: 100%; }
.menu-field-row .menu-input { flex: 1; min-width: 0; }
.btn-sm { padding: 8px 12px; font-size: 0.75rem; white-space: nowrap; }
.menu-field-hint { font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; line-height: 1.4; }
.menu-reset {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}
.btn-reset-course {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 14px;
  background: white; border: 1px solid #FECACA; color: #B91C1C;
  border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition-fast);
}
.btn-reset-course:hover {
  background: #FEF2F2; border-color: #F87171;
}

.btn-link {
  display: inline-block; margin-top: var(--space-md);
  background: none; border: none; color: var(--secondary);
  font-size: 0.8rem; font-weight: 500; cursor: pointer;
  text-decoration: underline; padding: 0;
}
.btn-link:hover { color: #1D4ED8; }

.menu-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 150; }

/* Slide viewport — scrollable content area */
.slide-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #F1F5F9;
  display: flex;
  flex-direction: column;
}

.course-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: var(--space-md);
  margin-bottom: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.slide-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-lg);
  outline: none;
  -webkit-overflow-scrolling: touch;
}

/* Narration strip — always visible at bottom of stage */
.narration-strip {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: 10px var(--space-md);
  min-height: var(--narration-height);
  background: #F8FAFC;
  border-top: 1px solid var(--border);
}
.narration-replay {
  flex-shrink: 0;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: white;
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-muted); font-size: 0.8rem;
  transition: all var(--transition-fast);
}
.narration-replay:hover { border-color: var(--secondary); color: var(--secondary); }
.narration-text {
  flex: 1;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
  margin: 0;
  padding-top: 6px;
}

/* Footer */
.course-footer {
  flex-shrink: 0;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.btn-nav {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border);
  background: white; color: var(--text);
  border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition-fast);
}
.btn-nav:hover:not(:disabled) { border-color: var(--secondary); color: var(--secondary); }
.btn-nav:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-next { background: var(--secondary); color: white; border-color: var(--secondary); }
.btn-next:hover:not(:disabled) { background: #1D4ED8; border-color: #1D4ED8; color: white; }
.slide-counter { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

/* DEV ONLY — remove before production */
.btn-dev-skip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border: 1px dashed var(--warning);
  background: #FFFBEB; color: #B45309;
  border-radius: var(--radius-sm); font-size: 0.72rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition-fast);
}
.btn-dev-skip:hover { background: #FEF3C7; border-color: #D97706; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: 10px 20px; background: var(--secondary); color: white;
  border: none; border-radius: var(--radius-sm); font-size: 0.9rem;
  font-weight: 600; cursor: pointer; transition: background var(--transition-fast);
}
.btn-primary:hover { background: #1D4ED8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm);
  padding: 10px 16px; background: white; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--secondary); color: var(--secondary); }

.btn-safe { background: #F0FDF4; color: #15803D; border: 2px solid #86EFAC; }
.btn-safe:hover, .btn-safe.selected { background: #22C55E; color: white; border-color: #22C55E; }
.btn-suspicious { background: #FEF2F2; color: #B91C1C; border: 2px solid #FCA5A5; }
.btn-suspicious:hover, .btn-suspicious.selected { background: #EF4444; color: white; border-color: #EF4444; }

.card {
  background: var(--surface); border-radius: var(--radius-md);
  border: 1px solid var(--border); padding: var(--space-lg);
}

/* Toast */
.toast-container {
  position: fixed; top: calc(var(--header-height) + 8px); right: 8px;
  z-index: 500; display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 8px 14px; background: var(--primary); color: white;
  border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 500;
  box-shadow: var(--shadow-md); pointer-events: auto;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--warning); }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* Responsive */
@media (max-width: 640px) {
  .app { max-width: none; box-shadow: none; }
  .course-stage { margin: 0; border-radius: 0; border-left: none; border-right: none; }
  .slide-content { padding: var(--space-md); }
  .brand-title { font-size: 0.75rem; max-width: 9rem; }
  .btn-nav span { display: none; }
  .btn-nav { padding: 8px 12px; }
  .btn-dev-skip span { display: none; }
  .header-center { max-width: 100px; }
  .score-badge .score-label { display: none; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .brand-title { font-size: 0.8rem; max-width: 14rem; }
}

@media (min-width: 1024px) {
  body { padding: var(--space-md); }
  .app {
    height: calc(100dvh - 2 * var(--space-md));
    max-height: calc(100dvh - 2 * var(--space-md));
  }
  .slide-content { padding: var(--space-xl) var(--space-xl); }
}
