/**
 * Quizzman Loading Screen — fc-load pattern (Flashcard-native)
 * Wavy path · nodes · runner · logo badge card
 */

:root {
  --qm-load-font: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --qm-load-bg: #faf8f5;
  --qm-load-bg-glow: rgba(254, 243, 199, 0.55);
  --qm-load-card-from: #fff;
  --qm-load-card-mid: #fffbeb;
  --qm-load-card-to: #f0fdfa;
  --qm-load-card-border: rgba(180, 83, 9, 0.16);
  --qm-load-card-shadow: rgba(180, 83, 9, 0.1);
  --qm-load-badge-border: #d97706;
  --qm-load-brand: #92400e;
  --qm-load-msg: #57534e;
  --qm-load-amber: #fbbf24;
  --qm-load-teal: #0d9488;
  --qm-load-blue: #2563eb;
}

[data-theme="dark"] .qm-load--boot {
  --qm-load-bg: #0c0a09;
  --qm-load-bg-glow: rgba(79, 70, 229, 0.2);
  --qm-load-card-from: #1c1917;
  --qm-load-card-mid: #292524;
  --qm-load-card-to: #1e1b4b;
  --qm-load-card-border: rgba(251, 191, 36, 0.2);
  --qm-load-card-shadow: rgba(0, 0, 0, 0.35);
  --qm-load-badge-border: #fbbf24;
  --qm-load-brand: #fcd34d;
  --qm-load-msg: #a8a29e;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, var(--qm-load-bg-glow), transparent 55%),
    var(--qm-load-bg);
}

[data-theme="dark"] .qm-load--boot .qm-load__badge {
  background: #292524;
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.15),
    0 4px 0 rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .qm-load--boot .qm-load__path-bg {
  stroke: rgba(168, 162, 158, 0.2);
}

[data-theme="dark"] .qm-load--boot .qm-load__node {
  fill: #57534e;
  stroke: #1c1917;
  animation-name: qmLoadNodeDark;
}

/* Critical paint before full CSS — boot shell only */
#qm-initial-loading {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #faf8f5;
}

html.qm-load-active,
html.qm-load-active body {
  overflow: hidden;
}

.qm-load {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--qm-load-font);
}

.qm-load--boot {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, var(--qm-load-bg-glow), transparent 55%),
    var(--qm-load-bg);
}

.qm-load--boot.qm-load--out {
  animation: qmLoadOut 0.35s ease-out forwards;
  pointer-events: none;
}

@keyframes qmLoadOut {
  to { opacity: 0; visibility: hidden; }
}

.qm-load--inline {
  position: relative;
  width: 100%;
  min-height: min(52vh, 400px);
  padding: 24px 16px;
  background: transparent;
}

.qm-load--dark {
  --qm-load-bg: #0c0a09;
  --qm-load-bg-glow: rgba(79, 70, 229, 0.2);
  --qm-load-card-from: #1c1917;
  --qm-load-card-mid: #292524;
  --qm-load-card-to: #1e1b4b;
  --qm-load-card-border: rgba(251, 191, 36, 0.2);
  --qm-load-card-shadow: rgba(0, 0, 0, 0.35);
  --qm-load-badge-border: #fbbf24;
  --qm-load-brand: #fcd34d;
  --qm-load-msg: #a8a29e;
}

.qm-load--dark.qm-load--boot {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, var(--qm-load-bg-glow), transparent 55%),
    var(--qm-load-bg);
}

.qm-load__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 320px);
  padding: 28px 24px 32px;
  border-radius: 20px;
  background: linear-gradient(165deg, var(--qm-load-card-from) 0%, var(--qm-load-card-mid) 45%, var(--qm-load-card-to) 100%);
  border: 2px solid var(--qm-load-card-border);
  box-shadow:
    0 8px 0 var(--qm-load-card-shadow),
    0 20px 48px rgba(28, 25, 23, 0.08);
  animation: qmLoadRise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes qmLoadRise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.qm-load__badge {
  width: 72px;
  height: 72px;
  padding: 6px;
  border-radius: 18px;
  background: #fff;
  border: 2px solid var(--qm-load-badge-border);
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.25),
    0 4px 0 rgba(217, 119, 6, 0.25);
  animation: qmLoadBadge 2.4s ease-in-out infinite;
}

.qm-load--dark .qm-load__badge {
  background: #292524;
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.15),
    0 4px 0 rgba(0, 0, 0, 0.4);
}

@keyframes qmLoadBadge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.qm-load__logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px;
}

.qm-load__brand {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--qm-load-brand);
}

.qm-load__tagline {
  margin: -6px 0 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--qm-load-msg);
  opacity: 0.75;
}

.qm-load__map {
  display: block;
  width: 100%;
  height: 72px;
  overflow: visible;
}

.qm-load__path-bg {
  fill: none;
  stroke: rgba(120, 113, 108, 0.16);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.qm-load--dark .qm-load__path-bg {
  stroke: rgba(168, 162, 158, 0.2);
}

.qm-load__path-fill {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: qmLoadPath 2.4s ease-in-out infinite;
  filter: drop-shadow(0 0 5px rgba(251, 191, 36, 0.45));
}

@keyframes qmLoadPath {
  0% { stroke-dashoffset: 100; opacity: 0.5; }
  45% { stroke-dashoffset: 0; opacity: 1; }
  55% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: -100; opacity: 0.5; }
}

.qm-load__node {
  fill: #d6d3d1;
  stroke: #fff;
  stroke-width: 2;
  animation: qmLoadNode 2.4s ease-in-out infinite;
}

.qm-load--dark .qm-load__node {
  fill: #57534e;
  stroke: #1c1917;
}

.qm-load__node--d1 { animation-delay: 0.35s; }
.qm-load__node--d2 { animation-delay: 0.7s; }
.qm-load__node--d3 { animation-delay: 1.05s; }

@keyframes qmLoadNode {
  0%, 100% { fill: #d6d3d1; }
  25%, 45% { fill: var(--qm-load-teal); }
  55% { fill: var(--qm-load-amber); }
}

.qm-load--dark .qm-load__node {
  animation-name: qmLoadNodeDark;
}

@keyframes qmLoadNodeDark {
  0%, 100% { fill: #57534e; }
  25%, 45% { fill: #2dd4bf; }
  55% { fill: #fbbf24; }
}

.qm-load__runner {
  filter: drop-shadow(0 2px 4px rgba(217, 119, 6, 0.45));
}

.qm-load__msg {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--qm-load-msg);
  letter-spacing: -0.01em;
  animation: qmLoadMsg 1.6s ease-in-out infinite;
}

@keyframes qmLoadMsg {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .qm-load__badge,
  .qm-load__path-fill,
  .qm-load__node,
  .qm-load__msg,
  .qm-load__runner animateMotion {
    animation: none !important;
  }

  .qm-load__path-fill {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}
