/* ============================================================
   The Flourish Index (mbti.josh.ua)
   Design tokens follow the validated reference dataviz palette:
   categorical slots 1-4 for the four metrics, sequential blue
   for the matrix, warm-neutral surfaces, hairline chrome.
   ============================================================ */

:root {
  color-scheme: light dark;

  /* surfaces & ink (light) */
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --deemph: #dcdbd3;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --shadow-lift: 0 10px 28px rgba(11, 11, 11, 0.08);

  /* metric series: categorical slots 1-4, light steps */
  --m-happiness: #2a78d6;
  --m-health: #1baf7a;
  --m-wealth: #eda100;
  --m-love: #008300;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --deemph: #383835;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 10px 28px rgba(0, 0, 0, 0.5);

    /* same four hues, stepped for the dark surface */
    --m-happiness: #3987e5;
    --m-health: #199e70;
    --m-wealth: #c98500;
    --m-love: #008300;
  }
}

/* ---------- base ---------- */

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 72px;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--ink);
  color: var(--page);
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: clamp(20px, 4vw, 32px);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 100;
  background: var(--ink);
  color: var(--page);
  padding: 10px 16px;
  border-radius: 0 0 10px 10px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

/* metric color hooks: marks only, never text */
.m-happiness { background: var(--m-happiness); }
.m-health    { background: var(--m-health); }
.m-wealth    { background: var(--m-wealth); }
.m-love      { background: var(--m-love); }

.d-happiness { fill: var(--m-happiness); }
.d-health    { fill: var(--m-health); }
.d-wealth    { fill: var(--m-wealth); }
.d-love      { fill: var(--m-love); }

/* ---------- header ---------- */

.site-head {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--page) 84%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: 20px;
}

.site-nav a {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.site-nav a:hover {
  color: var(--ink);
}

@media (max-width: 700px) {
  .site-nav {
    display: none;
  }
}

/* ---------- hero ---------- */

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  padding-top: clamp(56px, 9vh, 110px);
  padding-bottom: clamp(40px, 6vh, 72px);
}

.hero-text {
  max-width: 720px;
}

.eyebrow {
  margin: 0 0 14px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 640;
  font-size: clamp(44px, 7vw, 78px);
  line-height: 1.02;
  letter-spacing: -0.015em;
}

.standfirst {
  margin: 22px 0 0;
  font-size: clamp(16px, 2.2vw, 19px);
  line-height: 1.6;
  color: var(--ink-2);
  max-width: 62ch;
}

.standfirst strong {
  color: var(--ink);
  font-weight: 600;
}

.hero-meta {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.hero-meta a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--baseline);
  text-underline-offset: 3px;
}

.hero-meta a:hover {
  text-decoration-color: var(--ink);
}

.hero-ornament {
  flex: 0 0 auto;
}

@media (max-width: 820px) {
  .hero-ornament {
    display: none;
  }
}

.notice {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 14px;
  color: var(--ink-2);
}

/* ---------- sections ---------- */

.section {
  border-top: 1px solid var(--border);
  padding-top: 48px;
  padding-bottom: 40px;
}

h2 {
  margin: 0.15em 0 0.25em;
  font-family: var(--font-display);
  font-weight: 640;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.section-sub {
  margin: 0;
  max-width: 62ch;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-2);
}

.chart-card {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

/* reveal animation */
.reveal {
  opacity: 0;
  transform: translateY(14px);
}

.reveal.in {
  opacity: 1;
  transform: none;
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 0.72, 0.22, 1);
}

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal.in {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---------- controls & legend ---------- */

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.controls-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sort-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.sort-group button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: 500 13px/1 var(--font-sans);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s ease, color 0.15s ease;
}

.sort-group button:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.sort-group button.is-active {
  background: var(--ink);
  color: var(--page);
}

@media (max-width: 560px) {
  .sort-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    border-radius: 16px;
  }

  .sort-group button {
    justify-content: center;
    padding: 9px 6px;
    border-radius: 12px;
  }
}

.key-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  flex: 0 0 auto;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding-bottom: 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

.key-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* ---------- ranking chart ---------- */

.rk {
  margin-top: 4px;
}

.rk-row {
  display: grid;
  grid-template-columns: clamp(110px, 22%, 176px) 1fr 48px;
  gap: 0 14px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 8px;
}

.rk-item {
  transition: background 0.15s ease;
}

.rk-item:hover {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

.rk-axis {
  padding-top: 0;
  padding-bottom: 6px;
}

.rk-axis-track {
  position: relative;
  height: 14px;
}

.rk-tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rk-tick.is-first {
  transform: none;
}

.rk-tick.is-last {
  transform: translateX(-100%);
}

.rk-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.rk-rank {
  width: 18px;
  flex: 0 0 auto;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rk-name {
  display: flex;
  align-items: baseline;
  column-gap: 8px;
  min-width: 0;
}

.rk-code {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.rk-nick {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rk-track {
  display: flex;
  gap: 2px; /* the surface gap between stacked segments */
  height: 16px;
  border-left: 1px solid var(--baseline);
  /* hairlines at each tile's right edge: 25/50/75/100, none doubling the baseline */
  background-image: linear-gradient(to left, var(--grid) 0, var(--grid) 1px, transparent 1px);
  background-size: 25% 100%;
  background-repeat: repeat-x;
}

.rk-track .seg {
  display: block;
  height: 100%;
  transition: background 0.25s ease;
}

.rk-track .seg.is-end {
  border-radius: 0 4px 4px 0; /* rounded data-end, square at the baseline */
}

/* emphasis mode: the sorted metric keeps its hue, the rest recede */
.rk[data-emphasis="happiness"] .seg:not(.m-happiness),
.rk[data-emphasis="health"] .seg:not(.m-health),
.rk[data-emphasis="wealth"] .seg:not(.m-wealth),
.rk[data-emphasis="love"] .seg:not(.m-love) {
  background: var(--deemph);
}

/* the legend recedes with the marks, so the key never contradicts the chart */
.chart-card:has(.rk[data-emphasis="happiness"]) .key-swatch:not(.m-happiness),
.chart-card:has(.rk[data-emphasis="health"]) .key-swatch:not(.m-health),
.chart-card:has(.rk[data-emphasis="wealth"]) .key-swatch:not(.m-wealth),
.chart-card:has(.rk[data-emphasis="love"]) .key-swatch:not(.m-love) {
  background: var(--deemph);
}

.rk-total {
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .rk-nick {
    display: none;
  }
}

@media (max-width: 680px) {
  .rk-row {
    grid-template-columns: 92px 1fr 44px;
    gap: 0 10px;
  }
}

@media (max-width: 480px) {
  .rk-tick:nth-child(even) {
    display: none;
  }
}

/* ---------- score matrix ---------- */

.table-scroll {
  overflow-x: auto;
}

.matrix {
  width: 100%;
  min-width: 600px;
  border-collapse: separate;
  border-spacing: 2px; /* the surface gap between cells */
}

.matrix thead th {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  padding: 6px 10px 10px;
}

.matrix thead th:first-child {
  text-align: left;
}

.matrix tbody th {
  text-align: left;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
  border-radius: 6px;
  font-weight: 400;
}

.matrix-code {
  display: block;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.matrix-nick {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.matrix-cell {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 12px 8px;
  border-radius: 6px;
  min-width: 64px;
  transition: filter 0.12s ease;
}

.matrix-cell:hover {
  filter: brightness(1.06);
}

.matrix-total {
  text-align: center;
  font-size: 13.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.matrix-note {
  margin: 12px 2px 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- dimension leaders ---------- */

.leads-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

@media (max-width: 640px) {
  .leads-grid {
    grid-template-columns: 1fr;
  }
}

.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  height: 100%;
}

.lead-title {
  margin: 0;
  font: 650 15px/1.3 var(--font-sans);
  display: flex;
  align-items: center;
  gap: 9px;
}

.lead-desc {
  margin: 5px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.lead-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 11px;
}

.lead-row {
  display: grid;
  grid-template-columns: 14px minmax(96px, 118px) 1fr 30px;
  gap: 9px;
  align-items: center;
  border-radius: 6px;
}

.lead-pos {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lead-name {
  min-width: 0;
}

.lead-code {
  display: block;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.lead-nick {
  display: block;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-track {
  display: block;
  height: 10px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border-radius: 0 4px 4px 0;
  overflow: hidden;
}

.lead-bar {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
}

.lead-value {
  font-size: 12.5px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- type profiles ---------- */

.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

@media (max-width: 1024px) {
  .profile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }
}

.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.profile-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

@media (prefers-reduced-motion: reduce) {
  .profile-card,
  .profile-card:hover {
    transform: none;
    transition: none;
  }
}

.profile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.profile-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-code {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.profile-rank {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  padding: 2px 7px;
  border-radius: 999px;
}

.profile-nick {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.profile-total {
  text-align: right;
  white-space: nowrap;
}

.profile-total-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.profile-total-max {
  font-size: 11px;
  color: var(--muted);
  margin-left: 3px;
}

.profile-bars {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.profile-bar-row {
  display: grid;
  grid-template-columns: 64px 1fr 26px;
  gap: 9px;
  align-items: center;
}

.profile-bar-label {
  font-size: 11.5px;
  color: var(--muted);
}

.profile-track {
  display: block;
  height: 8px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border-radius: 0 4px 4px 0;
  overflow: hidden;
}

.profile-bar {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
}

.profile-bar-value {
  font-size: 12.5px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.profile-tagline {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- observations ---------- */

.obs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.obs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.obs-num {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.obs-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 640;
  font-size: 19px;
  letter-spacing: -0.005em;
  line-height: 1.25;
}

.obs-text {
  margin: 9px 0 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-2);
}

/* ---------- methodology ---------- */

.method {
  max-width: 70ch;
  margin-top: 18px;
}

.method p {
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink-2);
  margin: 0 0 14px;
}

.method strong {
  color: var(--ink);
}

.method ul {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.7;
}

.method li + li {
  margin-top: 6px;
}

.method a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--baseline);
  text-underline-offset: 3px;
}

.method a:hover {
  text-decoration-color: var(--ink);
}

/* ---------- footer ---------- */

.site-foot {
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

.site-foot-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-block: 34px 60px;
  font-size: 13px;
  color: var(--muted);
}

.site-foot a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--baseline);
  text-underline-offset: 3px;
}

.site-foot a:hover {
  text-decoration-color: var(--ink);
}

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  max-width: 260px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-lift);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.tooltip.is-visible {
  opacity: 1;
}

.tooltip-title {
  font-weight: 600;
}

.tooltip-subtitle {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 1px;
}

.tooltip-row {
  display: grid;
  grid-template-columns: 14px 30px 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.tooltip-key {
  height: 3px;
  border-radius: 2px;
}

.tooltip-value {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tooltip-label {
  color: var(--ink-2);
  font-size: 12px;
}

.tooltip-footer {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11.5px;
}
