/* Shell of the ElectroChemLab docs site.

   Each help page brings its own stylesheet, loaded into `@layer legacy`. Rules
   here are unlayered, so they win over the page wherever both speak; anything
   this file does not mention keeps the page's own look. The page accent
   (--page-accent, the same colour as the page's --accent) stays the wayfinding
   signal: one glance says which section you are in. */

:root {
  --paper: #f1f3f5;
  --surface: #ffffff;
  --ink: #17212b;
  --ink-soft: #586573;
  --rule: #d2d9e0;
  --page-accent: #2b415c;
  --bar: 52px;
  --toc: 300px;
  --serif: "Old Standard TT", "Times New Roman", serif;
  --sans: "Golos Text Variable", "Segoe UI", system-ui, sans-serif;
}

@view-transition {
  navigation: auto;
}

html {
  scroll-padding-top: calc(var(--bar) + 16px);
  -webkit-text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.62;
}

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

/* ---------- top bar ---------- */

.site-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--bar);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.site-brand-sub {
  font-weight: 400;
  color: var(--ink-soft);
}

.site-mark {
  width: 26px;
  height: 8px;
  border-radius: 4px;
  background: var(--page-accent);
}

.site-bar-gap {
  flex: 1;
}

.site-bar button,
.site-app {
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.site-bar button:hover,
.site-app:hover {
  border-color: var(--ink);
}

.site-app {
  border-color: var(--page-accent);
  background: var(--page-accent);
  color: #fff;
}

.site-bar kbd {
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8125rem;
}

.site-toc-button {
  display: none;
}

.site-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  height: 3px;
  background: var(--page-accent);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- a help page ---------- */

.doc .layout {
  display: flex;
  align-items: flex-start;
}

.doc nav.sidebar {
  position: sticky;
  top: var(--bar);
  flex: 0 0 var(--toc);
  width: var(--toc);
  height: calc(100vh - var(--bar));
  padding-top: 22px;
  font-family: var(--sans);
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / 0.35) transparent;
}

.doc nav.sidebar h1 {
  font: 400 1.3125rem/1.25 var(--serif);
  letter-spacing: 0;
}

.doc nav.sidebar .subtitle {
  font: 400 0.75rem/1.45 var(--sans);
  margin-top: 8px;
}

.doc main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 54rem;
  padding: 40px 56px 80px;
}

.doc main section {
  scroll-margin-top: calc(var(--bar) + 16px);
}

.doc main [id] {
  scroll-margin-top: calc(var(--bar) + 16px);
}

.doc main section h2 {
  font: 400 1.875rem/1.2 var(--serif);
  padding-bottom: 12px;
  margin: 0 0 22px;
  text-wrap: balance;
}

.doc main section h3 {
  font: 600 1.125rem/1.35 var(--sans);
  margin-top: 34px;
}

.doc main p {
  text-align: left;
  hyphens: auto;
}

.doc main .eq,
.doc main .site-scroll,
.doc main .tblwrap,
.doc main .scroll {
  overflow-x: auto;
  max-width: 100%;
}

/* A formula wider than the column scrolls in place instead of widening the page. */
.doc main mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.doc main .callout,
.doc main .step {
  border-radius: 4px;
}

.doc main img {
  max-width: 100%;
  height: auto;
}

.doc main .fig > img,
.doc main figure > img {
  cursor: zoom-in;
}

.doc main ul.refs li {
  scroll-margin-top: calc(var(--bar) + 24px);
  transition: background 0.4s;
}

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

.site-foot {
  margin: 0;
  padding: 28px 56px 44px;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.doc .site-foot {
  margin-left: var(--toc);
}

.site-foot p {
  margin: 0;
}

.site-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 47rem;
  margin-bottom: 28px;
}

.site-pager a {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--page-accent);
  border-radius: 4px;
  color: var(--ink);
  font: 400 1.125rem/1.3 var(--serif);
  text-decoration: none;
}

.site-pager a:hover {
  border-color: var(--page-accent);
}

.site-pager a.is-next {
  border-left-width: 1px;
  border-right: 4px solid var(--page-accent);
  text-align: right;
}

.site-pager small {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font: 400 0.8125rem/1.3 var(--sans);
}

/* ---------- dialogs ---------- */

dialog {
  border: 0;
  padding: 0;
  color: var(--ink);
}

dialog::backdrop {
  background: rgb(23 33 43 / 0.55);
}

dialog form button {
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  cursor: pointer;
}

.site-search {
  width: min(44rem, calc(100vw - 32px));
  max-height: min(80vh, 46rem);
  margin-top: 8vh;
  padding: 20px;
  border-radius: 6px;
  --pagefind-ui-font: var(--sans);
  --pagefind-ui-primary: var(--ink);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-border: var(--rule);
  --pagefind-ui-border-radius: 4px;
  --pagefind-ui-scale: 0.85;
}

.site-search form {
  margin-top: 14px;
  text-align: right;
}

.site-lightbox {
  max-width: 96vw;
  max-height: 96vh;
  padding: 12px;
  border-radius: 6px;
  background: #fff;
}

.site-lightbox img {
  display: block;
  max-width: calc(96vw - 24px);
  max-height: calc(96vh - 76px);
}

.site-lightbox form {
  margin-top: 10px;
  text-align: right;
}

/* ---------- landing ---------- */

.home {
  background: var(--paper);
}

.home .site-bar {
  background: var(--paper);
}

.home-main {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 24px 56px;
}

.home-head {
  padding: 56px 0 44px;
  max-width: 44rem;
}

.home-head h1 {
  margin: 0;
  font: 400 clamp(2.25rem, 5vw, 3.5rem) / 1.08 var(--serif);
  letter-spacing: -0.01em;
}

.home-head p {
  margin: 20px 0 0;
  font-size: 1.0625rem;
  color: var(--ink-soft);
}

.home-head a {
  color: var(--ink);
}

/* One stripe per help page, in that page's accent: the colours you will meet inside. */
.home-spectrum {
  display: flex;
  gap: 3px;
  margin-top: 28px;
  max-width: 26rem;
}

.home-spectrum i {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  transform-origin: left;
  animation: stripe 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}

.home-spectrum i:nth-child(n) {
  animation-delay: calc(sibling-index() * 35ms);
}

@keyframes stripe {
  from {
    transform: scaleX(0);
    opacity: 0;
  }
}

.home-group {
  margin-bottom: 40px;
}

.home-group h2 {
  margin: 0 0 14px;
  font: 600 0.9375rem/1.3 var(--sans);
  color: var(--ink-soft);
}

.home-group ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.home-group li {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 5px solid var(--page-accent);
  border-radius: 4px;
  transition: border-color 0.15s;
}

.home-group li:hover {
  border-color: var(--page-accent);
}

.home-group li > a:first-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 20px 16px;
  color: var(--ink);
  text-decoration: none;
}

.home-title {
  font: 400 1.4375rem/1.2 var(--serif);
  color: var(--page-accent);
}

.home-sub {
  flex: 1;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.home-meta {
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.home-app {
  margin: 0 20px 18px;
  padding: 7px 12px;
  border-radius: 4px;
  background: var(--page-accent);
  color: #fff;
  font-size: 0.875rem;
  text-align: center;
  text-decoration: none;
}

.home .site-foot {
  max-width: 68rem;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- narrow screens ---------- */

@media (max-width: 960px) {
  .site-toc-button {
    display: inline-block;
  }

  .site-brand-sub {
    display: none;
  }

  .doc nav.sidebar {
    position: fixed;
    top: var(--bar);
    left: 0;
    z-index: 20;
    width: min(20rem, 86vw);
    flex-basis: auto;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    visibility: hidden;
  }

  .toc-open nav.sidebar {
    transform: none;
    visibility: visible;
    box-shadow: 0 0 0 100vmax rgb(23 33 43 / 0.45);
  }

  .doc main {
    padding: 28px 20px 56px;
  }

  /* A long inline formula: the paragraph that holds it scrolls sideways. */
  .doc main :is(p, td, th, dd, .figcap, .caption, .step, .callout, .note) {
    overflow-x: auto;
    overflow-y: hidden;
  }

  .doc .site-foot,
  .site-foot {
    margin-left: 0;
    padding: 24px 20px 36px;
  }
}

@media (max-width: 560px) {
  .site-bar {
    padding: 0 12px;
    gap: 8px;
  }

  .site-bar kbd,
  .site-app {
    display: none;
  }

  .doc main section h2 {
    font-size: 1.5rem;
  }

  .site-pager {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }

  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .site-bar,
  .site-progress,
  .site-pager,
  .doc nav.sidebar {
    display: none;
  }

  .doc .site-foot {
    margin-left: 0;
  }
}
