/* Zaytun Project — site styles.
 *
 * Written for screen readers first and eyes second. Notes on the choices that matter:
 *   - Base font is 1.125rem (18px) and every size is relative, so browser zoom and
 *     user stylesheets work without anything collapsing.
 *   - Colours meet WCAG AA against their backgrounds; nothing is signalled by colour
 *     alone, and body links keep their underline.
 *   - Focus is always visible, and never removed.
 *   - Line length is capped near 70 characters, which helps low-vision and dyslexic
 *     readers as much as it helps anyone else.
 */

:root {
  --bg: #f7f5ef;
  --panel: #fffdf7;
  --ink: #1a1a16;
  --muted: #4d4b43;
  --rule: #d5cfbe;
  --accent: #4a6626;
  --accent-strong: #3c5420;
  --code-bg: #f0ede3;
  --term-bg: #1d1e19;
  --term-ink: #e4e0d2;
  --term-dim: #a6a394;
  --focus: #12408f;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14150f;
    --panel: #1c1d16;
    --ink: #eeeadd;
    --muted: #b3b0a1;
    --rule: #3a3b30;
    --accent: #a9c66d;
    --accent-strong: #c0da85;
    --code-bg: #1c1d16;
    --term-bg: #0d0e08;
    --term-ink: #e4e0d2;
    --term-dim: #9a9788;
    --focus: #8ab4ff;
  }
}

:root[data-theme="dark"] {
  --bg: #14150f;
  --panel: #1c1d16;
  --ink: #eeeadd;
  --muted: #b3b0a1;
  --rule: #3a3b30;
  --accent: #a9c66d;
  --accent-strong: #c0da85;
  --code-bg: #1c1d16;
  --term-bg: #0d0e08;
  --term-ink: #e4e0d2;
  --term-dim: #9a9788;
  --focus: #8ab4ff;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.125rem;
  line-height: 1.7;
  font-family: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

code, pre, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

/* --- skip link: first thing in the tab order, visible the moment it is focused --- */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--panel);
  color: var(--ink);
  padding: .75rem 1rem;
  border: 2px solid var(--focus);
  border-radius: 0 0 var(--radius) 0;
  z-index: 100;
}
.skip:focus { left: 0; }

/* --- focus, never removed --- */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

a { color: var(--accent-strong); }
main a, footer a { text-decoration: underline; text-underline-offset: .18em; }
a:hover { color: var(--ink); }

.wrap { max-width: 48rem; margin: 0 auto; padding: 0 1.25rem; }
.wrap-wide { max-width: 62rem; margin: 0 auto; padding: 0 1.25rem; }

/* --- masthead and navigation --- */
.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}
.masthead-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  align-items: baseline;
  padding: 1rem 1.25rem;
  max-width: 62rem;
  margin: 0 auto;
}
.sitename {
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  letter-spacing: -.01em;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
/* The mark beside the name. Its alt is empty, because the link it sits in already says
   "Zaytun Handbook" and a screen reader should not read the name twice. */
.sitemark {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
}
.masthead nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.25rem;
  margin: 0;
  padding: 0;
  font-size: 1rem;
}
.masthead nav a {
  text-decoration: none;
  color: var(--muted);
  padding: .15rem 0;
  border-bottom: 2px solid transparent;
}
.masthead nav a:hover { color: var(--ink); }
/* current page is marked with aria-current, and shown two ways: weight and a rule */
.masthead nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--accent);
}

/* --- headings --- */
h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.2;
  letter-spacing: -.02em;
  margin: 2.5rem 0 .5rem;
  font-weight: 700;
}
h2 {
  font-size: clamp(1.4rem, 3vw, 1.7rem);
  line-height: 1.3;
  margin: 2.75rem 0 .5rem;
  font-weight: 700;
}
h3 {
  font-size: 1.2rem;
  margin: 2rem 0 .35rem;
  font-weight: 700;
}
h4 { font-size: 1.05rem; margin: 1.5rem 0 .25rem; font-weight: 700; }

p, li { max-width: 70ch; }
p { margin: 0 0 1.1rem; }
.lede { font-size: 1.2rem; color: var(--ink); }
.sub { color: var(--muted); margin-top: -.2rem; }

ul, ol { padding-left: 1.4rem; }
li { margin-bottom: .5rem; }

blockquote {
  margin: 1.5rem 0;
  padding: .25rem 0 .25rem 1.25rem;
  border-left: 4px solid var(--accent);
  color: var(--ink);
  font-style: normal;
}

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

/* --- code --- */
figure { margin: 1.5rem 0; }
figure figcaption {
  font-size: .95rem;
  color: var(--muted);
  margin-bottom: .5rem;
}
figure figcaption b { color: var(--ink); }
pre {
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: .95rem;
  line-height: 1.55;
}
pre.term { background: var(--term-bg); color: var(--term-ink); border-color: var(--term-bg); }
pre.term .prompt { color: #b7d178; }
pre.term .dim { color: var(--term-dim); }
code { font-size: .95em; }
p code, li code, td code, dd code {
  background: var(--code-bg);
  padding: .1em .35em;
  border-radius: 4px;
}

/* --- description lists, used instead of layout tables --- */
dl { margin: 1.25rem 0; }
dt { font-weight: 700; margin-top: 1.1rem; }
dt:first-child { margin-top: 0; }
dd { margin: .15rem 0 0; color: var(--muted); max-width: 70ch; }
dd a { color: var(--accent-strong); }

/* --- real tables, for real tabular data --- */
table { border-collapse: collapse; margin: 1.25rem 0; width: 100%; font-size: 1rem; }
caption { text-align: left; color: var(--muted); padding-bottom: .5rem; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 700; }
.table-scroll { overflow-x: auto; }

/* --- panels --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin: 1.5rem 0;
}
.panel > :first-child { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }

/* --- game entries --- */
.game { border-top: 1px solid var(--rule); padding-top: 1.5rem; margin-top: 2.5rem; }
.game:first-of-type { border-top: 0; }
.meta { color: var(--muted); font-size: 1rem; margin: 0 0 1rem; }
.meta b { color: var(--ink); }

/* --- on-this-page contents --- */
.toc { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.25rem; }
.toc h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.toc ul { margin: 0; }
.toc li { margin-bottom: .3rem; }

footer {
  border-top: 1px solid var(--rule);
  margin-top: 4rem;
  padding: 2rem 0 3rem;
  color: var(--muted);
  font-size: 1rem;
}
footer p { margin: 0 0 .5rem; }

/* ---------------------------------------------------------------------------------------------
 * The handbook site.
 *
 * Everything above is the project site's stylesheet, unchanged, so the two read as one place.
 * What follows is only what a reference needs and a brochure does not: a contents tree, a filter
 * box, chapter pagination, and headings you can link to.
 * ------------------------------------------------------------------------------------------- */

/* --- the contents, on the index and at the top of each chapter --- */
.toc {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0 2.5rem;
}
.toc h2 {
  font-size: 1rem;
  margin: 0 0 .5rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.toc ul { margin: 0; padding-left: 1.1rem; }
.toc li { margin-bottom: .2rem; max-width: none; }

/* The full tree on the contents page: chapters in the body face, sections smaller under them,
 * and two columns where there is room for two. */
.toc-full > ul { padding-left: 0; list-style: none; columns: 2; column-gap: 2.5rem; }
.toc-full > ul > li {
  break-inside: avoid;
  margin-bottom: 1.25rem;
}
.toc-full > ul > li > a { font-weight: 700; }
.toc-full ul ul { list-style: none; padding-left: 0; margin-top: .25rem; }
.toc-full ul ul a { font-size: .95rem; }
@media (max-width: 48rem) { .toc-full > ul { columns: 1; } }

/* --- the filter box --- */
.filter { margin: 1.5rem 0; }
.filter label { display: block; font-size: .95rem; color: var(--muted); margin-bottom: .35rem; }
.filter input {
  font: inherit;
  font-size: 1rem;
  width: 100%;
  max-width: 28rem;
  padding: .5rem .7rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.filter p { margin: .4rem 0 0; color: var(--muted); font-size: .95rem; min-height: 1.7em; }

/* --- chapter pagination --- */
.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin: 3rem 0 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
.pager a { font-weight: 700; }

/* --- headings are landing places, so give them room to be landed on --- */
main :is(h2, h3, h4) { scroll-margin-top: 1rem; }

/* A reference is read in code as much as in prose, and its tables are wide. Both already scroll
 * rather than overflow -- see .table-scroll above -- and this keeps the type honest at 320px. */
main pre { max-width: 100%; }

/* The contents page lists every section and every subsection, but shows the subsections only
 * while something is being looked for: browsing wants forty entries, searching wants all 153. */
.toc-full .sub { display: none; }
.toc-full.filtering .sub { display: block; }
.toc-full .sub a { font-size: .9rem; color: var(--muted); }

/* A reference names things, and some of the things have long names. An inline `code` span cannot
 * wrap at a space it has not got, so at 320px one of them pushed the page four pixels wide and
 * gave the whole document a horizontal scrollbar. Inside a <pre> the block scrolls on its own and
 * must not break, so this is only the inline kind. */
:not(pre) > code { overflow-wrap: anywhere; }
