/* MarkBooks — markbooks.org stylesheet */

:root {
  --fg: #1a1a1a;
  --fg-secondary: #5a5a5a;
  --fg-tertiary: #8a8a8a;
  --bg: #fafaf8;
  --bg-code: #f0efeb;
  --accent: #c44d20;
  --accent-hover: #a33d17;
  --border: #e0dfdb;
  --serif: 'Source Serif 4', Georgia, serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
  --measure: 640px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e8e6e1;
    --fg-secondary: #a8a6a1;
    --fg-tertiary: #6a6864;
    --bg: #161614;
    --bg-code: #1e1e1c;
    --accent: #e06a3a;
    --accent-hover: #f07a4a;
    --border: #2a2a28;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--serif);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.7;
}

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

/* --- Layout --- */

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
}

/* --- Navigation --- */

nav {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  margin-bottom: 4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

nav .logo {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
}

nav .logo:hover {
  color: var(--accent-hover);
}

nav .nav-links {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
}

nav .nav-links a {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--fg-tertiary);
  text-decoration: none;
  transition: color 0.15s ease;
}

nav .nav-links a:hover {
  color: var(--fg);
}

/* --- Header --- */

header {
  margin-bottom: 4rem;
}

.mark {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
  display: block;
}

h1 {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 300;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 1.5rem;
}

.subtitle {
  font-size: 1.15rem;
  color: var(--fg-secondary);
  line-height: 1.65;
  max-width: 540px;
}

/* --- Sections --- */

section {
  margin-bottom: 3.5rem;
}

h2 {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

p {
  margin-bottom: 1rem;
}

p:last-child {
  margin-bottom: 0;
}

/* --- Code / Structure --- */

.structure {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.8;
  overflow-x: auto;
  margin-bottom: 1rem;
}

.structure .req {
  color: var(--accent);
}

.structure .opt {
  color: var(--fg-tertiary);
}

.structure .comment {
  color: var(--fg-tertiary);
  font-style: italic;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.7;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 1em;
}

/* --- Principles --- */

.principles {
  list-style: none;
  counter-reset: principle;
}

.principles li {
  counter-increment: principle;
  padding-left: 2rem;
  position: relative;
  margin-bottom: 0.75rem;
}

.principles li::before {
  content: counter(principle);
  position: absolute;
  left: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  top: 0.25rem;
}

.principles strong {
  font-weight: 600;
}

/* --- Tables --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

th {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  text-align: left;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 2px solid var(--border);
}

td {
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.meta-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.meta-table td {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.meta-table td:first-child {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--fg-tertiary);
  width: 140px;
  white-space: nowrap;
  padding-right: 1.5rem;
}

.meta-table td:last-child {
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* --- Links --- */

.links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.links a {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  padding-bottom: 1px;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.links a:hover {
  border-bottom-color: var(--accent);
}

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

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

/* --- Lists --- */

ul, ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.35rem;
}

li > ul, li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

/* --- Blockquote --- */

blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1.25rem;
  margin-bottom: 1.5rem;
  color: var(--fg-secondary);
}

/* --- Horizontal rule --- */

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

/* --- Spec page specifics --- */

.spec h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--fg);
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.spec h3 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--fg);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.spec h4 {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg-secondary);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.spec .spec-meta {
  font-size: 0.9rem;
  color: var(--fg-secondary);
  margin-bottom: 0.25rem;
}

.spec .spec-meta strong {
  color: var(--fg);
  font-weight: 600;
}

.spec .abstract {
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--fg-secondary);
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg-code);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.spec .toc {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem 1.5rem 1.5rem 2rem;
  margin-bottom: 3rem;
}

.spec .toc ol {
  margin-bottom: 0;
  padding-left: 1.25rem;
}

.spec .toc li {
  margin-bottom: 0.3rem;
}

.spec .toc a {
  text-decoration: none;
  color: var(--fg-secondary);
}

.spec .toc a:hover {
  color: var(--accent);
}

/* RFC 2119 keywords */
.spec .rfc-keyword {
  font-variant: small-caps;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* --- Footer --- */

footer {
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--fg-tertiary);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

footer a {
  color: var(--fg-tertiary);
  text-decoration: none;
}

footer a:hover {
  color: var(--fg);
}

/* --- Responsive --- */

@media (max-width: 480px) {
  html { font-size: 16px; }
  h1 { font-size: 1.8rem; }
  .page { padding: 2.5rem 1.25rem 4rem; }
  .meta-table td:first-child { width: 100px; }
  .spec h2 { font-size: 1.3rem; }
  nav { gap: 0.75rem; }
  nav .nav-links { gap: 1rem; margin-left: 0; }
}

/* --- Print --- */

@media print {
  body { background: white; color: black; }
  nav { display: none; }
  .page { padding: 0; max-width: none; }
  a { color: inherit; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #666; }
  pre, .structure { border-color: #ccc; }
  footer { border-color: #ccc; }
}
