/* The world graph page. Loaded after style.css, on this page only. */

body.graph-page {
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	background: var(--bg);
	background-attachment: fixed;
}

.graph-app {
	/* The canvas reads these, so every colour it draws follows the theme. */
	--graph-ink: #222222;
	--graph-muted: #5a574f;
	--graph-edge: #7d776a;
	--graph-surface: #f7f4ec;
	--graph-accent: var(--world-accent, var(--color-active));
	--graph-line: rgba(0, 0, 0, 0.12);

	display: grid;
	grid-template-rows: auto auto minmax(0, 1fr);
	height: 100%;
	color: var(--graph-ink);
	font-family: var(--font-ui);
}

@media (prefers-color-scheme: dark) {
	.graph-app {
		--graph-ink: #e4e2dc;
		--graph-muted: #a9a69c;
		--graph-edge: #8b877c;
		--graph-surface: #151515;
		--graph-line: rgba(255, 255, 255, 0.1);
	}
}

.graph-app [hidden] {
	display: none !important;
}

/* The site's headings are page titles with a rule under them; here they are labels. The h2s are
   the sidebars' titles and keep the Connections column's look from style.css. */
.graph-app h3,
.graph-app h4 {
	width: auto;
	border: 0;
	font-family: var(--font-ui);
	font-weight: 600;
	color: var(--graph-ink);
}

	/* Section headings in the sidebars are the Connections column's, weight and all. */
	.graph-app .relation h3 {
		font-weight: normal;
	}

.graph-app p,
.graph-app li {
	color: inherit;
}

/* ---------- top bar ---------- */

.graph-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 0.9rem;
	padding: 0.5rem 1rem;
	background: var(--color-surface);
	border-top: 3px solid var(--graph-accent);
	border-bottom: 1px solid var(--graph-line);
}

.graph-back {
	color: var(--graph-ink);
	text-decoration: none;
	font-family: var(--font-titles);
	font-size: 1.35rem;
	text-transform: capitalize;
	white-space: nowrap;
}

	.graph-back:hover {
		color: var(--graph-accent);
	}

.graph-name {
	font-size: 0.75rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--graph-muted);
}

.graph-search {
	position: relative;
	flex: 1 1 14rem;
	max-width: 26rem;
}

	.graph-search input {
		width: 100%;
		padding: 0.4rem 0.6rem;
		font: inherit;
		font-size: 0.9rem;
		color: var(--graph-ink);
		background: var(--graph-surface);
		border: 1px solid var(--graph-line);
		border-radius: 4px;
	}

		.graph-search input:focus {
			outline: none;
			border-color: var(--graph-accent);
		}

.graph-results {
	position: absolute;
	z-index: 20;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	margin: 0;
	padding: 0.25rem;
	list-style: none;
	background: var(--graph-surface);
	border: 1px solid var(--graph-line);
	border-radius: 4px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.graph-result,
.graph-result-none {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.35rem 0.5rem;
	border-radius: 3px;
	font-size: 0.9rem;
}

.graph-result {
	cursor: pointer;
}

	.graph-result:hover,
	.graph-result.active {
		background: var(--color-active-soft);
	}

.graph-result-none {
	color: var(--graph-muted);
}

.graph-tools {
	display: flex;
	gap: 0.4rem;
	margin-left: auto;
}

.graph-button {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.3rem 0.7rem;
	font: inherit;
	font-size: 0.8rem;
	line-height: 1.4;
	color: var(--graph-ink);
	background: var(--graph-surface);
	border: 1px solid var(--graph-line);
	border-radius: 4px;
	cursor: pointer;
	text-decoration: none;
	white-space: nowrap;
}

	.graph-button:hover,
	.graph-button:focus-visible {
		color: var(--graph-ink);
		border-color: var(--graph-accent);
	}

	.graph-button.primary,
	.graph-button.primary:hover {
		color: #fff;
		background: var(--graph-accent);
		border-color: var(--graph-accent);
	}

		.graph-button.primary:hover {
			filter: brightness(1.08);
		}

	.graph-button[aria-pressed="true"] {
		background: var(--color-active-soft);
		border-color: var(--graph-accent);
	}

/* Preset filters above a filter list, and how many lines are drawn. */
.graph-presets {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.4rem;
	margin-bottom: 0.5rem;
}

.graph-line-total {
	/* Room for four digits, so a count growing by one cannot wrap the row and move the list below. */
	min-width: 4.5em;
	white-space: nowrap;
	text-align: right;
	margin-left: auto;
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	color: var(--graph-muted);
}

/* How many lines a click on a relation adds (+) or removes (−). */
.graph-toggle-delta {
	margin-left: auto;
	padding-left: 0.4rem;
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	color: var(--graph-accent);
}

	.graph-toggle-delta.more {
		color: var(--graph-muted);
	}

	.graph-toggle-delta:not(:empty) + .count {
		margin-left: 0;
	}

/* ---------- body: filters, stage, panel ---------- */

.graph-body {
	display: grid;
	grid-template-columns: 16rem minmax(0, 1fr) auto;
	min-height: 0;
}

/* style.css places every aside in a world page's "aside" grid area, sticky and top-aligned. Here
   that area does not exist: the grid would invent tracks for it and squeeze the stage into a corner. */
.graph-app aside {
	grid-area: auto;
	justify-self: stretch;
	align-self: stretch;
}

.graph-filters,
.graph-panel {
	grid-row: 1;

	/* style.css gives every aside top: 1rem for its sticky panel; on these relative ones it
	   only pushed them a line down, below the canvas edge and past the bottom of the screen. */
	top: 0;
	min-height: 0;
	max-height: none;
	overflow-y: auto;

	/* Like a world page's columns: on the page's own ground, no box around them. */
	background: transparent;
}

.graph-filters {
	grid-column: 1;
	position: relative;
	padding: 0.75rem 1rem 1.5rem;
}

	.graph-filters .identity {
		margin-bottom: 0.75rem;
	}

	/* Only the drawer on a narrow screen has a close button. */
	.graph-filters .nav-close {
		display: none;
	}

.graph-app .graph-status {
	margin: 0.25rem 0 0.75rem;
	font-size: 0.8rem;
	/* Always two lines tall: the counts change with every filter, and a status that wrapped to a
	   second line only sometimes moved every filter below it. */
	line-height: 1.4;
	min-height: 2.8em;
	color: var(--graph-muted);
}

.graph-filter {
	margin-bottom: 1.1rem;
}

.graph-app .graph-section-title {
	margin: 0 0 0.4rem;
	font-size: 0.72rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--graph-muted);
}

.graph-legend {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Rows are buttons here and links in the Connections column, with the same look: .relations a in
   style.css, an accent bar down the left on hover. */
.graph-toggle {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	width: 100%;
	padding: 0.2rem 0.4rem;
	font: inherit;
	font-size: 0.85rem;
	line-height: 1.35;
	text-align: left;
	color: var(--color-link);
	background: none;
	border: 0;
	border-left: 2px solid transparent;
	border-radius: 0 var(--radius) var(--radius) 0;
	cursor: pointer;
	transition: background 0.12s ease, color 0.12s ease;
}

	.graph-toggle:hover {
		color: var(--color-active);
		border-left-color: var(--color-active);
		background: var(--color-active-soft);
	}

	.graph-toggle[aria-pressed="false"] {
		opacity: 0.45;
	}

		.graph-toggle[aria-pressed="false"] .graph-toggle-name {
			text-decoration: line-through;
		}

/* A kind and, where the world declares them, its sub-kinds folded away beneath it. */
.graph-legend-row {
	display: flex;
	align-items: center;
	gap: 0.15rem;
}

	.graph-legend-row .graph-toggle {
		flex: 1;
		min-width: 0;
	}

.graph-caret,
.graph-caret-spacer {
	flex: none;
	width: 1.1rem;
	height: 1.1rem;
}

.graph-caret {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	color: var(--graph-ink);
	background: none;
	border: 0;
	border-radius: 3px;
	cursor: pointer;
	opacity: 0.55;
}

	.graph-caret:hover {
		opacity: 1;
		background: var(--color-active-soft);
	}

	.graph-caret::before {
		content: "";
		border-style: solid;
		border-width: 0.3rem 0 0.3rem 0.36rem;
		border-color: transparent transparent transparent currentColor;
		transition: transform 0.12s ease;
	}

	.graph-caret[aria-expanded="true"]::before {
		transform: rotate(90deg);
	}

.graph-sublegend {
	margin: 0.05rem 0 0.2rem 1.5rem;
	padding: 0 0 0 0.35rem;
	list-style: none;
	border-left: 1px solid var(--graph-line);
}

	.graph-sublegend .graph-toggle {
		font-size: 0.8rem;
	}

.graph-toggle-name {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.graph-app .count {
	margin-left: auto;
	padding-left: 0.4rem;
	font-size: 0.75rem;
	font-weight: normal;
	font-variant-numeric: tabular-nums;
	color: var(--graph-muted);
}

.graph-swatch {
	flex: none;
	width: 16px;
	height: 16px;
}

.graph-app .graph-filter-hint {
	margin: 0.35rem 0 0;
	font-size: 0.75rem;
	color: var(--graph-muted);
}

.graph-check,
.graph-select-row {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0.2rem 0;
	font-size: 0.85rem;
	cursor: pointer;
}

	.graph-select-row select {
		margin-left: auto;
		font: inherit;
		font-size: 0.8rem;
		color: var(--graph-ink);
		background: var(--graph-surface);
		border: 1px solid var(--graph-line);
		border-radius: 3px;
	}

.graph-range {
	width: 100%;
	accent-color: var(--graph-accent);
}

.graph-key ul {
	margin: 0;
	padding-left: 1rem;
}

.graph-app .graph-key li {
	margin-bottom: 0.25rem;
	font-size: 0.78rem;
	color: var(--graph-muted);
}

.graph-stage {
	grid-column: 2;
	grid-row: 1;
	position: relative;
	min-height: 0;
	overflow: hidden;
	background: var(--graph-surface);
}

	/* Out of flow, so the pixel size the script gives it can never feed back into the layout it measures. */
	.graph-stage canvas {
		position: absolute;
		inset: 0;
		display: block;
		width: 100%;
		height: 100%;
		touch-action: none;
		cursor: grab;
	}

		.graph-stage canvas.dragging {
			cursor: grabbing;
		}

.graph-tip {
	position: absolute;
	z-index: 5;
	display: flex;
	flex-direction: column;
	max-width: 18rem;
	padding: 0.4rem 0.6rem;
	pointer-events: none;
	font-size: 0.85rem;
	background: var(--color-bg-soft);
	border: 1px solid var(--graph-line);
	border-radius: 4px;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

	.graph-tip span {
		font-size: 0.75rem;
		color: var(--graph-muted);
	}

.graph-app .graph-empty {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 2rem;
	text-align: center;
	color: var(--graph-muted);
}

/* ---------- selected node ---------- */

.graph-panel {
	grid-column: 3;
	position: relative;
	width: 21rem;
	padding: 1rem 1.1rem 1.5rem;
}

.graph-close {
	position: absolute;
	top: 0.5rem;
	right: 0.6rem;
	width: 2rem;
	height: 2rem;
	font-size: 1.4rem;
	line-height: 1;
	color: var(--graph-muted);
	background: none;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
}

	.graph-close:hover {
		color: var(--graph-ink);
		background: var(--color-active-soft);
	}

.graph-panel-image {
	display: block;
	width: 100%;
	max-height: 11rem;
	margin-bottom: 0.75rem;
	object-fit: cover;
	border-radius: 4px;
}

/* Not the Connections title's width: 100%: next to the margin that keeps it clear of the close
   button, that made it wider than the panel and gave the panel a sideways scrollbar. */
.graph-app .graph-panel-title {
	width: auto;
	margin: 0 2rem 0.25rem 0;
	font-size: 1.3rem;
}

.graph-app .graph-panel-meta {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0 0 0.6rem;
	font-size: 0.8rem;
	color: var(--graph-muted);
}

.graph-app .graph-panel-description {
	margin: 0 0 0.8rem;
	font-size: 0.9rem;
	line-height: 1.45;
}

.graph-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-bottom: 1rem;
}

.graph-depth {
	font: inherit;
	font-size: 0.8rem;
	color: var(--graph-ink);
	background: var(--graph-surface);
	border: 1px solid var(--graph-line);
	border-radius: 4px;
}

.graph-relation ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.graph-relation li {
	margin: 0 0 0.1rem;
}

.graph-link {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	width: 100%;
	padding: 0.2rem 0.4rem;
	font: inherit;
	font-size: 0.88rem;
	line-height: 1.35;
	text-align: left;
	color: var(--color-link);
	background: none;
	border: 0;
	border-left: 2px solid transparent;
	border-radius: 0 var(--radius) var(--radius) 0;
	cursor: pointer;
	transition: background 0.12s ease, color 0.12s ease;
}

	.graph-link:hover,
	.graph-link:focus-visible {
		color: var(--color-active);
		border-left-color: var(--color-active);
		background: var(--color-active-soft);
	}

.graph-link-title {
	flex: 1;
	min-width: 0;
}

.graph-link-world {
	font-size: 0.72rem;
	white-space: nowrap;
	color: var(--graph-muted);
}

.graph-link-when,
.graph-link-note {
	display: block;
	margin: 0 0 0.25rem 1.9rem;
	font-size: 0.75rem;
	color: var(--graph-muted);
}

.graph-link-note {
	font-style: italic;
}

.graph-app .graph-panel-hint {
	font-size: 0.8rem;
	color: var(--graph-muted);
}

/* ---------- narrow screens: filters are the world page's drawer, the panel a bottom bar ---------- */

/* The same query as style.css's mobile bar, so the bar and the drawer it opens arrive together. */
@media (max-width: 768px), (pointer: coarse), (orientation: portrait) {
	.graph-body {
		position: relative;
		grid-template-columns: minmax(0, 1fr);
	}

	.graph-stage {
		grid-column: 1;
	}

	/* The mobile bar above already names the world and draws the accent line. */
	.graph-back,
	.graph-name {
		display: none;
	}

	.graph-bar {
		border-top: 0;
	}

	/* A world page's nav drawer (.has-drawer nav in style.css), here for the filters. */
	.graph-filters {
		position: fixed;
		z-index: 1000;
		inset: 0 auto 0 0;
		width: min(85vw, 22rem);
		padding: 3.5rem 1rem 1.5rem;
		padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
		overscroll-behavior: contain;
		background-color: var(--color-bg-soft);
		background-image: var(--bg);
		box-shadow: 4px 0 20px rgba(0, 0, 0, 0.35);
		transform: translateX(-100%);
		visibility: hidden;
		transition: transform 0.25s ease, visibility 0s linear 0.25s;
	}

	.graph-app.filters-open .graph-filters {
		transform: none;
		visibility: visible;
		transition: transform 0.25s ease, visibility 0s;
	}

		.graph-filters .nav-close {
			display: block;
		}

	.graph-panel {
		grid-column: auto;
		position: absolute;
		z-index: 9;
		top: auto;
		left: 0;
		right: 0;
		bottom: 0;
		width: auto;
		max-height: 55%;
		padding: 0.6rem 1rem 0.75rem;
		padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
		background: var(--color-bg-soft);
		border-left: 0;
		border-top: 1px solid var(--graph-line);
		border-radius: 10px 10px 0 0;
		box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.2);
	}

		/* A small bar, not the whole sheet: the name, what it is, and the way to its page.
		   The picture, the description and the connections stay on wide screens. */
		.graph-panel-image,
		.graph-app .graph-panel-description,
		.graph-connections,
		.graph-app .graph-panel-hint {
			display: none;
		}

		.graph-app .graph-panel-title {
			margin: 0 2.25rem 0.1rem 0;
			font-size: 1.05rem;
		}

		.graph-app .graph-panel-meta {
			margin-bottom: 0.5rem;
		}

		.graph-actions {
			margin-bottom: 0;
		}

	.graph-tools {
		margin-left: 0;
	}
}
