/* ═══════════════════════════════════════════════════════
   TestLab — Shared CSS Variables & Base Styles
   ═══════════════════════════════════════════════════════ */

:root {
  /* ── Palette ─────────────────────────────────────── */
  --tl-primary: #4f46e5;
  --tl-primary-light: #818cf8;
  --tl-primary-dark: #3730a3;
  --tl-accent: #f59e0b;
  --tl-accent-light: #fbbf24;
  --tl-success: #10b981;
  --tl-success-light: #34d399;
  --tl-danger: #ef4444;
  --tl-danger-light: #f87171;
  --tl-warning: #f59e0b;
  --tl-info: #3b82f6;

  /* ── Light theme (student) ──────────────────────── */
  --tl-bg: #f8fafc;
  --tl-bg-card: #ffffff;
  --tl-bg-elevated: #f1f5f9;
  --tl-text: #1e293b;
  --tl-text-secondary: #64748b;
  --tl-text-muted: #94a3b8;
  --tl-border: #e2e8f0;
  --tl-border-focus: var(--tl-primary);
  --tl-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --tl-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.04);
  --tl-shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.12);

  /* ── Spacing ─────────────────────────────────────── */
  --tl-space-xs: 0.25rem;
  --tl-space-sm: 0.5rem;
  --tl-space-md: 1rem;
  --tl-space-lg: 1.5rem;
  --tl-space-xl: 2rem;
  --tl-space-2xl: 3rem;

  /* ── Typography ──────────────────────────────────── */
  --tl-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --tl-font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --tl-text-xs: clamp(0.7rem, 1.5vw, 0.75rem);
  --tl-text-sm: clamp(0.8rem, 1.8vw, 0.875rem);
  --tl-text-base: clamp(0.9rem, 2vw, 1rem);
  --tl-text-lg: clamp(1rem, 2.5vw, 1.125rem);
  --tl-text-xl: clamp(1.1rem, 3vw, 1.25rem);
  --tl-text-2xl: clamp(1.3rem, 3.5vw, 1.5rem);
  --tl-text-3xl: clamp(1.6rem, 4vw, 1.875rem);

  /* ── Radius ──────────────────────────────────────── */
  --tl-radius-sm: 0.375rem;
  --tl-radius-md: 0.5rem;
  --tl-radius-lg: 0.75rem;
  --tl-radius-xl: 1rem;
  --tl-radius-full: 9999px;

  /* ── Transitions ─────────────────────────────────── */
  --tl-transition: 150ms ease;
  --tl-transition-slow: 300ms ease;
}

/* ── Dark Theme (student) ────────────────────────── */

[data-theme="dark"] {
  --tl-bg: #0f172a;
  --tl-bg-card: #1e293b;
  --tl-bg-elevated: #334155;
  --tl-text: #f1f5f9;
  --tl-text-secondary: #94a3b8;
  --tl-text-muted: #64748b;
  --tl-border: #334155;
  --tl-border-focus: var(--tl-primary-light);
  --tl-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --tl-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.3);
  --tl-shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* ── Reset ──────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--tl-font);
  font-size: var(--tl-text-base);
  line-height: 1.6;
  color: var(--tl-text);
  background: var(--tl-bg);
  min-height: 100dvh;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

img, svg { display: block; max-width: 100%; }

/* ── Utility Classes ───────────────────────────────── */

.tl-container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 var(--tl-space-lg);
}

.tl-card {
  background: var(--tl-bg-card);
  border: 1px solid var(--tl-border);
  border-radius: var(--tl-radius-lg);
  box-shadow: var(--tl-shadow);
  padding: var(--tl-space-lg);
}

.tl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tl-space-sm);
  padding: var(--tl-space-sm) var(--tl-space-lg);
  border: none;
  border-radius: var(--tl-radius-md);
  font-weight: 600;
  font-size: var(--tl-text-base);
  cursor: pointer;
  transition: all var(--tl-transition);
  min-height: 48px;
  min-width: 48px;
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
}

.tl-btn:active { transform: scale(0.97); }
.tl-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.tl-btn-primary {
  background: var(--tl-primary);
  color: white;
}
.tl-btn-primary:hover:not(:disabled) { background: var(--tl-primary-dark); }

.tl-btn-success {
  background: var(--tl-success);
  color: white;
}
.tl-btn-success:hover:not(:disabled) { background: #059669; }

.tl-btn-danger {
  background: var(--tl-danger);
  color: white;
}
.tl-btn-danger:hover:not(:disabled) { background: #dc2626; }

.tl-btn-outline {
  background: transparent;
  color: var(--tl-primary);
  border: 2px solid var(--tl-primary);
}
.tl-btn-outline:hover:not(:disabled) { background: var(--tl-primary); color: white; }

.tl-btn-lg {
  padding: var(--tl-space-md) var(--tl-space-xl);
  font-size: var(--tl-text-lg);
  min-height: 56px;
  border-radius: var(--tl-radius-lg);
}

.tl-input {
  width: 100%;
  padding: var(--tl-space-sm) var(--tl-space-md);
  border: 2px solid var(--tl-border);
  border-radius: var(--tl-radius-md);
  font-size: var(--tl-text-lg);
  background: var(--tl-bg-card);
  color: var(--tl-text);
  transition: border-color var(--tl-transition);
  min-height: 48px;
}

.tl-input:focus {
  outline: none;
  border-color: var(--tl-border-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.tl-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--tl-radius-full);
  font-size: var(--tl-text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tl-badge-success { background: #d1fae5; color: #065f46; }
.tl-badge-warning { background: #fef3c7; color: #92400e; }
.tl-badge-danger { background: #fee2e2; color: #991b1b; }
.tl-badge-info { background: #dbeafe; color: #1e40af; }
.tl-badge-neutral { background: #f1f5f9; color: #475569; }

/* ── Connection status indicator ───────────────────── */

.tl-connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.tl-connection-dot.connected { background: var(--tl-success); }
.tl-connection-dot.disconnected { background: var(--tl-danger); animation: tl-pulse 1.5s infinite; }

@keyframes tl-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Progress bar ──────────────────────────────────── */

.tl-progress {
  width: 100%;
  height: 8px;
  background: var(--tl-bg-elevated);
  border-radius: var(--tl-radius-full);
  overflow: hidden;
}
.tl-progress-bar {
  height: 100%;
  background: var(--tl-primary);
  border-radius: var(--tl-radius-full);
  transition: width 0.5s ease;
}

/* ── Animations ────────────────────────────────────── */

@keyframes tl-fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tl-slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes tl-scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.tl-animate-in {
  animation: tl-fadeIn 0.4s ease forwards;
}

/* ── Modal ─────────────────────────────────────────── */

.tl-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--tl-space-lg);
  animation: tl-fadeIn 0.2s ease;
}

.tl-modal {
  background: var(--tl-bg-card);
  border-radius: var(--tl-radius-xl);
  box-shadow: var(--tl-shadow-xl);
  padding: var(--tl-space-xl);
  max-width: 500px;
  width: 100%;
  animation: tl-scaleIn 0.3s ease;
}

.tl-modal h2 {
  font-size: var(--tl-text-xl);
  margin-bottom: var(--tl-space-md);
}

.tl-modal-actions {
  display: flex;
  gap: var(--tl-space-sm);
  margin-top: var(--tl-space-lg);
  justify-content: flex-end;
}

/* ── Hidden utility ────────────────────────────────── */

.tl-hidden { display: none !important; }

/* ── Responsive safe area ──────────────────────────── */

@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Disclaimer / Copyright Footer ───────────────── */

.tl-disclaimer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px var(--tl-space-md);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 900;
}

.tl-disclaimer-logo {
  height: 22px;
  width: auto;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.tl-disclaimer:hover .tl-disclaimer-logo { opacity: 1; }

.tl-disclaimer-text {
  font-family: var(--tl-font);
  font-size: 0.68rem;
  color: var(--tl-text-secondary, #64748b);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* Dark variant for teacher dashboard */
.tl-disclaimer--dark {
  background: rgba(15, 23, 42, 0.8);
  border-top-color: rgba(255, 255, 255, 0.06);
}

.tl-disclaimer--dark .tl-disclaimer-text {
  color: rgba(148, 163, 184, 0.8);
}

.tl-disclaimer--dark .tl-disclaimer-logo {
  filter: invert(1) brightness(0.85);
  opacity: 0.55;
}

.tl-disclaimer--dark:hover .tl-disclaimer-logo { opacity: 0.9; }

/* ── Privacy link in footer ─────────────────────────── */

.tl-privacy-link {
  background: transparent;
  border: none;
  padding: 0 0 0 8px;
  margin: 0;
  font: inherit;
  font-size: 0.68rem;
  color: var(--tl-text-secondary, #64748b);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.tl-privacy-link:hover,
.tl-privacy-link:focus-visible {
  opacity: 1;
  color: var(--tl-primary, #2563eb);
  outline: none;
}

.tl-disclaimer--dark .tl-privacy-link {
  color: rgba(148, 163, 184, 0.85);
}
.tl-disclaimer--dark .tl-privacy-link:hover,
.tl-disclaimer--dark .tl-privacy-link:focus-visible {
  color: #e2e8f0;
}

.tl-privacy-modal .tl-privacy-body {
  margin: 0;
}
