/* The ground every page stands on: the reset, the type, the controls everyone shares.
   Reads only tokens.css. Each block is one component, scoped to its own class; nothing in here
   is overridden by a later sheet, and nothing uses !important. */

/* ---- Reset -------------------------------------------------------------- */

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

html {
	-webkit-text-size-adjust: 100%;
	scrollbar-width: thin;
	scrollbar-color: var(--surface-open) transparent;
}

body,
h1, h2, h3, h4, h5, h6,
p, ul, ol, dl, dd,
figure, blockquote, pre,
fieldset, legend {
	margin: 0;
}

fieldset {
	padding: 0;
	border: 0;
	min-width: 0;
}

ul, ol {
	padding-left: 1.25em;
}

img, svg, video {
	display: block;
	max-width: 100%;
}

img {
	height: auto;
}

button, input, select, textarea {
	font: inherit;
	color: inherit;
	letter-spacing: inherit;
}

button {
	cursor: pointer;
}

[hidden]:not([hidden="until-found"]) {
	display: none;
}

/* ---- The page ------------------------------------------------------------ */

body {
	min-height: 100vh;
	font-family: var(--font-ui);
	font-size: var(--text-md);
	line-height: var(--leading);
	color: var(--ink);
	background: var(--ground) var(--paper);
	background-attachment: fixed;
}

/* A world chooses its ground. Glow lays the world's colour over the top of the page; plain is bare paper. */
body.bg-glow,
body.bg-strong-glow {
	background-image: radial-gradient(var(--glow-size, 1100px 520px) at 50% -12%, color-mix(in srgb, var(--accent) var(--glow, 10%), transparent), transparent 70%), var(--ground);
}

body.bg-strong-glow {
	--glow-size: 1400px 760px;
	--glow: 22%;
}

body.bg-plain,
body.editor-page {
	background-image: none;
}

body.bg-parchment {
	background-image: linear-gradient(var(--parchment-veil), var(--parchment-veil)), var(--parchment);
}

/* A world's own picture behind its pages, veiled in the page colour so the text still reads. */
body.bg-picture {
	background-image: linear-gradient(var(--backdrop-veil), var(--backdrop-veil)), var(--backdrop, none);
	background-size: cover;
	background-position: center top;
}

::selection {
	background: color-mix(in srgb, var(--accent) 35%, transparent);
}

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

::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

::-webkit-scrollbar-thumb {
	border: 2px solid transparent;
	border-radius: var(--radius);
	background-color: var(--surface-open);
	background-clip: content-box;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
	background: transparent;
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		transition-duration: 0s;
		animation-duration: 0s;
	}
}

/* ---- Type ---------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
	font-weight: 600;
	line-height: 1.25;
	overflow-wrap: break-word;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4, h5, h6 { font-size: var(--text-md); }

/* Titles: the house face, in the page's accent. Used by the article and by page heads. */
.title {
	font-family: var(--font-titles);
	font-weight: normal;
	color: var(--accent);
}

a {
	color: inherit;
	text-decoration: none;
	transition: color var(--ease);
}

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

/* A quiet heading over a group: small caps-ish UI text on a hairline. */
.section-heading {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-3);
	padding-bottom: var(--space-2);
	border-bottom: var(--rule);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-faint);
}

.muted {
	color: var(--ink-muted);
}

small,
.small {
	font-size: var(--text-sm);
}

code, kbd, pre {
	font-family: var(--font-mono);
	font-size: 0.9em;
}

code {
	padding: 0 0.3em;
	border-radius: var(--radius);
	background: var(--surface);
}

pre {
	padding: var(--space-3);
	border-radius: var(--radius);
	background: var(--surface);
	overflow-x: auto;
}

pre code {
	padding: 0;
	background: none;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Prose: anything written, rendered from markdown ---------------------- */
/* The blocks stand apart by one flow gap; headings take one more above. Every heading
   is a title in the house face; the first two carry a rule. */

.prose {
	display: flex;
	flex-direction: column;
	gap: var(--flow);
	font-family: var(--font-prose);
	font-size: var(--text-prose);
	line-height: var(--leading-prose);
	overflow-wrap: break-word;
}

.prose > h1,
.prose > h2,
.prose > h3,
.prose > h4 {
	margin-top: var(--space-4);
	font-family: var(--font-titles);
	font-weight: normal;
	color: var(--accent);
}

.prose > h1 {
	margin-top: 0;
	padding-bottom: var(--space-2);
	border-bottom: var(--rule-strong);
	font-size: var(--text-3xl);
}

.prose > h2 {
	padding-bottom: var(--space-1);
	border-bottom: var(--rule);
	font-size: var(--text-2xl);
}

.prose > h3 {
	font-size: var(--text-xl);
}

.prose > h4 {
	font-family: var(--font-ui);
	font-size: var(--text-md);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-muted);
}

.prose a {
	color: var(--accent-ink);
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
	text-decoration-thickness: 1px;
	text-underline-offset: var(--underline-offset);
	transition: text-decoration-color var(--ease);
}

.prose a:hover {
	color: var(--accent-ink);
	text-decoration-color: currentColor;
}

.prose ul,
.prose ol {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
}

.prose li::marker {
	color: var(--accent);
}

.prose blockquote {
	padding: var(--space-2) var(--space-4);
	border-left: var(--rule-strong);
	font-style: italic;
	color: var(--ink-muted);
}

.prose hr {
	height: 1px;
	border: 0;
	background: var(--line-strong);
}

.prose img {
	width: 100%;
	border-radius: var(--radius);
}

.prose table {
	font-family: var(--font-ui);
	font-size: var(--text-sm);
}

.prose details > summary {
	cursor: pointer;
	color: var(--accent-ink);
}

/* ---- Tables: ruled, never boxed --------------------------------------------- */

table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--text-sm);
	line-height: var(--leading);
}

th, td {
	padding: var(--space-2) var(--space-3);
	text-align: left;
	vertical-align: top;
	border-bottom: var(--rule);
	overflow-wrap: anywhere;
}

thead th {
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-muted);
	border-bottom: var(--rule-strong);
}

td.num,
th.num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* ---- Controls ------------------------------------------------------------- */

.button,
button.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	min-height: var(--control-h);
	padding: 0 var(--space-4);
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-size: var(--text-sm);
	font-weight: 600;
	line-height: 1;
	white-space: nowrap;
	cursor: pointer;
	transition: border-color var(--ease), background var(--ease), color var(--ease);
}

.button:hover {
	border-color: var(--accent);
	color: var(--accent-ink);
}

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

.button.primary:hover {
	background: color-mix(in srgb, var(--accent) 88%, white);
	color: var(--on-accent);
}

.button.ghost {
	border-color: transparent;
	background: transparent;
}

.button.danger {
	border-color: var(--danger);
	color: var(--danger);
	background: transparent;
}

.button.danger:hover {
	background: color-mix(in srgb, var(--danger) 12%, transparent);
	color: var(--danger);
}

.button.small {
	min-height: calc(var(--control-h) - var(--space-2));
	padding: 0 var(--space-3);
	font-size: var(--text-xs);
}

.button.big {
	min-height: calc(var(--control-h) + var(--space-2));
	padding: 0 var(--space-5);
	font-size: var(--text-md);
}

.button:disabled,
.button[aria-disabled="true"] {
	opacity: 0.5;
	cursor: default;
}

/* A text link that is a <button>: the same words, no box. */
.link-button {
	padding: 0;
	border: 0;
	background: none;
	color: var(--accent-ink);
	text-decoration: underline;
	text-underline-offset: var(--underline-offset);
}

/* Fields. One look wherever one stands: a hairline box on paper. */
input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]),
select,
textarea {
	width: 100%;
	min-height: var(--control-h);
	padding: var(--space-1) var(--space-3);
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-size: var(--text-md);
	transition: border-color var(--ease);
}

textarea {
	padding: var(--space-2) var(--space-3);
	line-height: var(--leading);
	resize: vertical;
}

input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]):hover,
select:hover,
textarea:hover {
	border-color: var(--accent);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
	outline: 2px solid var(--accent-soft);
	outline-offset: 0;
	border-color: var(--accent);
}

input::placeholder,
textarea::placeholder {
	color: var(--ink-faint);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"] {
	accent-color: var(--accent);
}

input[type="color"] {
	width: var(--control-h);
	height: var(--control-h);
	padding: 0;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: none;
}

input[readonly],
textarea[readonly] {
	color: var(--ink-muted);
	background: var(--surface);
}

label {
	cursor: pointer;
}

/* A checkbox drawn as a switch: the same input, so keyboard and screen reader still work. */
.switch {
	appearance: none;
	position: relative;
	flex: none;
	width: 2.1rem;
	height: 1.2rem;
	margin: 0;
	border-radius: 1rem;
	background: var(--surface-open);
	cursor: pointer;
	transition: background var(--ease);
}

.switch::before {
	content: "";
	position: absolute;
	top: 0.15rem;
	left: 0.15rem;
	width: 0.9rem;
	height: 0.9rem;
	border-radius: var(--radius-round);
	background: var(--paper);
	transition: transform var(--ease);
}

.switch:checked {
	background: var(--accent);
}

.switch:checked::before {
	transform: translateX(0.9rem);
}

/* A form as one column: label over field. Labels and fields are siblings, so the column gap is the
   small one between a caption and its field; each next caption takes the flow gap above it. */
.stack {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
}

.stack > label:not(:first-child),
.stack > fieldset:not(:first-child),
.stack > .actions {
	margin-top: calc(var(--flow) - var(--space-1));
}

.stack label,
.field > label,
.field-label {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-muted);
}

/* A label that holds a checkbox or radio reads as a sentence beside it, not as a caption over it. */
/* A mark inside a caption keeps its own width. */
.stack label > .pill,
.field-label > .pill {
	align-self: flex-start;
}

.stack label:has(> input[type="checkbox"], > input[type="radio"]),
.check {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: var(--space-2);
	font-size: var(--text-sm);
	font-weight: normal;
	letter-spacing: normal;
	text-transform: none;
	color: var(--ink);
}

.field-hint {
	font-size: var(--text-sm);
	color: var(--ink-muted);
}

.field-hint.good { color: var(--ok); }
.field-hint.bad { color: var(--danger); }

/* Controls side by side at the end of a form or a section. */
.actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2);
}

.actions.center {
	justify-content: center;
}

form.inline {
	display: inline-flex;
	gap: var(--space-2);
	align-items: center;
}

/* ---- Marks: pills, chips, avatars ----------------------------------------- */

.pill {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	padding: 0 var(--space-2);
	border-radius: var(--radius);
	background: var(--accent-soft);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-tight);
	line-height: 1.6;
	text-transform: uppercase;
	white-space: nowrap;
	vertical-align: middle;
}

.pill.ok { background: color-mix(in srgb, var(--ok) 22%, transparent); }
.pill.warn { background: color-mix(in srgb, var(--warn) 25%, transparent); }
.pill.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.pill.quiet { background: var(--surface); color: var(--ink-muted); }

/* A row of small named things: the characters someone plays. */
.character-chips {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-1);
}

.character-chip {
	padding: 0 var(--space-2);
	border: var(--rule);
	border-radius: var(--radius);
	font-size: var(--text-xs);
	line-height: 1.7;
}

.avatar {
	display: inline-grid;
	place-items: center;
	flex: none;
	width: var(--control-h);
	height: var(--control-h);
	border-radius: var(--radius-round);
	background: var(--accent);
	color: var(--on-accent);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	font-weight: 700;
	text-decoration: none;
	text-transform: uppercase;
}

.avatar.small {
	width: 1.6rem;
	height: 1.6rem;
	font-size: var(--text-xs);
}

/* ---- Messages ----------------------------------------------------------- */

.notice,
.banner {
	padding: var(--space-2) var(--space-4);
	border-left: 3px solid var(--ok);
	background: color-mix(in srgb, var(--ok) 10%, transparent);
	font-size: var(--text-sm);
}

.notice.warn,
.banner.warn {
	border-color: var(--warn);
	background: color-mix(in srgb, var(--warn) 12%, transparent);
}

.notice.error,
.banner.error,
.login-error,
.error {
	border-color: var(--danger);
	background: color-mix(in srgb, var(--danger) 10%, transparent);
	color: var(--ink);
}

.banner.celebrate {
	border-color: var(--accent);
	background: var(--accent-soft);
}

/* ---- Sections: a ruled group, not a floating card ---------------------------- */

.card {
	display: flex;
	flex-direction: column;
	gap: var(--flow);
	padding: var(--space-5);
	border: var(--rule);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--paper) 70%, transparent);
}

.card > h2,
.card > h3 {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	gap: var(--space-3);
	padding-bottom: var(--space-2);
	border-bottom: var(--rule);
	font-size: var(--text-md);
	font-weight: 600;
}

.card > h2 > .pill,
.card > h3 > .pill {
	margin-left: auto;
}

.card.quiet {
	border-color: transparent;
	background: transparent;
	padding: 0;
}

.card.danger-zone {
	border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.card.danger-zone > h2 {
	color: var(--danger);
}

/* ---- Folding and dialogs ---------------------------------------------------- */

summary {
	cursor: pointer;
	list-style: none;
}

summary::-webkit-details-marker {
	display: none;
}

dialog {
	width: min(32rem, calc(100vw - 2 * var(--gutter)));
	padding: var(--space-5);
	border: var(--rule);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
}

dialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

/* ---- Footer ----------------------------------------------------------------- */

footer {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-7) var(--gutter) var(--space-6);
	font-size: var(--text-xs);
	letter-spacing: var(--tracking-wide);
	text-transform: uppercase;
	color: var(--ink-faint);
}

footer .footer-rule {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	width: min(16rem, 70%);
	color: var(--accent);
	letter-spacing: 0;
}

footer .footer-rule::before,
footer .footer-rule::after {
	content: "";
	flex: 1;
	height: 1px;
	background: var(--line-strong);
}
