/* ConnectedEarth term graph — prototype 0.3.1
   Base colours from the Blocksy palette (Site Architecture §3.1).
   Relationship colours are a test palette (outside the brand set, by decision for this test). */

.ce-term-graph {
	--ctg-canvas: var(--theme-palette-color-4, #1E2245);
	--ctg-accent: var(--theme-palette-color-1, #FFB300);
	--ctg-on-accent: var(--theme-palette-color-5, #1A1A2E);
	--ctg-chip: var(--theme-palette-color-7, #FFFFFF);
	--ctg-ink: var(--theme-palette-color-3, #252B52);
	--ctg-pill-ink: #1E2245;
	--ctg-border: var(--ce-border, #E2E4EB);

	/* One colour per relationship; inverse pairs share. */
	--ctg-enables: #6FD39B;
	--ctg-depends-on: #7FA6F5;
	--ctg-constrains: #F2837B;
	--ctg-contrasts-with: #F3AE7A;
	--ctg-measures: #DCCB82;
	--ctg-measured-by: #DCCB82;
	--ctg-used-in: #5FCFD3;
	--ctg-is-a: #B39DF5;
	--ctg-part-of: #CDBEF7;
	--ctg-replaces: #E79BD0;
	--ctg-related-terms: #A7ABBF;

	margin: 2rem 0;
}

.ce-term-graph__title {
	margin: 0 0 0.75rem;
	color: var(--ctg-ink);
}

/* Resting frame holds the card's footprint; the stage can grow out of it. */
.ce-term-graph__frame {
	position: relative;
	display: none;
	width: 100%;
	height: 282px;
	max-width: 100%;
}

.ce-term-graph.is-enhanced .ce-term-graph__frame {
	display: block;
}

/* The stage fills its parent: the frame at rest, the floating portal when expanded. */
.ce-term-graph__stage {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	border-radius: 8px;
	background: var(--ctg-canvas);
	touch-action: pan-y;
	cursor: grab;
	user-select: none;
	-webkit-user-select: none;
}

.ce-term-graph__stage:focus-visible {
	outline: 2px solid var(--ctg-accent);
	outline-offset: 2px;
}

/* Expanded graph floats above the page, outside any clipping or stacking of its card. */
.ce-term-graph.ce-term-graph--portal {
	position: fixed;
	z-index: 99990;
	margin: 0;
	border-radius: 8px;
	box-shadow: 0 12px 40px rgba(20, 22, 50, 0.45);
	transition: left 0.18s ease-out, top 0.18s ease-out, width 0.18s ease-out, height 0.18s ease-out;
}

.ce-term-graph__stage.is-dragging {
	cursor: grabbing;
}

.ce-term-graph__canvas,
.ce-term-graph__links,
.ce-term-graph__edge-labels {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.ce-term-graph__edge-labels,
.ce-term-graph__links {
	pointer-events: none;
}

.ce-term-graph__term,
.ce-term-graph__center,
.ce-term-graph__edge-label {
	position: absolute;
	left: 0;
	top: 0;
	will-change: transform;
}

/* The theme animates link changes; that made pills trail the lines while dragging. */
.ce-term-graph .ce-term-graph__term,
.ce-term-graph .ce-term-graph__center,
.ce-term-graph .ce-term-graph__edge-label {
	transition: none !important;
	animation: none !important;
}

/* Pills are hidden at rest (dots are drawn instead) and shown when expanded. */
.ce-term-graph__term {
	display: none;
	pointer-events: auto;
	max-width: 12em;
	padding: 0.28rem 0.7rem;
	border-radius: 999px;
	background: var(--ctg-chip);
	color: var(--ctg-pill-ink);
	font-family: "Exo 2", sans-serif;
	font-size: 0.82rem;
	font-weight: 700;
	line-height: 1.15;
	text-align: center;
	text-decoration: none;
	white-space: normal;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
	-webkit-user-drag: none;
	cursor: pointer;
}

.ce-term-graph.is-expanded .ce-term-graph__term {
	display: block;
}

.ce-term-graph__term:hover,
.ce-term-graph__term:focus-visible,
.ce-term-graph__term.is-active {
	background: var(--ctg-chip) !important;
	color: var(--ctg-pill-ink);
	text-decoration: none;
}

.ce-term-graph__term:focus-visible {
	outline: 2px solid var(--ctg-accent);
	outline-offset: 2px;
}

.ce-term-graph__center {
	max-width: 10em;
	padding: 0.3rem 0.7rem;
	border-radius: 999px;
	background: var(--ctg-accent);
	color: var(--ctg-on-accent);
	font-family: "Exo 2", sans-serif;
	font-size: 0.85rem;
	font-weight: 800;
	line-height: 1.15;
	text-align: center;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.ce-term-graph.is-expanded .ce-term-graph__center {
	font-size: 1rem;
	padding: 0.4rem 0.9rem;
}

.ce-term-graph__edge-label {
	display: none;
	padding: 0 0.25rem;
	border-radius: 3px;
	background: var(--ctg-canvas);
	font-family: "Lato", sans-serif;
	font-size: 0.7rem;
	white-space: nowrap;
}

.ce-term-graph.is-expanded .ce-term-graph__edge-label {
	display: block;
}

.ce-term-graph__edge-label.is-active {
	font-weight: 700;
}

.ce-term-graph__hint {
	display: none;
	margin: 0.4rem 0 0;
	color: var(--ctg-ink);
	font-size: 0.78rem;
}

.ce-term-graph.is-enhanced .ce-term-graph__hint {
	display: block;
}

/* Text version: shown without JavaScript and on small screens. */
.ce-term-graph__fallback {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ce-term-graph__fallback li {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.3rem 0.6rem;
	padding: 0.4rem 0;
	border-bottom: 1px solid var(--ctg-border);
}

.ce-term-graph__rel {
	min-width: 8em;
	color: var(--ctg-ink);
	font-size: 0.85rem;
}

.ce-term-graph__chip {
	padding: 0.2rem 0.65rem;
	border-radius: 999px;
	background: var(--ctg-related-terms);
	color: var(--ctg-pill-ink);
	font-family: "Exo 2", sans-serif;
	font-size: 0.85rem;
	font-weight: 700;
	text-decoration: none;
}

.ce-term-graph__chip[data-type="enables"] { background: var(--ctg-enables); }
.ce-term-graph__chip[data-type="depends_on"] { background: var(--ctg-depends-on); }
.ce-term-graph__chip[data-type="constrains"] { background: var(--ctg-constrains); }
.ce-term-graph__chip[data-type="contrasts_with"] { background: var(--ctg-contrasts-with); }
.ce-term-graph__chip[data-type="measures"] { background: var(--ctg-measures); }
.ce-term-graph__chip[data-type="measured_by"] { background: var(--ctg-measured-by); }
.ce-term-graph__chip[data-type="used_in"] { background: var(--ctg-used-in); }
.ce-term-graph__chip[data-type="is_a"] { background: var(--ctg-is-a); }
.ce-term-graph__chip[data-type="part_of"] { background: var(--ctg-part-of); }
.ce-term-graph__chip[data-type="replaces"] { background: var(--ctg-replaces); }

.ce-term-graph__chip:hover,
.ce-term-graph__chip:focus-visible {
	background: var(--ctg-chip);
	box-shadow: inset 0 0 0 2px var(--ctg-ink);
}

@media (min-width: 601px) {
	.ce-term-graph.is-enhanced .ce-term-graph__fallback {
		display: none;
	}
}

@media (max-width: 600px) {
	.ce-term-graph.is-enhanced .ce-term-graph__frame,
	.ce-term-graph.is-enhanced .ce-term-graph__hint {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ce-term-graph.ce-term-graph--portal {
		transition: none;
	}
}

/* Preview on a real term page (?ctg-preview=1): hide the old graph, keep the card and its heading. */
body.ctg-preview .ont-graph > :not(h1):not(h2):not(h3):not(h4):not(h5):not(h6):not(.ce-term-graph) {
	display: none !important;
}

body.ctg-preview .ont-graph .ce-term-graph {
	margin: 0;
}
