/* 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 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. */
.graph-app h2,
.graph-app h3,
.graph-app h4 {
	width: auto;
	border: 0;
	font-family: var(--font-ui);
	font-weight: 600;
	color: var(--graph-ink);
}

.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);
	}

.graph-filters-button {
	display: none;
}

/* ---------- 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;
	min-height: 0;
	max-height: none;
	overflow-y: auto;
	background: var(--color-bg-soft);
}

.graph-filters {
	grid-column: 1;
	position: relative;
	padding: 0.75rem 0.9rem 1.5rem;
	border-right: 1px solid var(--graph-line);
}

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

.graph-app .graph-status {
	margin: 0.25rem 0 0.75rem;
	font-size: 0.8rem;
	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;
}

.graph-toggle {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	width: 100%;
	padding: 0.25rem 0.4rem;
	font: inherit;
	font-size: 0.85rem;
	text-align: left;
	color: var(--graph-ink);
	background: none;
	border: 0;
	border-radius: 3px;
	cursor: pointer;
}

	.graph-toggle:hover {
		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;
	border-left: 1px solid var(--graph-line);
}

.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;
}

.graph-app .graph-panel-title {
	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-app .graph-relation h4 {
	display: flex;
	margin: 0.8rem 0 0.25rem;
	font-size: 0.85rem;
}

.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.25rem 0.35rem;
	font: inherit;
	font-size: 0.88rem;
	text-align: left;
	color: var(--graph-ink);
	background: none;
	border: 0;
	border-radius: 3px;
	cursor: pointer;
}

	.graph-link:hover,
	.graph-link:focus-visible {
		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 slide in, the panel is a bottom sheet ---------- */

@media (max-width: 900px) {
	.graph-body {
		position: relative;
		grid-template-columns: minmax(0, 1fr);
	}

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

	.graph-filters-button {
		display: inline-flex;
	}

	.graph-filters {
		position: absolute;
		z-index: 10;
		inset: 0 auto 0 0;
		width: min(18rem, 85vw);
		box-shadow: 4px 0 18px rgba(0, 0, 0, 0.25);
		transform: translateX(-105%);
		transition: transform 0.2s ease;
	}

	.graph-app.filters-open .graph-filters {
		transform: none;
	}

	.graph-panel {
		grid-column: auto;
		position: absolute;
		z-index: 9;
		top: auto;
		left: 0;
		right: 0;
		bottom: 0;
		width: auto;
		max-height: 55%;
		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);
	}

	.graph-back {
		font-size: 1.1rem;
	}

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