/* VeraMath Main Styles
   Purple Theme, Poppins Font, Mobile-First Design
   Optimized for performance
*/

/* 
   NOTE: Google Fonts (Poppins) is loaded via HTML <link> tags with preconnect 
   hints for better performance instead of using @import here.
*/

/* CSS Variables */
:root {
  /* Purple Theme Colors */
  --primary: #8b5cf6;
  --primary-dark: #7c3aed;
  --primary-light: #a78bfa;
  --primary-rgb: 139, 92, 246;
  --primary-glow: rgba(var(--primary-rgb), 0.3);

  /* Background Colors */
  --bg-dark: #0f0a1f;
  --bg-surface: #1a1425;
  --bg-card: #231a33;
  --bg-elevated: #2d2242;

  /* Text Colors */
  --text-primary: #f8f8ff;
  --text-secondary: #b8b8c8;
  --text-muted: #7a7a8c;

  /* Status Colors */
  --success: #10b981;
  --success-light: #34d399;
  --warning: #f59e0b;
  --warning-light: #fbbf24;
  --error: #ef4444;
  --error-light: #f87171;
  --info: #3b82f6;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  --gradient-glow: linear-gradient(
    135deg,
    rgba(var(--primary-rgb), 0.2) 0%,
    rgba(var(--primary-rgb), 0.1) 100%
  );

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--primary-glow);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 70px;
  --max-content-width: 1200px;
}

/* Reset & Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

h1 {
  font-size: 2.25rem;
}
h2 {
  font-size: 1.875rem;
}
h3 {
  font-size: 1.5rem;
}
h4 {
  font-size: 1.25rem;
}
h5 {
  font-size: 1.125rem;
}
h6 {
  font-size: 1rem;
}

p {
  margin-bottom: var(--space-md);
}
a {
  color: var(--primary-light);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--primary);
}

/* Utility Classes */
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.text-muted {
  color: var(--text-muted);
}
.text-success {
  color: var(--success);
}
.text-warning {
  color: var(--warning);
}
.text-error {
  color: var(--error);
}
.text-primary {
  color: var(--primary);
}

.font-light {
  font-weight: 300;
}
.font-medium {
  font-weight: 500;
}
.font-semibold {
  font-weight: 600;
}
.font-bold {
  font-weight: 700;
}

.mb-0 {
  margin-bottom: 0;
}
.mb-1 {
  margin-bottom: var(--space-sm);
}
.mb-2 {
  margin-bottom: var(--space-md);
}
.mb-3 {
  margin-bottom: var(--space-lg);
}
.mt-2 {
  margin-top: var(--space-md);
}
.mt-3 {
  margin-top: var(--space-lg);
}

/* Container */
.container {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* Grid System */
.grid {
  display: grid;
  gap: var(--space-md);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* Flex Utilities */
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.justify-center {
  justify-content: center;
}
.gap-1 {
  gap: var(--space-sm);
}
.gap-2 {
  gap: var(--space-md);
}
.gap-3 {
  gap: var(--space-lg);
}

/* Card Component */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  border: 1px solid rgba(128, 128, 128, 0.15);
  transition: transform var(--transition-normal),
    box-shadow var(--transition-normal);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.card-glow {
  box-shadow: var(--shadow-glow);
  border-color: rgba(var(--primary-rgb), 0.2);
}

/* Stats Card */
.stat-card {
  background: var(--gradient-glow);
  border: 1px solid rgba(var(--primary-rgb), 0.2);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-light);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.stat-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  color: white;
}

.stat-icon svg {
  width: 24px;
  height: 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-normal);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.4);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid rgba(128, 128, 128, 0.2);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: var(--primary);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-light);
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--error-light);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0.75rem;
  aspect-ratio: 1;
}

/* Form Elements */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid rgba(128, 128, 128, 0.3);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23B8B8C8' viewBox='0 0 16 16'%3E%3Cpath d='M8 10.5l-5-5h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
}

.form-error {
  font-size: 0.8125rem;
  color: var(--error);
  margin-top: var(--space-xs);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Alerts */
.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success);
  color: var(--success-light);
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  color: var(--error-light);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--warning);
  color: var(--warning-light);
}

.alert-info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid var(--info);
  color: var(--info);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-primary {
  background: var(--primary);
  color: white;
}
.badge-success {
  background: var(--success);
  color: white;
}
.badge-warning {
  background: var(--warning);
  color: #1a1a1a;
}
.badge-error {
  background: var(--error);
  color: white;
}
.badge-muted {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* Table */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(128, 128, 128, 0.15);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table th,
.table td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody tr {
  background: var(--bg-card);
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--bg-elevated);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 31, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal),
    visibility var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
}

/* Progress Bar */
.progress {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

/* Timer Component */
.timer-display {
  font-size: 4rem;
  font-weight: 700;
  color: var(--primary-light);
  text-align: center;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px var(--primary-glow);
}

.timer-label {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: var(--space-sm);
}

/* Task Container */
.task-container {
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
}

.task-problem {
  font-size: 2rem;
  font-weight: 600;
  padding: var(--space-xl);
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  font-family: "Courier New", monospace;
  letter-spacing: 2px;
}

.captcha-text {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 8px;
  padding: var(--space-xl);
  background: linear-gradient(
    135deg,
    var(--bg-elevated) 0%,
    var(--bg-card) 100%
  );
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  user-select: none;
  text-transform: uppercase;
}

/* Answer Input Large */
.answer-input {
  font-size: 1.5rem;
  text-align: center;
  padding: var(--space-lg);
  letter-spacing: 2px;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --header-height: 60px;
  }

  h1 {
    font-size: 1.75rem;
  }
  h2 {
    font-size: 1.5rem;
  }
  h3 {
    font-size: 1.25rem;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .card {
    padding: var(--space-md);
  }

  .timer-display {
    font-size: 3rem;
  }

  .task-problem {
    font-size: 1.5rem;
    padding: var(--space-lg);
  }

  .captcha-text {
    font-size: 1.75rem;
    letter-spacing: 4px;
  }

  .hide-mobile {
    display: none !important;
  }

  .table th,
  .table td {
    padding: var(--space-sm);
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
  }

  .modal {
    margin: var(--space-sm);
  }

  .stat-value {
    font-size: 1.5rem;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-fade-in {
  animation: fadeIn var(--transition-normal) ease-out;
}
.animate-slide-up {
  animation: slideUp var(--transition-slow) ease-out;
}
.animate-pulse {
  animation: pulse 2s infinite;
}
.animate-spin {
  animation: spin 1s linear infinite;
}

/* Loader */
.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-lg);
  opacity: 0.5;
}

/* Tooltip */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}
