/* Design Tokens — Spacing, Typography, Radius, Shadows
 * Load BEFORE style.css / style-v2.css
 * Adds new tokens only — does NOT override existing ones
 */

:root {
  /* ── Spacing grid (8pt base + 4pt sub-grid) ── */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;
  --space-8: 48px;
  --space-9: 64px;
  --space-10: 80px;

  /* ── Typography scale (iOS SF Pro inspired) ── */
  --text-xs: 10px;
  --text-caption: 12px;
  --text-footnote: 13px;
  --text-subhead: 15px;
  --text-callout: 16px;
  --text-body: 16px;
  --text-body-lg: 17px;
  --text-title3: 20px;
  --text-title2: 22px;
  --text-title1: 28px;
  --text-hero: 34px;
  --text-hero-lg: 60px;

  /* ── Heading sizes (modal titles, section headers) ── */
  --text-h3: 18px;
  --text-h4: 15px;

  /* ── Corner radius (extended from existing --radius-*) ── */
  --radius-pill: 9999px;
  --radius-md: 10px; /* between existing --radius (8px) and --radius-lg (12px) */
  --radius-2xl: 24px; /* extra-large for modals */

  /* ── Shadow elevation (MD3 inspired) ── */
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12); /* between --shadow-sm and --shadow */

  /* ── Z-index stack (single source of truth) ── */
  --z-base: 0;
  --z-content: 10;
  --z-sticky: 50;
  --z-tooltip: 55;
  --z-header: 100;
  --z-overlay: 300;
  --z-modal: 500;
  --z-toast: 9999;

  /* ── Overlay backdrop ── */
  --overlay-bg: rgba(0, 0, 0, 0.7);

  /* ── Touch target minimum ── */
  --touch-min: 44px;

  /* ── Mobile safe area (iOS env fallback) ── */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 16px);
  --safe-right: env(safe-area-inset-right, 16px);

  /* ── Transition timing ── */
  --transition-fast: 0.15s;
  --transition-modal: 0.3s;

  /* ── Section header typography (worksheet canvas) ── */
  --sec-font-size: 15px;
  --sec-font-family: 'Quicksand', sans-serif;
  --sec-font-weight: 700;

  /* ── Icon design tokens (B01 branding) ── */
  --icon-stroke-action: 1.5px;
  --icon-stroke-game: 2px;
  --icon-stroke-nav: 1px;
  --icon-color: currentColor;
  --icon-size-action: 24px;
  --icon-size-game: 48px;
  --icon-size-nav: 24px;
  --icon-btn-padding: 10px;       /* ensures 44px touch target with 24px icon */
  --spinner-size-sm: 16px;
  --spinner-size-md: 24px;
  --spinner-size-lg: 32px;
  --spinner-stroke: 2px;
  --sec-color: #000000;

  /* ── Block tag label (e.g. "True / False" next to section number) ── */
  --block-tag-transform: capitalize;
}

/* ── Dark theme: WCAG AA contrast overrides (web-design-mastery Level 3) ── */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: hsl(239, 84%, 72%);        /* #6C64F2 — 4.9:1 on #0F172A */
    --primary-hover: hsl(239, 84%, 78%);
    --danger: hsl(0, 82%, 68%);           /* #EF4444 — 4.6:1 on #0F172A */
    --danger-hover: hsl(0, 82%, 74%);
    --warning: hsl(39, 92%, 60%);         /* #EAB308 — 4.7:1 on #0F172A */
    --success: hsl(142, 51%, 48%);        /* #22C55E — 4.5:1 on #0F172A */
    --sec-color: var(--text, #f1f5f9);   /* Was #000000 — invisible on dark bg */
  }
}

/* ── Mobile: disable 300ms tap delay ── */
html {
  touch-action: manipulation;
}

/* ── iOS: prevent auto-zoom on input focus ── */
@media (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* ═══════════════════════════════════════════════════════════
   STATE CLASSES — Loading / Error / Empty
   Use these on every view. Never ship a page without all three.
   ═══════════════════════════════════════════════════════════ */

/* ── Loading (skeleton shimmer) ── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface, #1e293b) 25%,
    var(--border-light, #334155) 50%,
    var(--bg-surface, #1e293b) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm, 4px);
  min-height: 1em;
}
.skeleton-text {
  height: 1em;
  margin-bottom: var(--space-2, 8px);
  width: 80%;
}
.skeleton-text:last-child {
  width: 60%;
}
.skeleton-title {
  height: 1.5em;
  margin-bottom: var(--space-3, 12px);
  width: 50%;
}
.skeleton-card {
  height: 120px;
}
.skeleton-btn {
  height: 36px;
  width: 120px;
  border-radius: var(--radius-md, 8px);
}
@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ── Error state ── */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8, 48px) var(--space-4, 16px);
  text-align: center;
  color: var(--text-dim, #94a3b8);
  min-height: 200px;
}
.error-state-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-3, 12px);
  opacity: 0.6;
}
.error-state-title {
  font-size: var(--text-lg, 1.125rem);
  font-weight: 600;
  color: var(--text, #f1f5f9);
  margin-bottom: var(--space-2, 8px);
}
.error-state-message {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-dim, #94a3b8);
  margin-bottom: var(--space-5, 24px);
  max-width: 400px;
  line-height: var(--leading-relaxed, 1.75);
}
.error-state-retry {
  padding: var(--space-2, 8px) var(--space-5, 24px);
  background: var(--primary, #4f46e5);
  color: white;
  border: none;
  border-radius: var(--radius-md, 8px);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.error-state-retry:hover {
  background: var(--primary-hover, #4338ca);
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8, 48px) var(--space-4, 16px);
  text-align: center;
  border: 2px dashed var(--border, #475569);
  border-radius: var(--radius-lg, 12px);
  color: var(--text-dim, #94a3b8);
  min-height: 200px;
  margin: var(--space-4, 16px);
}
.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-3, 12px);
  opacity: 0.5;
}
.empty-state-title {
  font-size: var(--text-lg, 1.125rem);
  font-weight: 600;
  color: var(--text, #f1f5f9);
  margin-bottom: var(--space-2, 8px);
}
.empty-state-message {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-dim, #94a3b8);
  margin-bottom: var(--space-5, 24px);
  max-width: 400px;
  line-height: var(--leading-relaxed, 1.75);
}
.empty-state-cta {
  padding: var(--space-2, 8px) var(--space-5, 24px);
  background: var(--primary, #4f46e5);
  color: white;
  border: none;
  border-radius: var(--radius-md, 8px);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.empty-state-cta:hover {
  background: var(--primary-hover, #4338ca);
}

/* ── Skip-link (WCAG 2.4.1 Bypass Blocks) ── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 8px;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* ── Visually hidden (screen-reader only) ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
