/* Lemmata packs: the app's Library, opened to the public.
 *
 * The same paper-and-ink world as the app and lemmata.sous.systems (their
 * DESIGN.md): one monospace for everything formal and for the chrome, the
 * system sans for sentences, hairlines instead of boxes, Proof Blue for keys,
 * links and the current pack, Verified Green only for a pack's verdict, and
 * no red at all: a trap is a description, not a failure.
 */

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("fonts/jetbrains-mono-greek-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("fonts/jetbrains-mono-math-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+2100-214F, U+2190-21FF, U+2200-22FF;
}

/* The name as LaTeX sets it, L\text{emma}t\alpha (Latin Modern Math glyphs, GUST Font License). */
@font-face {
  font-family: "Lemmata Wordmark";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("fonts/latinmodern-wordmark.woff2") format("woff2");
}

:root {
  --paper: #ffffff;
  --paper-raised: #f7f8f9;
  --paper-lowered: #eff1f4;
  --rule: #dde1e6;
  --control-border: #8a909c;
  --ink: #16181d;
  --ink-quiet: #555b6a;
  --ink-dim: #666c7a;
  --accent: #0a5fbf;
  --accent-fill: #0a5fbf;
  --accent-quiet: rgba(10, 95, 191, 0.08);
  --on-accent: #ffffff;
  --verified: #157333;
  --hairline: color-mix(in oklab, var(--ink) 8%, var(--paper));
  --selection: rgba(10, 95, 191, 0.18);
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 2px;
  --top: 56px;
  --rail: 288px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #0e1013;
  --paper-raised: #15181c;
  --paper-lowered: #1a1e23;
  --rule: #262b32;
  --control-border: #646b77;
  --ink: #e6e8ec;
  --ink-quiet: #9ba3b0;
  --ink-dim: #7f8795;
  --accent: #6cb0ff;
  --accent-fill: #1f6feb;
  --accent-quiet: rgba(108, 176, 255, 0.1);
  --verified: #4ab960;
  --selection: rgba(108, 176, 255, 0.26);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--top) + 16px);
  scrollbar-color: var(--control-border) var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--selection);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

code,
pre {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

code {
  font-size: 0.9em;
}

h1,
h2,
h3 {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 30;
  padding: 8px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 13px;
}

.skip-link:focus {
  top: 10px;
}

.icon {
  width: 18px;
  height: 18px;
}

/* --- Buttons ---------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.button--primary {
  background: var(--accent-fill);
  color: var(--on-accent);
}

.button--primary:hover {
  background: color-mix(in oklab, var(--accent-fill) 86%, var(--ink));
}

.button--outline {
  border-color: var(--control-border);
  color: var(--ink);
}

.button--outline:hover {
  background: var(--paper-lowered);
}

.text-link {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

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

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--top);
  padding: 0 20px;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
}

.wm--static {
  font-family: "Lemmata Wordmark", "Latin Modern Math", "Cambria Math", serif;
  font-weight: 400;
  font-size: 1.5em;
  line-height: 1;
  color: var(--ink);
}

.brand {
  align-items: baseline;
}

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

.top-links {
  display: flex;
  gap: 20px;
  margin-left: auto;
}

.top-links a {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-quiet);
  text-decoration: none;
}

.top-links a:hover,
.top-links a[aria-current="page"] {
  color: var(--ink);
}

.rail-toggle {
  display: none;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-quiet);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--paper-lowered);
  color: var(--ink);
}

[data-theme="light"] .icon--sun,
[data-theme="dark"] .icon--moon {
  display: none;
}

/* --- Rail and main ---------------------------------------------------------- */

/* The rail's surface runs the full height of the page, however long. */
.layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: calc(100vh - var(--top));
  background: linear-gradient(to right, var(--paper-raised) calc(var(--rail) - 1px), var(--rule) calc(var(--rail) - 1px) var(--rail), var(--paper) var(--rail));
}

.rail {
  position: sticky;
  top: var(--top);
  align-self: start;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--top));
  overflow-y: auto;
  padding: 16px 0 16px;
}

.search {
  padding: 0 16px 12px;
}

.search input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
}

.search input::placeholder {
  color: var(--ink-dim);
}

.search input:focus-visible {
  outline-offset: 0;
  border-color: transparent;
}

.rail-groups,
.rail-groups ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail-group + .rail-group {
  margin-top: 12px;
}

.rail-label {
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-quiet);
}

.rail-pack {
  display: grid;
  gap: 1px;
  padding: 8px 16px;
  color: var(--ink);
  text-decoration: none;
}

.rail-pack:hover {
  background: var(--paper-lowered);
}

.rail-pack[aria-current="page"] {
  background: var(--paper-lowered);
}

.rail-pack[aria-current="page"] .rail-title {
  color: var(--accent);
  font-weight: 700;
}

.rail-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

.rail-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}

.rail-empty {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--ink-quiet);
}

.rail-publish {
  margin-top: auto;
  padding: 16px 16px 0;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

main {
  min-width: 0;
  padding: 40px clamp(20px, 4vw, 56px) 0;
  max-width: 980px;
}

.page-head {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--rule);
}

.page-head h1 {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  line-height: 1.15;
}

.lede {
  margin-top: 12px;
  max-width: 64ch;
  font-size: 16px;
  color: var(--ink-quiet);
}

.figures {
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-quiet);
  font-variant-numeric: tabular-nums;
}

.verified-word {
  color: var(--verified);
  font-weight: 700;
}

.section-label {
  margin: 36px 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-quiet);
}

/* --- Packs ----------------------------------------------------------------- */

.pack-title {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  line-height: 1.15;
}

h3.pack-title {
  font-size: 1.25rem;
}

.pack-title a {
  color: var(--ink);
  text-decoration: none;
}

.pack-title a:hover {
  color: var(--accent);
}

.pack-code {
  margin-right: 0.5em;
  color: var(--accent);
}

.pack-meta {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}

.pack-meta code {
  font-size: 1em;
}

.pack-meta span {
  white-space: nowrap;
}

.pack-meta span:not(:last-child)::after {
  content: " ·";
}

.pack-summary {
  margin-top: 10px;
  max-width: 64ch;
  color: var(--ink-quiet);
}

.verified {
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-quiet);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.briefs {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.brief {
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
}

.brief .pack-summary {
  font-size: 14px;
}

.brief-counts {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}

.results .result-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.result {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}

.result a {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
}

.result-where {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}

.result-title {
  font-size: 14px;
}

.publish-band {
  margin-top: 48px;
}

.publish-band h2 {
  font-size: 1.25rem;
}

.publish-band p {
  margin: 8px 0 12px;
  max-width: 64ch;
  color: var(--ink-quiet);
}

/* --- Chapters and the key rail ------------------------------------------- */

.filter-note {
  margin-top: 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-quiet);
}

.chapter {
  margin-top: 40px;
}

.chapter-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 10px;
  font-size: 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.chapter-number {
  min-width: 1.5em;
  color: var(--ink-dim);
}

.chapter-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink-dim);
}

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

/* The key rail: the notes' numbering, down a hairline column.  Each entry is
   one line, title and verdict; the line itself opens the proof. */
.entry {
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr);
  border-bottom: 1px solid var(--hairline);
}

.entry-key {
  padding: 10px 16px 10px 0;
  border-right: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-quiet);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.entry-key:hover {
  color: var(--accent);
}

.entry:target .entry-key,
.entry.is-match .entry-key {
  color: var(--accent);
}

.entry:target {
  background: var(--accent-quiet);
}

.entry-body {
  min-width: 0;
  padding: 0 0 0 12px;
}

.entry-source summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 0;
  cursor: pointer;
  list-style: none;
}

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

.entry-source summary:hover .entry-title {
  color: var(--accent);
}

.chevron {
  flex: none;
  width: 12px;
  height: 12px;
  align-self: center;
  color: var(--ink-dim);
  transition: transform 0.15s ease;
}

.entry-source[open] .chevron {
  transform: rotate(90deg);
}

.entry-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.entry-verdict {
  flex: none;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.entry.is-trap .entry-verdict {
  color: var(--ink-quiet);
  font-weight: 700;
}

.entry-why {
  margin: -4px 0 10px 20px;
  font-size: 14px;
  color: var(--ink-quiet);
  max-width: 68ch;
}

/* An opened proof, set as the app's editor sets it. */
.entry-source pre {
  margin: 0 0 12px 20px;
  padding: 10px 14px 10px 0;
  overflow-x: auto;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 4;
  counter-reset: line;
}

.entry-source code {
  display: grid;
  font-size: 1em;
}

.src-line {
  white-space: pre;
}

.src-line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 2.75em;
  margin-right: 12px;
  padding-right: 8px;
  text-align: right;
  color: var(--ink-dim);
  border-right: 1px solid var(--hairline);
  user-select: none;
}

.kw {
  color: var(--accent);
}

.glue {
  color: var(--ink-dim);
}

.brief[hidden],
.entry[hidden],
.chapter[hidden],
.rail-group[hidden],
.rail-groups li[hidden] {
  display: none;
}

/* --- The guide -------------------------------------------------------------- */

.guide {
  max-width: 72ch;
}

.guide h2 {
  margin: 40px 0 12px;
  font-size: 1.2rem;
}

.guide li,
.guide p {
  color: var(--ink-quiet);
}

.guide li + li {
  margin-top: 8px;
}

.guide strong {
  color: var(--ink);
}

.guide ul {
  margin-top: 8px;
}

.rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 32px;
  margin: 0;
  border-top: 1px solid var(--rule);
}

.rules > div {
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.rules dt {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
}

.rules dd {
  margin: 4px 0 0;
  color: var(--ink-quiet);
}

.foot {
  margin-top: 64px;
  padding: 20px 0 32px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--ink-dim);
}

/* --- Narrow screens --------------------------------------------------------- */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .rail {
    position: static;
    height: auto;
    max-height: none;
    background: var(--paper-raised);
    border-bottom: 1px solid var(--rule);
  }

  /* Narrow: the rail is the search and one button; the packs open under it. */
  .rail {
    padding: 12px 0;
  }

  .search {
    padding-bottom: 8px;
  }

  .rail-toggle {
    display: block;
    margin: 0 16px;
    text-align: left;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .rail:not(.is-open) .rail-groups,
  .rail:not(.is-open) .rail-publish,
  .rail:not(.is-open) .rail-empty {
    display: none;
  }

  .rail-groups {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    margin-top: 8px;
  }

  .rail-group + .rail-group {
    margin-top: 0;
  }

  .rail-publish {
    margin-top: 8px;
    border-top: 0;
  }

  .top-links {
    display: none;
  }

  .top-open {
    margin-left: auto;
  }

  main {
    padding-top: 28px;
  }
}

@media (max-width: 560px) {
  .brand-sub {
    display: none;
  }

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

  .entry-key {
    padding: 10px 0 0;
    border-right: 0;
  }

  .entry-body {
    padding: 0;
  }

  .entry-source summary {
    padding-top: 2px;
    flex-wrap: wrap;
  }

  /* The verdict shares the key's line, so a proof is two lines, not three. */
  .entry {
    position: relative;
  }

  .entry-verdict {
    position: absolute;
    top: 11px;
    right: 0;
  }

  .result {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

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

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* The narrowest phones: the verdict goes back under the key, where it fits. */
@media (max-width: 360px) {
  .entry-verdict {
    position: static;
    flex-basis: 100%;
    padding-left: 20px;
  }
}
