/* The cotty documentation site. One stylesheet, no build step.
   The design is described in docs/en/handbook/site-design.md. */

/* One column is the width of one character of code. It is a length, so that it is
   measured once, on the screen element, and means the same everywhere below it. */
@property --col { syntax: "<length>"; inherits: true; initial-value: 8px; }

:root {
  color-scheme: light dark;

  /* Paper, the light theme. */
  --paper: #ffffff;
  --surface: #f3f5fb;
  --ink: #0a0f1f;
  --ink-2: #454e69;
  --ink-3: #5e6781;
  --rule: #d3d9e8;
  --blue: #0047ff;
  --rose: #db0a6c;
  --rose-signal: #ff1f7a;

  /* Type scale. Each step multiplies by the square root of the golden ratio,
     so two steps multiply by the golden ratio. */
  --step--1: 0.786rem;
  --step-0: 1rem;
  --step-1: 1.272rem;
  --step-2: 1.618rem;
  --step-3: 2.058rem;
  --step-4: 2.618rem;
  --step-6: 4.236rem;

  /* Rhythm. A row is one line of text. A gap is a row divided by the golden ratio. */
  --row: 1.618rem;
  --gap: 1rem;
  --half: 0.618rem;
  --hair: 0.382rem;

  /* Two voices: prose is set in the sans, the machine speaks in the mono. */
  --sans: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "DejaVu Sans Mono", "Noto Sans Mono CJK SC", monospace;
}

/* Glass, the dark theme. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #070b18;
    --surface: #0f1528;
    --ink: #eef1fa;
    --ink-2: #a9b2cc;
    --ink-3: #7f89a6;
    --rule: #27304d;
    --blue: #7aa5ff;
    --rose: #ff6ba6;
    --rose-signal: #ff5c9d;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 106.25%; -webkit-text-size-adjust: 100%; scroll-padding-top: var(--row); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  line-height: 1.618;
  text-rendering: optimizeLegibility;
}

/* The screen is set in the code font, and its children return to the prose font. */
.screen {
  font-family: var(--mono);
  font-size: var(--step--1);
  --col: 1ch;

  /* The page is 132 columns: 24 of navigation, 80 of text, 20 of contents, and
     two gutters of 4. A narrow code font would make these too small to read,
     so each has a least width in rem, in nearly the same proportions. */
  --nav: max(calc(24 * var(--col)), 12rem);
  --text: max(calc(80 * var(--col)), 36rem);
  --toc: max(calc(20 * var(--col)), 10rem);
  --gutter: max(calc(4 * var(--col)), 2rem);
  --edge: calc(3 * var(--col));
}
.screen > * { font-family: var(--sans); font-size: 1rem; }

::selection { color: var(--paper); background: var(--blue); }

:focus-visible { outline: 2px solid var(--rose-signal); outline-offset: 2px; border-radius: 2px; }

a { color: var(--blue); text-decoration: none; }

.skip { position: absolute; left: -100rem; top: 0; padding: var(--hair) var(--gap); color: var(--paper); background: var(--blue); font-family: var(--mono); font-size: var(--step--1); z-index: 1; }
.skip:focus { left: 0; }

/* The cursor. It blinks four times and then rests, so that nothing on the page moves for long. */

.cursor { display: inline-block; width: 0.5em; height: 0.9em; margin-left: 0.12em; vertical-align: -0.1em; background: var(--blue); animation: blink 1.1s steps(1) 4; }
@keyframes blink { 50% { opacity: 0; } }

/* The name: co + tty. */

.wordmark { font-family: var(--mono); font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.wordmark-co { color: var(--blue); }
.wordmark-tty { color: var(--rose-signal); }

/* Header. It has no rule under it: a line is drawn only where it says something. */

.site-header-inner, .layout, .site-footer-inner {
  box-sizing: content-box;
  max-width: calc(var(--nav) + var(--text) + var(--toc) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--edge);
}

.site-header-inner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--hair) var(--gutter); padding-block: var(--half); }

.site-title { font-size: var(--step-1); line-height: 1; }

.site-nav { display: flex; flex-wrap: wrap; flex: 1; gap: 0 calc(3 * var(--col)); }
.site-nav a { padding: var(--hair) 0; color: var(--ink-2); font-family: var(--mono); font-size: var(--step--1); white-space: nowrap; border-bottom: 2px solid transparent; }
.site-nav a:hover { color: var(--blue); }
.site-nav a[aria-current] { color: var(--ink); border-bottom-color: var(--rose-signal); }

.site-languages { display: flex; gap: calc(2 * var(--col)); margin-left: auto; font-family: var(--mono); font-size: var(--step--1); }
.site-languages span { color: var(--ink); }
.site-languages a:hover { text-decoration: underline; }

/* Search */

.site-search { position: relative; }
.site-search input {
  width: max(calc(24 * var(--col)), 11rem);
  padding: var(--hair) calc(4 * var(--col)) var(--hair) calc(1.5 * var(--col));
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink-3);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: var(--step--1);
}
.site-search input::placeholder { color: var(--ink-3); opacity: 1; }
.site-search kbd { position: absolute; right: calc(1 * var(--col)); top: 50%; transform: translateY(-50%); pointer-events: none; }
.site-search:focus-within kbd { display: none; }

/* On a narrow screen the header has three rows: the name and the languages, the sections, the search. */
@media (max-width: 47.99em) {
  .site-nav { order: 1; flex-basis: 100%; }
  .site-search { order: 2; flex-basis: 100%; }
  .site-search input { width: 100%; }
}

kbd { padding: 0 0.5ch; color: var(--ink-2); background: var(--surface); border: 1px solid var(--ink-3); border-bottom-width: 2px; border-radius: 3px; font-family: var(--mono); font-size: var(--step--1); line-height: 1.4; }

.search-results { box-sizing: content-box; max-width: var(--text); margin: var(--gap) auto 0; padding-inline: var(--edge); }
.search-results a { display: block; padding: var(--half) 0; color: var(--ink); border-bottom: 1px solid var(--rule); }
.search-results a:hover strong { color: var(--blue); }
.search-results p { color: var(--ink-2); font-family: var(--mono); font-size: var(--step--1); }
.search-section { margin-left: calc(2 * var(--col)); color: var(--ink-3); font-family: var(--mono); font-size: var(--step--1); }
.search-snippet { display: block; color: var(--ink-2); font-size: 0.9rem; }

mark { padding: 0 0.1em; color: inherit; background: color-mix(in oklab, var(--rose-signal) 24%, transparent); border-radius: 2px; }

/* Layout. A narrower screen drops the contents first, then moves the navigation below the text. */

.layout { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: calc(2 * var(--row)); padding-block: calc(1.5 * var(--row)) 0; }
.layout-home { justify-content: center; }
main { min-width: 0; }
.sidebar { order: 2; padding-top: var(--row); border-top: 1px solid var(--rule); }
.toc { display: none; }

@media (min-width: 58em) {
  .layout { grid-template-columns: var(--nav) minmax(0, var(--text)); column-gap: var(--gutter); }
  .layout-home { grid-template-columns: minmax(0, var(--text)); }
  .sidebar { order: 0; padding-top: 0; border-top: 0; position: sticky; top: var(--row); align-self: start; max-height: calc(100vh - 2 * var(--row)); overflow-y: auto; }
}

@media (min-width: 71em) {
  .layout { grid-template-columns: var(--nav) minmax(0, var(--text)) var(--toc); }
  .layout-home { grid-template-columns: minmax(0, var(--text)); }
  .toc { display: block; position: sticky; top: var(--row); align-self: start; max-height: calc(100vh - 2 * var(--row)); overflow-y: auto; }
  .toc-inline { display: none; }
}

/* Navigation within a section */

.sidebar { font-size: 0.9rem; line-height: 1.4; }
.sidebar-title, .toc-title, .toc-inline summary { display: block; margin: 0 0 var(--half); color: var(--ink-3); font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.06em; text-transform: uppercase; }
.sidebar-title:hover { color: var(--blue); }
.sidebar-title[aria-current] { color: var(--ink); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar > ul { border-left: 1px solid var(--rule); }
.sidebar a:not(.sidebar-title) { display: block; margin-left: -1px; padding: var(--hair) 0 var(--hair) calc(2 * var(--col)); color: var(--ink-2); border-left: 2px solid transparent; }
.sidebar ul ul a:not(.sidebar-title) { padding-left: calc(4 * var(--col)); }
.sidebar a:not(.sidebar-title):hover { color: var(--blue); }
.sidebar a[aria-current]:not(.sidebar-title) { color: var(--ink); font-weight: 600; border-left-color: var(--rose-signal); }
/* A folder inside the section is a label, not a page among pages. */
.sidebar li:has(> ul) > a { margin-top: var(--half); color: var(--ink-3); font-family: var(--mono); font-size: var(--step--1); }

/* Contents of a page */

.toc, .toc-inline { font-size: 0.85rem; line-height: 1.4; }
.toc ol, .toc-inline ol { list-style: none; margin: 0; padding: 0; }
.toc a, .toc-inline a { display: block; padding: 0.25rem 0; color: var(--ink-2); }
.toc a:hover, .toc-inline a:hover { color: var(--blue); }
.toc-inline .toc-l3 a { padding-left: calc(2 * var(--col)); }
/* The section being read carries the same mark as the current page in the navigation. */
.toc ol { border-left: 1px solid var(--rule); }
.toc a { margin-left: -1px; padding-left: calc(2 * var(--col)); border-left: 2px solid transparent; }
.toc .toc-l3 a { padding-left: calc(4 * var(--col)); }
.toc a[aria-current], .toc-inline a[aria-current] { color: var(--ink); }
.toc a[aria-current] { border-left-color: var(--rose-signal); }
.toc-inline { margin: 0 0 var(--row); padding: var(--half) 0; border-bottom: 1px solid var(--rule); }
.toc-inline summary { margin: 0; cursor: pointer; list-style: none; }
.toc-inline summary::-webkit-details-marker { display: none; }
.toc-inline summary::before { content: "+"; display: inline-block; width: 2ch; color: var(--blue); }
.toc-inline[open] summary::before { content: "\2212"; }
.toc-inline[open] summary { margin-bottom: var(--half); }

/* Page header: the title, the title again as paper tape, and the status line. */

.page-header { margin: 0 0 calc(1.5 * var(--row)); }

h1 { margin: 0 0 var(--gap); font-size: var(--step-3); font-weight: 700; line-height: 1.272; letter-spacing: -0.021em; text-wrap: balance; }

.tape { display: block; width: auto; height: var(--step-4); max-width: 100%; margin: 0 0 var(--gap); fill: none; stroke-linecap: round; }
.tape-data { stroke: var(--blue); stroke-width: 7.2; }
.tape-feed { stroke: var(--rose-signal); stroke-width: 4.6; }

.meta { display: flex; flex-wrap: wrap; gap: 0.2rem calc(4 * var(--col)); margin: 0; padding: var(--half) 0; color: var(--ink-2); font-family: var(--mono); font-size: var(--step--1); border-block: 1px solid var(--rule); }
.meta div { display: flex; align-items: baseline; gap: 1ch; }
.meta dt { color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; }
.meta dd { margin: 0; color: var(--ink); }
.meta a:hover { text-decoration: underline; }

/* Status, in reverse video. Rose asks for a decision and blue is settled.
   An outline is the earlier state and a fill the later one. */

.status { display: inline-block; padding: 0 1ch; font-family: var(--mono); font-size: var(--step--1); line-height: 1.45; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; border: 1px solid; border-radius: 2px; }
.status-draft, .status-planning { color: var(--rose); }
.status-discussion, .status-active { color: var(--paper); background: var(--rose); border-color: var(--rose); }
.status-accepted { color: var(--blue); }
.status-implemented, .status-shipped { color: var(--paper); background: var(--blue); border-color: var(--blue); }
.status-rejected, .status-withdrawn, .status-superseded { color: var(--ink-2); border-style: dashed; border-color: var(--ink-3); text-decoration: line-through; }

/* Home */

.hero { margin: var(--row) 0 calc(2 * var(--row)); }
.hero .wordmark { margin: 0; font-size: var(--step-6); line-height: 1.272; letter-spacing: -0.04em; }
.hero-tagline { margin: var(--half) 0 var(--row); color: var(--ink-2); font-size: var(--step-1); line-height: 1.4; text-wrap: balance; }
.hero .tape { height: var(--step-6); margin: 0; }

/* Prose */

.prose p, .prose ul, .prose ol, .prose dl, .prose blockquote, .prose > pre, .highlight, .table-scroll { margin: 0 0 var(--gap); }

h2, h3, h4 { position: relative; font-weight: 650; text-wrap: balance; }
h2 { margin: calc(2 * var(--row)) 0 var(--gap); font-size: var(--step-2); line-height: 1.272; letter-spacing: -0.014em; }
h3 { margin: var(--step-4) 0 var(--half); font-size: var(--step-1); line-height: 1.4; }
h4 { margin: var(--row) 0 var(--hair); font-size: 1rem; }

/* Under a second-level heading, the other cursor: the underline. */
h2::after { content: ""; display: block; width: calc(3 * var(--col)); height: 2px; margin-top: var(--hair); background: var(--blue); }

/* A heading links to itself. The mark hangs in the margin and shows on hover. */
.anchor { position: absolute; left: calc(-3 * var(--col)); width: calc(3 * var(--col)); color: var(--ink-3); font-family: var(--mono); font-weight: 400; opacity: 0; }
.anchor::before { content: "#"; }
:is(h2, h3, h4):hover .anchor, .anchor:focus { opacity: 1; }
.anchor:hover { color: var(--rose); }
@media (max-width: 57.99em) { .anchor { display: none; } }

.prose a { text-decoration: underline; text-decoration-thickness: 0.06em; text-underline-offset: 0.22em; text-decoration-color: color-mix(in oklab, var(--blue) 40%, transparent); }
.prose a:hover { text-decoration-thickness: 0.1em; text-decoration-color: var(--rose-signal); }
.prose a.anchor { text-decoration: none; }
/* A link that leaves the site says so. */
.prose a[href^="http"]::after { content: "↗"; margin-left: 0.1em; color: var(--ink-3); font-size: 0.75em; }

.prose ul, .prose ol { padding-left: calc(3 * var(--col)); }
.prose li { margin: var(--hair) 0; }
.prose li > ul, .prose li > ol { margin: var(--hair) 0; }
.prose li::marker { color: var(--ink-3); }
.prose ol > li::marker { font-family: var(--mono); font-size: var(--step--1); }

.prose blockquote { padding-left: calc(2 * var(--col)); color: var(--ink-2); border-left: 2px solid var(--rose-signal); }

hr { margin: var(--row) 0; border: 0; border-top: 1px solid var(--rule); }

/* End of transmission. */
.eot { display: flex; align-items: center; gap: calc(2 * var(--col)); margin: calc(2 * var(--row)) 0 0; color: var(--ink-3); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; }
.eot span { padding: 0 0.6ch; line-height: 1.5; border: 1px solid currentColor; border-radius: 2px; }
.eot::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }

/* Tables: rules across, none down. */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
th, td { padding: var(--half) calc(3 * var(--col)) var(--half) 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
th:last-child, td:last-child { padding-right: 0; }
thead th { color: var(--ink-2); font-family: var(--mono); font-size: var(--step--1); font-weight: 600; white-space: nowrap; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
tbody tr:last-child td { border-bottom-color: var(--ink-3); }
td:first-child code, .swatch { white-space: nowrap; }
.swatch::before { content: ""; display: inline-block; width: 0.85em; height: 0.85em; margin-right: 0.6ch; vertical-align: -0.08em; background: var(--swatch); border: 1px solid var(--ink-3); border-radius: 2px; }
.align-right { text-align: right; }
.align-center { text-align: center; }

/* Code. A block hangs two columns into each margin, so that its text lines up
   with the prose and a line of 80 characters fits without scrolling. */

code { padding: 0.1em 0.25em; font-family: var(--mono); font-size: 0.88em; background: var(--surface); border-radius: 3px; }
pre { position: relative; margin: 0; padding: var(--gap) calc(2 * var(--col)); overflow-x: auto; font-size: var(--step--1); line-height: 1.5; tab-size: 4; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; }
pre code { padding: 0; font-size: inherit; background: none; border-radius: 0; }
@media (min-width: 58em) {
  .prose pre { margin-inline: calc(-2 * var(--col) - 1px); }
}
/* The language of a block, in its corner. */
pre code[data-lang]:not([data-lang="text"], [data-lang="fallback"])::after { content: attr(data-lang); position: absolute; top: var(--hair); right: calc(2 * var(--col)); color: var(--ink-3); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; }

.session .prompt { color: var(--ink-3); user-select: none; }

/* Diagrams: once drawn, the block is a picture, not code. */

pre.mermaid[data-processed] { padding: var(--half) 0; text-align: center; background: none; border: 0; }

/* Listings */

.listing { list-style: none; }
.prose ul.listing { padding: 0; }
.listing li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 calc(3 * var(--col)); margin: 0; padding: var(--half) 0; border-bottom: 1px solid var(--rule); }
.listing-dated time { color: var(--ink-3); font-family: var(--mono); font-size: var(--step--1); }

/* Footer */

.site-footer { margin-top: var(--row); }
.site-footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--hair) calc(4 * var(--col)); padding-block: var(--row); color: var(--ink-3); font-family: var(--mono); font-size: var(--step--1); }
.site-footer p { margin: 0; }
.site-footer .wordmark { margin-right: 1ch; }
.site-footer .cursor { animation: none; }
.site-footer ul { display: flex; flex-wrap: wrap; gap: 0 calc(3 * var(--col)); list-style: none; margin: 0; padding: 0; }
.site-footer a { color: var(--ink-2); }
.site-footer a:hover { color: var(--blue); }

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

@media print {
  .site-header, .sidebar, .toc, .toc-inline, .site-footer, .skip, .anchor { display: none; }
  .layout { display: block; padding: 0; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
/* Code colors. Written for this project, with the class names that Hugo's highlighter emits.
   Two hues only: blue for the words of the language, rose for literal text. */

.chroma { color: var(--ink); background: var(--surface); }
.chroma .err { color: inherit; }
.chroma .hl { display: block; background: color-mix(in oklab, var(--rose-signal) 14%, transparent); }
.chroma .ln, .chroma .lnt { margin-right: 2ch; color: var(--ink-3); user-select: none; }

/* Comments */
.chroma .c, .chroma .ch, .chroma .cm, .chroma .c1, .chroma .cs, .chroma .cp, .chroma .cpf { color: var(--ink-3); font-style: italic; }

/* Keywords, tags and attribute names */
.chroma .k, .chroma .kc, .chroma .kd, .chroma .kn, .chroma .kp, .chroma .kr, .chroma .kt,
.chroma .nt, .chroma .na, .chroma .nb, .chroma .bp, .chroma .ow { color: var(--blue); }

/* Strings and other literal text */
.chroma .s, .chroma .sa, .chroma .sb, .chroma .sc, .chroma .dl, .chroma .sd, .chroma .s2, .chroma .se,
.chroma .sh, .chroma .si, .chroma .sx, .chroma .sr, .chroma .s1, .chroma .ss { color: var(--rose); }

/* Numbers and names that are defined */
.chroma .m, .chroma .mb, .chroma .mf, .chroma .mh, .chroma .mi, .chroma .il, .chroma .mo,
.chroma .nf, .chroma .fm, .chroma .nc, .chroma .nn { font-weight: 600; }

/* Operators and punctuation */
.chroma .o, .chroma .p { color: var(--ink-2); }

/* Markup inside code: headings, emphasis, changes */
.chroma .gh, .chroma .gu { color: var(--blue); font-weight: 600; }
.chroma .ge { font-style: italic; }
.chroma .gs { font-weight: 700; }
.chroma .gi { color: var(--blue); }
.chroma .gd { color: var(--ink-3); text-decoration: line-through; }
