/* The pieces that appear inside a world page beyond its prose: the stub a page leaves for someone
   else, secret blocks, the character sheet, dice, the NPC chat, the hover card, the D&D stat block,
   the live faces. Reads tokens.css and builds on base.css and shell.css. One component per block,
   each scoped to its own class; the article (.prose) is base, the columns are shell. */

/* ---- The stub: a page written for someone else, named and nothing more --------------- */

.stub {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding: var(--space-6) var(--space-5);
	border-radius: var(--radius);
	background: var(--surface);
	font-family: var(--font-ui);
	font-size: var(--text-md);
	line-height: var(--leading);
	text-align: center;
}

.stub-action,
.stub-back {
	font-size: var(--text-sm);
	color: var(--ink-muted);
}

/* ---- Secrets: a block for some readers, marked; or the mark alone when it is withheld ----- */

.secret {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-1) 0 var(--space-1) var(--space-4);
	border-left: 3px solid var(--accent);
}

.secret-label,
.secret.secret-withheld {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--accent);
}

.secret.secret-withheld {
	padding: var(--space-2) var(--space-4);
	border-left-style: dashed;
	color: var(--ink-muted);
}

/* ---- Links that leave the site -------------------------------------------------------- */

.container > main a[href^="https"]:not(:has(img))::after {
	content: "\2009\2197";
	font-size: var(--text-sm);
	opacity: 0.6;
}

/* ---- Dice: "2d6+3" in the text rolls, a d20 table rolls on itself, results land in a tray ---- */

.dice-roll {
	padding: 0 var(--space-1);
	border: 0;
	border-bottom: 1px dashed var(--accent);
	border-radius: var(--radius);
	background: var(--accent-soft);
	color: inherit;
	font: inherit;
	white-space: nowrap;
	transition: background var(--ease), color var(--ease);
}

.dice-roll:hover,
.dice-roll:focus-visible {
	background: var(--accent);
	color: var(--on-accent);
	outline: none;
}

.dice-table-roll {
	align-self: flex-start;
	min-height: calc(var(--control-h) - var(--space-2));
	padding: 0 var(--space-3);
	border: 1px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	transition: background var(--ease), color var(--ease);
}

.dice-table-roll:hover {
	background: var(--accent);
	color: var(--on-accent);
}

tr.dice-hit td {
	background: var(--accent-soft);
	border-bottom-color: var(--accent);
	font-weight: 600;
}

/* The tray: the last few rolls, newest on top, in the corner. It moves up when the live pill is there. */
.dice-tray {
	--tray-w: 24rem;
	position: fixed;
	left: var(--space-4);
	bottom: var(--space-4);
	z-index: var(--z-fab);
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	width: min(var(--tray-w), calc(100vw - 2 * var(--space-4)));
	padding: var(--space-2) calc(var(--control-h) + var(--space-2)) var(--space-2) var(--space-3);
	border: var(--rule);
	border-left: 3px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	line-height: var(--leading);
}

.dice-tray[hidden] {
	display: none;
}

body:has(.live-pill:not([hidden])) .dice-tray {
	bottom: calc(var(--space-4) + var(--control-h) + var(--space-2));
}

.dice-tray-close {
	position: absolute;
	top: 0;
	right: 0;
	display: grid;
	place-items: center;
	width: var(--control-h);
	height: var(--control-h);
	border: 0;
	background: none;
	color: var(--ink-muted);
	font-size: var(--text-lg);
	line-height: 1;
}

.dice-result {
	display: flex;
	align-items: baseline;
	gap: var(--space-2);
	opacity: 0.6;
}

.dice-result:first-of-type {
	opacity: 1;
	animation: dice-land 0.35s ease-out;
}

.dice-what {
	font-weight: 600;
	white-space: nowrap;
}

.dice-how {
	color: var(--ink-muted);
	overflow-wrap: anywhere;
}

.dice-total {
	margin-left: auto;
	font-family: var(--font-titles);
	font-size: var(--text-lg);
	color: var(--accent);
}

.dice-result.dice-crit .dice-total::after {
	content: " \2605";
}

.dice-result.dice-fumble .dice-total {
	color: var(--danger);
}

@keyframes dice-land {
	from { transform: translateY(var(--space-2)) rotate(-2deg); opacity: 0; }
	to { transform: none; opacity: 1; }
}

/* ---- The character sheet: a D&D Beyond character as built, laid out like a stat block --------- */
/* The small-caps face is the stat block's; it is loaded here and nowhere else. */

@font-face {
	font-family: MrsEavesSmallCaps;
	src: url(/ui/mrseavessmallcaps.ttf) format("truetype");
	font-weight: 100;
	font-style: normal;
}

.sheet {
	--sheet-line: color-mix(in srgb, var(--accent) 35%, var(--line-strong));
	--sheet-tint: color-mix(in srgb, var(--accent) 6%, transparent);
	--sheet-portrait: 4.5rem;
	--sheet-seal: 3.6rem;
	--sheet-dot: 0.55rem;
	--sheet-col: 11rem;
	--sheet-who: 12rem;
	--sheet-vital: 7rem;
	--sheet-feature: 15rem;
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	padding: var(--space-5);
	border-top: 3px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	line-height: var(--leading);
}

.sheet.sheet-empty {
	padding: var(--space-3) var(--space-4);
}

.sheet h3,
.sheet h4,
.sheet-name,
.sheet dt,
.sheet-ability-name,
.sheet-level span,
.sheet-section > summary {
	font-family: MrsEavesSmallCaps, var(--font-ui);
}

/* Every label in the sheet is quiet; the number beside it carries the weight. */
.sheet dt,
.sheet-ability-name {
	color: var(--ink-muted);
}

/* Who: portrait, name, what they are, and their level in a seal on the right. */
.sheet-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-4);
	padding-bottom: var(--space-3);
	border-bottom: 2px solid var(--sheet-line);
}

.sheet-portrait {
	flex: none;
	width: var(--sheet-portrait);
	height: var(--sheet-portrait);
	border: 2px solid var(--accent);
	border-radius: var(--radius-round);
	object-fit: cover;
}

.sheet-who {
	flex: 1 1 var(--sheet-who);
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	min-width: 0;
}

.sheet-name {
	font-size: var(--text-xl);
	line-height: 1.1;
	color: var(--accent);
}

.sheet-line {
	font-weight: 600;
}

.sheet-origin {
	font-size: var(--text-xs);
	color: var(--ink-muted);
}

.sheet-level {
	flex: none;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: var(--sheet-seal);
	height: var(--sheet-seal);
	border: 2px solid var(--accent);
	border-radius: var(--radius-round);
	font-size: var(--text-lg);
	font-weight: 700;
	line-height: 1;
}

.sheet-level span {
	font-size: var(--text-xs);
	font-weight: normal;
	text-transform: lowercase;
	color: var(--ink-muted);
}

/* The numbers that stay put. */
.sheet-vitals {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(var(--sheet-vital), 1fr));
	gap: var(--space-2);
}

.sheet-vitals > div {
	padding: var(--space-2);
	border-radius: var(--radius);
	background: var(--surface);
	text-align: center;
}

.sheet-vitals dd {
	font-size: var(--text-lg);
	font-weight: 700;
}

.sheet-abilities {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: var(--space-2);
}

.sheet-ability {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-1);
	padding: var(--space-2) var(--space-1);
	border: 1px solid var(--sheet-line);
	border-radius: var(--radius);
	background: var(--sheet-tint);
	text-align: center;
}

.sheet-ability-mod {
	font-size: var(--text-xl);
	font-weight: 700;
	line-height: 1.1;
}

.sheet-ability-score {
	padding: 0 var(--space-2);
	border: var(--rule);
	border-radius: var(--radius);
	font-size: var(--text-xs);
}

.sheet-save {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
	width: 100%;
	padding-top: var(--space-1);
	border-top: var(--rule);
	font-size: var(--text-xs);
	color: var(--ink-muted);
}

.sheet-save.is-proficient {
	color: var(--ink);
	font-weight: 600;
}

/* Proficiency as a dot: empty, half, full, or ringed for expertise. */
.sheet-dot {
	flex: none;
	width: var(--sheet-dot);
	height: var(--sheet-dot);
	border: 1px solid var(--ink-muted);
	border-radius: var(--radius-round);
}

.is-half > .sheet-dot {
	border-color: var(--accent);
	background: linear-gradient(90deg, var(--accent) 50%, transparent 50%);
}

.is-proficient > .sheet-dot,
.is-expert > .sheet-dot {
	border-color: var(--accent);
	background: var(--accent);
}

.is-expert > .sheet-dot {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

/* Advantage on a roll, marked beside its number. */
.sheet-adv {
	margin-left: var(--space-1);
	padding: 0 var(--space-1);
	border-radius: var(--radius);
	background: var(--accent);
	color: var(--on-accent);
	font-size: var(--text-xs);
	font-weight: 700;
	text-decoration: none;
	vertical-align: middle;
	cursor: help;
}

.sheet-columns {
	display: grid;
	grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
	gap: var(--space-5);
}

.sheet-panel {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.sheet h3 {
	padding-bottom: var(--space-1);
	border-bottom: 1px solid var(--sheet-line);
	font-size: var(--text-md);
	font-weight: normal;
	color: var(--accent);
}

.sheet-skills {
	margin: 0;
	padding: 0;
	list-style: none;
	columns: var(--sheet-col) 2;
	column-gap: var(--space-4);
}

.sheet-skills li {
	display: flex;
	align-items: baseline;
	gap: var(--space-2);
	padding: var(--space-1) 0;
	border-bottom: var(--rule);
	break-inside: avoid;
}

.sheet-skills li:not(.is-proficient, .is-expert) {
	color: var(--ink-muted);
}

.sheet-skill-name {
	flex: 1;
	min-width: 0;
}

.sheet-skill-name small {
	font-size: var(--text-xs);
	color: var(--ink-faint);
}

.sheet-skill-bonus {
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.sheet-facts {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	gap: var(--space-1) var(--space-3);
}

/* The long reads, folded away until asked for. */
.sheet-section {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	padding-top: var(--space-3);
	border-top: 1px solid var(--sheet-line);
}

.sheet-section > summary {
	font-size: var(--text-md);
	color: var(--accent);
}

.sheet-section > summary small {
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	color: var(--ink-muted);
}

.sheet-section h4 {
	font-size: var(--text-sm);
	font-weight: normal;
	color: var(--ink-muted);
}

.sheet-section p {
	font-family: var(--font-prose);
	font-size: var(--text-md);
}

.sheet-features {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--sheet-feature), 1fr));
	gap: var(--space-2);
	align-items: start;
}

.sheet-feature {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	border: var(--rule);
	border-radius: var(--radius);
}

.sheet-feature > summary {
	padding: var(--space-1) var(--space-3);
	font-weight: 600;
}

.sheet-feature[open] {
	grid-column: 1 / -1;
	padding-bottom: var(--space-2);
	background: var(--sheet-tint);
}

.sheet-feature[open] > summary {
	border-bottom: var(--rule);
}

.sheet-feature > p {
	padding: 0 var(--space-3);
}

.sheet-looks {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2) var(--space-5);
}

.sheet-looks dd {
	font-weight: 600;
}

.sheet-foot {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: var(--space-1) var(--space-4);
	padding-top: var(--space-3);
	border-top: var(--rule);
	font-size: var(--text-xs);
	color: var(--ink-muted);
}

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

	.sheet-abilities {
		grid-template-columns: repeat(3, 1fr);
	}
}

/* ---- The D&D stat block: a blockquote marked {.dnd}, on its own parchment ---------------- */
/* The one place with colours of its own: the printed stat block's red on paper, by night too. */

.prose blockquote.dnd {
	--dnd-red: #822000;
	--dnd-ink: #000;
	--dnd-line: color-mix(in srgb, var(--dnd-red) 25%, transparent);
	--dnd-paper: url(/ui/paper-texture.webp);
	--dnd-top: url(/ui/stat-block-top-texture.webp);
	--dnd-bar: url(/ui/stat-block-header-bar.svg);
	--dnd-bar-h: 10px;
	position: relative;
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	padding: var(--space-4);
	border: 1px solid var(--dnd-line);
	border-radius: var(--radius);
	background: var(--dnd-top) top center / 100% auto no-repeat, var(--dnd-paper) repeat;
	color: var(--dnd-ink);
	font-family: var(--font-ui);
	font-size: var(--text-md);
	font-style: normal;
	line-height: var(--leading);
}

.prose blockquote.dnd > hr {
	height: var(--dnd-bar-h);
	background: var(--dnd-bar) center / 100% auto no-repeat;
}

.prose blockquote.dnd > h1,
.prose blockquote.dnd > h2 {
	font-family: MrsEavesSmallCaps, var(--font-ui);
	font-weight: 700;
	color: var(--dnd-red);
}

.prose blockquote.dnd > h1 {
	font-size: var(--text-2xl);
}

.prose blockquote.dnd > h2 {
	padding-bottom: var(--space-1);
	border-bottom: 1px solid var(--dnd-red);
	font-size: var(--text-lg);
}

.prose blockquote.dnd > h3 {
	font-size: var(--text-md);
}

.prose blockquote.dnd > table,
.prose blockquote.dnd > ul,
.prose blockquote.dnd li::marker {
	color: var(--dnd-red);
}

.prose blockquote.dnd th {
	border-bottom: 2px solid var(--dnd-red);
	color: var(--dnd-red);
}

.prose blockquote.dnd td {
	border-bottom-color: var(--dnd-line);
}

/* A portrait in the first paragraph sits in the top right corner. */
.prose blockquote.dnd > p:first-child > img {
	position: absolute;
	top: var(--space-4);
	right: var(--space-4);
	width: auto;
	max-width: 30%;
}

/* ---- The hover card: a page under the pointer, before it is opened ----------------------- */

.preview-card {
	--preview-w: 22rem;
	--preview-img: 9rem;
	position: absolute;
	z-index: var(--z-fab);
	width: min(var(--preview-w), calc(100vw - 2 * var(--space-4)));
	border: var(--rule);
	border-top: 3px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	overflow: hidden;
	animation: preview-in 0.12s ease-out;
}

@keyframes preview-in {
	from { opacity: 0; transform: translateY(calc(-1 * var(--space-1))); }
	to { opacity: 1; transform: none; }
}

.preview-image {
	width: 100%;
	height: var(--preview-img);
	object-fit: cover;
	background: var(--surface);
}

.preview-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-4);
}

.preview-body h4 {
	font-family: var(--font-titles);
	font-size: var(--text-lg);
	font-weight: normal;
	line-height: 1.2;
	color: var(--accent);
}

.preview-meta {
	font-size: var(--text-xs);
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-faint);
}

.preview-desc {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 5;
	line-clamp: 5;
	overflow: hidden;
	font-size: var(--text-sm);
	line-height: var(--leading);
	color: var(--ink-muted);
}

@media (hover: none) {
	.preview-card {
		display: none;
	}
}

/* ---- The NPC chat: talk to the page's character, in the corner. DM's machine only ---------- */

.npc-chat {
	--chat-w: 26rem;
	--chat-log-h: 28rem;
	position: fixed;
	right: var(--space-4);
	bottom: var(--space-4);
	z-index: var(--z-fab);
	width: min(var(--chat-w), calc(100vw - 2 * var(--space-4)));
	border: var(--rule);
	border-top: 3px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	line-height: var(--leading);
}

/* With the secrets on, the whole box is marked: what is said here must not be seen by players. */
.npc-chat.secrets-on {
	border-color: var(--danger);
}

.npc-chat.collapsed {
	width: auto;
}

.npc-chat.collapsed .npc-chat-body {
	display: none;
}

.npc-chat-toggle {
	display: block;
	width: 100%;
	min-height: var(--control-h);
	padding: 0 var(--space-4);
	border: 0;
	background: none;
	color: var(--ink);
	font-weight: 600;
	text-align: left;
}

.npc-chat-body {
	display: flex;
	flex-direction: column;
	border-top: var(--rule);
}

.npc-chat-log {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	max-height: min(50vh, var(--chat-log-h));
	padding: var(--space-3) var(--space-4);
	overflow-y: auto;
}

.npc-chat-intro {
	font-size: var(--text-xs);
	font-style: italic;
	color: var(--ink-muted);
}

.npc-chat-msg {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
}

.npc-chat-who {
	font-size: var(--text-xs);
	letter-spacing: var(--tracking-caps);
	text-transform: uppercase;
	color: var(--ink-muted);
}

.npc-chat-msg.assistant .npc-chat-who {
	color: var(--accent);
}

.npc-chat-text {
	white-space: pre-wrap;
}

.npc-chat-msg.assistant .npc-chat-text {
	font-family: var(--font-prose);
	font-size: var(--text-md);
	font-style: italic;
}

.npc-chat-msg.thinking .npc-chat-text::after {
	content: "\2026";
	animation: npc-think 1s steps(4) infinite;
}

.npc-chat-msg.failed .npc-chat-text {
	font-family: var(--font-ui);
	font-style: normal;
	color: var(--danger);
}

@keyframes npc-think {
	0% { opacity: 0.2; }
	50% { opacity: 1; }
	100% { opacity: 0.2; }
}

.npc-chat-form {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-4);
	border-top: var(--rule);
}

.npc-chat-buttons {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

.npc-chat-buttons button[hidden] {
	display: none;
}

.npc-chat-secrets {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	margin-right: auto;
	font-size: var(--text-xs);
	color: var(--ink-muted);
}

.npc-chat.secrets-on .npc-chat-secrets {
	color: var(--danger);
	font-weight: 700;
}

/* On a phone the chat sits above the round Edit button in the same corner. */
@media (max-width: 768px) {
	.npc-chat {
		bottom: calc(var(--target) + 2 * var(--space-4));
	}
}

/* ---- Live: who else is here, who is editing, a word when the page is saved ---------------- */
/* A face takes its hue from the script (one per person) and keeps it in both themes. */

.live-pill,
.editor-faces {
	--face: 1.9rem;
	display: inline-flex;
	align-items: center;
}

.live-face {
	display: inline-grid;
	place-items: center;
	flex: none;
	width: var(--face);
	height: var(--face);
	margin-left: calc(-1 * var(--space-1));
	border: 2px solid var(--paper);
	border-radius: var(--radius-round);
	background: hsl(var(--face-hue, 30) 45% 38%);
	color: hsl(var(--face-hue, 30) 45% 96%);
	font-family: var(--font-ui);
	font-size: var(--text-xs);
	font-weight: 600;
	line-height: 1;
}

.live-face:first-child {
	margin-left: 0;
}

.live-face.editing {
	outline: 2px solid hsl(var(--face-hue, 30) 70% 60%);
}

.live-face.more {
	background: var(--surface-open);
	color: var(--ink);
}

.live-pill {
	position: fixed;
	left: var(--space-4);
	bottom: var(--space-4);
	z-index: var(--z-fab);
	min-height: var(--control-h);
	padding: 0 var(--space-3) 0 var(--space-1);
	border: var(--rule);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
}

.live-pill .live-text {
	margin-left: var(--space-2);
}

.live-toast {
	position: fixed;
	left: 50%;
	bottom: var(--space-4);
	z-index: var(--z-fab);
	display: flex;
	align-items: center;
	gap: var(--space-3);
	max-width: calc(100vw - 2 * var(--space-4));
	padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
	border: 1px solid var(--accent);
	border-radius: var(--radius);
	background: var(--paper);
	color: var(--ink);
	font-family: var(--font-ui);
	font-size: var(--text-sm);
	transform: translateX(-50%);
}

.live-pill[hidden],
.live-toast[hidden] {
	display: none;
}

.live-toast button {
	min-height: calc(var(--control-h) - var(--space-2));
	padding: 0 var(--space-3);
	border: var(--rule);
	border-radius: var(--radius);
	background: none;
	color: inherit;
	font-size: var(--text-sm);
	white-space: nowrap;
}

.live-toast .live-close {
	padding: 0 var(--space-2);
	border: 0;
	font-size: var(--text-lg);
	line-height: 1;
}

@media (max-width: 760px) {
	.live-pill .live-text {
		display: none;
	}

	.live-toast {
		bottom: calc(var(--space-4) + var(--control-h) + var(--space-2));
	}
}


/* ---- Print: nothing that floats over the page ----------------------------------------- */

@media print {
	.dice-tray,
	.npc-chat,
	.preview-card,
	.live-pill,
	.live-toast {
		display: none;
	}
}
