/*
 * Quill Quest — dark scheme.
 *
 * Overrides LAYER 2 ONLY. Nothing here touches a primitive, a type step, a space
 * step, or a component token: those are scheme-independent by construction, and the
 * whole reason the token architecture has three layers is so this file can be this
 * short. If you find yourself needing to override a layer 1 or layer 3 token here,
 * the token is in the wrong layer — promote the ROLE to layer 2 instead (see
 * --qq-c-elevation-* in tokens.css for the worked example).
 *
 * Applies on two triggers, both required:
 *   [data-qq-scheme="dark"]                  explicit user choice, set by scheme.js
 *   prefers-color-scheme + no explicit light  OS preference, honoured by default
 *
 * The :not([data-qq-scheme="light"]) guard is what lets an explicit "light" choice
 * beat the OS preference. Without it, a visitor on a dark-set OS could not choose light.
 *
 * Every ratio below was computed by .dev/bin/contrast against the LIGHTEST dark
 * surface (#222228), not the canvas, because that is the worst case and solving for
 * the canvas produces values that fail inside pull-quotes and ad wells.
 *
 * @package quill-quest
 */

[data-qq-scheme="dark"] {

	/* ---- Surfaces ---------------------------------------------------
	 * Elevation goes lighter, as dark UI conventionally does. The washes lose the
	 * pink entirely: a tinted dark surface reads as a rendering fault rather than
	 * as brand, and pink-50 on black is not a wash, it is a glow.
	 */
	--qq-c-canvas: var(--qq-night-900);
	--qq-c-surface: var(--qq-night-800);
	--qq-c-raised: var(--qq-night-700);
	--qq-c-sunken: var(--qq-night-600);
	--qq-c-wash: var(--qq-night-800);
	--qq-c-wash-strong: var(--qq-night-700);

	/* ---- Text -------------------------------------------------------
	 * Not pure white. #E8E8ED at 12.95:1 on the lightest dark surface is already
	 * far past AA; pure white on near-black causes halation for astigmatic readers
	 * and costs nothing to avoid.
	 */
	--qq-c-text: var(--qq-night-100);
	--qq-c-text-secondary: var(--qq-night-200);
	--qq-c-text-muted: var(--qq-night-300);

	/* On a dark scheme the brand pill inverts: light pink fill, dark text.
	 * See --qq-c-brand-fill below for why that is the only pairing that satisfies
	 * both 1.4.3 (text on the fill) and 1.4.11 (fill against the canvas). */
	--qq-c-text-on-brand: var(--qq-ink);
	--qq-c-text-on-accent: var(--qq-ink);
	--qq-c-text-on-scrim: var(--qq-white);

	/* ---- Borders ----------------------------------------------------
	 * Same split as light, same reason. #2C2C34 is 1.14-1.42:1 across the dark
	 * surfaces — a divider, never a control boundary. #757582 was chosen over the
	 * tighter #6B6B78 because #6B6B78 lands at exactly 3.01:1 on #222228, and a
	 * 0.01 margin is not a margin.
	 */
	--qq-c-border: var(--qq-night-500);
	--qq-c-border-strong: var(--qq-night-400);
	--qq-c-field-border: var(--qq-night-400);

	/* ---- Brand roles ------------------------------------------------
	 * The brand pink swaps jobs between schemes, which is the single most useful
	 * thing the arithmetic turned up:
	 *
	 *   light  #FF0090 fails as text (3.71:1 white on it, 2.x as text on white),
	 *          so text uses #AD0060 and #FF0090 is graphics only.
	 *   dark   #FF0090 PASSES as a fill against the canvas (5.30:1, clearing the
	 *          3:1 boundary requirement) and takes dark text cleanly. So dark mode
	 *          gets the actual brand colour on its buttons and light mode does not.
	 *
	 * --qq-c-brand-ink is the 30% tint, not raw #FF0090: raw pink as running text
	 * is 4.99:1 on the surface but only 4.26:1 on #222228, so it fails inside a
	 * pull-quote. The tint clears every dark surface at 5.23:1 or better.
	 *
	 * --qq-c-highlight becomes usable as text here — amber is 7.37:1 on #222228,
	 * against 2.10:1 on white. It is still graphics-only in the light scheme.
	 */
	--qq-c-brand: var(--qq-pink-500);
	--qq-c-brand-ink: var(--qq-pink-300);
	--qq-c-brand-fill: var(--qq-pink-500);
	--qq-c-brand-fill-hover: var(--qq-pink-300);
	--qq-c-highlight: var(--qq-amber-500);

	/* ---- Links ------------------------------------------------------ */
	--qq-c-link: var(--qq-pink-300);
	--qq-c-link-hover: var(--qq-night-50);
	--qq-c-link-visited: var(--qq-hue-grape-ink);

	/* ---- Focus ------------------------------------------------------
	 * The sandwich inverts: white ring, near-black halo. The pair still contrasts
	 * with itself at 19.80:1, which is the property the whole approach rests on —
	 * on any surface the theme can produce, at least one of the two rings clears
	 * 3:1. Verified across all 11 surfaces in both schemes.
	 */
	--qq-c-focus-ring: var(--qq-white);
	--qq-c-focus-halo: var(--qq-ink);

	/* ---- Category accent defaults ----------------------------------- */
	--qq-c-accent-fill: var(--qq-hue-pink-ink);
	--qq-c-accent-ink: var(--qq-hue-pink-ink);

	/* ---- Elevation --------------------------------------------------
	 * A shadow tuned for white does almost nothing on #0B0B0D. Dark planes are
	 * separated by the lighter surface colour plus a hairline ring; the shadow is
	 * kept only to anchor genuinely floating things, at a much higher alpha.
	 */
	--qq-c-elevation-flat: none;
	--qq-c-elevation-raised: 0 0 0 1px rgb(255 255 255 / 6%);
	--qq-c-elevation-float: 0 0 0 1px rgb(255 255 255 / 8%), 0 8px 24px rgb(0 0 0 / 56%);
	--qq-c-elevation-overlay: 0 0 0 1px rgb(255 255 255 / 10%), 0 18px 48px rgb(0 0 0 / 68%);

	/* ---- Ad wells ---------------------------------------------------
	 * Still background-color only (§7.5 P3). The well is deliberately LIGHTER than
	 * the canvas so an unfilled slot reads as reserved space rather than as a hole,
	 * without ever becoming an LCP candidate.
	 */
	--qq-c-ad-well: var(--qq-night-800);
	--qq-c-ad-label: var(--qq-night-300);
}

/*
 * OS preference. Identical body to the block above — the scheme values live in one
 * place conceptually but CSS has no way to alias a selector without either
 * duplicating the declarations or paying for a second stylesheet, and duplicating
 * ~40 custom properties in the critical layer is cheaper than either. The pairing is
 * checked by .dev/bin/tokens-check so the two blocks cannot drift.
 */
@media ( prefers-color-scheme: dark ) {

	html:not([data-qq-scheme="light"]) {
		--qq-c-canvas: var(--qq-night-900);
		--qq-c-surface: var(--qq-night-800);
		--qq-c-raised: var(--qq-night-700);
		--qq-c-sunken: var(--qq-night-600);
		--qq-c-wash: var(--qq-night-800);
		--qq-c-wash-strong: var(--qq-night-700);

		--qq-c-text: var(--qq-night-100);
		--qq-c-text-secondary: var(--qq-night-200);
		--qq-c-text-muted: var(--qq-night-300);
		--qq-c-text-on-brand: var(--qq-ink);
		--qq-c-text-on-accent: var(--qq-ink);
		--qq-c-text-on-scrim: var(--qq-white);

		--qq-c-border: var(--qq-night-500);
		--qq-c-border-strong: var(--qq-night-400);
		--qq-c-field-border: var(--qq-night-400);

		--qq-c-brand: var(--qq-pink-500);
		--qq-c-brand-ink: var(--qq-pink-300);
		--qq-c-brand-fill: var(--qq-pink-500);
		--qq-c-brand-fill-hover: var(--qq-pink-300);
		--qq-c-highlight: var(--qq-amber-500);

		--qq-c-link: var(--qq-pink-300);
		--qq-c-link-hover: var(--qq-night-50);
		--qq-c-link-visited: var(--qq-hue-grape-ink);

		--qq-c-focus-ring: var(--qq-white);
		--qq-c-focus-halo: var(--qq-ink);

		--qq-c-accent-fill: var(--qq-hue-pink-ink);
		--qq-c-accent-ink: var(--qq-hue-pink-ink);

		--qq-c-elevation-flat: none;
		--qq-c-elevation-raised: 0 0 0 1px rgb(255 255 255 / 6%);
		--qq-c-elevation-float: 0 0 0 1px rgb(255 255 255 / 8%), 0 8px 24px rgb(0 0 0 / 56%);
		--qq-c-elevation-overlay: 0 0 0 1px rgb(255 255 255 / 10%), 0 18px 48px rgb(0 0 0 / 68%);

		--qq-c-ad-well: var(--qq-night-800);
		--qq-c-ad-label: var(--qq-night-300);
	}
}
