/* ============================================================
   BASE RESET & GLOBAL STYLES
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

html {
  font-size: calc(var(--font-base) * var(--font-scale));
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

/* ═══ Artistic Background: Brand gradient mesh + subtle grid ═══ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at 15% 15%, rgba(67, 97, 238, 0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%, rgba(247, 37, 133, 0.04) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 90%, rgba(76, 201, 240, 0.05) 0%, transparent 50%);
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.3;
  pointer-events: none;
}

[data-theme="dark"] body::before {
  background:
    radial-gradient(ellipse at 15% 15%, rgba(99, 129, 255, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%, rgba(255, 77, 166, 0.06) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 90%, rgba(92, 225, 255, 0.06) 0%, transparent 50%);
}

[data-theme="dark"] body::after {
  opacity: 0.1;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Focus rings for accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  z-index: 9999;
  border-radius: 0 0 8px 0;
}

.skip-link:focus {
  top: 0;
}

/* Hidden state */
.hidden {
  display: none !important;
}

/* RTL support */
[dir="rtl"] body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Cairo", sans-serif;
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .flex-gap,
[dir="rtl"] .flex-between,
[dir="rtl"] .quiz-nav,
[dir="rtl"] .modal-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .nav-tabs {
  flex-direction: row-reverse;
}

[dir="rtl"] .header-controls {
  flex-direction: row-reverse;
}

[dir="rtl"] .brand {
  flex-direction: row-reverse;
}

[dir="rtl"] .stat-grid {
  direction: rtl;
}

[dir="rtl"] .quiz-tile-meta {
  flex-direction: row-reverse;
}

[dir="rtl"] .q-edit-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .tbl-wrap table {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .form-input,
[dir="rtl"] .form-select,
[dir="rtl"] .form-textarea {
  text-align: right;
}

[dir="rtl"] .toast-stack {
  left: 16px;
  right: auto;
}

/* ============================================================
   PAGE TRANSITIONS
   ============================================================ */
.view-enter {
  animation: viewFadeIn 180ms ease-out;
}

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

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

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 20px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* ============================================================
   BUTTON LOADING STATE
   ============================================================ */
.btn.loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.btn.loading .btn-text {
  opacity: 0;
}

.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-secondary.loading::after {
  border-color: var(--border);
  border-top-color: var(--text);
}

/* Print styles */
@media print {
  .app-header,
  .nav-tabs,
  .btn {
    display: none !important;
  }
}
