/*
 * Quizr — application.css
 *
 * Single entry point. Sections in order:
 *   1. Design tokens (CSS custom properties, dark default + light override)
 *   2. Reset & base
 *   3. Typography helpers
 *   4. Layout helpers
 *   5. Components (buttons, pills, inputs, cards, badges, logo)
 *   6. Animations / keyframes
 *   7. Styleguide-page-only utilities
 */

/* ──────────────────────────────────────────────────────────────────────
 * 1. Design tokens
 * ────────────────────────────────────────────────────────────────────── */

:root,
[data-theme="dark"] {
  /* Surfaces */
  --color-bg:            #080812;
  --color-surface:       #0F172A;
  --color-card:          #111827;
  --color-card-alt:      #1F2937;
  --color-border:        #374151;
  --color-border-subtle: #1F2937;

  /* Text */
  --color-text:          #F9FAFB;
  --color-text-muted:    #9CA3AF;
  --color-text-faint:    #6B7280;

  /* Accents */
  --color-accent:        #6366F1;
  --color-accent-hover:  #4F46E5;
  --color-accent-dim:    rgba(99, 102, 241, 0.13);
  --color-accent-bdr:    rgba(99, 102, 241, 0.27);
  --color-cyan:          #22D3EE;
  --color-success:       #10B981;
  --color-warning:       #F59E0B;
  --color-danger:        #EF4444;

  /* Option colours (MC tile colour-coding) */
  --color-opt-a:         #6366F1;
  --color-opt-b:         #EC4899;
  --color-opt-c:         #F59E0B;
  --color-opt-d:         #10B981;

  /* Radii */
  --radius-pill:         99px;
  --radius-lg:           20px;
  --radius-md:           14px;
  --radius-sm:           10px;
  --radius-button:       12px;
  --radius-input:        12px;

  /* Shadows */
  --shadow-card-hover:   0 20px 40px rgba(0, 0, 0, 0.33);
  --shadow-modal:        0 40px 80px rgba(0, 0, 0, 0.4),
                         0 0 0 1px rgba(255, 255, 255, 0.07);
  --shadow-accent-glow:  0 8px 24px rgba(99, 102, 241, 0.27);

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 100px;

  --page-padding-x: 32px;

  /* Typography */
  --font-sans: 'Outfit', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --color-bg:            #F8FAFC;
  --color-surface:       #FFFFFF;
  --color-card:          #FFFFFF;
  --color-card-alt:      #F9FAFB;
  --color-border:        #E2E8F0;
  --color-border-subtle: #EEF2F7;

  --color-text:          #0F172A;
  --color-text-muted:    #64748B;
  --color-text-faint:    #94A3B8;

  --color-accent-dim:    #EEF2FF;
  --color-accent-bdr:    rgba(99, 102, 241, 0.27);

  --shadow-card-hover:   0 12px 24px rgba(15, 23, 42, 0.08);
  --shadow-modal:        0 24px 48px rgba(15, 23, 42, 0.12);
}

/* Respect reduced motion across the whole app */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ──────────────────────────────────────────────────────────────────────
 * 2. Reset & base
 * ────────────────────────────────────────────────────────────────────── */

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

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

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

a { color: inherit; text-decoration: none; }
a:hover { color: var(--color-accent); }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }

input, textarea, select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

ul, ol { list-style: none; }

/* ──────────────────────────────────────────────────────────────────────
 * 3. Typography helpers
 * ────────────────────────────────────────────────────────────────────── */

.h-hero {
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1.1;
}

.h-section {
  font-size: clamp(32px, 4.5vw, 48px);
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1.15;
}

.h-card {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.text-caption {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--color-text-muted);
}

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

.text-gradient {
  background: linear-gradient(135deg, var(--color-accent), var(--color-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ──────────────────────────────────────────────────────────────────────
 * 4. Layout helpers
 * ────────────────────────────────────────────────────────────────────── */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--page-padding-x);
}

.container-narrow { max-width: 900px; margin: 0 auto; padding: 0 var(--page-padding-x); }
.container-wide   { max-width: 1400px; margin: 0 auto; padding: 0 var(--page-padding-x); }

.stack { display: flex; flex-direction: column; }
.row   { display: flex; flex-direction: row; }
.center { display: flex; align-items: center; justify-content: center; }

/* ──────────────────────────────────────────────────────────────────────
 * 5. Components
 * ────────────────────────────────────────────────────────────────────── */

/* Logo mark — the indigo "Q" square */
.logo-mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: -1px;
}
.logo-mark__square {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--color-accent);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.35);
}
.logo-mark--lg .logo-mark__square { width: 56px; height: 56px; border-radius: 14px; font-size: 26px; }
.logo-mark--lg { font-size: 44px; letter-spacing: -2px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-button);
  border: 1px solid transparent;
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--color-accent-hover); color: #fff; }
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--color-card-alt);
  color: var(--color-text-faint);
  cursor: default;
  transform: none;
}

.btn--ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-muted);
}
.btn--ghost:hover {
  background: var(--color-card-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--danger { background: var(--color-danger); }
.btn--danger:hover { background: #DC2626; }

.btn--success { background: var(--color-success); }
.btn--success:hover { background: #0EA371; }

.btn--lg { padding: 16px 28px; font-size: 17px; border-radius: 14px; }
.btn--sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn--block { width: 100%; }

/* Pills (status badges, tags) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  background: var(--color-card-alt);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  text-transform: capitalize;
  white-space: nowrap;
}
.pill--accent  { background: var(--color-accent-dim); color: var(--color-accent); border-color: var(--color-accent-bdr); }
.pill--success { background: rgba(16, 185, 129, 0.13); color: var(--color-success); border-color: rgba(16, 185, 129, 0.27); }
.pill--warning { background: rgba(245, 158, 11, 0.13); color: var(--color-warning); border-color: rgba(245, 158, 11, 0.27); }
.pill--danger  { background: rgba(239, 68, 68, 0.13); color: var(--color-danger); border-color: rgba(239, 68, 68, 0.27); }

.pill__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.pill__dot--pulse { animation: pulse 2s ease-in-out infinite; }

/* Inputs */
.input {
  display: block;
  width: 100%;
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-input);
  padding: 13px 16px;
  font-size: 15px;
  color: var(--color-text);
  transition: border-color 0.15s ease;
}
.input::placeholder { color: var(--color-text-faint); }
.input:focus { border-color: var(--color-accent); }
.input[aria-invalid="true"] { border-color: var(--color-danger); }

.input-error {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--color-danger);
}

.input-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

/* Cards */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card--md { border-radius: var(--radius-md); padding: var(--space-5); }
.card--hoverable {
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.card--hoverable:hover {
  transform: translateY(-4px);
  border-color: var(--color-border);
  box-shadow: var(--shadow-card-hover);
}

/* Icon glyph (Unicode icons inside a tinted square) */
.icon-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--color-accent-dim);
  color: var(--color-accent);
  font-size: 16px;
  flex-shrink: 0;
}
.icon-glyph--lg { width: 44px; height: 44px; border-radius: 12px; font-size: 22px; }

/* ──────────────────────────────────────────────────────────────────────
 * 6. Animations
 * ────────────────────────────────────────────────────────────────────── */

@keyframes pulse  { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes float  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes shake  { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes pop    { 0% { transform: scale(0.9); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

.anim-fade-up { animation: fadeUp 0.5s ease both; }
.anim-fade-in { animation: fadeIn 0.4s ease both; }
.anim-float   { animation: float 5s ease-in-out infinite; }

/* ──────────────────────────────────────────────────────────────────────
 * 7. Styleguide page (dev-only)
 * ────────────────────────────────────────────────────────────────────── */

.styleguide {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px var(--page-padding-x) 96px;
}
.styleguide section {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--color-border-subtle);
}
.styleguide h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}
.styleguide__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.styleguide__swatch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}
.styleguide__swatch span {
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--color-border-subtle);
}
.styleguide__row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.styleguide__theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
}
