/*
 * C, Ocean Edition I
 *
 * Light theme after the Lua reference manual: a bordered white card on a
 * faintly grey field, navy headings and links, no underlines.
 *
 * Dark theme after git-scm: the same relationship inverted, warm neutral
 * greys with an orange link.
 *
 * Both palettes are taken from the live stylesheets rather than approximated.
 */

/* ------------------------------------------------------------------ */
/* palette                                                             */
/* ------------------------------------------------------------------ */

:root {
	--field:          #f8f8f8;
	--card:           #ffffff;
	--card-border:    #cccccc;

	--text:           #000000;
	--text-muted:     #555555;
	--heading:        #000080;

	--link:           #000080;
	--link-hover-bg:  #d0d0ff;
	--link-active:    #ff0000;

	--code-bg:        #f4f4f4;
	--code-border:    #e4e4e4;
	--code-text:      #202020;

	--rule:           #e0e0e0;
	--target-bg:      #f0f0f0;
	--table-stripe:   #fafafa;
	--table-border:   #dddddd;

	--nav-bg:         #fbfbfb;
	--mark-bg:        #ffff00;
	--mark-text:      #000000;

	--body-font:      Helvetica, Arial, sans-serif;
	--head-font:      Verdana, Geneva, sans-serif;
	--mono-font:      "DejaVu Sans Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
	--field:          #2a2a2a;
	--card:           #333333;
	--card-border:    #5e5e5a;

	--text:           #b3b1b1;
	--text-muted:     #bdbbb0;
	--heading:        #d7834f;

	--link:           #d7834f;
	--link-hover-bg:  #47412d;
	--link-active:    #e0a079;

	--code-bg:        #515150;
	--code-border:    #494945;
	--code-text:      #afa7a0;

	--rule:           #494945;
	--target-bg:      #47412d;
	--table-stripe:   #3a3a38;
	--table-border:   #5e5e5a;

	--nav-bg:         #3d3d3a;
	--mark-bg:        #898882;
	--mark-text:      #d2d2d2;
}

/* ------------------------------------------------------------------ */
/* the card                                                            */
/* ------------------------------------------------------------------ */

html {
	background-color: var(--field);
	-webkit-text-size-adjust: 100%;
}

body {
	background-color: var(--card);
	color: var(--text);
	font-family: var(--body-font);
	line-height: 1.45;
	margin: 16px auto;
	padding: 32px;
	border: solid var(--card-border) 1px;
	border-radius: 20px;
	max-width: 62em;
	width: 90%;
}

@media (max-width: 640px) {
	body {
		margin: 0;
		padding: 18px;
		width: auto;
		border: none;
		border-radius: 0;
	}
}

/* ------------------------------------------------------------------ */
/* headings                                                            */
/* ------------------------------------------------------------------ */

h1, h2, h3, h4, h5, h6 {
	color: var(--heading);
	font-family: var(--head-font);
	font-weight: normal;
	font-style: normal;
	text-align: left;
	line-height: 1.25;
}

h1 { font-size: 1.9rem; margin: 0 0 0.2em 0; }
h2 { font-size: 1.45rem; margin: 1.9em 0 0.6em 0; }
h3 { font-size: 1.15rem; margin: 1.6em 0 0.5em 0; }
h4 { font-size: 1.02rem; margin: 1.4em 0 0.4em 0; }

/* Lua marks each section with a diamond. */
.prose h2::before {
	content: "\2756";
	padding-right: 0.5em;
	opacity: 0.65;
}

h2 a.anchor, h3 a.anchor, h4 a.anchor,
h5 a.anchor, h6 a.anchor {
	color: inherit;
}

a.anchor:hover {
	background: none;
	text-decoration: underline;
}

/* ------------------------------------------------------------------ */
/* links                                                               */
/* ------------------------------------------------------------------ */

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

a:hover {
	background-color: var(--link-hover-bg);
	border-radius: 4px;
}

a:active {
	color: var(--link-active);
}

a.xref {
	white-space: nowrap;
	border-bottom: 1px dotted var(--link);
}

a.xref:hover {
	border-bottom-color: transparent;
}

/* The reader arrived at a clause by following a link: say which one. */
:target {
	background-color: var(--target-bg);
	margin: -8px;
	padding: 8px;
	border-radius: 8px;
	outline: none;
}

/* ------------------------------------------------------------------ */
/* masthead and menubar                                                */
/* ------------------------------------------------------------------ */

.masthead {
	margin-bottom: 0.6em;
}

.masthead .edition {
	margin: 0 0 0.1em 0;
	font-size: 0.82rem;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: var(--text-muted);
}

.masthead .edition a {
	color: inherit;
}

.menubar {
	padding: 0.5em 0;
	margin-bottom: 1.2em;
	border-top: 1px solid var(--rule);
	border-bottom: 1px solid var(--rule);
	font-size: 0.92rem;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5em;
}

.menubar .sep {
	color: var(--text-muted);
	opacity: 0.6;
}

.menubar a:hover {
	margin: -3px;
	padding: 3px;
	border-radius: 4px;
}

.theme-toggle {
	margin-left: auto;
	font: inherit;
	font-size: 0.86rem;
	color: var(--link);
	background: none;
	border: 1px solid var(--rule);
	border-radius: 4px;
	padding: 2px 10px;
	cursor: pointer;
}

.theme-toggle:hover {
	background-color: var(--link-hover-bg);
}

/* ------------------------------------------------------------------ */
/* metadata block                                                      */
/* ------------------------------------------------------------------ */

.meta {
	font-size: 0.9rem;
	color: var(--text-muted);
	background-color: var(--nav-bg);
	border: 1px solid var(--rule);
	border-radius: 8px;
	padding: 0.7em 1em;
	margin-bottom: 1.6em;
}

.meta p { margin: 0.2em 0; }

.meta dl {
	margin: 0;
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0.15em 0.9em;
}

.meta dl > div {
	display: contents;
}

.meta dt {
	font-family: var(--head-font);
	font-size: 0.82rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--text-muted);
	white-space: nowrap;
}

.meta dd {
	margin: 0;
	color: var(--text);
}

/* ------------------------------------------------------------------ */
/* table of contents                                                   */
/* ------------------------------------------------------------------ */

.toc {
	background-color: var(--nav-bg);
	border: 1px solid var(--rule);
	border-radius: 8px;
	padding: 0.6em 1.4em 1em;
	margin-bottom: 2em;
	font-size: 0.94rem;
}

.toc summary {
	font-family: var(--head-font);
	font-size: 0.82rem;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: var(--text-muted);
	cursor: pointer;
	padding: 0.5em 0;
	list-style-position: outside;
}

.toc summary:hover {
	color: var(--heading);
}

.toc summary .count {
	text-transform: none;
	letter-spacing: 0;
	opacity: 0.75;
}

.toc summary .count::before {
	content: " \00B7 ";
}

.toc details[open] > summary {
	margin-bottom: 0.4em;
}

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

.toc ul ul {
	padding-left: 1.3em;
}

.toc li {
	margin: 0.15em 0;
}

/* ------------------------------------------------------------------ */
/* prose                                                               */
/* ------------------------------------------------------------------ */

/* Lua justifies its body text. Hyphenation keeps rivers from opening up. */
.prose p,
.prose li {
	text-align: justify;
	hyphens: auto;
	-webkit-hyphens: auto;
}

.prose p {
	margin: 0.8em 0;
}

.prose ul, .prose ol {
	margin: 0.8em 0;
	padding-left: 1.6em;
}

.prose li {
	margin: 0.25em 0;
}

.prose blockquote {
	margin: 1.1em 0;
	padding: 0.1em 1.2em;
	border-left: 3px solid var(--heading);
	color: var(--text-muted);
}

.prose hr {
	border: none;
	border-top: 1px solid var(--rule);
	margin: 2em 0;
}

strong {
	font-weight: bold;
	color: var(--text);
}

mark {
	background-color: var(--mark-bg);
	color: var(--mark-text);
}

/* ------------------------------------------------------------------ */
/* code                                                                */
/* ------------------------------------------------------------------ */

code {
	font-family: var(--mono-font);
	font-size: 0.9em;
	background-color: var(--code-bg);
	color: var(--code-text);
	border: 1px solid var(--code-border);
	border-radius: 3px;
	padding: 0.05em 0.35em;
}

pre {
	background-color: var(--code-bg);
	border: 1px solid var(--code-border);
	border-radius: 8px;
	padding: 0.9em 1.1em;
	overflow-x: auto;
	line-height: 1.4;
	margin: 1.1em 0;
}

pre code {
	background: none;
	border: none;
	padding: 0;
	font-size: 0.88rem;
	white-space: pre;
	tab-size: 4;
	-moz-tab-size: 4;
}

/* ------------------------------------------------------------------ */
/* tables                                                              */
/* ------------------------------------------------------------------ */

.table-scroll {
	overflow-x: auto;
	margin: 1.2em 0;
	max-width: 100%;
}

.table-scroll table {
	margin: 0;
}

table {
	border-collapse: collapse;
	margin: 1.2em 0;
	width: 100%;
	font-size: 0.94rem;
}

th, td {
	border: 1px solid var(--table-border);
	padding: 0.45em 0.7em;
	text-align: left;
	vertical-align: top;
}

th {
	background-color: var(--nav-bg);
	font-family: var(--head-font);
	font-weight: normal;
	color: var(--heading);
}

tbody tr:nth-child(even) {
	background-color: var(--table-stripe);
}

/* ------------------------------------------------------------------ */
/* footer                                                              */
/* ------------------------------------------------------------------ */

footer {
	margin-top: 2.5em;
	padding-top: 1em;
	border-top: 1px solid var(--rule);
	font-size: 0.85rem;
	color: var(--text-muted);
}

footer p { margin: 0.3em 0; }

/* ------------------------------------------------------------------ */
/* landing page                                                        */
/* ------------------------------------------------------------------ */

.lede {
	font-size: 1.08rem;
	color: var(--text);
}

.cards {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
	gap: 1em;
	margin: 1.6em 0;
	padding: 0;
	list-style: none;
}

.cards li {
	border: 1px solid var(--rule);
	border-radius: 8px;
	padding: 0.9em 1.1em;
	background-color: var(--nav-bg);
	margin: 0;
}

.cards h3 {
	margin: 0 0 0.3em 0;
	font-size: 1.02rem;
}

.cards p {
	margin: 0;
	font-size: 0.92rem;
	color: var(--text-muted);
}

.laws {
	counter-reset: law;
	list-style: none;
	padding-left: 0;
}

.laws li {
	counter-increment: law;
	margin: 0.45em 0;
	padding-left: 2.4em;
	position: relative;
}

.laws li::before {
	content: counter(law);
	position: absolute;
	left: 0;
	top: 0;
	width: 1.7em;
	text-align: right;
	color: var(--heading);
	font-family: var(--head-font);
}

/* ------------------------------------------------------------------ */
/* search                                                              */
/* ------------------------------------------------------------------ */

#search-form {
	display: flex;
	gap: 0.6em;
	margin: 1.4em 0;
}

#search-input {
	flex: 1;
	font: inherit;
	padding: 0.55em 0.8em;
	border: 1px solid var(--card-border);
	border-radius: 6px;
	background-color: var(--card);
	color: var(--text);
}

#search-input:focus {
	outline: 2px solid var(--link);
	outline-offset: -1px;
}

#search-status {
	color: var(--text-muted);
	font-size: 0.92rem;
}

#search-results {
	list-style: none;
	padding-left: 0;
	margin-top: 1.4em;
}

#search-results li {
	margin: 0 0 1.3em 0;
	padding-bottom: 1.1em;
	border-bottom: 1px solid var(--rule);
}

#search-results .result-title {
	font-family: var(--head-font);
	font-size: 1.02rem;
}

#search-results .result-doc {
	font-size: 0.82rem;
	color: var(--text-muted);
	margin: 0.15em 0 0.35em 0;
}

#search-results .result-body {
	margin: 0;
	font-size: 0.92rem;
	color: var(--text-muted);
}

.noscript {
	border: 1px solid var(--rule);
	border-radius: 8px;
	padding: 0.8em 1.1em;
	background-color: var(--nav-bg);
}

/* ------------------------------------------------------------------ */
/* print                                                               */
/* ------------------------------------------------------------------ */

@media print {
	html { background: #fff; }

	body {
		border: none;
		border-radius: 0;
		max-width: none;
		width: auto;
		margin: 0;
		padding: 0;
		color: #000;
		background: #fff;
		font-size: 10.5pt;
	}

	.menubar,
	.theme-toggle,
	.toc,
	footer {
		display: none;
	}

	h1, h2, h3, h4 { color: #000; }

	a { color: #000; }

	/* A printed clause reference is useless as a link, so show the target. */
	a.xref::after {
		content: " (" attr(title) ")";
		font-size: 0.85em;
	}

	pre, table, blockquote {
		page-break-inside: avoid;
	}

	h2, h3, h4 {
		page-break-after: avoid;
	}
}
