/* colours come from the reference data-viz palette:
   sequential blue ramp for the value heatmap, status green/red for start/goal,
   categorical orange for the path so it stays legible on top of the blue ramp */
:root {
	--surface: #fcfcfb;
	--text-primary: #0b0b0b;
	--text-secondary: #52514e;
	--start: #0ca30c;
	--goal: #d03b3b;
	--path: #eb6834;
	--ramp-light: #cde2fb;
	--ramp-dark: #0d366b;
	--line: #d8d7d2;
	--inspect: #b0740a;   /* gold — inspect accent (badge, formula arrows, wall note) */
	--brand: #4a3aa7;     /* violet — Get started button */
	--tour: #7c3aed;      /* bright violet — the pulsing tour spotlight */
}

body {
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	color: var(--text-primary);
	background: var(--surface);
	margin: 0 0 40px 0;
	padding: 0 12px;
}

#topbar {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 18px;
	margin: 20px 0;
	flex-wrap: wrap;
}

h1 {
	text-align: center;
	font-weight: 300;
	margin: 0;
}

.cta {
	padding: 8px 16px;
	font-size: 14px;
	font-weight: 600;
	font-family: inherit;
	color: #ffffff;
	background: var(--brand);
	border: 1px solid var(--brand);
	border-radius: 6px;
	cursor: pointer;
}

.cta:hover {
	background: #3d2f8c;
}

h3 {
	text-align: center;
	font-weight: 400;
	font-size: 15px;
	color: var(--text-secondary);
	margin: 0 0 8px 0;
}

/* ---------------------------------------------------------------- controls */

#controls {
	max-width: 1100px;
	margin: 0 auto 20px auto;
}

.ctrl-row {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 8px 28px;
	margin-bottom: 10px;
}

.group {
	display: flex;
	align-items: center;
	gap: 8px;
}

label {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 13px;
	color: var(--text-secondary);
}

input[type="number"] {
	width: 68px;
	padding: 4px 6px;
	font-size: 13px;
	border: 1px solid #c9c8c3;
	border-radius: 4px;
	background: #ffffff;
	color: var(--text-primary);
}

input[type="range"] {
	cursor: pointer;
}

#speed {
	width: 130px;
}

.readout {
	font-size: 12px;
	color: var(--text-secondary);
	/* fixed width so the row does not reflow as the number changes */
	width: 82px;
}

.hint {
	font-size: 13px;
	color: var(--text-secondary);
}

button {
	padding: 5px 12px;
	font-size: 13px;
	font-family: inherit;
	border: 1px solid #c9c8c3;
	border-radius: 4px;
	background: #ffffff;
	color: var(--text-primary);
	cursor: pointer;
}

button:hover {
	background: #f0efec;
}

button.primary {
	background: #2a78d6;
	border-color: #2a78d6;
	color: #ffffff;
	width: 64px;
}

button.primary:hover {
	background: #256abf;
}

/* the placement mode is a two-state toggle: the active one must be unmistakable */
button.mode.is-active {
	background: var(--text-primary);
	border-color: var(--text-primary);
	color: #ffffff;
}

.epoch-row {
	gap: 12px;
}

#epoch-slider {
	flex: 1;
	min-width: 240px;
	max-width: 760px;
}

#status {
	text-align: center;
	font-size: 13px;
	color: var(--text-secondary);
	/* reserved so the grids never jump when the message changes */
	height: 18px;
}

/* ------------------------------------------------------------------ grids */

#main {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: flex-start;
	gap: 16px 32px;
}

canvas {
	display: block;
	cursor: crosshair;
}

/* ----------------------------------------------------------------- legend */

#legend {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px 22px;
	margin-top: 18px;
	font-size: 12px;
	color: var(--text-secondary);
}

.key {
	display: flex;
	align-items: center;
	gap: 6px;
}

.swatch {
	width: 22px;
	height: 11px;
	border-radius: 2px;
	display: inline-block;
}

.swatch-start { background: var(--start); }
.swatch-goal { background: var(--goal); }
.swatch-path { background: var(--path); }
.swatch-ramp {
	width: 80px;
	background: linear-gradient(to right, var(--ramp-light), var(--ramp-dark));
}

/* -------------------------------------------------------------- explainer */
/* the maths is written in plain HTML/CSS (unicode + a CSS fraction) rather
   than pulling in MathJax/KaTeX, so the page keeps its zero dependencies and
   still renders offline */

#explainer {
	max-width: 720px;
	margin: 28px auto 0 auto;
	border: 1px solid #e4e3de;
	border-radius: 8px;
	background: #ffffff;
}

#explainer > summary {
	cursor: pointer;
	padding: 12px 18px;
	font-size: 15px;
	font-weight: 600;
	color: var(--text-primary);
	list-style-position: inside;
}

#explainer[open] > summary {
	border-bottom: 1px solid #eeede9;
}

.explainer-body {
	padding: 4px 22px 20px 22px;
	font-size: 14px;
	line-height: 1.62;
	color: #2f2e2b;
}

.explainer-body h4 {
	margin: 22px 0 6px 0;
	font-size: 14px;
	font-weight: 600;
	color: var(--text-primary);
}

.explainer-body p {
	margin: 6px 0;
}

.explainer-body .note {
	margin-top: 16px;
	padding: 10px 14px;
	background: #f7f6f3;
	border-left: 3px solid var(--path);
	border-radius: 0 4px 4px 0;
	font-size: 13px;
	color: var(--text-secondary);
}

/* an italic serif for maths symbols so V, s, π read as variables */
.m {
	font-family: "Cambria Math", Georgia, "Times New Roman", serif;
	font-style: italic;
	white-space: nowrap;
}

.eq {
	margin: 12px 0;
	padding: 10px 14px;
	text-align: center;
	background: #f7f6f3;
	border-radius: 6px;
	font-family: "Cambria Math", Georgia, "Times New Roman", serif;
	font-size: 16px;
}

.eq-big {
	font-size: 18px;
}

.eq .paren {
	font-size: 1.15em;
}

/* an inline vertical fraction for the 1/4 factor */
.frac {
	display: inline-flex;
	flex-direction: column;
	vertical-align: middle;
	text-align: center;
	margin: 0 2px;
	font-size: 0.7em;
	line-height: 1.05;
}

.frac .num {
	border-bottom: 1px solid currentColor;
	padding: 0 3px;
}

.frac .den {
	padding: 0 3px;
}

/* ------------------------------------------------------------ inspector */

#inspector {
	max-width: 960px;
	margin: 18px auto 0 auto;
	border: 1px solid #e4e3de;
	border-radius: 8px;
	background: #ffffff;
	padding: 14px 18px;
}

.inspector-empty {
	margin: 0;
	text-align: center;
	font-size: 13px;
	color: var(--text-secondary);
}

.insp-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 6px 16px;
	border-bottom: 1px solid #eeede9;
	padding-bottom: 8px;
	margin-bottom: 8px;
}

.insp-cell {
	font-size: 13px;
	color: var(--text-secondary);
}

.insp-badge {
	font-size: 16px;
	font-weight: 600;
	color: var(--inspect);
}

.insp-formula .eq {
	margin: 6px 0;
	padding: 8px 12px;
	text-align: left;
	white-space: nowrap;
}

.insp-formula .eq-result {
	background: #efeaf7;
	color: var(--inspect);
	font-weight: 600;
}

/* direction glyph, shared by the formula and the grid highlight, so ↑→↓← read as
   "these cells" in both places */
.g {
	color: var(--inspect);
	font-style: normal;
	font-weight: 700;
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.wall-term {
	color: #b4b3ad;
	text-decoration: underline dotted;
	cursor: help;
}

.insp-note {
	margin: 8px 0 0 0;
	font-size: 13px;
	line-height: 1.5;
	color: var(--text-secondary);
}

/* ----------------------------------------------------------------- tour */

#tour[hidden] {
	display: none;
}

#tour {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 20px;
	display: flex;
	justify-content: center;
	pointer-events: none; /* only the card catches clicks; the page stays usable */
	z-index: 1000;
}

#tour-card {
	pointer-events: auto;
	box-sizing: border-box; /* keep padding inside the width so it never overflows a phone */
	width: min(440px, calc(100vw - 32px));
	background: #ffffff;
	border: 1px solid #d7d6d1;
	border-radius: 12px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
	padding: 16px 20px 14px 20px;
}

#tour-progress {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--inspect);
}

#tour-title {
	margin: 4px 0 8px 0;
	font-size: 17px;
	font-weight: 600;
	color: var(--text-primary);
}

#tour-text {
	font-size: 14px;
	line-height: 1.55;
	color: #2f2e2b;
}

#tour-nav {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 14px;
}

#tour-nav .spacer {
	flex: 1;
}

.link {
	background: none;
	border: none;
	padding: 6px 4px;
	color: var(--text-secondary);
	text-decoration: underline;
	cursor: pointer;
	font-family: inherit;
	font-size: 13px;
}

/* the element the current tour step is talking about -- a thick spotlight that
   pulses so the eye is drawn straight to it */
@keyframes tour-pulse {
	0%   { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.55), 0 0 14px 2px rgba(124, 58, 237, 0.35); }
	70%  { box-shadow: 0 0 0 12px rgba(124, 58, 237, 0), 0 0 22px 6px rgba(124, 58, 237, 0.15); }
	100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0), 0 0 14px 2px rgba(124, 58, 237, 0.35); }
}

.tour-highlight {
	outline: 4px solid var(--tour);
	outline-offset: 3px;
	border-radius: 6px;
	animation: tour-pulse 1.15s ease-in-out infinite;
}

/* one-click "try a full 20x20 maze" button on the final tour step */
.tour-cta {
	display: block;
	width: 100%;
	margin: 12px 0 0 0;
}

.tour-or {
	display: block;
	margin-top: 10px;
	font-size: 13px;
	line-height: 1.5;
	color: var(--text-secondary);
}

/* -------------------------------------------------------------- KaTeX math */
/* real LaTeX (bundled locally under assets/katex). display formulas can be wider
   than a phone, so each one scrolls inside its own box instead of the page */
.tex-block {
	margin: 12px 0;
	overflow-x: auto;
	overflow-y: hidden;
}

.tex-block .katex-display {
	margin: 0.4em 0;
}

.explainer-body ul {
	margin: 8px 0;
	padding-left: 22px;
	line-height: 1.55;
}

.explainer-body li {
	margin: 4px 0;
}

#legend-note {
	max-width: 720px;
	margin: 8px auto 0 auto;
	text-align: center;
	font-size: 13px;
	line-height: 1.5;
	color: var(--text-secondary);
}

/* the derivation is scaled to fit by JS (fit_inspector_formula), so no scrollbar */
.insp-formula {
	overflow: hidden;
	padding: 6px 0 2px 0;
}

.insp-formula .katex-display {
	margin: 0.3em 0;
	text-align: left;
}

.insp-badge .katex {
	font-size: 1.05em;
}
