/* ============================================================================
   QUANT GUILD — DESIGN SYSTEM  (concept "01-prime")
   ----------------------------------------------------------------------------
   Component layer. Requires qg_tokens.css to be loaded first.

   Conventions
     .qg-*            component root
     .qg-*__element   child part
     .qg-*--modifier  variant
     .is-*            state driven by JS

   Nothing here styles a bare element selector other than inside a .qg-*
   scope, so dropping this file onto a legacy page cannot restyle it by
   accident. Pages opt in by adding .qg classes (or .qg-page on <body>).
   ========================================================================== */

/* ---------------------------------------------------------------- 1. SCOPE */

.qg-page {
  font-family: var(--qg-font);
  font-size: 17px;
  line-height: var(--qg-lh-base);
  color: var(--qg-text-body);
  background: var(--qg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}

.qg-page--app {
  font-size: var(--qg-fs-base);
  background: var(--qg-surface-2);
}

.qg-page *,
.qg-page *::before,
.qg-page *::after {
  box-sizing: border-box;
}

.qg-page :focus-visible,
.qg-focusable:focus-visible {
  outline: var(--qg-focus-ring);
  outline-offset: var(--qg-focus-offset);
  border-radius: 4px;
}

/* Visible focus for keyboard users anywhere the design system is loaded. */
.qg-btn:focus-visible,
.qg-tlink:focus-visible,
.qg-chip:focus-visible,
.qg-icon-btn:focus-visible,
.qg-theme-toggle:focus-visible,
.qg-tabs a:focus-visible,
.qg-table a:focus-visible {
  outline: var(--qg-focus-ring);
  outline-offset: var(--qg-focus-offset);
}

.qg-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;
}

/* --------------------------------------------------------------- 2. LAYOUT */

.qg-shell {
  width: 100%;
  max-width: var(--qg-maxw);
  margin-inline: auto;
  padding-inline: var(--qg-gutter);
}

.qg-section {
  position: relative;
  padding-block: var(--qg-section-pad);
}

.qg-section--tint {
  background: var(--qg-surface-2);
  border-block: 1px solid var(--qg-line);
}

.qg-section--flush {
  padding-block: var(--qg-s10);
}

.qg-stack > * + * {
  margin-top: var(--qg-s4);
}

/* ----------------------------------------------------------- 3. TYPOGRAPHY */

.qg-display,
.qg-h1,
.qg-h2,
.qg-h3,
.qg-h4 {
  color: var(--qg-text);
  margin: 0;
}

.qg-display {
  font-family: var(--qg-font-display);
  font-size: var(--qg-fs-display);
  line-height: 1.05;
  letter-spacing: var(--qg-ls-display);
  font-weight: 600;
}

.qg-h1 {
  font-family: var(--qg-font-display);
  font-size: var(--qg-fs-h1);
  line-height: 1.12;
  letter-spacing: -0.032em;
  font-weight: 600;
}

.qg-h2 {
  font-family: var(--qg-font-display);
  font-size: var(--qg-fs-h2);
  line-height: var(--qg-lh-tight);
  letter-spacing: var(--qg-ls-h);
  font-weight: 600;
}

.qg-h3 {
  font-size: var(--qg-fs-h3);
  line-height: var(--qg-lh-snug);
  letter-spacing: -0.018em;
  font-weight: 600;
}

.qg-h4 {
  font-size: var(--qg-fs-h4);
  line-height: 1.4;
  letter-spacing: -0.012em;
  font-weight: 600;
}

.qg-lede {
  font-size: var(--qg-fs-lede);
  line-height: var(--qg-lh-base);
  letter-spacing: var(--qg-ls-body);
  color: var(--qg-text-body);
  margin: 0;
}

.qg-sub {
  font-size: var(--qg-fs-base);
  line-height: var(--qg-lh-base);
  color: var(--qg-text-muted);
  margin: 0;
}

.qg-eyebrow {
  display: block;
  font-size: var(--qg-fs-eyebrow);
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: var(--qg-ls-eyebrow);
  color: var(--qg-accent);
}

.qg-eyebrow--muted {
  color: var(--qg-text-muted);
}

.qg-eyebrow--gold {
  color: var(--qg-gold-text);
}

.qg-mono {
  font-family: var(--qg-font-mono);
  font-feature-settings: normal;
}

.qg-tnum {
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- 4. BUTTONS */

.qg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--qg-s2);
  height: 44px;
  padding: 0 var(--qg-s5);
  border: 1px solid transparent;
  border-radius: var(--qg-r-btn);
  font-family: inherit;
  font-size: var(--qg-fs-base);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  background: none;
  transition: background var(--qg-dur) var(--qg-ease),
    transform var(--qg-dur) var(--qg-ease),
    box-shadow var(--qg-dur) var(--qg-ease),
    border-color var(--qg-dur) var(--qg-ease),
    color var(--qg-dur) var(--qg-ease);
}

.qg-btn--xs {
  height: 32px;
  padding: 0 var(--qg-s3);
  font-size: 12.5px;
  border-radius: var(--qg-r-ctl);
}

.qg-btn--sm {
  height: 38px;
  padding: 0 var(--qg-s4);
  font-size: var(--qg-fs-sm);
  border-radius: var(--qg-r-ctl);
}

.qg-btn--lg {
  height: 52px;
  padding: 0 26px;
  font-size: 16px;
}

.qg-btn--block {
  width: 100%;
}

.qg-btn--primary {
  background: var(--qg-blue);
  color: #fff;
  box-shadow: var(--qg-sh-btn);
}

.qg-btn--primary:hover {
  background: var(--qg-blue-deep);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--qg-sh-btn-hover);
}

.qg-btn--primary:active {
  transform: translateY(0);
}

html[data-theme='dark'] .qg-btn--primary {
  background: var(--qg-blue-bright);
}

html[data-theme='dark'] .qg-btn--primary:hover {
  background: #0a74dd;
}

.qg-btn--ghost {
  background: var(--qg-surface);
  color: var(--qg-text);
  border-color: var(--qg-line);
  box-shadow: var(--qg-sh-hair);
}

.qg-btn--ghost:hover {
  color: var(--qg-accent);
  border-color: var(--qg-accent-line);
  background: var(--qg-surface-tint);
  transform: translateY(-1px);
}

.qg-btn--quiet {
  color: var(--qg-text-body);
}

.qg-btn--quiet:hover {
  color: var(--qg-text);
  background: var(--qg-surface-2);
  border-color: var(--qg-line);
}

/* Gold is a signal, never a surface: capped at pill size by design. */
.qg-btn--gold {
  height: 32px;
  padding: 0 var(--qg-s3);
  font-size: 12.5px;
  border-radius: var(--qg-r-pill);
  background: var(--qg-gold-soft);
  border-color: var(--qg-gold-line);
  color: var(--qg-gold-text);
}

.qg-btn--gold:hover {
  background: rgba(255, 203, 5, 0.22);
  border-color: var(--qg-gold-deep);
}

.qg-btn__chev {
  font-size: 10px;
  color: var(--qg-text-muted);
  transition: transform var(--qg-dur) var(--qg-ease), color var(--qg-dur) var(--qg-ease);
}

.qg-btn:hover .qg-btn__chev {
  transform: translateX(3px);
  color: var(--qg-accent);
}

.qg-btn--primary .qg-btn__chev {
  color: rgba(255, 255, 255, 0.75);
}

.qg-btn--primary:hover .qg-btn__chev {
  color: #fff;
}

/* Text link with a sliding chevron. */
.qg-tlink {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--qg-fs-sm);
  font-weight: 600;
  color: var(--qg-link);
  letter-spacing: -0.01em;
  text-decoration: none;
  transition: color var(--qg-dur-fast) var(--qg-ease);
}

.qg-tlink i {
  font-size: 10px;
  transition: transform var(--qg-dur) var(--qg-ease);
}

.qg-tlink:hover {
  color: var(--qg-accent-hover);
}

.qg-tlink:hover i {
  transform: translateX(4px);
}

.qg-icon-btn {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-ctl);
  background: var(--qg-surface);
  color: var(--qg-text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--qg-dur-fast) var(--qg-ease),
    color var(--qg-dur-fast) var(--qg-ease),
    background var(--qg-dur-fast) var(--qg-ease);
}

.qg-icon-btn:hover {
  border-color: var(--qg-accent-line);
  color: var(--qg-accent);
  background: var(--qg-surface-tint);
}

/* ----------------------------------------------------- 5. CHIPS AND PILLS */

.qg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--qg-r-pill);
  border: 1px solid var(--qg-line);
  background: var(--qg-surface);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--qg-text-muted);
  white-space: nowrap;
  text-decoration: none;
}

.qg-chip--blue {
  background: var(--qg-surface-tint);
  border-color: var(--qg-surface-tint-line);
  color: var(--qg-accent);
}

.qg-chip--gold {
  background: var(--qg-gold-soft);
  border-color: var(--qg-gold-line);
  color: var(--qg-gold-text);
}

.qg-chip--gold i {
  color: var(--qg-gold-deep);
}

html[data-theme='dark'] .qg-chip--gold i {
  color: var(--qg-gold);
}

.qg-chip--pos {
  background: var(--qg-pos-soft);
  border-color: var(--qg-pos-line);
  color: var(--qg-pos);
}

.qg-chip--neg {
  background: var(--qg-neg-soft);
  border-color: var(--qg-neg-line);
  color: var(--qg-neg);
}

/* Interactive quick-link pill (hero "jump straight in" row). */
.qg-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border-radius: var(--qg-r-pill);
  border: 1px solid var(--qg-line);
  background: var(--qg-surface);
  box-shadow: var(--qg-sh-hair);
  font-size: 13px;
  font-weight: 500;
  color: var(--qg-text-body);
  text-decoration: none;
  transition: color var(--qg-dur) var(--qg-ease),
    border-color var(--qg-dur) var(--qg-ease),
    background var(--qg-dur) var(--qg-ease),
    transform var(--qg-dur) var(--qg-ease);
}

.qg-pill i {
  font-size: 10.5px;
  color: var(--qg-text-muted);
  transition: color var(--qg-dur) var(--qg-ease);
}

.qg-pill:hover {
  color: var(--qg-accent);
  border-color: var(--qg-accent-line);
  background: var(--qg-surface-tint);
  transform: translateY(-1px);
}

.qg-pill:hover i {
  color: var(--qg-accent);
}

/* -------------------------------------------------- 6. CARDS AND PANELS */

.qg-card {
  background: var(--qg-surface);
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-card);
  box-shadow: var(--qg-sh-hair);
}

.qg-card--pad {
  padding: var(--qg-s5);
}

.qg-card--hover {
  transition: box-shadow var(--qg-dur-slow) var(--qg-ease),
    transform var(--qg-dur-slow) var(--qg-ease),
    border-color var(--qg-dur-slow) var(--qg-ease);
}

.qg-card--hover:hover {
  box-shadow: var(--qg-sh-card);
  transform: translateY(-2px);
  border-color: var(--qg-line-strong);
}

.qg-panel {
  background: var(--qg-surface);
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-card);
  box-shadow: var(--qg-sh-hair);
  overflow: hidden;
}

.qg-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--qg-s5);
  flex-wrap: wrap;
  padding: 22px var(--qg-s6);
  border-bottom: 1px solid var(--qg-line);
}

.qg-panel__head h2,
.qg-panel__head h3 {
  margin: 0;
  font-family: var(--qg-font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.024em;
  color: var(--qg-text);
}

.qg-panel__head p {
  margin: var(--qg-s1) 0 0;
  font-size: var(--qg-fs-sm);
  color: var(--qg-text-muted);
  max-width: 620px;
}

.qg-panel__acts {
  display: flex;
  gap: var(--qg-s2);
  flex: none;
}

.qg-panel__body {
  padding: var(--qg-s6);
}

.qg-panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qg-s3);
  padding: 14px var(--qg-s5);
  border-top: 1px solid var(--qg-line);
  background: var(--qg-surface);
}

/* Tinted inset well, used for sample questions / formulas. */
.qg-inset {
  padding: 18px;
  border-radius: var(--qg-r-ctl);
  background: var(--qg-surface-tint);
  border: 1px solid var(--qg-surface-tint-line);
}

.qg-medallion {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: var(--qg-r-ctl);
  display: grid;
  place-items: center;
  background: var(--qg-surface-tint);
  border: 1px solid var(--qg-surface-tint-line);
  color: var(--qg-accent);
  font-size: 14px;
}

.qg-medallion--sm {
  width: 28px;
  height: 28px;
  font-size: 11.5px;
}

.qg-medallion--gold {
  background: var(--qg-gold-soft);
  border-color: var(--qg-gold-line);
  color: var(--qg-gold-text);
}

/* ------------------------------------------------------ 7. SECTION HEADS */

.qg-sec-head {
  max-width: 620px;
}

.qg-sec-head .qg-eyebrow {
  margin-bottom: 18px;
}

.qg-sec-head .qg-h1,
.qg-sec-head .qg-h2 {
  margin-bottom: var(--qg-s4);
}

.qg-sec-head .qg-lede {
  color: var(--qg-text-muted);
}

/* Compact in-page section bar: title + sub on the left, actions right. */
.qg-sec-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--qg-s5);
  flex-wrap: wrap;
  margin-bottom: var(--qg-s4);
}

.qg-sec-bar h2 {
  margin: 0;
  font-family: var(--qg-font-display);
  font-size: var(--qg-fs-h3);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.024em;
  color: var(--qg-text);
}

.qg-sec-bar p {
  margin: 3px 0 0;
  font-size: var(--qg-fs-sm);
  color: var(--qg-text-muted);
}

.qg-sec-bar__acts {
  display: flex;
  gap: var(--qg-s2);
  flex-wrap: wrap;
}

.qg-rule {
  height: 1px;
  background: var(--qg-line);
  border: 0;
  margin: 28px 0 0;
}

/* ------------------------------------------------------------- 8. TABS */

.qg-tabs {
  display: flex;
  gap: var(--qg-s1);
  border-bottom: 1px solid var(--qg-line);
  margin-bottom: -1px;
  overflow-x: auto;
  scrollbar-width: none;
}

.qg-tabs::-webkit-scrollbar {
  display: none;
}

.qg-tabs a {
  position: relative;
  padding: 0 14px 12px;
  font-size: var(--qg-fs-sm);
  font-weight: 500;
  color: var(--qg-text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--qg-dur-fast) var(--qg-ease);
}

.qg-tabs a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background var(--qg-dur) var(--qg-ease);
}

.qg-tabs a:hover {
  color: var(--qg-text);
}

.qg-tabs a.is-active,
.qg-tabs a.active {
  color: var(--qg-accent);
  font-weight: 600;
}

.qg-tabs a.is-active::after,
.qg-tabs a.active::after {
  background: var(--qg-accent);
}

/* -------------------------------------------------------- 9. STAT BLOCKS */

.qg-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--qg-s5);
}

.qg-stat {
  padding: var(--qg-s5);
  background: var(--qg-surface);
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-card);
  box-shadow: var(--qg-sh-hair);
  transition: box-shadow var(--qg-dur-slow) var(--qg-ease),
    transform var(--qg-dur-slow) var(--qg-ease),
    border-color var(--qg-dur-slow) var(--qg-ease);
}

.qg-stat:hover {
  box-shadow: var(--qg-sh-card);
  transform: translateY(-2px);
  border-color: var(--qg-line-strong);
}

.qg-stat__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qg-s3);
}

.qg-stat__label {
  font-size: var(--qg-fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--qg-text-muted);
}

.qg-stat__row {
  display: flex;
  align-items: flex-end;
  gap: var(--qg-s3);
  margin-top: 14px;
}

.qg-stat__num {
  font-family: var(--qg-font-display);
  font-size: 36px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.035em;
  color: var(--qg-text);
  font-variant-numeric: tabular-nums;
}

.qg-stat__row .qg-chip {
  margin-bottom: var(--qg-s1);
}

.qg-stat__foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--qg-s4);
  margin-top: var(--qg-s4);
}

.qg-stat__note {
  font-size: var(--qg-fs-xs);
  color: var(--qg-text-muted);
}

/* Pure-CSS bar sparkline; heights are set inline per bar. */
.qg-spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
  flex: none;
}

.qg-spark i {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: var(--qg-wash);
  transition: background var(--qg-dur) var(--qg-ease);
}

.qg-spark i:last-child {
  background: var(--qg-accent);
}

.qg-stat:hover .qg-spark i {
  background: var(--qg-accent-soft);
}

.qg-stat:hover .qg-spark i:last-child {
  background: var(--qg-accent);
}

/* ------------------------------------------------- 10. PROGRESS AND DIALS */

.qg-track {
  height: 8px;
  border-radius: var(--qg-r-pill);
  background: var(--qg-surface-3);
  overflow: hidden;
}

.qg-track--thin {
  height: 7px;
}

.qg-track__fill {
  height: 100%;
  border-radius: var(--qg-r-pill);
  background: linear-gradient(90deg, var(--qg-blue), var(--qg-blue-bright));
  transition: width 0.8s var(--qg-ease);
}

html[data-theme='dark'] .qg-track__fill {
  background: linear-gradient(90deg, var(--qg-blue-bright), #4d94e8);
}

.qg-progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--qg-s2);
}

.qg-progress-top b {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--qg-text);
}

.qg-progress-top span {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--qg-accent);
  font-variant-numeric: tabular-nums;
}

.qg-dial {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto;
}

.qg-dial--sm {
  width: 62px;
  height: 62px;
}

.qg-dial svg {
  transform: rotate(-90deg);
  display: block;
}

.qg-dial__track {
  stroke: var(--qg-surface-3);
}

.qg-dial__bar {
  stroke: var(--qg-accent);
  stroke-linecap: round;
  transition: stroke-dasharray 0.6s var(--qg-ease), stroke 0.4s var(--qg-ease);
}

.qg-dial__bar--pos {
  stroke: var(--qg-pos);
}

.qg-dial__bar--neg {
  stroke: var(--qg-neg);
}

.qg-dial__val {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.qg-dial__val b {
  font-family: var(--qg-font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--qg-text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.qg-dial__val em {
  font-style: normal;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--qg-text-faint);
  margin-top: 3px;
}

.qg-dial--sm .qg-dial__val b {
  font-size: 16px;
}

.qg-dial-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--qg-s2);
  margin-top: 14px;
}

.qg-dial-meta__name {
  font-size: var(--qg-fs-sm);
  font-weight: 600;
  color: var(--qg-text);
  letter-spacing: -0.01em;
}

.qg-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--qg-fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.qg-delta i {
  font-size: 8.5px;
}

.qg-delta--up {
  color: var(--qg-pos);
}

.qg-delta--down {
  color: var(--qg-neg);
}

.qg-delta--flat {
  color: var(--qg-text-muted);
}

/* ------------------------------------------------- 11. ROMAN RANK BADGES */
/* A struck hallmark: shield outline + Roman numeral. Five tiers escalate
   from faint neutral (I) to full Guild Blue (V). Rendered as inline SVG so
   it scales crisply and inherits currentColor-free tier palettes. */

.qg-rank {
  display: inline-flex;
  align-items: center;
  gap: var(--qg-s2);
  line-height: 1;
  text-decoration: none;
  vertical-align: middle;
}

.qg-rank__crest {
  display: inline-block;
  flex: none;
  line-height: 0;
}

.qg-rank__crest svg {
  width: 24px;
  height: 28px;
  overflow: visible;
  display: block;
}

.qg-rank__crest path {
  fill: var(--qg-surface);
  stroke: #dbe1ea;
  stroke-width: 1;
  transition: stroke var(--qg-dur) var(--qg-ease), fill var(--qg-dur) var(--qg-ease);
}

.qg-rank__crest text {
  font-family: var(--qg-font-mono);
  font-size: 8.5px;
  font-weight: 500;
  fill: var(--qg-faint);
  text-anchor: middle;
  letter-spacing: 0.04em;
  transition: fill var(--qg-dur) var(--qg-ease);
}

.qg-rank__label {
  font-size: var(--qg-fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--qg-text-body);
  white-space: nowrap;
}

.qg-rank__sub {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--qg-text-muted);
}

/* Tier ramp */
.qg-rank--1 .qg-rank__crest path { stroke: #dde3ec; }
.qg-rank--1 .qg-rank__crest text { fill: #b7c0cd; }
.qg-rank--2 .qg-rank__crest path { stroke: #ccd6e6; }
.qg-rank--2 .qg-rank__crest text { fill: #9aa6b8; }
.qg-rank--3 .qg-rank__crest path { stroke: #a9bedd; }
.qg-rank--3 .qg-rank__crest text { fill: #7489a6; }
.qg-rank--4 .qg-rank__crest path { stroke: #6f94c9; }
.qg-rank--4 .qg-rank__crest text { fill: #3e6aa5; }
.qg-rank--5 .qg-rank__crest path { stroke: var(--qg-blue); }
.qg-rank--5 .qg-rank__crest text { fill: var(--qg-blue); }

html[data-theme='dark'] .qg-rank--1 .qg-rank__crest path { stroke: #2b3542; }
html[data-theme='dark'] .qg-rank--1 .qg-rank__crest text { fill: #6d7889; }
html[data-theme='dark'] .qg-rank--2 .qg-rank__crest path { stroke: #35465c; }
html[data-theme='dark'] .qg-rank--2 .qg-rank__crest text { fill: #8793a6; }
html[data-theme='dark'] .qg-rank--3 .qg-rank__crest path { stroke: #3f5b7e; }
html[data-theme='dark'] .qg-rank--3 .qg-rank__crest text { fill: #9fb4d0; }
html[data-theme='dark'] .qg-rank--4 .qg-rank__crest path { stroke: #4d7cb5; }
html[data-theme='dark'] .qg-rank--4 .qg-rank__crest text { fill: #9cc3f0; }
html[data-theme='dark'] .qg-rank--5 .qg-rank__crest path { stroke: var(--qg-accent); }
html[data-theme='dark'] .qg-rank--5 .qg-rank__crest text { fill: var(--qg-accent); }

/* Sizes */
.qg-rank--sm .qg-rank__crest svg { width: 19px; height: 22px; }
.qg-rank--sm .qg-rank__crest text { font-size: 7px; }
.qg-rank--sm .qg-rank__label { font-size: 11px; }
.qg-rank--lg .qg-rank__crest svg { width: 38px; height: 44px; }
.qg-rank--lg .qg-rank__crest text { font-size: 13px; }
.qg-rank--lg .qg-rank__label {
  font-family: var(--qg-font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--qg-text);
}

/* Filled treatment for the hero/current-rank crest. */
.qg-rank--solid .qg-rank__crest path {
  fill: var(--qg-blue);
  stroke: var(--qg-blue-deep);
}

.qg-rank--solid .qg-rank__crest text {
  fill: #fff;
}

html[data-theme='dark'] .qg-rank--solid .qg-rank__crest path {
  fill: var(--qg-blue-bright);
  stroke: var(--qg-blue-bright);
}

/* Chip-wrapped rank, for nav/sidebar/table use. */
.qg-rank--chip {
  height: 26px;
  padding: 0 10px 0 6px;
  border-radius: var(--qg-r-pill);
  border: 1px solid var(--qg-line);
  background: var(--qg-surface);
  gap: 6px;
}

.qg-rank--chip .qg-rank__crest svg {
  width: 17px;
  height: 20px;
}

.qg-rank--chip .qg-rank__crest text {
  font-size: 6.5px;
}

.qg-rank--chip .qg-rank__label {
  font-size: 11.5px;
}

/* Numeral-only variant, used when the sidebar is collapsed. */
.qg-rank--compact .qg-rank__label,
.qg-rank--compact .qg-rank__sub {
  display: none;
}

/* The five-rung ladder from the screenshot: crests over a hairline base
   with QUANT I / QUANT V end labels. */
.qg-ladder {
  margin: 0;
}

.qg-ladder__rungs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  justify-items: center;
}

.qg-ladder__base {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--qg-line);
  margin-top: var(--qg-s3);
}

.qg-ladder__base i {
  display: block;
  height: 4px;
  width: 1px;
  background: var(--qg-line);
  justify-self: center;
}

.qg-ladder__ends {
  display: flex;
  justify-content: space-between;
  margin-top: var(--qg-s2);
  font-family: var(--qg-font-mono);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  color: var(--qg-text-faint);
}

.qg-ladder__caption {
  margin-top: var(--qg-s3);
  font-family: var(--qg-font-mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--qg-text-faint);
}

/* A rung the member has not reached yet is dimmed. */
.qg-ladder__rungs .qg-rank.is-locked {
  opacity: 0.55;
}

.qg-ladder__rungs .qg-rank.is-current {
  flex-direction: column;
  gap: 5px;
}

.qg-ladder__rungs .qg-rank.is-current .qg-rank__crest svg {
  filter: drop-shadow(0 1px 4px rgba(0, 74, 173, 0.28));
  transform: scale(1.12);
  transform-origin: center bottom;
}

.qg-ladder__tick {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--qg-blue);
  color: #fff;
  font-size: 8px;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--qg-surface);
}

.qg-ladder__tick i {
  color: #fff;
}

/* ------------------------------------------------------------ 12. TABLES */

.qg-table-scroll {
  overflow-x: auto;
}

.qg-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 13px;
}

.qg-table th,
.qg-table td {
  text-align: left;
}

.qg-table thead th {
  padding: 10px var(--qg-s2);
  font-size: var(--qg-fs-xs);
  font-weight: 600;
  line-height: 1.25;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--qg-text-muted);
  background: var(--qg-surface-2);
  border-bottom: 1px solid var(--qg-line);
}

.qg-table thead th:first-child {
  padding-left: 18px;
}

.qg-table thead th:last-child {
  padding-right: 18px;
}

.qg-table tbody td {
  padding: var(--qg-s3) var(--qg-s2);
  border-bottom: 1px solid var(--qg-line-soft);
  vertical-align: middle;
  color: var(--qg-text-body);
}

.qg-table tbody td:first-child {
  padding-left: 18px;
}

.qg-table tbody td:last-child {
  padding-right: 18px;
}

.qg-table tbody tr {
  transition: background var(--qg-dur-fast) var(--qg-ease);
}

.qg-table tbody tr:hover {
  background: var(--qg-surface-2);
}

.qg-table tbody tr:last-child td {
  border-bottom: 0;
}

.qg-table--click tbody tr {
  cursor: pointer;
}

.qg-cell-q {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--qg-text);
  letter-spacing: -0.008em;
  line-height: 1.45;
  text-decoration: none;
  transition: color var(--qg-dur-fast) var(--qg-ease);
}

.qg-table tbody tr:hover .qg-cell-q {
  color: var(--qg-accent);
}

.qg-table .qg-num,
.qg-num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.qg-table td.qg-num {
  white-space: nowrap;
}

.qg-cell-type {
  font-size: var(--qg-fs-xs);
  font-weight: 500;
  color: var(--qg-text-body);
  white-space: nowrap;
}

.qg-cell-lvl {
  font-size: var(--qg-fs-xs);
  font-weight: 500;
  color: var(--qg-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.qg-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--qg-fs-xs);
  font-weight: 500;
  white-space: nowrap;
}

.qg-status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}

.qg-status--ok {
  color: var(--qg-pos);
}

.qg-status--ok .qg-status__dot {
  background: var(--qg-pos);
  box-shadow: 0 0 0 3px var(--qg-pos-soft);
}

.qg-status--bad {
  color: var(--qg-neg);
}

.qg-status--bad .qg-status__dot {
  background: var(--qg-neg);
  box-shadow: 0 0 0 3px var(--qg-neg-soft);
}

.qg-status--na {
  color: var(--qg-text-muted);
}

.qg-status--na .qg-status__dot {
  background: var(--qg-text-faint);
  box-shadow: 0 0 0 3px rgba(107, 118, 137, 0.1);
}

.qg-table__count {
  flex: none;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--qg-r-pill);
  display: inline-flex;
  align-items: center;
  background: var(--qg-surface-2);
  border: 1px solid var(--qg-line);
  font-size: 11px;
  font-weight: 600;
  color: var(--qg-text-muted);
  font-variant-numeric: tabular-nums;
}

.qg-empty {
  padding: var(--qg-s7) var(--qg-s5);
  text-align: center;
  color: var(--qg-text-muted);
}

.qg-empty i {
  font-size: 22px;
  color: var(--qg-text-faint);
  margin-bottom: var(--qg-s3);
  display: block;
}

.qg-empty p {
  margin: 0;
  font-size: var(--qg-fs-sm);
}

/* ------------------------------------------------------- 13. VIDEO CARDS */
/* Always gets a real cover image or the branded blue field, never a bare
   iframe on a grey box. The iframe/video is only swapped in on activation
   when data-qg-video-src is present. */

.qg-video {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--qg-surface);
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-card);
  box-shadow: var(--qg-sh-hair);
  transition: box-shadow var(--qg-dur-slow) var(--qg-ease),
    transform var(--qg-dur-slow) var(--qg-ease),
    border-color var(--qg-dur-slow) var(--qg-ease);
}

.qg-video:hover {
  box-shadow: var(--qg-sh-lift);
  transform: translateY(-2px);
  border-color: var(--qg-line-strong);
}

.qg-video__thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    radial-gradient(520px 220px at 24% 0%, rgba(0, 102, 204, 0.42), transparent 62%),
    linear-gradient(140deg, var(--qg-abyss-2) 0%, #00306e 52%, var(--qg-blue) 100%);
  border: 0;
  padding: 0;
  width: 100%;
  display: block;
  cursor: pointer;
}

.qg-video__thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: linear-gradient(120deg, #000, transparent 72%);
  mask-image: linear-gradient(120deg, #000, transparent 72%);
  pointer-events: none;
}

.qg-video__cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qg-video__play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.95);
  color: var(--qg-blue);
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 20, 46, 0.4);
  transition: transform var(--qg-dur-slow) var(--qg-ease), background var(--qg-dur-slow) var(--qg-ease);
}

.qg-video__play i {
  margin-left: 3px;
}

.qg-video:hover .qg-video__play,
.qg-video__thumb:hover .qg-video__play {
  transform: translate(-50%, -50%) scale(1.07);
  background: #fff;
}

.qg-video__dur {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  height: 22px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  background: rgba(0, 20, 46, 0.6);
  backdrop-filter: blur(6px);
  font-size: 10.5px;
  font-weight: 600;
  color: #dce6f5;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.qg-video__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  z-index: 3;
}

.qg-video__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: var(--qg-s5);
}

.qg-video__body .qg-h4 {
  margin-bottom: var(--qg-s3);
}

.qg-video__body p {
  margin: 0 0 var(--qg-s4);
  font-size: 14.5px;
  line-height: var(--qg-lh-base);
  color: var(--qg-text-muted);
}

.qg-video__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--qg-s3);
  margin-top: auto;
  padding-top: var(--qg-s4);
  border-top: 1px solid var(--qg-line);
}

.qg-video__meta {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--qg-text-faint);
}

/* ------------------------------------------------------- 14. THEME TOGGLE */
/* Custom two-stop rail. The knob slides, the sun rays retract into a
   crescent, and a soft brand glow blooms under the cursor on hover. */

.qg-theme-toggle {
  --qg-tt-w: 58px;
  --qg-tt-h: 30px;
  --qg-tt-knob: 24px;
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  width: var(--qg-tt-w);
  height: var(--qg-tt-h);
  padding: 0;
  border: 1px solid var(--qg-line);
  border-radius: var(--qg-r-pill);
  background: var(--qg-surface-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--qg-dur-slow) var(--qg-ease),
    border-color var(--qg-dur-slow) var(--qg-ease),
    box-shadow var(--qg-dur-slow) var(--qg-ease);
}

.qg-theme-toggle:hover {
  border-color: var(--qg-accent-line);
  box-shadow: 0 0 0 4px var(--qg-accent-soft);
}

/* The sky: a blue dawn in light mode, an abyss in dark mode. */
.qg-theme-toggle__sky {
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  overflow: hidden;
  background: linear-gradient(120deg, var(--qg-wash-2), var(--qg-wash));
  transition: background var(--qg-dur-slow) var(--qg-ease);
}

html[data-theme='dark'] .qg-theme-toggle__sky {
  background: linear-gradient(120deg, var(--qg-abyss), var(--qg-abyss-2));
}

/* Stars fade in with the dark sky. */
.qg-theme-toggle__stars {
  position: absolute;
  inset: 0;
  opacity: 0;
  background-image:
    radial-gradient(1px 1px at 22% 34%, #fff, transparent),
    radial-gradient(1px 1px at 36% 68%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1.4px 1.4px at 14% 62%, var(--qg-gold), transparent);
  transition: opacity var(--qg-dur-slow) var(--qg-ease);
}

html[data-theme='dark'] .qg-theme-toggle__stars {
  opacity: 1;
}

.qg-theme-toggle__knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: var(--qg-tt-knob);
  height: var(--qg-tt-knob);
  margin-top: calc(var(--qg-tt-knob) / -2);
  border-radius: 50%;
  background: var(--qg-gold);
  box-shadow: 0 1px 3px rgba(12, 17, 27, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.46s var(--qg-ease), background 0.46s var(--qg-ease),
    box-shadow 0.46s var(--qg-ease);
}

/* Sun rays: four hairlines that spin and retract on the way to night. */
.qg-theme-toggle__rays {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  opacity: 1;
  transition: opacity 0.36s var(--qg-ease), transform 0.56s var(--qg-ease);
  background:
    linear-gradient(to right, var(--qg-gold-deep) 0 2px, transparent 2px calc(100% - 2px), var(--qg-gold-deep) calc(100% - 2px) 100%) center / 100% 1.5px no-repeat,
    linear-gradient(to bottom, var(--qg-gold-deep) 0 2px, transparent 2px calc(100% - 2px), var(--qg-gold-deep) calc(100% - 2px) 100%) center / 1.5px 100% no-repeat;
}

/* The crescent: a shadow disc that slides over the knob at night. */
.qg-theme-toggle__crescent {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--qg-abyss);
  transform: translate(60%, -60%) scale(0.2);
  opacity: 0;
  transition: transform 0.5s var(--qg-ease), opacity 0.3s var(--qg-ease);
}

html[data-theme='dark'] .qg-theme-toggle__knob {
  transform: translateX(calc(var(--qg-tt-w) - var(--qg-tt-knob) - 8px)) translateY(0);
  background: #e9eef7;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

html[data-theme='dark'] .qg-theme-toggle__rays {
  opacity: 0;
  transform: rotate(140deg) scale(0.4);
}

html[data-theme='dark'] .qg-theme-toggle__crescent {
  transform: translate(26%, -22%) scale(0.86);
  opacity: 1;
}

/* Hover: the knob leans toward the destination and the rail brightens. */
.qg-theme-toggle:hover .qg-theme-toggle__knob {
  transform: translateX(5px) scale(1.06);
}

html[data-theme='dark'] .qg-theme-toggle:hover .qg-theme-toggle__knob {
  transform: translateX(calc(var(--qg-tt-w) - var(--qg-tt-knob) - 13px)) scale(1.06);
}

.qg-theme-toggle:hover .qg-theme-toggle__rays {
  transform: rotate(40deg);
}

.qg-theme-toggle:active .qg-theme-toggle__knob {
  transform: scale(0.92);
}

html[data-theme='dark'] .qg-theme-toggle:active .qg-theme-toggle__knob {
  transform: translateX(calc(var(--qg-tt-w) - var(--qg-tt-knob) - 8px)) scale(0.92);
}

/* Inline label variant for nav rails that have room for one. */
.qg-theme-toggle-field {
  display: inline-flex;
  align-items: center;
  gap: var(--qg-s3);
}

.qg-theme-toggle-field__label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--qg-text-muted);
}

.qg-theme-toggle--sm {
  --qg-tt-w: 48px;
  --qg-tt-h: 26px;
  --qg-tt-knob: 20px;
}

/* ------------------------------------------------------- 15. SCROLL REVEAL */

/* Nothing here is hidden by CSS alone. qg_app.js adds .is-armed to each target
   and then reveals it, so content is visible by default and the animation is a
   pure enhancement. Any JS failure therefore degrades to a plain, readable
   page rather than a blank one. */
.qg-fx.is-armed {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s var(--qg-ease), transform 0.7s var(--qg-ease);
  transition-delay: var(--qg-fx-delay, 0ms);
}

.qg-fx.is-armed.is-in {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .qg-page *,
  .qg-theme-toggle * {
    animation: none !important;
    transition: none !important;
  }

  .qg-fx.is-armed {
    opacity: 1;
    transform: none;
  }
}

/* -------------------------------------------------------- 16. RESPONSIVE */

@media (max-width: 1000px) {
  .qg-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .qg-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .qg-btn--lg {
    height: 48px;
  }

  .qg-sec-bar {
    align-items: flex-start;
  }
}

@media (max-width: 400px) {
  .qg-stat__num {
    font-size: 30px;
  }

  .qg-panel__head {
    padding: 18px var(--qg-s4);
  }

  .qg-panel__body {
    padding: var(--qg-s4);
  }
}
