/* The ruler of the chapters with the lens, and the points that top up on scroll.
   The page of a made-up course, the Keelson Analyst Track: five chapters, each a stage as tall as the window, under a
   fixed bar with a short ruler in the middle and a glass pill of points on the right. */
:root {
  --page: #0c0f0e;                        /* the page */
  --glow: rgba(120, 170, 150, 0.10);      /* the soft light under the bar */
  --ink: #f1eee7;                         /* titles */
  --muted: #8d938e;                       /* lines and small words */
  --tick: rgba(255, 255, 255, 0.35);      /* the small ticks */
  --tick-major: rgba(255, 255, 255, 0.6); /* the chapter ticks and their names */
  --needle: rgba(255, 255, 255, 0.92);    /* the still needle */
  --accent: #ffc232;                      /* the gold of the points */
  --glass: rgba(255, 255, 255, 0.05);     /* the body of the pill */
  --edge: rgba(255, 255, 255, 0.1);       /* the edge of the pill and of the chips */
  --glow-time: 1.8s;                      /* how long the edge of the pill stays lit */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

html.lenis,
html.lenis body {
  height: auto;
}

.lenis.lenis-smooth {
  scroll-behavior: auto !important;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: 'Geist Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* the light under the bar and a fine grain, fixed behind everything */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 46% at 50% -8%, var(--glow), transparent 70%),
    radial-gradient(120% 80% at 50% 120%, rgba(0, 0, 0, 0.5), transparent 60%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- the bar */
.hud {
  position: fixed;
  inset: 0 0 auto 0;
  height: 76px;
  z-index: 10;
  pointer-events: none;
}

.hud::before {
  content: '';
  position: absolute;
  inset: 0 0 -18px 0;
  background: linear-gradient(var(--page) 0%, rgba(12, 15, 14, 0.92) 55%, rgba(12, 15, 14, 0));
  pointer-events: none;
}

.ruler {
  --w: 300px;
  position: absolute;
  top: 16px;
  left: 50%;
  width: var(--w);
  height: 60px;
  transform: translateX(-50%);
  pointer-events: auto;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 8% 92%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0%, #000 8% 92%, transparent 100%);
}

.ruler.is-nav {
  -webkit-mask-image: none;
  mask-image: none;
}

.ruler__track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  will-change: transform;
  transition: opacity 0.25s;
}

.tick {
  position: absolute;
  top: 0;
  width: 12px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tick__line {
  width: 1px;
  height: 9px;
  background: var(--tick);
  transform-origin: top;
  will-change: transform;
}

.tick--major .tick__line {
  height: 18px;
  background: var(--tick-major);
  transition: background 0.4s;
}

.tick__label {
  margin-top: 4px;
  font: 500 11px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--tick-major);
  transition: color 0.4s;
}

.tick--major.is-here .tick__line {
  background: var(--accent);
}

.tick--major.is-here .tick__label {
  color: var(--ink);
}

.ruler__needle {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 18px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--needle);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
  transform-origin: top;
  transition: opacity 0.25s;
}

.ruler.is-nav .ruler__track,
.ruler.is-nav .ruler__needle {
  opacity: 0;
}

/* the five buttons that take the place of the track */
.ruler__nav {
  position: absolute;
  top: 0;
  left: 50%;
  display: flex;
  gap: 26px;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.ruler.is-nav .ruler__nav {
  opacity: 1;
  pointer-events: auto;
}

.stop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 2px 2px 8px;
  border: 0;
  background: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.62);
  font: 500 10px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.stop__name {
  white-space: nowrap;
  pointer-events: none;
}

.stop__line {
  width: 28px;
  height: 1px;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  transition: width 0.2s cubic-bezier(0.3, 1.5, 0.5, 1), height 0.2s, background 0.2s;
}

.stop.is-active {
  color: var(--ink);
}

.stop.is-active .stop__line {
  width: 40px;
  height: 2px;
  background: var(--ink);
}

.stop:active .stop__line {
  width: 24px;
}

.stop:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

/* while the page travels to a chapter, a small ring turns over its name */
.stop__spin {
  position: absolute;
  left: 50%;
  top: 3px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--ink);
  border-radius: 50%;
  opacity: 0;
  animation: spin 0.7s linear infinite;
  pointer-events: none;
}

.stop.is-loading .stop__name {
  opacity: 0;
}

.stop.is-loading .stop__spin {
  opacity: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (hover: hover) {
  .stop:hover {
    color: var(--ink);
  }

  .stop:hover .stop__line {
    width: 40px;
    background: var(--ink);
  }
}

/* ---------------------------------------------------------------- the pill of points */
.xp {
  position: absolute;
  top: 16px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 15px 10px 12px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(120%) blur(14px);
  backdrop-filter: saturate(120%) blur(14px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.08);
  font-size: 15px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  pointer-events: auto;
}

/* the edge that catches the light, drawn with a mask so only the 1px ring shows */
.xp::after {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.4), transparent 35% 65%, rgba(255, 255, 255, 0.4));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box exclude, linear-gradient(#fff 0 0);
  pointer-events: none;
}

/* the gold ring that lights up when points arrive */
.xp::before {
  content: '';
  position: absolute;
  inset: -2px;
  border: 2px solid transparent;
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
}

.xp.is-ripple {
  animation: xpFill var(--glow-time) ease-out;
}

.xp.is-ripple::before {
  animation: xpRing var(--glow-time) ease-out;
}

@keyframes xpRing {
  0% {
    opacity: 0;
    border-color: rgba(255, 200, 50, 0);
    box-shadow: 0 0 0 rgba(255, 190, 40, 0);
  }
  12% {
    opacity: 1;
    border-color: rgba(255, 200, 50, 0.9);
    box-shadow: 0 0 14px rgba(255, 190, 40, 0.7), 0 0 30px rgba(255, 170, 0, 0.3);
  }
  40% {
    opacity: 1;
    border-color: rgba(255, 200, 50, 0.5);
    box-shadow: 0 0 10px rgba(255, 190, 40, 0.4), 0 0 22px rgba(255, 170, 0, 0.15);
  }
  100% {
    opacity: 0;
    border-color: rgba(255, 200, 50, 0);
    box-shadow: 0 0 0 rgba(255, 190, 40, 0);
  }
}

@keyframes xpFill {
  0% {
    background-color: var(--glass);
  }
  12% {
    background-color: rgba(255, 194, 50, 0.2);
  }
  40% {
    background-color: rgba(255, 194, 50, 0.09);
  }
  100% {
    background-color: var(--glass);
  }
}

.xp__icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.xp__hex {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.3;
  stroke-linejoin: round;
}

.xp__core {
  fill: var(--accent);
  transform-origin: 8px 8px;
}

.xp__value {
  display: inline-block;
  min-width: 2.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.xp__label {
  opacity: 0.6;
}

/* +100 that rises out of the pill */
.xp__gain {
  position: absolute;
  right: 14px;
  top: 100%;
  margin-top: 6px;
  font: 500 11px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.06em;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the chapters */
.chapter {
  height: 100vh;
  display: grid;
  align-items: center;
  padding: 84px clamp(22px, 7vw, 96px) 24px;
  overflow: hidden;
}

.chapter__inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.chapter__kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 clamp(12px, 2.6vh, 22px);
  font: 500 11px/1.3 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.chapter__kicker b {
  font-weight: 500;
  color: var(--ink);
}

.soft {
  color: var(--muted);
}

.chapter__title {
  margin: 0;
  max-width: 13em;
  font-size: clamp(29px, min(7.4vw, 10.5vh), 88px);
  font-weight: 560;
  line-height: 1.02;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.word {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  padding-bottom: 0.08em;
  margin-bottom: -0.08em;
}

.word__in {
  display: inline-block;
}

.chapter__line {
  max-width: 31em;
  margin: clamp(10px, 2.4vh, 22px) 0 0;
  font-size: clamp(14px, min(1.7vw, 3.4vh), 18px);
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px clamp(18px, 3vw, 34px);
  margin-top: clamp(16px, 4vh, 40px);
  padding-top: clamp(12px, 2.4vh, 18px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.meta__cell {
  display: grid;
  gap: 4px;
}

.meta__cell span {
  font: 500 10px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta__cell b {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* the chip of the chapter: +100 XP, then Earned with a drawn check */
.reward {
  position: relative;
  display: grid;
  margin-left: auto;
  padding: 7px 12px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  font: 500 11px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  transition: border-color 0.6s, color 0.6s;
}

.reward > span {
  grid-area: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.reward__done {
  opacity: 0;
  color: var(--accent);
}

.reward svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reward.is-earned {
  border-color: rgba(255, 194, 50, 0.35);
}

/* ---------------------------------------------------------------- narrow screens: same pieces, closer */
@media (max-width: 560px) {
  .ruler {
    --w: min(300px, calc(100vw - 128px));
    left: 12px;
    top: 12px;
    transform: none;
  }

  .ruler__nav {
    left: 0;
    gap: 14px;
    transform: none;
  }

  /* the five buttons need the whole row: the pill steps aside while they are open */
  .xp {
    transition: opacity 0.25s;
  }

  .hud.is-nav .xp {
    opacity: 0;
    pointer-events: none;
  }

  .xp {
    top: 12px;
    right: 12px;
    padding: 8px 12px 8px 10px;
    font-size: 14px;
    gap: 5px;
  }

  .tick__label {
    font-size: 10px;
  }

  .chapter {
    padding-top: 70px;
    padding-bottom: 16px;
  }

  .meta__cell b {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stop__spin {
    animation: none;
  }

  .xp.is-ripple {
    animation: none;
  }

  .xp.is-ripple::before {
    animation: xpRingFade var(--glow-time) ease-out;
  }

  @keyframes xpRingFade {
    0%, 100% {
      opacity: 0;
    }
    20% {
      opacity: 1;
      border-color: rgba(255, 200, 50, 0.7);
    }
  }
}
