/* ─────────────────────────────────────────────────────────────────────
   Sovereign Credit Rating Explorer — shared stylesheet
   Black-and-white base, grayscale accents, mobile-first.
   Light + dark themes via CSS variables. Body.dark toggles.
   ───────────────────────────────────────────────────────────────────── */

:root {
  --bg:        #f5f5f3;
  --bg-card:   #ffffff;
  --bg-soft:   #ececea;
  --ink:       #1a1a1a;
  --ink-soft:  #444444;
  --muted:     #888888;
  --muted-2:   #c8c8c6;
  --border:    #cccccc;
  --border-soft: #e0e0de;
  --accent:    #1a1a1a;
  --link:      #2a2a2a;
  --link-hover-bg: #1a1a1a;
  --link-hover-fg: #ffffff;
  --tooltip-bg: #1a1a1a;
  --tooltip-fg: #f5f5f3;
}
body.dark {
  --bg:        #121212;
  --bg-card:   #1c1c1c;
  --bg-soft:   #232323;
  --ink:       #e8e8e6;
  --ink-soft:  #c8c8c6;
  --muted:     #888888;
  --muted-2:   #444444;
  --border:    #3a3a3a;
  --border-soft: #2a2a2a;
  --accent:    #e8e8e6;
  --link:      #d8d8d6;
  --link-hover-bg: #e8e8e6;
  --link-hover-fg: #121212;
  --tooltip-bg: #e8e8e6;
  --tooltip-fg: #121212;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15.5px; scroll-behavior: smooth; }
body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ── header / nav ─────────────────────────────────────────────── */
header.site {
  background: var(--bg-card);
  border-bottom: 2px solid var(--accent);
  padding: 16px 28px 8px;
  position: relative;
}
header.site .head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}
header.site .head-text { flex: 1; min-width: 0; }
header.site h1 {
  font-size: 1.45rem;
  font-weight: bold;
  letter-spacing: 0.01em;
}
header.site .credit { display: none; } /* moved to bottom-left imprint */

/* Tiny bottom-left attribution imprint */
.imprint {
  position: fixed;
  bottom: 6px;
  left: 8px;
  z-index: 40;
  font-family: 'Georgia', serif;
  font-style: italic;
  font-size: 0.62rem;
  color: var(--muted);
  background: transparent;
  pointer-events: auto;
  line-height: 1.3;
  max-width: 220px;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.imprint:hover { opacity: 1; }
.imprint a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted-2); }
.imprint a:hover { color: var(--ink); background: transparent; border-bottom-color: var(--ink); }
@media (max-width: 600px) { .imprint { font-size: 0.56rem; max-width: 160px; } }
header.site .sub-tagline {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 4px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

/* ── top-right control pills ──────────────────────────────────── */
.controls-rail {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  padding-top: 2px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.pill:hover { border-color: var(--accent); color: var(--ink); }
.pill.on {
  background: var(--accent);
  color: var(--bg-card);
  border-color: var(--accent);
}
.pill .dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
}
.pill.on .dot { background: var(--bg-card); }
.pill.square {
  border-radius: 4px;
  padding: 4px 8px;
}
.lang-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  min-width: 130px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.78rem;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.lang-menu.open { display: block; }
.lang-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 6px 12px;
  font: inherit;
  color: var(--ink-soft);
  cursor: pointer;
}
.lang-menu button:hover { background: var(--bg-soft); color: var(--ink); }
.lang-wrap { position: relative; }

nav.site {
  background: var(--accent);
  padding: 0 12px;
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  align-items: stretch;
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 36px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
}
body.dark nav.site { background: #0a0a0a; }
nav.site::-webkit-scrollbar { height: 4px; }
nav.site::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 2px; }
nav.site a {
  display: inline-block;
  padding: 9px 9px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #bbbbbb;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
nav.site a:hover { color: #ffffff; background: transparent; }
nav.site a.active { color: #ffffff; border-bottom-color: #ffffff; }
nav.site .nav-sep {
  display: inline-block;
  align-self: center;
  width: 1px;
  height: 18px;
  background: #555555;
  margin: 0 6px;
}
nav.site .nav-spacer { flex: 1; }

/* ── main column ──────────────────────────────────────────────── */
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 36px 24px 80px;
}

h2 {
  font-size: 1.25rem;
  font-weight: bold;
  margin-top: 44px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
  scroll-margin-top: 60px;
}
h3 {
  font-size: 1.05rem;
  font-weight: bold;
  margin-top: 28px;
  margin-bottom: 8px;
  color: var(--ink);
  scroll-margin-top: 60px;
}
h4 {
  font-size: 0.95rem;
  font-weight: bold;
  margin-top: 18px;
  margin-bottom: 6px;
  color: var(--ink-soft);
}

p { line-height: 1.78; margin-bottom: 14px; }
ul, ol { margin: 10px 0 16px 24px; line-height: 1.78; }
li { margin-bottom: 6px; }
a { color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { background: var(--link-hover-bg); color: var(--link-hover-fg); text-decoration-color: var(--link-hover-fg); }

/* ── code, formula blocks ─────────────────────────────────────── */
code {
  font-family: 'Courier New', monospace;
  font-size: 0.86em;
  background: var(--bg-soft);
  padding: 1px 5px;
  border: 1px solid var(--border);
  color: var(--ink);
}
.formula-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 16px 20px;
  margin: 18px 0;
  font-family: 'Courier New', monospace;
  font-size: 0.88rem;
  line-height: 1.8;
  overflow-x: auto;
  color: var(--ink);
}
.formula-block .label {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

/* ── tables ───────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.83rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin: 18px 0;
  color: var(--ink);
}
thead th {
  background: var(--accent);
  color: var(--bg-card);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 8px 12px;
  text-align: left;
}
tbody tr:nth-child(even) { background: var(--bg-soft); }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
tbody td:first-child { font-weight: 700; }

.table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin: -8px 0 10px;
}
.table-actions button {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  cursor: pointer;
}
.table-actions button:hover { background: var(--accent); color: var(--bg-card); border-color: var(--accent); }

/* ── callouts ─────────────────────────────────────────────────── */
.callout {
  background: var(--bg-soft);
  border: 1px solid var(--muted-2);
  border-left: 4px solid var(--accent);
  padding: 14px 18px;
  margin: 18px 0;
  font-size: 0.88rem;
  line-height: 1.7;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
}
.callout strong { color: var(--ink); }

/* ── section number badge ─────────────────────────────────────── */
.section-num {
  display: inline-block;
  background: var(--accent);
  color: var(--bg-card);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  margin-right: 8px;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

/* ── endnote refs ─────────────────────────────────────────────── */
sup.note-ref a {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.7rem;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  padding: 0 1px;
}
sup.note-ref a:hover { color: var(--link-hover-fg); background: var(--link-hover-bg); }
.endnotes {
  margin-top: 60px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink-soft);
}
.endnotes h3 {
  font-family: 'Georgia', serif;
  font-size: 1.0rem;
  margin-bottom: 14px;
}
.endnotes ol { margin-left: 22px; }
.endnotes li {
  margin-bottom: 8px;
  line-height: 1.6;
  scroll-margin-top: 80px;
}
.endnotes li:target { background: var(--bg-soft); padding: 4px 8px; margin-left: 14px; }
.endnotes li::marker { color: var(--muted); }

/* ── floating Table of Contents ───────────────────────────────── */
#floating-toc {
  position: fixed;
  top: 90px;
  left: 0;
  width: 240px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  padding: 14px 14px 14px 22px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 30;
}
#floating-toc.visible { opacity: 0.97; pointer-events: auto; }
#floating-toc .toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
#floating-toc ul { list-style: none; margin: 0; padding: 0; }
#floating-toc li { margin-bottom: 6px; line-height: 1.4; }
#floating-toc li.h3 { padding-left: 14px; font-size: 0.74rem; }
#floating-toc a {
  color: var(--ink);
  text-decoration: none;
  display: block;
  padding: 2px 0 2px 8px;
  margin-left: -10px;
  border-left: 2px solid transparent;
  background: transparent;
  opacity: 0.85;
}
#floating-toc a:hover { color: var(--ink); opacity: 1; border-left-color: var(--accent); background: transparent; }
#floating-toc a.current { color: var(--ink); opacity: 1; font-weight: 700; border-left-color: var(--accent); }
#floating-toc .toc-title { color: var(--ink-soft); }

@media (max-width: 1180px) { #floating-toc { display: none; } }

/* ── footer ───────────────────────────────────────────────────── */
.page-footer {
  margin-top: 50px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
}
footer.site {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding: 18px 28px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.74rem;
  color: var(--ink-soft);
  line-height: 1.6;
}
footer.site .row {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  justify-content: space-between;
}
footer.site .links { display: flex; gap: 16px; flex-wrap: wrap; }
footer.site a { color: var(--ink-soft); text-decoration: underline; }
footer.site a:hover { color: var(--ink); background: transparent; text-decoration-color: var(--ink); }
footer.site .copyright {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── mobile ───────────────────────────────────────────────────── */
@media (max-width: 700px) {
  header.site { padding: 12px 14px 6px; }
  header.site .head-row { flex-direction: column; gap: 8px; }
  header.site h1 { font-size: 1.18rem; }
  .controls-rail { width: 100%; flex-wrap: wrap; }
  .pill { font-size: 0.6rem; padding: 3px 7px; }
  nav.site { padding: 0 6px; }
  nav.site a { padding: 8px 8px; font-size: 0.62rem; letter-spacing: 0.04em; }
  nav.site .nav-sep { display: none; }
  main { padding: 22px 14px 60px; }
  h2 { font-size: 1.1rem; margin-top: 32px; }
  table { font-size: 0.78rem; display: block; overflow-x: auto; }
}

/* ── tag chips ────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--bg-soft);
  color: var(--ink-soft);
  border: 1px solid var(--muted-2);
}

/* ── PDF view button ──────────────────────────────────────────── */
.pdf-btn {
  display: inline-block;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  margin-left: 8px;
  background: var(--accent);
  color: var(--bg-card);
  text-decoration: none;
  border: 1px solid var(--accent);
}
.pdf-btn:hover { background: var(--bg-card); color: var(--accent); }

/* ── hover tooltip system ─────────────────────────────────────── */
.term {
  border-bottom: 1px dotted var(--muted-2);
  cursor: help;
  position: relative;
}
body.no-tooltips .term { border-bottom: none; cursor: inherit; }
#tip-box {
  position: fixed;
  max-width: 320px;
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  padding: 10px 14px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(0,0,0,0.20);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 200;
  border-radius: 4px;
}
#tip-box.visible { opacity: 0.97; }
#tip-box .tip-source {
  display: block;
  margin-top: 6px;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
}
body.no-tooltips #tip-box { display: none; }

/* ── NOTES toggle: hides every secondary annotation layer ─────── */
body.no-notes .meta,
body.no-notes .endnotes,
body.no-notes sup.note-ref,
body.no-notes .chart-note { display: none !important; }

/* ── Plotly chart contrast — both modes ─────────────────────────── */
/* Light mode: force axis/legend text to true black (Plotly's default is grey #444) */
body:not(.dark) .js-plotly-plot text { fill: #1a1a1a !important; }
body:not(.dark) .js-plotly-plot .xgrid path,
body:not(.dark) .js-plotly-plot .ygrid path { stroke: rgba(60,60,60,0.18) !important; }

/* Dark mode: text+axis to near-white, gridlines to light translucent. */
body.dark .js-plotly-plot text { fill: #ececec !important; }
body.dark .js-plotly-plot .xgrid path,
body.dark .js-plotly-plot .ygrid path,
body.dark .js-plotly-plot .zerolinelayer path { stroke: rgba(230,230,230,0.22) !important; }
body.dark .js-plotly-plot .xaxislayer-above path,
body.dark .js-plotly-plot .yaxislayer-above path { stroke: #ececec !important; }
body.dark .js-plotly-plot .modebar-btn path { fill: #d8d8d8 !important; }
body.dark .modebar-group { background: rgba(40,40,40,0.4) !important; }

/* Dark mode: swap dark trace fills/strokes for light ones so bars and lines
   are visible against the dark background. Targets Plotly's inline rgb()
   styles via CSS attribute substring match. */
body.dark .js-plotly-plot path[style*="fill: rgb(26, 26, 26)"] { fill: rgb(232, 232, 232) !important; }
body.dark .js-plotly-plot path[style*="stroke: rgb(26, 26, 26)"] { stroke: rgb(232, 232, 232) !important; }
body.dark .js-plotly-plot path[style*="fill: rgb(0, 0, 0)"] { fill: rgb(232, 232, 232) !important; }
body.dark .js-plotly-plot path[style*="stroke: rgb(0, 0, 0)"] { stroke: rgb(232, 232, 232) !important; }
body.dark .js-plotly-plot path[style*="fill: rgb(68, 68, 68)"] { fill: rgb(204, 204, 204) !important; }
body.dark .js-plotly-plot path[style*="stroke: rgb(68, 68, 68)"] { stroke: rgb(204, 204, 204) !important; }
body.dark .js-plotly-plot path[style*="fill: rgb(85, 85, 85)"] { fill: rgb(192, 192, 192) !important; }
body.dark .js-plotly-plot path[style*="stroke: rgb(85, 85, 85)"] { stroke: rgb(192, 192, 192) !important; }
body.dark .js-plotly-plot path[style*="fill: rgb(136, 136, 136)"] { fill: rgb(180, 180, 180) !important; }
body.dark .js-plotly-plot path[style*="stroke: rgb(136, 136, 136)"] { stroke: rgb(180, 180, 180) !important; }
/* Annotation lines (dashed verticals on stories charts) */
body.dark .js-plotly-plot .annotation path { stroke: #ececec !important; }
body.dark .js-plotly-plot .infolayer .annotation-text-g text { fill: #ececec !important; }

/* ── Dark mode: code, formula, and pre blocks render terminal-green-on-black ── */
body.dark code,
body.dark pre.code-block,
body.dark .formula-block,
body.dark span.formula,
body.dark .copyable pre,
body.dark .example pre {
  background: #000 !important;
  color: #43ff7e !important;
  border-color: #1f5530 !important;
  text-shadow: 0 0 6px rgba(67, 255, 126, 0.45);
  font-family: 'Courier New', 'Consolas', monospace !important;
}
body.dark code { padding: 1px 4px; border-radius: 2px; }
body.dark pre.code-block { box-shadow: 0 0 12px rgba(67, 255, 126, 0.18) inset; }
body.dark .formula-block { box-shadow: 0 0 8px rgba(67, 255, 126, 0.12) inset; }
body.dark .formula-block .label { color: #b0e8c0 !important; text-shadow: none; }

/* ── Small advisory note under the controls rail (top-right) ─────── */
.scr-best-note {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: right;
  margin: 4px 18px 0 0;
  letter-spacing: 0.02em;
  font-style: italic;
}
@media (max-width: 700px) { .scr-best-note { display: none; } }

/* ── Citations page dark-mode coverage ────────────────────────────── */
body.dark .style-note {
  background: var(--bg-soft) !important;
  color: var(--ink) !important;
  border-left-color: var(--accent) !important;
}
body.dark .style-note strong { color: var(--ink) !important; }
body.dark #cite-search {
  background: var(--bg-card) !important;
  color: var(--ink) !important;
  border-color: var(--border) !important;
}
body.dark #cite-search:focus { outline-color: var(--accent) !important; }
body.dark .group-heading {
  background: var(--bg-card) !important;
  color: var(--ink) !important;
  border: 1px solid var(--border) !important;
}
body.dark .cite-entry { border-bottom-color: var(--border) !important; }
body.dark .cite-entry .meta { color: var(--muted) !important; }
body.dark .cite-entry a.doi { color: var(--ink-soft) !important; }

/* ── Plotly legend background — dark mode needs dark fill + light text ── */
body.dark .js-plotly-plot .legend > rect.bg,
body.dark .js-plotly-plot .legend rect:first-child {
  fill: rgba(20, 24, 32, 0.92) !important;
  stroke: rgba(180, 190, 200, 0.4) !important;
  stroke-width: 1px !important;
}
body.dark .js-plotly-plot .legend text { fill: #ececec !important; }

/* Light mode: white bg, dark text (Plotly defaults are usually OK) */
body:not(.dark) .js-plotly-plot .legend > rect.bg {
  fill: rgba(255, 255, 255, 0.96) !important;
  stroke: rgba(60, 60, 60, 0.4) !important;
}

/* ── Mobile responsive: trim chart-box margins on narrow screens ──── */
@media (max-width: 700px) {
  .chart-box, .chart-wrap { padding: 4px 2px 36px 2px !important; margin: 12px 0 !important; overflow: visible; position: relative; }
  .chart-box > div, .chart-wrap > div { min-height: 280px; width: 100% !important; }
  .js-plotly-plot, .js-plotly-plot .plotly { width: 100% !important; }
  .js-plotly-plot .gtitle { font-size: 11px !important; }
  .js-plotly-plot .legend text { font-size: 9px !important; }
  .js-plotly-plot .xtick text, .js-plotly-plot .ytick text { font-size: 9px !important; }
  .js-plotly-plot .legend { transform: translate(0, 0); }
  /* Modebar — push below the chart so it can't overlap the legend or title.
     Plotly's default modebar uses inline-style position:absolute with top
     and right set, plus a transform; we override all of them with !important
     and a more specific selector to win. */
  div.js-plotly-plot div.modebar-container,
  .js-plotly-plot .modebar-container {
    top: auto !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    text-align: right !important;
  }
  div.js-plotly-plot div.modebar,
  .js-plotly-plot .modebar {
    position: absolute !important;
    top: auto !important;
    bottom: -38px !important;
    right: 4px !important;
    left: auto !important;
    transform: none !important;
    background: transparent !important;
    opacity: 0.9 !important;
    display: inline-flex !important;
  }
  .js-plotly-plot .modebar-btn { padding: 5px !important; }
  .js-plotly-plot .modebar-group { background: transparent !important; }
  /* Wider, more tappable view-switcher buttons */
  .scr-view-switcher { gap: 4px !important; flex-wrap: wrap; }
  .scr-view-switcher button {
    flex: 1 1 0;
    min-width: 78px;
    padding: 8px 10px !important;
    font-size: 0.7rem !important;
    min-height: 36px;
  }
  /* Generic input controls — taller on mobile so they're tappable */
  select, input[type=range], input[type=number], input[type=text], button {
    font-size: 0.85rem;
  }
  select, input[type=number], input[type=text] { min-height: 34px; }
  /* TOC hidden via existing rule (max-width 1180), stays hidden */
  /* On phones, simulate hover-glow via tap (CSS-only fallback) */
  .js-plotly-plot .scatterlayer .trace path.js-line:active,
  .js-plotly-plot .barlayer .trace .point path:active {
    filter: drop-shadow(0 0 4px rgba(255,255,255,0.85)) drop-shadow(0 0 10px rgba(255,255,255,0.5)) !important;
  }
}

/* Tap-target friendly: any input, button, or pill on touch devices ─── */
@media (hover: none) and (pointer: coarse) {
  .pill { min-height: 34px; padding: 6px 12px !important; }
  .scr-view-switcher button { min-height: 38px; }
  /* Tooltips: dismissable by tapping anywhere on the page */
  #tip-box { max-width: 88vw; font-size: 0.82rem; padding: 12px 16px; }
}

/* ── Hover labels: uniform high-contrast bg + readable text ─────── */
/* Cover all the SVG element types Plotly uses for hover bubble:
   - hovertext > path  (scatter trace hover)
   - hovertext > rect  (heatmap hover)
   - g.hovertext path  (newer plotly)
   - all descendants for text  */
body.dark .js-plotly-plot g.hovertext path,
body.dark .js-plotly-plot g.hovertext rect,
body.dark .js-plotly-plot .hovertext path,
body.dark .js-plotly-plot .hovertext rect {
  fill: #1a1a1a !important;
  stroke: #f0f0f0 !important;
  stroke-width: 1.5px !important;
  fill-opacity: 1 !important;
}
body.dark .js-plotly-plot g.hovertext text,
body.dark .js-plotly-plot g.hovertext text tspan,
body.dark .js-plotly-plot .hovertext text,
body.dark .js-plotly-plot .hovertext text tspan {
  fill: #ffffff !important;
  font-weight: 600 !important;
}
/* Light mode equivalent */
body:not(.dark) .js-plotly-plot g.hovertext path,
body:not(.dark) .js-plotly-plot g.hovertext rect,
body:not(.dark) .js-plotly-plot .hovertext path,
body:not(.dark) .js-plotly-plot .hovertext rect {
  fill: #ffffff !important;
  stroke: #1a1a1a !important;
  stroke-width: 1.5px !important;
  fill-opacity: 1 !important;
}
body:not(.dark) .js-plotly-plot g.hovertext text,
body:not(.dark) .js-plotly-plot g.hovertext text tspan,
body:not(.dark) .js-plotly-plot .hovertext text,
body:not(.dark) .js-plotly-plot .hovertext text tspan {
  fill: #1a1a1a !important;
  font-weight: 600 !important;
}

/* ── Modebar: replace white highlight with simple invert on hover ── */
.js-plotly-plot .modebar-btn { transition: filter 0.12s ease, opacity 0.12s ease; }
.js-plotly-plot .modebar-btn:hover {
  filter: invert(1) hue-rotate(180deg) !important;
  background: transparent !important;
}
body.dark .js-plotly-plot .modebar-btn:hover {
  filter: invert(0) brightness(1.5) !important;
  background: transparent !important;
}

/* ── Dark-mode neon-glow hover halo: triggered by JS class via plotly_hover ── */
body.dark .js-plotly-plot .scatterlayer .trace.scr-trace-glow path.js-line {
  filter:
    drop-shadow(0 0 calc(3px * var(--scr-zoom, 1)) rgba(255,255,255,0.95))
    drop-shadow(0 0 calc(8px * var(--scr-zoom, 1)) rgba(255,255,255,0.55));
}
body.dark .js-plotly-plot .barlayer .trace.scr-trace-glow .point path {
  filter:
    drop-shadow(0 0 calc(3px * var(--scr-zoom, 1)) rgba(255,255,255,0.95))
    drop-shadow(0 0 calc(8px * var(--scr-zoom, 1)) rgba(255,255,255,0.5));
}
.js-plotly-plot .scatterlayer .trace path.js-line,
.js-plotly-plot .barlayer .trace .point path {
  transition: filter 0.18s ease;
}

/* ── Copy-PNG overlay button (tables, examples, figures) ──────── */
.copyable-wrap { position: relative; }
.copy-png-bar {
  position: absolute;
  top: 6px; right: 6px;
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 12;
}
.copyable-wrap:hover .copy-png-bar { opacity: 0.96; }
.copy-png-bar .copy-png-btn { position: static !important; }
.copy-png-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  background: rgba(255,255,255,0.94);
  color: var(--ink-soft);
  border: 1px solid var(--muted-2);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s, background 0.15s, color 0.15s;
  z-index: 12;
  border-radius: 2px;
}
.copyable-wrap:hover .copy-png-btn,
.copy-png-btn:focus { opacity: 0.96; }
.copy-png-btn:hover { background: var(--accent); color: var(--bg-card); border-color: var(--accent); }
.copy-png-btn[disabled] { opacity: 0.7; cursor: progress; }
body.dark .copy-png-btn { background: rgba(40,40,40,0.94); color: #ddd; border-color: #555; }
body.dark .copy-png-btn:hover { background: var(--accent); color: var(--bg-card); }

/* ── Fullscreen chart styling ──────────────────────────────── */
.chart-box:fullscreen,
.chart-box:-webkit-full-screen,
.chart-box:-moz-full-screen {
  background: var(--bg-card);
  padding: 24px;
  display: flex; flex-direction: column;
}
.chart-box:fullscreen .js-plotly-plot,
.chart-box:-webkit-full-screen .js-plotly-plot {
  width: 100% !important; height: 100% !important; flex: 1;
}
body.dark .chart-box:fullscreen { background: #161821; }

/* Also support the html2canvas wrapper */
.copyable-wrap:fullscreen { background: var(--bg-card); padding: 24px; }
body.dark .copyable-wrap:fullscreen { background: #161821; }

/* ── Toast (Copy confirmation, etc) ───────────────────────────── */
#scr-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,20,20,0.94);
  color: #fff;
  padding: 8px 16px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  border-radius: 3px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#scr-toast.visible { opacity: 1; }

/* ── expandable details (worked examples) ─────────────────────── */
details.example {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted-2);
  padding: 0;
  margin: 12px 0 16px;
  font-size: 0.92rem;
}
details.example > summary {
  padding: 8px 14px;
  cursor: pointer;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  list-style: none;
  user-select: none;
}
details.example > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s;
}
details.example[open] > summary::before { transform: rotate(90deg); }
details.example > summary:hover { background: var(--bg-soft); }
details.example .ex-body {
  padding: 4px 18px 14px;
  font-family: 'Georgia', serif;
  line-height: 1.7;
}
details.example .ex-body code,
details.example .ex-body .calc {
  font-family: 'Courier New', monospace;
  background: var(--bg-soft);
  padding: 1px 5px;
  border: 1px solid var(--border);
  font-size: 0.86rem;
}
details.example .ex-body .step {
  display: block;
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 2px solid var(--muted-2);
  background: var(--bg);
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

/* ── chart-area annotation toggle helper class ─ used by JS ───── */
body.no-chart-annot .chart-annotation { display: none; }

/* ── Plotly chart container theming ───────────────────────────── */
.chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 8px;
  margin: 14px 0;
}
body.dark .chart-box { background: var(--bg-card); }
body.dark .js-plotly-plot .plotly text { fill: var(--ink) !important; }


/* ── v80d nav dropdown (Macro Relatives) ──────────────────────────────── */
.nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  flex-shrink: 0;
}
.nav-dropdown-label {
  display: inline-block;
  padding: 9px 9px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #bbbbbb;
  cursor: pointer;
  user-select: none;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-dropdown-label:hover { color: #ffffff; }
.nav-dropdown-label.active { color: #ffffff; border-bottom-color: #ffffff; }

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border, #cccccc);
  min-width: 170px;
  z-index: 200;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
.nav-dropdown.open .nav-dropdown-menu { display: block; }

.nav-dropdown-menu a {
  display: block;
  padding: 8px 14px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink, #1a1a1a);
  text-decoration: none;
  border-bottom: 1px solid var(--border-soft, #e0e0de);
  white-space: nowrap;
}
.nav-dropdown-menu a:last-child { border-bottom: none; }
.nav-dropdown-menu a:hover {
  background: var(--accent, #1a1a1a);
  color: var(--bg-card, #ffffff);
}
.nav-dropdown-menu a.active {
  background: var(--bg-soft, #ececea);
  color: var(--ink, #1a1a1a);
  font-weight: 700;
}

body.dark .nav-dropdown-menu {
  background: var(--bg-card);
  border-color: var(--border);
}
body.dark .nav-dropdown-menu a { color: var(--ink); }
body.dark .nav-dropdown-menu a:hover { background: var(--accent); color: var(--bg-card); }

/* ── v80d kill drag-to-zoom default cursor (modebar zoom button still works) ── */
.js-plotly-plot .draglayer .nsewdrag,
.js-plotly-plot .draglayer .ewdrag,
.js-plotly-plot .draglayer .nsdrag {
  cursor: crosshair;
}
