/* ============================================================
   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;
}

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