:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #1e2328;
  --muted: #68737d;
  --line: #dbe2e6;
  --input-bg: #ffffff;
  --button-bg: #fafdfe;
  --range-track: #e8eef1;
  --bar-bg: #edf2f4;
  --table-head: #f7fafb;
  --teal: #147d7e;
  --blue: #315c9a;
  --red: #cb453f;
  --orange: #d88426;
  --yellow: #d6a722;
  --green: #22885f;
  --deep-green: #126b55;
  --shadow: 0 14px 38px rgba(26, 35, 43, 0.08);
  --panel-shadow: 0 10px 30px rgba(26, 35, 43, 0.04);
  --hero-bg:
    linear-gradient(120deg, rgba(20, 125, 126, 0.94), rgba(49, 92, 154, 0.92)),
    radial-gradient(circle at 82% 18%, rgba(255, 255, 255, 0.3), transparent 28%),
    #1f6e83;
  --hero-ink: #f7fbfc;
  --hero-muted: rgba(247, 251, 252, 0.75);
  --hero-panel: rgba(255, 255, 255, 0.12);
  --hero-panel-border: rgba(255, 255, 255, 0.25);
  --thumb-border: #ffffff;
  --tooltip-bg: rgba(30, 35, 40, 0.95);
  --tooltip-ink: #ffffff;
  --timeline-label-bg: rgba(255, 255, 255, 0.88);
  --chart-grid: #e5ebee;
  --chart-grid-strong: #c9d4da;
  --chart-label: #68737d;
  --chart-line: #147d7e;
  --chart-area: rgba(20, 125, 126, 0.12);
  --chart-focus: #1e2328;
  --chart-dot-stroke: #ffffff;
  --chart-band-extreme-fear: rgba(177, 62, 58, 0.18);
  --chart-band-fear: rgba(190, 101, 30, 0.17);
  --chart-band-neutral: rgba(188, 144, 24, 0.18);
  --chart-band-greed: rgba(38, 126, 88, 0.17);
  --chart-band-extreme-greed: rgba(17, 94, 75, 0.19);
  --timeline-bg: #e8eef2;
  --timeline-grid: #c7d1da;
  --timeline-text: #68798d;
  --timeline-fill: #96a9ba;
  --timeline-line: #72889e;
  --timeline-mask: rgba(245, 247, 248, 0.58);
  --timeline-selection: rgba(255, 255, 255, 0.12);
  --timeline-selection-stroke: #7c8792;
  --timeline-handle: #ffffff;
  --timeline-handle-stroke: #8d98a3;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111614;
  --panel: #181d1a;
  --ink: #eef3ef;
  --muted: #9ba7a0;
  --line: #2d3731;
  --input-bg: #111614;
  --button-bg: #161f1b;
  --range-track: #2a342f;
  --bar-bg: #263029;
  --table-head: #151b18;
  --teal: #2aa1a2;
  --blue: #4d75b0;
  --red: #e25a55;
  --orange: #e0963d;
  --yellow: #e2bb38;
  --green: #36a875;
  --deep-green: #1f8f73;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.34);
  --panel-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  --hero-bg:
    linear-gradient(120deg, rgba(12, 86, 84, 0.95), rgba(45, 67, 99, 0.9)),
    radial-gradient(circle at 82% 18%, rgba(255, 255, 255, 0.12), transparent 28%),
    #123331;
  --hero-ink: #f4faf7;
  --hero-muted: rgba(244, 250, 247, 0.72);
  --hero-panel: rgba(255, 255, 255, 0.08);
  --hero-panel-border: rgba(255, 255, 255, 0.16);
  --thumb-border: #e8f2ef;
  --tooltip-bg: rgba(238, 243, 239, 0.96);
  --tooltip-ink: #111614;
  --timeline-label-bg: rgba(24, 29, 26, 0.9);
  --chart-grid: #2a342f;
  --chart-grid-strong: #405048;
  --chart-label: #9ba7a0;
  --chart-line: #2bb6b3;
  --chart-area: rgba(42, 161, 162, 0.14);
  --chart-focus: #dfe7e2;
  --chart-dot-stroke: #111614;
  --chart-band-extreme-fear: rgba(226, 90, 85, 0.23);
  --chart-band-fear: rgba(224, 150, 61, 0.2);
  --chart-band-neutral: rgba(226, 187, 56, 0.18);
  --chart-band-greed: rgba(54, 168, 117, 0.18);
  --chart-band-extreme-greed: rgba(31, 143, 115, 0.25);
  --timeline-bg: #202923;
  --timeline-grid: #39463f;
  --timeline-text: #9ba7a0;
  --timeline-fill: #506359;
  --timeline-line: #7f968b;
  --timeline-mask: rgba(17, 22, 20, 0.6);
  --timeline-selection: rgba(255, 255, 255, 0.08);
  --timeline-selection-stroke: #96a49c;
  --timeline-handle: #eef3ef;
  --timeline-handle-stroke: #76847c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #111614;
    --panel: #181d1a;
    --ink: #eef3ef;
    --muted: #9ba7a0;
    --line: #2d3731;
    --input-bg: #111614;
    --button-bg: #161f1b;
    --range-track: #2a342f;
    --bar-bg: #263029;
    --table-head: #151b18;
    --teal: #2aa1a2;
    --blue: #4d75b0;
    --red: #e25a55;
    --orange: #e0963d;
    --yellow: #e2bb38;
    --green: #36a875;
    --deep-green: #1f8f73;
    --shadow: 0 16px 44px rgba(0, 0, 0, 0.34);
    --panel-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
    --hero-bg:
      linear-gradient(120deg, rgba(12, 86, 84, 0.95), rgba(45, 67, 99, 0.9)),
      radial-gradient(circle at 82% 18%, rgba(255, 255, 255, 0.12), transparent 28%),
      #123331;
    --hero-ink: #f4faf7;
    --hero-muted: rgba(244, 250, 247, 0.72);
    --hero-panel: rgba(255, 255, 255, 0.08);
    --hero-panel-border: rgba(255, 255, 255, 0.16);
    --thumb-border: #e8f2ef;
    --tooltip-bg: rgba(238, 243, 239, 0.96);
    --tooltip-ink: #111614;
    --timeline-label-bg: rgba(24, 29, 26, 0.9);
    --chart-grid: #2a342f;
    --chart-grid-strong: #405048;
    --chart-label: #9ba7a0;
    --chart-line: #2bb6b3;
    --chart-area: rgba(42, 161, 162, 0.14);
    --chart-focus: #dfe7e2;
    --chart-dot-stroke: #111614;
    --chart-band-extreme-fear: rgba(226, 90, 85, 0.23);
    --chart-band-fear: rgba(224, 150, 61, 0.2);
    --chart-band-neutral: rgba(226, 187, 56, 0.18);
    --chart-band-greed: rgba(54, 168, 117, 0.18);
    --chart-band-extreme-greed: rgba(31, 143, 115, 0.25);
    --timeline-bg: #202923;
    --timeline-grid: #39463f;
    --timeline-text: #9ba7a0;
    --timeline-fill: #506359;
    --timeline-line: #7f968b;
    --timeline-mask: rgba(17, 22, 20, 0.6);
    --timeline-selection: rgba(255, 255, 255, 0.08);
    --timeline-selection-stroke: #96a49c;
    --timeline-handle: #eef3ef;
    --timeline-handle-stroke: #76847c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

svg {
  max-width: 100%;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1560px, calc(100% - 20px));
  margin: 0 auto;
  padding: 12px 0 24px;
}

.hero-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 230px);
  gap: 10px;
  align-items: center;
  min-height: 76px;
  padding: 10px 14px;
  color: var(--hero-ink);
  background: var(--hero-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-copy {
  align-self: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--hero-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 5px;
  font-size: clamp(1.35rem, 2.4vw, 2.15rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 3px;
  font-size: 0.95rem;
  letter-spacing: 0;
}

.hero-meta {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--hero-muted);
  overflow: hidden;
  font-size: 0.78rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-content: center;
  align-items: center;
  column-gap: 8px;
  min-height: 56px;
  padding: 8px 10px;
  background: var(--hero-panel);
  border: 1px solid var(--hero-panel-border);
  border-radius: 8px;
}

.latest-label {
  grid-column: 1 / -1;
  color: var(--hero-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.latest-panel strong {
  margin: 0;
  font-size: clamp(1.8rem, 3.6vw, 2.6rem);
  line-height: 0.95;
}

.latest-panel span:last-of-type {
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.latest-panel time {
  grid-column: 1 / -1;
  margin-top: 0;
  color: var(--hero-muted);
  font-size: 0.75rem;
}

.toolbar,
.range-panel,
.chart-panel,
.breakdown-panel,
.table-panel,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
}

.toolbar {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding: 10px;
}

.preset-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.preset-button,
.icon-button,
.language-button {
  display: inline-grid;
  place-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  background: var(--button-bg);
  color: var(--ink);
  border-radius: 8px;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.preset-button {
  min-width: 50px;
  padding: 0 11px;
  font-size: 0.86rem;
  font-weight: 700;
}

.preset-button:hover,
.icon-button:hover,
.language-button:hover {
  border-color: rgba(20, 125, 126, 0.5);
}

.preset-button.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.date-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  justify-content: flex-end;
  min-width: 0;
}

label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.date-controls label {
  grid-template-columns: auto auto;
  align-items: center;
}

input[type="date"],
input[type="search"] {
  min-height: 32px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 0 10px;
}

.icon-button {
  width: 36px;
  padding: 0;
  color: var(--teal);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}

.icon-button span {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  line-height: 1;
}

.language-button {
  min-width: 42px;
  padding: 0 10px;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 900;
}

.theme-button span {
  transform: none;
}

.theme-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.range-panel {
  display: grid;
  grid-template-columns: minmax(190px, 270px) minmax(0, 1fr);
  column-gap: 14px;
  align-items: center;
  margin-top: 10px;
  padding: 10px 12px;
}

.range-header,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  min-width: 0;
}

.range-header {
  align-items: center;
}

.range-header p,
.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.range-header strong {
  white-space: nowrap;
  font-size: 1.25rem;
}

.range-slider {
  position: relative;
  grid-column: 2;
  height: 28px;
  margin-top: 0;
}

.range-track,
.range-fill {
  position: absolute;
  top: 50%;
  height: 6px;
  transform: translateY(-50%);
  border-radius: 999px;
}

.range-track {
  inset-inline: 0;
  background: var(--range-track);
}

.range-fill {
  left: 0;
  right: 0;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--green));
}

.range-slider input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  background: none;
  pointer-events: none;
  appearance: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--thumb-border);
  background: var(--teal);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(26, 35, 43, 0.22);
  pointer-events: auto;
  appearance: none;
}

.range-slider input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--thumb-border);
  background: var(--teal);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(26, 35, 43, 0.22);
  pointer-events: auto;
}

.range-labels {
  display: flex;
  grid-column: 2;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.76rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.stat-card {
  min-height: 64px;
  padding: 8px 10px;
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
}

.stat-card span {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin: 5px 0 3px;
  font-size: 1.45rem;
  line-height: 1;
}

.stat-card small {
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
  gap: 10px;
  margin-top: 10px;
}

.chart-panel,
.breakdown-panel,
.table-panel {
  padding: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.74rem;
  min-width: 0;
}

.legend span {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  white-space: nowrap;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.extreme-fear {
  background: var(--red);
}

.fear {
  background: var(--orange);
}

.neutral {
  background: var(--yellow);
}

.greed {
  background: var(--green);
}

.extreme-greed {
  background: var(--deep-green);
}

.chart-wrap {
  position: relative;
  height: clamp(260px, 30vw, 360px);
  margin-top: 6px;
}

#historyChart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 150px;
  max-width: 210px;
  padding: 9px 10px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  font-size: 1.05rem;
}

.timeline-selector {
  position: relative;
  margin-top: 0;
  padding: 0;
}

#timelineChart {
  display: block;
  width: 100%;
  height: 64px;
  overflow: visible;
  touch-action: none;
  user-select: none;
}

.timeline-range-text {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 2px 0 0 auto;
  padding: 3px 7px;
  background: var(--timeline-label-bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.source-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-note a {
  color: var(--teal);
  font-weight: 800;
  text-decoration: none;
}

.source-note a:hover {
  text-decoration: underline;
}

.breakdown-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.breakdown-row {
  display: grid;
  gap: 4px;
}

.breakdown-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
}

.breakdown-bar {
  height: 7px;
  overflow: hidden;
  background: var(--bar-bg);
  border-radius: 999px;
}

.breakdown-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.table-panel {
  margin-top: 10px;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
  font-size: 0.84rem;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head);
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.value-pill {
  display: inline-grid;
  min-width: 36px;
  min-height: 24px;
  place-items: center;
  color: #ffffff;
  border-radius: 8px;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

@media (max-width: 1180px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
  }

  .hero-band {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 200px);
  }

  .main-grid {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  }

  .chart-wrap {
    height: clamp(280px, 36vw, 340px);
  }
}

@media (max-width: 980px) {
  .hero-band,
  .main-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .preset-group {
    display: grid;
    grid-template-columns: repeat(6, minmax(74px, 1fr));
  }

  .preset-button {
    min-width: 0;
    padding-inline: 8px;
  }

  .date-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) 36px 36px 46px;
    align-items: end;
    justify-content: stretch;
  }

  .date-controls label {
    grid-template-columns: 1fr;
  }

  .date-controls input {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-heading {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }

  .breakdown-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .hero-band {
    gap: 8px;
  }

  .hero-meta {
    white-space: normal;
  }

  .latest-panel {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  }

  .range-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .range-slider,
  .range-labels {
    grid-column: 1;
  }

  .chart-wrap {
    height: clamp(300px, 62vw, 380px);
  }

  #timelineChart {
    height: 72px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 14px, 1440px);
    padding: 8px 0 18px;
  }

  .hero-band {
    padding: 12px;
    border-radius: 8px;
  }

  h1 {
    font-size: 1.32rem;
  }

  .latest-panel {
    min-height: 64px;
  }

  .toolbar,
  .range-panel,
  .chart-panel,
  .breakdown-panel,
  .table-panel {
    padding: 9px;
  }

  .preset-group {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .preset-button {
    flex: 0 0 auto;
    min-width: 64px;
  }

  .date-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .date-controls label {
    grid-column: span 3;
  }

  .icon-button,
  .language-button {
    width: auto;
    min-width: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .range-header {
    display: grid;
  }

  .range-header strong {
    white-space: normal;
    font-size: 1.05rem;
  }

  .chart-wrap {
    height: 330px;
  }

  .legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .legend span {
    white-space: normal;
  }

  .breakdown-list {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 520px;
    font-size: 0.8rem;
  }

  th,
  td {
    padding: 7px 8px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
  }
}

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

  .chart-wrap {
    height: 310px;
  }

  .timeline-range-text {
    margin-left: 0;
  }

  .source-note {
    font-size: 0.68rem;
  }
}

.about-panel {
  margin-top: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--panel-shadow);
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px;
  margin-top: 8px;
}

.about-grid h3 {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 0.92rem;
}

.about-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.7;
}

a.language-button {
  text-decoration: none;
}

.not-found {
  max-width: 560px;
  margin: 15vh auto;
  padding: 20px;
  text-align: center;
}

.not-found h1 {
  margin-bottom: 8px;
  color: var(--ink);
}

.not-found p {
  color: var(--muted);
  line-height: 1.7;
}

.not-found a {
  color: var(--teal);
  font-weight: 700;
}
