/* TOKENS */

:root {
  --bg: #ffffff;
  --ink: #1b1f24;
  --muted: #62686f;
  --line: #e3e6ea;
  --accent: #0b62d6;
  --head: 3.5rem;
  --font-mono: "mrly-mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-mrly: "MrlyFont", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #0d1117;
    --ink: #e6e9ec;
    --muted: #9aa1a9;
    --line: #262c36;
    --accent: #6cb2ff;
  }
}

:root.dark {
  --bg: #0d1117;
  --ink: #e6e9ec;
  --muted: #9aa1a9;
  --line: #262c36;
  --accent: #6cb2ff;
}

:root.light {
  color-scheme: light;
}

:root.dark {
  color-scheme: dark;
}

/* FONTS */

@font-face {
  font-family: "mrly-mono";
  src: url("/fonts/mono.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "MrlyFont";
  src: url("/fonts/MrlyFont.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "mrly-icons";
  src: url("/fonts/site.woff2") format("woff2");
  font-display: block;
}

:root.mrlyfont body {
  font-family: var(--font-mrly);
}

.ic {
  font-family: "mrly-icons";
  font-weight: 400;
  font-style: normal;
  font-size: 1.25em;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  display: inline-block;
  vertical-align: middle;
}

/* BASE */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  overflow-wrap: break-word;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration: underline;
}

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

::selection {
  background: var(--accent);
  color: var(--bg);
}

[id] {
  scroll-margin-top: 4rem;
}

:target {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 4px;
}

/* PROGRESS */

@supports (animation-timeline: scroll()) {
  body::before {
    content: "";
    position: fixed;
    inset: 0 0 auto 0;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: 0 50%;
    animation: progress linear;
    animation-timeline: scroll();
    z-index: 30;
  }

  @keyframes progress {
    to {
      transform: scaleX(1);
    }
  }
}

/* HEADER */

header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: var(--head);
  padding: 0 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.lettermark {
  display: block;
  color: var(--ink);
}

.headmark {
  display: block;
  width: clamp(8.5rem, 28vw, 10.5rem);
  height: auto;
}

.headmark g {
  transition-property: translate;
  transition-delay: 0ms;
}

.headmark g:nth-child(1),
.headmark g:nth-child(8) {
  transition-duration: 420ms;
  transition-timing-function: steps(7, end);
}

.headmark g:nth-child(2),
.headmark g:nth-child(7) {
  transition-duration: 300ms;
  transition-timing-function: steps(5, end);
}

.headmark g:nth-child(3),
.headmark g:nth-child(6) {
  transition-duration: 180ms;
  transition-timing-function: steps(3, end);
}

.headmark g:nth-child(4),
.headmark g:nth-child(5) {
  transition-duration: 60ms;
  transition-timing-function: steps(1, end);
}

:root.scrolled .headmark g:nth-child(1) { translate: 21px; }
:root.scrolled .headmark g:nth-child(8) { translate: -21px; }
:root.scrolled .headmark g:nth-child(2) { translate: 15px; transition-delay: 120ms; }
:root.scrolled .headmark g:nth-child(7) { translate: -15px; transition-delay: 120ms; }
:root.scrolled .headmark g:nth-child(3) { translate: 9px; transition-delay: 240ms; }
:root.scrolled .headmark g:nth-child(6) { translate: -9px; transition-delay: 240ms; }
:root.scrolled .headmark g:nth-child(4) { translate: 3px; transition-delay: 360ms; }
:root.scrolled .headmark g:nth-child(5) { translate: -3px; transition-delay: 360ms; }

.panel-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
}

.panel-btn:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.panel-btn .glyph {
  width: 1rem;
  height: 1rem;
}

#tree-btn {
  justify-self: start;
}

#side-btn {
  justify-self: end;
}

@supports selector(:popover-open) {
  .panel-btn {
    display: inline-flex;
  }
}

/* LAYOUT */

.layout {
  padding: 0 1.25rem 3rem;
  max-width: 48.5rem;
  margin: 0 auto;
}

main {
  min-width: 0;
}

/* PANELS */

.tree,
.side {
  display: none;
}

.tree:popover-open,
.side:popover-open {
  display: block;
  position: fixed;
  width: min(20rem, 85vw);
  height: 100%;
  margin: 0;
  padding: 1rem 1.25rem 2rem;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
  scrollbar-width: thin;
}

.tree:popover-open {
  inset: 0 auto 0 0;
  border-right: 1px solid var(--line);
}

.side:popover-open {
  inset: 0 0 0 auto;
  border-left: 1px solid var(--line);
}

.tree::backdrop,
.side::backdrop {
  background: color-mix(in srgb, var(--ink) 25%, transparent);
}

@media (min-width: 60rem) {
  #tree-btn {
    display: none;
  }

  .layout {
    display: grid;
    grid-template-columns: 16rem minmax(0, 46rem);
    gap: 3rem;
    max-width: none;
    justify-content: center;
  }

  .tree {
    display: block;
    position: sticky;
    inset: auto;
    top: var(--head);
    width: auto;
    height: auto;
    max-height: calc(100vh - var(--head));
    margin: 0;
    padding: 0.35rem 0 2rem;
    border: 0;
    background: none;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .tree::backdrop {
    display: none;
  }
}

@media (min-width: 84rem) {
  #side-btn {
    display: none;
  }

  .layout {
    grid-template-columns: 16rem minmax(0, 46rem) 14rem;
  }

  .side {
    display: block;
    position: sticky;
    inset: auto;
    top: var(--head);
    width: auto;
    height: auto;
    max-height: calc(100vh - var(--head));
    margin: 0;
    padding: 0.35rem 0 2rem;
    border: 0;
    background: none;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .side::backdrop {
    display: none;
  }
}

footer {
  margin-top: 4rem;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

footer a {
  color: var(--muted);
}

footer nav {
  margin: 0.35rem 0;
}

/* CONTENT */

h1 {
  font-size: clamp(1.6rem, 1.3rem + 1.5vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 1.2rem 0 0.75rem;
}

h2 {
  font-size: clamp(1.2rem, 1.05rem + 0.7vw, 1.4rem);
  line-height: 1.3;
  margin: 2.5rem 0 0.75rem;
}

p {
  margin: 0.9rem 0;
}

ul,
ol {
  padding-left: 1.4rem;
}

li {
  margin: 0.3rem 0;
}

strong {
  font-weight: 650;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.5rem 0;
}

blockquote {
  margin: 1.25rem 0;
  padding: 0.1rem 1.1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
}

.banner {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 630;
  background: var(--line);
  border-radius: 12px;
  margin: 0 0 1.5rem;
}

pre {
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  line-height: 1.5;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: color-mix(in srgb, var(--line) 45%, transparent);
  border-radius: 6px;
  padding: 0.1em 0.35em;
}

pre code {
  background: none;
  border-radius: 0;
  padding: 0;
  font-size: 0.85rem;
}

.crumbs {
  display: flow-root;
  margin: 0.5rem 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.crumbs .raw {
  float: right;
}

.crumbs .updated {
  float: right;
  margin-right: 0.75rem;
}

.listing {
  list-style: none;
  padding: 0;
  margin: 2rem 0;
}

.listing li {
  margin: 0;
  padding: 0.4rem 0;
  border-top: 1px solid var(--line);
}

.listing li:last-child {
  border-bottom: 1px solid var(--line);
}

.listing a {
  font-weight: 600;
  color: var(--ink);
}

/* TABLES */

.table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  margin: 1.25rem 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.45rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

th {
  font-weight: 650;
  white-space: nowrap;
  border-bottom: 2px solid var(--line);
}

td {
  border-bottom: 1px solid var(--line);
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

/* EXPLORER */

.tree {
  font-size: 0.85rem;
  line-height: 1.5;
}

.tree a {
  display: block;
  color: var(--muted);
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.tree a:hover {
  color: var(--ink);
  text-decoration: none;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.tree a[aria-current] {
  color: var(--accent);
  font-weight: 600;
}

.tree .root {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.35rem;
}

.tree summary {
  display: flex;
  align-items: center;
  list-style: none;
  cursor: pointer;
}

.tree summary::-webkit-details-marker {
  display: none;
}

.tree summary::before {
  content: "\25B8";
  display: inline-block;
  width: 1em;
  flex: none;
  color: var(--muted);
  transition: rotate 0.15s;
}

.tree details[open] > summary::before {
  rotate: 90deg;
}

.tree summary a {
  flex: 1;
}

.tree .sub {
  margin-left: 0.45rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--line);
}

.tree .leaf {
  padding-left: 1.4rem;
}

/* SIDE */

.toc {
  font-size: 0.85rem;
}

.toc p {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc li {
  margin: 0.35rem 0;
}

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

.toc a:hover {
  color: var(--ink);
  text-decoration: none;
}

.page {
  margin-top: 1.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.page p {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.page .updated {
  display: block;
  margin-bottom: 0.35rem;
}

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

.page .raw:hover {
  color: var(--ink);
}

.toggles {
  display: none;
  gap: 0.5rem;
  margin-top: 1.75rem;
}

:root.js .toggles {
  display: flex;
}

.toggles button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}

.toggles button:hover {
  color: var(--ink);
  border-color: var(--muted);
}

/* HERO */

.hero {
  display: block;
  width: min(100%, 34rem);
  height: auto;
  margin: 2.5rem auto 2rem;
}

.hero g {
  animation-duration: 5s;
  animation-timing-function: steps(6, end);
  animation-fill-mode: forwards;
}

.hero g:nth-child(1) { animation-name: hero0; }
.hero g:nth-child(2) { animation-name: hero1; }
.hero g:nth-child(3) { animation-name: hero2; }
.hero g:nth-child(4) { animation-name: hero3; }
.hero g:nth-child(5) { animation-name: hero4; }
.hero g:nth-child(6) { animation-name: hero5; }
.hero g:nth-child(7) { animation-name: hero6; }
.hero g:nth-child(8) { animation-name: hero7; }

.hero-x {
  display: none;
}

@keyframes hero0 {
  72% { translate: 0; }
  77% { translate: 6px; }
  82% { translate: 12px; }
  87% { translate: 18px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: 21px; }
}

@keyframes hero1 {
  0%, 6% { opacity: 0; }
  6.2% { opacity: 1; }
  77% { translate: 0; }
  82% { translate: 6px; }
  87% { translate: 12px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: 15px; }
}

@keyframes hero2 {
  0%, 12% { opacity: 0; }
  12.2% { opacity: 1; }
  82% { translate: 0; }
  87% { translate: 6px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: 9px; }
}

@keyframes hero3 {
  0%, 18% { opacity: 0; }
  18.2% { opacity: 1; }
  87% { translate: 0; animation-timing-function: steps(3, end); }
  92%, 100% { translate: 3px; }
}

@keyframes hero4 {
  0%, 24% { opacity: 0; }
  24.2% { opacity: 1; }
  87% { translate: 0; animation-timing-function: steps(3, end); }
  92%, 100% { translate: -3px; }
}

@keyframes hero5 {
  0%, 30% { opacity: 0; }
  30.2% { opacity: 1; }
  82% { translate: 0; }
  87% { translate: -6px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: -9px; }
}

@keyframes hero6 {
  0%, 36% { opacity: 0; }
  36.2% { opacity: 1; }
  77% { translate: 0; }
  82% { translate: -6px; }
  87% { translate: -12px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: -15px; }
}

@keyframes hero7 {
  0%, 42% { opacity: 0; }
  42.2% { opacity: 1; }
  72% { translate: 0; }
  77% { translate: -6px; }
  82% { translate: -12px; }
  87% { translate: -18px; animation-timing-function: steps(3, end); }
  92%, 100% { translate: -21px; }
}

/* MOTION */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .hero {
    display: none;
  }

  .hero-x {
    display: block;
    width: 4.25rem;
    height: auto;
    margin: 2rem auto;
  }

  .headmark g {
    transition: none;
  }

  body::before {
    display: none;
  }
}

/* PRINT */

@media print {
  .tree,
  .side,
  .toggles,
  .raw,
  .panel-btn,
  body::before {
    display: none !important;
  }

  .layout {
    display: block;
  }
}
