/* The section nav and masthead on every page (markup from lib/masthead.js). Colors and sizes come
   from the page's own tokens, so light and dark mode follow the page. */

/* Market ticker, a full-width band between the section nav and the masthead: Fear & Greed, a
   separator, then the rest, scrolling past in a loop (masthead.js fills it and starts the scroll).
   Hovering pauses it; with reduced motion it stays still and can be swiped instead. */
.ticker {
  display: flex; align-items: stretch; height: 40px;
  border-block: 1px solid var(--rule);
  font-family: var(--mono); font-size: var(--fs-12); color: var(--ink); white-space: nowrap; /* the masthead's small text size */
}
.ticker[hidden] { display: none; }
.ticker .num { font-variant-numeric: tabular-nums; }
.ticker-name { color: var(--muted); }
.ticker-item, .ticker-fg { display: inline-flex; align-items: center; gap: 8px; }
.ticker-sep { flex: none; width: 1px; height: 22px; background: var(--rule); }
/* The movers are spaced like the majors: --ticker-gap between coins, 8px between symbol and change */
.ticker-movers { display: inline-flex; gap: var(--ticker-gap); }
.ticker-mover { display: inline-flex; gap: 8px; }
.ticker-fg-reading { display: inline-flex; gap: 8px; }
/* The reading ("12 Extreme Fear") takes the gauge's colors: the palette's red on the fear side, its
   green on the greed side, grey at neutral */
.ticker-fg[data-band="extreme-fear"] .ticker-fg-reading, .ticker-fg[data-band="fear"] .ticker-fg-reading { color: var(--down); }
.ticker-fg[data-band="neutral"] .ticker-fg-reading { color: var(--muted); }
.ticker-fg[data-band="greed"] .ticker-fg-reading, .ticker-fg[data-band="extreme-greed"] .ticker-fg-reading { color: var(--up); }
.ticker-gauge {
  position: relative; width: 50px; height: 3px; border-radius: 1.5px;
  /* the palette's red to a lighter version of its green */
  --fg-red: var(--down); --fg-green: color-mix(in srgb, var(--up) 60%, #fff);
  background: linear-gradient(90deg, var(--fg-red), var(--fg-green));
}
/* Dark mode: the palette's red and green are light there, so the slider and ball use darker shades */
:root[data-theme="dark"] .ticker-gauge {
  --fg-red: color-mix(in srgb, var(--down) 70%, #000); --fg-green: color-mix(in srgb, var(--up) 75%, #000);
}
/* The ball: solid, no outline, in the line's color at the point where it sits (masthead.js sets
   --fg-pos to the reading, 0 to 100, as it places it) */
.ticker-gauge-knob {
  position: absolute; top: 50%; left: 0; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  border-radius: 50%; background: color-mix(in srgb, var(--fg-red), var(--fg-green) calc(var(--fg-pos, 0) * 1%));
}
.ticker-track {
  flex: 1 1 auto; min-width: 0; overflow: hidden; display: flex; align-items: center;
  /* Items fade in at the right edge and out at the left */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 80px, #000 calc(100% - 120px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 80px, #000 calc(100% - 120px), transparent);
}
.ticker-run { display: flex; width: max-content; }
.ticker { --ticker-gap: 36px; }
/* Padding only at the end, so the pipe before Fear & Greed (where the loop comes round) is spaced like the others */
.ticker-list { display: flex; align-items: center; gap: var(--ticker-gap); padding-inline: 0 var(--ticker-gap); }
.ticker-run.scrolling { animation: ticker-scroll var(--ticker-duration, 60s) linear infinite; }
.ticker:hover .ticker-run, .ticker:focus-within .ticker-run { animation-play-state: paused; }
@keyframes ticker-scroll { to { transform: translateX(var(--ticker-shift, -50%)); } }
/* Each item comes in smaller, fading in through the right edge, and once it's fully visible
   (masthead.js adds .in) grows smoothly to full size; on the way out at the left (.out) it shrinks
   back the same way as it fades out */
.ticker.popping .ticker-pop { display: inline-flex; transform: scale(0.82); transform-origin: 50% 60%; }
.ticker.popping .ticker-pop.in { animation: ticker-pop 1.4s cubic-bezier(0.25, 0.6, 0.35, 1) both; }
/* Already in view when the page loads, or a fresh copy of one that is: full size, no pop */
.ticker.popping .ticker-pop.in.seen { animation: none; transform: none; }
/* Shrinks steadily until the item touches the left edge: masthead.js sets the duration to the time
   it takes to travel the last POP_LINE pixels */
.ticker.popping .ticker-pop.in.out, .ticker.popping .ticker-pop.in.seen.out { animation: ticker-shrink var(--ticker-exit, 1.56s) linear both; transform-origin: 0% 60%; }
/* (it shrinks toward its left side, so that side stays on course and meets the edge) */
@keyframes ticker-pop {
  from { transform: scale(0.82); }
  to { transform: scale(1); }
}
@keyframes ticker-shrink {
  from { transform: scale(1); }
  to { transform: scale(0.82); }
}
.ticker-gauge { flex: none; }
@media (max-width: 640px) {
  .ticker { --ticker-gap: 24px; }
}
.ticker-up, .ticker-change.up { color: var(--up); }
.ticker-down, .ticker-change.down { color: var(--down); }
@media (prefers-reduced-motion: reduce) {
  .ticker-track { overflow-x: auto; scrollbar-width: none; }
  .ticker-track::-webkit-scrollbar { display: none; }
  .ticker-run.scrolling { animation: none; }
  .ticker-list[aria-hidden="true"] { display: none; }
  .ticker.popping .ticker-pop, .ticker.popping .ticker-pop.in { transform: none; animation: none; }
}

/* Section nav: the links scroll sideways on narrow screens; the theme menu stays at the right */
nav.sections .wrap { display: flex; align-items: center; gap: var(--s2); }
/* Pages with no ticker or masthead under the nav (the directory) close it with a hairline, the
   same as the ticker's: full width, in the lighter rule color */
nav.sections.ruled { border-bottom: 1px solid var(--rule); }
nav.sections .wrap > ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: var(--s3); white-space: nowrap;
  flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none;
}
nav.sections .wrap > ul::-webkit-scrollbar { display: none; }
nav.sections .wrap > ul a {
  display: inline-flex; align-items: center; height: 60px;
  font-family: var(--mono); font-size: var(--fs-12); font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  transition: color 0.15s ease;
}
nav.sections .wrap > ul a:hover { color: var(--accent-text); }
nav.sections .wrap > ul a[aria-current="page"] { color: var(--accent-text); }

/* Masthead: the wordmark on the left and the ad unit on the right share the top row and its rule */
.masthead { padding-block: 0; }
.masthead-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  height: 130px; border-bottom: 1px solid var(--line);
}
.wordmark {
  display: flex;
  flex: 1 1 auto; min-width: 0;
  justify-content: flex-start;
  align-items: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.6rem, 10.4vw, 5.75rem);
  line-height: 1;
  letter-spacing: -0.045em;
  color: var(--ink);
  height: 100%;
  white-space: nowrap;
  overflow: hidden;
}
.wordmark-text { display: inline-block; padding-right: 0.04em; }
.wordmark em {
  font-style: italic; font-weight: 500;
  letter-spacing: -0.02em;
}

/* The ad unit, up to 650px wide. The frame keeps a 728x90 banner's proportions, so a scaled banner
   fills it with no bands above or below. The ad's own page is light: in dark mode the browser would
   paint a white backdrop behind a frame whose color scheme differs from the page's, and slivers of
   it show around a scaled banner, so the frame is marked light and stays transparent. */
.masthead-ad { flex: 0 1 650px; min-width: 0; }
.masthead-ad iframe {
  display: block; width: 100%; height: auto; aspect-ratio: 728 / 90;
  border: 0; padding: 0; overflow: hidden;
  color-scheme: light; background: transparent;
}
/* Phones and small tablets: the wordmark gets the row to itself */
@media (max-width: 759px) { .masthead-ad { display: none; } }

/* The ad unit on its own, under the nav, on pages without the masthead (the directory): centered
   at its full 728x90 size, and gone on phones like the masthead's */
.top-ad .wrap { display: flex; justify-content: center; padding-block: var(--s3); }
.top-ad .masthead-ad { flex: 0 1 728px; }
@media (max-width: 759px) { .top-ad { display: none; } }

/* Tagline and date bar */
.masthead-meta {
  display: flex; justify-content: space-between; flex-wrap: wrap;
  align-items: center; align-content: center;
  gap: var(--s1) var(--s3);
  min-height: 50px;
  padding-block: 10px;
  border-bottom: 1px solid var(--line);
}
.tagline { font-style: italic; color: var(--muted); font-size: var(--fs-12); }
.utility-left { display: flex; flex-wrap: wrap; gap: var(--s1) 12px; }
.utility-left span { white-space: nowrap; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
/* The separator between items on a line: 12px each side, from the row's gap */
.bullet { font-family: var(--mono); font-size: var(--fs-12); font-weight: 400; color: var(--muted); }

/* Newsletter button in the nav's top-right corner, solid ink with cream text: black in light mode,
   the headlines' white in dark mode (where the ink is light). It goes to the signup on the front page. */
.nav-newsletter {
  flex: none; display: inline-flex; align-items: center; min-height: 36px; padding-inline: var(--s2);
  font-family: var(--mono); font-size: var(--fs-12); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--ink); color: var(--paper2); border: 1px solid var(--ink); border-radius: var(--r-sm);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.nav-newsletter:hover {
  background: color-mix(in srgb, var(--ink) 82%, var(--paper2)); border-color: color-mix(in srgb, var(--ink) 82%, var(--paper2)); color: var(--paper2);
}
.nav-newsletter:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Color theme menu, at the right of the nav. The button shows the reader's choice; the menu lists
   all three with a check on the current one. Tints of --ink, so it reads in light and dark mode. */
.theme-menu { position: relative; flex: none; }
.theme-menu .icon { display: block; flex: none; }
.theme-menu-button {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--muted);
  cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.theme-menu-button:hover, .theme-menu-button[aria-expanded="true"] {
  background: color-mix(in srgb, var(--ink) 9%, transparent); color: var(--ink);
}
.theme-menu-button:focus-visible, .theme-menu-list button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.theme-menu-button .icon { display: none; }
.theme-menu[data-choice="system"] .show-system,
.theme-menu[data-choice="light"] .show-light,
.theme-menu[data-choice="dark"] .show-dark { display: block; }

.theme-menu-list {
  position: absolute; z-index: 30; top: calc(100% + 8px); right: 0; min-width: 196px;
  list-style: none; margin: 0; padding: 6px;
  background: var(--paper2); border: 1px solid var(--ink); border-radius: var(--r-md);
}
/* In dark mode the ink is a light grey-white, too bright for an outline, so it uses the palette's mid grey */
:root[data-theme="dark"] .theme-menu-list { border-color: var(--line); }
.theme-menu-list[hidden] { display: none; }
.theme-menu-list button {
  display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 10px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text);
  font-family: var(--mono); font-size: var(--fs-14); text-align: left; cursor: pointer;
}
.theme-menu-list button .icon { color: var(--muted); }
.theme-menu-list button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.theme-menu-list button[aria-checked="true"] {
  background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); font-weight: 700;
}
.theme-menu-list button span { flex: 1; }
.theme-menu-list .check { visibility: hidden; color: var(--accent-text); }
.theme-menu-list button[aria-checked="true"] .check { visibility: visible; }

