﻿/* =============================================================
   WorldBuilder UI system
   Loaded after Bootstrap, site.css and theme.css (see the layouts in Pages/Shared).
   Every color comes from theme.css tokens, so every palette works in light and dark.
   Guide: docs/UI-Guide.md
============================================================= */

:root {
	/* Type scale */
	--wb-text-xs: 0.8rem;
	--wb-text-sm: 0.875rem;
	--wb-text-base: 1rem;
	--wb-text-md: 1.125rem;
	--wb-text-lg: 1.25rem;
	--wb-text-xl: 1.5rem;
	--wb-text-2xl: 2rem;

	/* Spacing scale */
	--wb-space-1: 0.25rem;
	--wb-space-2: 0.5rem;
	--wb-space-3: 0.75rem;
	--wb-space-4: 1rem;
	--wb-space-5: 1.25rem;
	--wb-space-6: 1.5rem;
	--wb-space-7: 2rem;
	--wb-space-8: 3rem;

	/* Radius */
	--wb-radius-sm: 6px;
	--wb-radius-md: 8px;
	--wb-radius-lg: 12px;
	--wb-radius-pill: 999px;

	/* Widths for forms and narrow cards */
	--wb-measure-sm: 420px;
	--wb-measure-md: 560px;
	--wb-measure-lg: 720px;
}

.wb-measure-sm { max-width: var(--wb-measure-sm); }
.wb-measure-md { max-width: var(--wb-measure-md); }
.wb-measure-lg { max-width: var(--wb-measure-lg); }

/* -------------------------------------------------------------
   Page header: title, optional subtitle, actions on the right
   <header class="wb-page-header">
     <div><h1 class="wb-page-title">…</h1><p class="wb-page-subtitle">…</p></div>
     <div class="wb-page-actions">…buttons…</div>
   </header>
------------------------------------------------------------- */
.wb-page-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--wb-space-4);
	margin: var(--wb-space-6) 0;
}

.wb-page-title {
	margin: 0;
	font-family: var(--wb-heading-font, var(--wb-ui-font));
	font-size: var(--wb-text-2xl);
	font-weight: var(--wb-heading-weight, 600);
	line-height: 1.2;
}

.wb-page-subtitle {
	margin: var(--wb-space-1) 0 0;
	font-size: var(--wb-text-sm);
	color: var(--wb-muted);
}

.wb-page-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: var(--wb-space-2);
}

/* Section heading inside a page */
.wb-section-title {
	margin: var(--wb-space-7) 0 var(--wb-space-3);
	font-family: var(--wb-heading-font, var(--wb-ui-font));
	font-size: var(--wb-text-lg);
	font-weight: var(--wb-heading-weight, 600);
}

/* -------------------------------------------------------------
   Card (raised, for a self-contained block such as a form)
   Panel (flat, for grouping on the page: stats, filters, charts)
------------------------------------------------------------- */
.wb-card {
	padding: var(--wb-space-6);
	background: var(--wb-surface);
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-md);
	box-shadow: var(--wb-shadow-sm);
	color: var(--bs-body-color);
}

.wb-panel {
	padding: var(--wb-space-4) var(--wb-space-5);
	background: var(--wb-surface);
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-md);
	color: var(--bs-body-color);
}

.wb-card-title,
.wb-panel-title {
	margin: 0 0 var(--wb-space-3);
	font-family: var(--wb-heading-font, var(--wb-ui-font));
	font-size: var(--wb-text-base);
	font-weight: var(--wb-heading-weight, 600);
}

.wb-card-title {
	font-size: var(--wb-text-lg);
}

/* -------------------------------------------------------------
   Empty state: optional icon, a title, one line, a call to action
------------------------------------------------------------- */
.wb-empty {
	padding: var(--wb-space-8) var(--wb-space-4);
	text-align: center;
	background: var(--wb-surface-2);
	border: 1px dashed var(--wb-border);
	border-radius: var(--wb-radius-md);
	color: var(--bs-body-color);
}

.wb-empty-icon {
	display: block;
	width: 32px;
	height: 32px;
	margin: 0 auto var(--wb-space-3);
	color: var(--wb-muted);
}

.wb-empty-title {
	margin: 0 0 var(--wb-space-2);
	font-family: var(--wb-heading-font, var(--wb-ui-font));
	font-size: var(--wb-text-xl);
	font-weight: var(--wb-heading-weight, 600);
}

.wb-empty-text {
	max-width: 36rem;
	margin: 0 auto var(--wb-space-4);
	color: var(--wb-muted);
}

	.wb-empty-text:last-child {
		margin-bottom: 0;
	}

.wb-empty-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var(--wb-space-3);
}

/* Smaller version for a section inside a page or panel */
.wb-empty--compact {
	padding: var(--wb-space-6) var(--wb-space-4);
}

	.wb-empty--compact .wb-empty-title {
		font-size: var(--wb-text-md);
	}

/* -------------------------------------------------------------
   Pills (labels, tags, small links) and badges (counts)
------------------------------------------------------------- */
.wb-pill {
	display: inline-flex;
	align-items: center;
	gap: var(--wb-space-1);
	padding: 0.05rem var(--wb-space-2);
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-pill);
	background: var(--wb-surface);
	color: var(--bs-body-color);
	font-size: var(--wb-text-xs);
	line-height: 1.6;
	white-space: nowrap;
	text-decoration: none;
}

a.wb-pill:hover,
button.wb-pill:hover {
	border-color: var(--wb-muted);
	color: var(--bs-body-color);
	text-decoration: none;
}

a.wb-pill:focus-visible,
button.wb-pill:focus-visible {
	outline: 2px solid var(--wb-focus-ring);
	outline-offset: 2px;
}

.wb-pill--muted { color: var(--wb-muted); }
.wb-pill--accent { background: var(--wb-accent-subtle); border-color: transparent; }
.wb-pill--attention { background: var(--wb-attention); border-color: transparent; color: var(--wb-attention-text, currentColor); }
.wb-pill--danger { color: var(--wb-danger-text); border-color: currentColor; }
.wb-pill--success { color: var(--wb-success-text); border-color: currentColor; }

.wb-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 1.6em;
	padding: 0 0.45em;
	border-radius: var(--wb-radius-pill);
	background: var(--wb-surface-2);
	color: var(--bs-body-color);
	font-size: var(--wb-text-xs);
	font-weight: 600;
	line-height: 1.6;
}

.wb-badge--accent { background: var(--wb-accent); color: var(--wb-on-accent); }
.wb-badge--attention { background: var(--wb-attention); color: var(--wb-attention-text, currentColor); }
.wb-badge--danger { background: var(--wb-danger-text); color: var(--wb-surface); }

/* -------------------------------------------------------------
   Form field: label, control, hint, error
   Controls are Bootstrap's .form-control / .form-select.
------------------------------------------------------------- */
.wb-field {
	display: flex;
	flex-direction: column;
	margin-bottom: var(--wb-space-5);
}

	.wb-field > label,
	.wb-field-label {
		margin-bottom: var(--wb-space-1);
		font-weight: 600;
	}

	.wb-field .form-control,
	.wb-field .form-select {
		background-color: var(--wb-surface);
		border-color: var(--wb-input-border, var(--wb-border));
		color: var(--bs-body-color);
	}

		.wb-field .form-control:focus,
		.wb-field .form-select:focus {
			border-color: var(--wb-accent);
		}

.wb-field-hint {
	margin-top: var(--wb-space-1);
	font-size: var(--wb-text-sm);
	color: var(--wb-muted);
}

.wb-field-error {
	margin-top: var(--wb-space-1);
	font-size: var(--wb-text-sm);
	color: var(--wb-danger-text);
}

	.wb-field-error:empty {
		display: none;
	}

/* A group of radios or checkboxes */
fieldset.wb-field {
	min-width: 0;
	margin-left: 0;
	margin-right: 0;
	padding: 0;
	border: 0;
}

.wb-field-legend {
	margin-bottom: var(--wb-space-2);
	font-size: var(--wb-text-base);
	font-weight: 600;
}

/* Buttons at the end of a form */
.wb-form-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--wb-space-3);
	margin-top: var(--wb-space-6);
}

/* -------------------------------------------------------------
   List rows
   <ul class="wb-list"><li class="wb-list-row">
     <span class="wb-list-row-main">…</span> …meta, pills, buttons…
   </li></ul>
   The row itself may be an <a> to make the whole row a link.
------------------------------------------------------------- */
.wb-list {
	display: flex;
	flex-direction: column;
	gap: var(--wb-space-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.wb-list-row {
	display: flex;
	align-items: center;
	gap: var(--wb-space-2);
	min-height: 2.75rem;
	padding: var(--wb-space-2) var(--wb-space-3);
	background: var(--wb-surface-2);
	border-radius: var(--wb-radius-sm);
	color: var(--bs-body-color);
}

.wb-list-row-main {
	flex: 1 1 auto;
	min-width: 0;
	overflow-wrap: anywhere;
}

.wb-list-row-meta {
	flex: none;
	font-size: var(--wb-text-sm);
	color: var(--wb-muted);
}

a.wb-list-row {
	text-decoration: none;
}

	a.wb-list-row:hover {
		background: color-mix(in srgb, var(--wb-surface-2), var(--bs-body-color) 6%);
		color: var(--bs-body-color);
	}

	a.wb-list-row:focus-visible {
		outline: 2px solid var(--wb-focus-ring);
		outline-offset: 2px;
	}

/* -------------------------------------------------------------
   Menu: add to a Bootstrap .dropdown-menu
------------------------------------------------------------- */
.wb-menu {
	--bs-dropdown-bg: var(--wb-surface);
	--bs-dropdown-color: var(--bs-body-color);
	--bs-dropdown-border-color: var(--wb-border);
	--bs-dropdown-border-radius: var(--wb-radius-md);
	--bs-dropdown-padding-x: var(--wb-space-1);
	--bs-dropdown-padding-y: var(--wb-space-1);
	--bs-dropdown-link-color: var(--bs-body-color);
	--bs-dropdown-link-hover-color: var(--bs-body-color);
	--bs-dropdown-link-hover-bg: var(--wb-surface-2);
	--bs-dropdown-link-active-color: var(--bs-body-color);
	--bs-dropdown-link-active-bg: var(--wb-accent-subtle);
	--bs-dropdown-divider-bg: var(--wb-border);
	--bs-dropdown-item-padding-x: var(--wb-space-3);
	--bs-dropdown-item-padding-y: 0.4rem;
	box-shadow: var(--wb-shadow-md);
}

	.wb-menu .dropdown-item {
		border-radius: var(--wb-radius-sm);
	}

	.wb-menu .dropdown-divider {
		margin: var(--wb-space-1) 0;
	}

	.wb-menu .wb-menu-item-danger,
	.wb-menu .wb-menu-item-danger:hover {
		color: var(--wb-danger-text);
	}

/* -------------------------------------------------------------
   Toolbar: a row of controls above content
------------------------------------------------------------- */
.wb-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--wb-space-2);
	margin-bottom: var(--wb-space-4);
}

	.wb-toolbar .form-control,
	.wb-toolbar .form-select {
		width: auto;
	}

.wb-toolbar-spacer {
	flex: 1 1 auto;
}

/* -------------------------------------------------------------
   Buttons: opt-in modifiers layered on Bootstrap .btn.
   .btn-primary (the palette accent) and .btn-outline-secondary are
   themed in theme.css. Nothing here changes a
   plain .btn, so the editor toolbar is unaffected.
------------------------------------------------------------- */

/* Quiet: no border or fill until hovered, for secondary actions in rows */
.btn.btn-quiet {
	--bs-btn-color: var(--wb-muted);
	--bs-btn-bg: transparent;
	--bs-btn-border-color: transparent;
	--bs-btn-hover-color: var(--bs-body-color);
	--bs-btn-hover-bg: var(--wb-hover);
	--bs-btn-hover-border-color: transparent;
	--bs-btn-active-color: var(--bs-body-color);
	--bs-btn-active-bg: var(--wb-hover);
	--bs-btn-active-border-color: transparent;
}

/* Danger without the red fill: destructive actions that aren't the main one */
.btn.btn-danger-text {
	--bs-btn-color: var(--wb-danger-text);
	--bs-btn-bg: transparent;
	--bs-btn-border-color: transparent;
	--bs-btn-hover-color: var(--wb-danger-text);
	--bs-btn-hover-bg: color-mix(in srgb, var(--wb-danger-text) 12%, transparent);
	--bs-btn-hover-border-color: transparent;
	--bs-btn-active-color: var(--wb-danger-text);
	--bs-btn-active-bg: color-mix(in srgb, var(--wb-danger-text) 18%, transparent);
	--bs-btn-active-border-color: transparent;
}

/* Square, icon-only. Always give it an aria-label. */
.btn.btn-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	padding: 0;
	line-height: 1;
}

/* -------------------------------------------------------------
   Theme picker (_Header.cshtml, wired by theme.js)
   Each option shows the palette's light and dark ground with its
   accent dot. These are previews of fixed palettes, so the swatch
   colours are literal on purpose.
------------------------------------------------------------- */
.wb-theme-menu {
	min-width: 13rem;
}

	.wb-theme-menu .dropdown-item {
		display: flex;
		align-items: center;
		gap: var(--wb-space-3);
	}

.wb-theme-swatch {
	display: inline-flex;
	flex: none;
	width: 2.25rem;
	height: 1.25rem;
	overflow: hidden;
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-sm);
}

	.wb-theme-swatch > span {
		position: relative;
		flex: 1 1 50%;
		background: var(--sw-ground);
	}

		.wb-theme-swatch > span::after {
			content: "";
			position: absolute;
			top: 50%;
			left: 50%;
			width: 7px;
			height: 7px;
			margin: -3.5px 0 0 -3.5px;
			border-radius: 50%;
			background: var(--sw-accent);
		}

.wb-theme-swatch--paper > :first-child { --sw-ground: #fbf8f2; --sw-accent: #2c4a78; }
.wb-theme-swatch--paper > :last-child { --sw-ground: #1f1d19; --sw-accent: #8eaee0; }
.wb-theme-swatch--lamp > :first-child { --sw-ground: #fbfaf8; --sw-accent: #8a5a12; }
.wb-theme-swatch--lamp > :last-child { --sw-ground: #1b1813; --sw-accent: #e2a447; }
.wb-theme-swatch--studio > :first-child { --sw-ground: #ffffff; --sw-accent: #22685c; }
.wb-theme-swatch--studio > :last-child { --sw-ground: #181c1f; --sw-accent: #5fb3a1; }
.wb-theme-swatch--classic > :first-child { --sw-ground: #ffffff; --sw-accent: #3f5fe0; }
.wb-theme-swatch--classic > :last-child { --sw-ground: #0f172a; --sw-accent: #6ea8fe; }

.wb-theme-name {
	flex: 1 1 auto;
}

.wb-theme-check {
	flex: none;
	width: 16px;
	height: 16px;
	color: var(--wb-accent);
	visibility: hidden;
}

	.wb-theme-menu [aria-checked="true"] .wb-theme-check {
		visibility: visible;
	}

	.wb-theme-menu [aria-checked="true"] {
		font-weight: 600;
	}


/* -------------------------------------------------------------
   Skip link (first thing in <body> in all three layouts).
   Bootstrap's .visually-hidden-focusable hides it until it has focus.
------------------------------------------------------------- */
.wb-skip:focus,
.wb-skip:focus-visible {
	position: fixed !important;
	top: var(--wb-space-2);
	left: var(--wb-space-2);
	z-index: 2000;
	padding: var(--wb-space-2) var(--wb-space-4);
	border: 2px solid var(--wb-focus-ring);
	border-radius: var(--wb-radius-sm);
	background: var(--wb-surface);
	color: var(--bs-body-color);
	box-shadow: var(--wb-shadow-md);
	font-weight: 600;
	text-decoration: none;
}

/* <main id="main" tabindex="-1"> is only a skip-link target, not a control */
#main:focus {
	outline: none;
}

/* -------------------------------------------------------------
   Reduced motion: honour the OS setting everywhere (WCAG 2.3.3).
   Animations and transitions finish at once; smooth scrolling is off.
   JS that scrolls checks matchMedia('(prefers-reduced-motion: reduce)').
------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/* -------------------------------------------------------------
   Forced colours (Windows High Contrast): box-shadow focus rings and
   coloured dots disappear, so give focus a real outline.
------------------------------------------------------------- */
@media (forced-colors: active) {
	:focus-visible {
		outline: 2px solid CanvasText !important;
		outline-offset: 2px;
	}
}

/* -------------------------------------------------------------
   Branches (docs/Design-Branching.md): the muted "not in this branch" label
   on Outline items and Hero's Journey stages linked to a chapter outside
   the current branch. Text, not colour alone.
------------------------------------------------------------- */
.wb-branch-missing {
	display: inline-block;
	font-size: var(--wb-text-xs);
	font-style: italic;
	color: var(--wb-muted);
	white-space: nowrap;
}

/* Tabs (Circles) */
/* -------------------------------------------------------------
   Tabs: a row of links between sibling views of one area, each with its
   own URL (Circles: "Shared with me" | "Circles I run"). The current tab
   has aria-current="page"; the underline marks it, and the bold weight
   means it never depends on colour alone.
   <nav class="wb-tabs" aria-label="Circles">
     <a class="wb-tab" href="…" aria-current="page">Shared with me</a>
     <a class="wb-tab" href="…">Circles I run</a>
   </nav>
------------------------------------------------------------- */
.wb-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wb-space-1);
	margin: calc(-1 * var(--wb-space-3)) 0 var(--wb-space-4);
	border-bottom: 1px solid var(--wb-border);
}

.wb-tab {
	display: inline-block;
	padding: var(--wb-space-2) var(--wb-space-3);
	margin-bottom: -1px;
	border-bottom: 2px solid transparent;
	border-radius: var(--wb-radius-sm) var(--wb-radius-sm) 0 0;
	color: var(--wb-muted);
	font-size: var(--wb-text-sm);
	text-decoration: none;
}

.wb-tab:hover {
	color: var(--bs-body-color);
	background: var(--wb-hover);
	text-decoration: none;
}

.wb-tab:focus-visible {
	outline: 2px solid var(--wb-focus-ring);
	outline-offset: 2px;
}

.wb-tab[aria-current="page"] {
	color: var(--bs-body-color);
	font-weight: 600;
	border-bottom-color: var(--wb-accent);
}

/* View switcher (Plan, Notes) */
/* -------------------------------------------------------------
   Switcher between the two views behind one book tab (Pages/Shared/_ViewSwitch.cshtml):
   Plan = Outline | Hero's Journey, Notes = Notes | Characters | Family tree. Real links; the current
   one has aria-current="page" (tint and bold weight, so not colour alone). It takes the
   place of the visible page title, and is sized like .btn-sm so it fits a toolbar row.
   <nav class="wb-switch" aria-label="Plan views">
     <a class="wb-switch-item" href="…" aria-current="page">Outline</a>
     <a class="wb-switch-item" href="…">Hero's Journey</a>
   </nav>
------------------------------------------------------------- */
.wb-switch {
	display: inline-flex;
	vertical-align: top; /* no baseline gap under it, so it adds no height to a toolbar row */
	flex: none;
	max-width: 100%;
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-sm);
	background: var(--wb-surface);
	overflow: hidden;
}

.wb-switch-item {
	display: block;
	padding: var(--wb-space-1) var(--wb-space-3);
	color: var(--wb-muted);
	font-size: var(--wb-text-sm);
	line-height: 1.5;
	text-decoration: none;
	white-space: nowrap;
}

	.wb-switch-item + .wb-switch-item {
		border-left: 1px solid var(--wb-border);
	}

	.wb-switch-item:hover {
		color: var(--bs-body-color);
		background: var(--wb-hover);
		text-decoration: none;
	}

	/* inset, because the switcher clips its rounded corners */
	.wb-switch-item:focus-visible {
		outline: 2px solid var(--wb-focus-ring);
		outline-offset: -2px;
	}

	.wb-switch-item[aria-current="page"] {
		color: var(--bs-body-color);
		background: var(--wb-accent-subtle);
		font-weight: 600;
	}

@media (forced-colors: active) {
	.wb-switch-item[aria-current="page"] {
		text-decoration: underline;
	}
}

/* a little room between the switcher and the page subtitle under it */
.wb-switch ~ .wb-page-subtitle {
	margin-top: var(--wb-space-2);
}

/* -------------------------------------------------------------
   Character cards (Pages/Characters/Index): a grid of raised
   cards, the name is a stretched link so the whole card opens
   the character's page.
   <ul class="wb-char-grid">
     <li class="wb-char-card">
       <h2 class="wb-char-card-name"><a class="stretched-link" href="…">Mara Varren</a></h2>
       <p class="wb-char-card-aka">Also Mae</p>
       <p class="wb-char-card-role">Heir to House Varren</p>
       <p class="wb-char-card-excerpt">The start of the description…</p>
       <p class="wb-char-card-meta">Appears in 4 chapters</p>
     </li>
   </ul>
------------------------------------------------------------- */
.wb-char-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
	gap: var(--wb-space-4);
	margin: 0;
	padding: 0;
	list-style: none;
}

.wb-char-card {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: var(--wb-space-1);
	min-width: 0;
	padding: var(--wb-space-4) var(--wb-space-5);
	background: var(--wb-surface);
	border: 1px solid var(--wb-border);
	border-radius: var(--wb-radius-md);
	box-shadow: var(--wb-shadow-sm);
	color: var(--bs-body-color);
}

	.wb-char-card:hover {
		border-color: var(--wb-input-border, var(--wb-border));
	}

	.wb-char-card:has(.stretched-link:focus-visible) {
		outline: 2px solid var(--wb-focus-ring);
		outline-offset: 2px;
	}

	.wb-char-card p {
		margin: 0;
	}

.wb-char-card-name {
	margin: 0;
	font-family: var(--wb-heading-font, var(--wb-ui-font));
	font-size: var(--wb-text-lg);
	font-weight: var(--wb-heading-weight, 600);
	overflow-wrap: anywhere;
}

	.wb-char-card-name a {
		color: inherit;
		text-decoration: none;
	}

		.wb-char-card-name a:hover {
			text-decoration: underline;
		}

		.wb-char-card-name a:focus-visible {
			outline: none;
		}

.wb-char-card-aka,
.wb-char-card-meta {
	font-size: var(--wb-text-sm);
	color: var(--wb-muted);
	overflow-wrap: anywhere;
}

.wb-char-card-role {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.wb-char-card-excerpt {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	overflow-wrap: anywhere;
}

	.wb-char-card .wb-char-card-meta {
		margin-top: auto;
		padding-top: var(--wb-space-2);
	}

@media (forced-colors: active) {
	.wb-char-card:has(.stretched-link:focus-visible) {
		outline: 2px solid Highlight;
	}
}
