/* AlignOn brand skin for Forgejo.
 *
 * Loaded LAST, from templates/custom/header.tmpl, which Forgejo renders at the end of <head>,
 * after index.css and theme-*.css. So this is a thin override on top of whichever built-in theme
 * is active, not a fork of one: a Forgejo upgrade that adds variables keeps working, because the
 * ones added will still resolve through the ramps redefined here.
 *
 * Forgejo builds every theme out of two neutral ramps (--zinc-* light, --steel-* dark) plus a
 * --color-primary-* ramp; the ~180 semantic tokens are var() references onto those. Repointing the
 * three ramps therefore repaints the whole forge, and the only literals below are the handful of
 * tokens the built-in themes hardcode rather than derive.
 *
 * Colours come from space-ui/src/routes/theme-tokens.css (aoblue + slate), converted oklch->sRGB
 * because Forgejo composes alpha variants by hex suffix.
 *
 * Scoped to the three standard themes by name. The deuteranopia/protanopia/tritanopia themes pick
 * their colours for a reason and must keep them, so they are left entirely alone.
 *
 * What this deliberately does NOT touch: the semantic palette. --color-green/red/yellow and the
 * success/error/warning/info groups mean something in a forge (green is merge and positive, red is
 * destructive, the diff pair is universal), so they keep Forgejo's values even though they are
 * off-palette. This is why the "Go Back" on a repo 404 is still forge green: it is Fomantic's
 * `.ui.green.button`, the same class the merge button uses, and repainting it AlignOn blue would
 * either take merge with it or need a one-off selector that rots. Neutrals and the brand accent are
 * ours; meaning stays Forgejo's.
 */

@font-face {
	font-family: Poppins;
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('../fonts/poppins-latin-400-normal.woff2') format('woff2');
}
@font-face {
	font-family: Poppins;
	font-style: normal;
	font-weight: 500;
	font-display: swap;
	src: url('../fonts/poppins-latin-500-normal.woff2') format('woff2');
}
@font-face {
	font-family: Poppins;
	font-style: normal;
	font-weight: 600;
	font-display: swap;
	src: url('../fonts/poppins-latin-600-normal.woff2') format('woff2');
}
@font-face {
	font-family: Poppins;
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('../fonts/poppins-latin-700-normal.woff2') format('woff2');
}

/* Type and geometry are theme-independent, so they apply to every theme including the
   colour-vision ones. --fonts-proportional rather than --fonts-regular: the latter derives from it
   and carries the emoji and CJK fallbacks, which we want to keep. */
:root {
	--fonts-proportional: Poppins, -apple-system, 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', Arial;
	--border-radius: 6px;
	--border-radius-medium: 8px;
}

/* ── Neutral ramps ─────────────────────────────────────────────────────────
   Ramp identity does not depend on light/dark (each built-in theme reads the one it needs), so
   both are set once. zinc -> slate, at Forgejo's own step lightnesses. steel -> the cockpit's dark
   neutrals: same lightness curve as Forgejo's, ~6x less chroma, so nothing reads blue-grey. */
[data-theme='forgejo-auto'],
[data-theme='forgejo-light'],
[data-theme='forgejo-dark'] {
	--zinc-50: #f8fafc;
	--zinc-100: #f1f5f9;
	--zinc-150: #e9eff5;
	--zinc-200: #e2e8f0;
	--zinc-250: #d6dfea;
	--zinc-300: #cad5e2;
	--zinc-350: #adbbce;
	--zinc-400: #90a1b9;
	--zinc-450: #798aa3;
	--zinc-500: #62748e;
	--zinc-550: #53647d;
	--zinc-600: #45556c;
	--zinc-650: #3b4b62;
	--zinc-700: #314158;
	--zinc-750: #26354a;
	--zinc-800: #1d293d;
	--zinc-850: #152034;
	--zinc-900: #0f172b;

	--steel-900: #040506;
	--steel-850: #0a0b0e;
	--steel-800: #101114;
	--steel-750: #15171b;
	--steel-700: #1d1f22;
	--steel-650: #25272a;
	--steel-600: #303236;
	--steel-550: #3e4045;
	--steel-500: #4d5054;
	--steel-450: #5d6064;
	--steel-400: #6d7075;
	--steel-350: #7e8187;
	--steel-300: #8f9298;
	--steel-250: #a1a4aa;
	--steel-200: #b3b6bb;
	--steel-150: #ced1d6;
	--steel-100: #e5e8ec;

	/* The console/log widget is dark in every theme, so it is set once here rather than per mode. */
	--color-console-fg: #e5e8ec;
	--color-console-fg-subtle: #8f9298;
	--color-console-bg: #0a0b0e;
	--color-console-border: #25272a;
	--color-console-hover-bg: #ffffff16;
	--color-console-active-bg: #303236;
	--color-console-menu-bg: #1d1f22;
	--color-console-menu-border: #303236;
}

/* ── Light: primary is aoblue-500, the wordmark blue (7.6:1 on white, both as text and behind
      white text) ────────────────────────────────────────────────────────── */
[data-theme='forgejo-light'],
[data-theme='forgejo-auto'] {
	--color-primary: #0029ff;
	--color-primary-contrast: #ffffff;
	--color-primary-dark-1: #000fe1;
	--color-primary-dark-2: #000cd7;
	--color-primary-dark-3: #000cd7;
	--color-primary-dark-4: #0511ad;
	--color-primary-dark-5: #0511ad;
	--color-primary-dark-6: #0e1a86;
	--color-primary-dark-7: #0e1a86;
	--color-primary-light-1: #3c6cff;
	--color-primary-light-2: #72a3ff;
	--color-primary-light-3: #a7c9ff;
	--color-primary-light-4: #cee3ff;
	--color-primary-light-5: #e4efff;
	--color-primary-light-6: #eff4ff;
	--color-primary-light-7: #f7faff;
	--color-primary-alpha-10: #0029ff19;
	--color-primary-alpha-20: #0029ff33;
	--color-primary-alpha-30: #0029ff4b;
	--color-primary-alpha-40: #0029ff66;
	--color-primary-alpha-50: #0029ff80;
	--color-primary-alpha-60: #0029ff99;
	--color-primary-alpha-70: #0029ffb3;
	--color-primary-alpha-80: #0029ffcc;
	--color-primary-alpha-90: #0029ffe1;

	/* Figure and ground, inverted from stock. Forgejo puts white on the page and grey in the
	   boxes; the cockpit does the opposite, and that polarity is the loudest structural signal of
	   the AlignOn look. Cards go white, the canvas drops to slate, and the two chrome strips stay
	   above the canvas so they still read as elevated. */
	--color-body: var(--zinc-100);
	--color-box-body: #ffffff;
	--color-box-header: var(--zinc-50);
	--color-card: #ffffff;
	--color-menu: #ffffff;
	--color-nav-bg: #ffffff;
	--color-secondary-nav-bg: #ffffff;
	--color-header-wrapper: #ffffff;
	--color-header-wrapper-transparent: #ffffff00;
	/* Stock light --color-footer IS --zinc-100, which is what the canvas just became, so without
	   this the footer strip disappears into the page. It joins the other chrome strips at white. */
	--color-footer: #ffffff;

	/* Forgejo's border token. Stock light is --zinc-200, the exact value theme-tokens.css rejects
	   as "washed" for its own hairline, and against white cards it barely registers. This is the
	   cockpit's --border. */
	--color-secondary: #d9dbdf;

	/* Hardcoded in the built-in light theme (warm greys), so they do not follow the ramp. */
	--color-hover: #e2e8f0aa;
	--color-active: #dbe3ee;
	--color-label-bg: #cad5e27b;
	--color-label-hover-bg: #cad5e2a0;
	--color-label-active-bg: #cad5e2;
	--color-label-bg-alt: #cad5e2;

	/* In light the CTA already is the brand blue with white on it, so these are pass-throughs; see
	   the rule at the foot of this file for what they are for. */
	--ao-cta: var(--color-primary);
	--ao-cta-fg: var(--color-primary-contrast);
	--ao-cta-hover: var(--color-primary-hover);
}

/* ── Dark ──────────────────────────────────────────────────────────────────
   Primary lightens to aoblue-300 (7.6:1 on the dark body; aoblue-500 is 2.5:1 there and
   aoblue-400 only 4.3:1) and the ramp inverts, which is the shape the built-in dark theme uses.
   The block is written twice because an explicit `forgejo-dark` and a `forgejo-auto` under a dark
   OS are two different conditions and CSS has no way to name them once. Edit both. */
[data-theme='forgejo-dark'] {
	--color-primary: #72a3ff;
	--color-primary-contrast: #05091a;
	--color-primary-dark-1: #a7c9ff;
	--color-primary-dark-2: #a7c9ff;
	--color-primary-dark-3: #cee3ff;
	--color-primary-dark-4: #cee3ff;
	--color-primary-dark-5: #e4efff;
	--color-primary-dark-6: #e4efff;
	--color-primary-dark-7: #f7faff;
	--color-primary-light-1: #3c6cff;
	--color-primary-light-2: #0029ff;
	--color-primary-light-3: #000fe1;
	--color-primary-light-4: #000cd7;
	--color-primary-light-5: #000cd7;
	--color-primary-light-6: #0511ad;
	--color-primary-light-7: #0511ad;
	--color-primary-alpha-10: #3c6cff19;
	--color-primary-alpha-20: #3c6cff33;
	--color-primary-alpha-30: #3c6cff4b;
	--color-primary-alpha-40: #3c6cff66;
	--color-primary-alpha-50: #3c6cff80;
	--color-primary-alpha-60: #3c6cff99;
	--color-primary-alpha-70: #3c6cffb3;
	--color-primary-alpha-80: #3c6cffcc;
	--color-primary-alpha-90: #3c6cffe1;
	--color-primary-hover: var(--color-primary-dark-1);
	--color-primary-active: var(--color-primary-dark-3);

	--color-header-wrapper-transparent: #0a0b0e00;
	--color-expand-button: #303236;
	/* Derived, these land deep-blue-on-blue and the match is unreadable. */
	--color-highlight-fg: #cee3ff;
	--color-highlight-bg: #0029ff66;

	/* Restores what the built-in dark theme sets, because the light block above matches
	   `forgejo-auto` too and would otherwise leave pale-grey hovers and near-white label pills on
	   a dark page. Ramp references, not literals, so they cannot drift from the steel values. */

	/* Every one of these is set by the light block, which also matches `forgejo-auto`; without a
	   dark counterpart the light value survives onto a dark page. --color-secondary is Forgejo's
	   border token (~90 uses) and its stock dark value equals --color-box-header exactly, so a box
	   header has no outline at all; one step up is the cockpit's dark hairline. */
	--color-secondary: var(--steel-650);
	--color-body: var(--steel-800);
	--color-box-body: var(--steel-750);
	--color-box-header: var(--steel-700);
	--color-card: var(--steel-700);
	--color-menu: var(--steel-700);
	--color-nav-bg: var(--steel-900);
	--color-secondary-nav-bg: var(--steel-800);
	--color-header-wrapper: var(--steel-850);

	/* --color-primary has to serve link text on a near-black page, so it is a pale blue and a
	   button filled with it needs a dark label, the exact inverse of the light CTA and of the
	   cockpit's. One token cannot do both jobs: white-on-fill wants a fill luminance <= 0.183 and
	   link-text-on-page wants >= 0.2. So the CTA gets its own fill, picked to clear BOTH
	   thresholds it does have to meet (white text 4.5:1, and 3:1 against the page so the button
	   has an edge). Hover darkens, as in light. */
	--ao-cta: #3969ff;
	--ao-cta-fg: #ffffff;
	--ao-cta-hover: #2a55e6;

	/* Counterparts for the light block's --color-footer and --color-secondary: stock dark values,
	   restated because the light block matches forgejo-auto and would otherwise win here. */
	--color-footer: var(--steel-900);
	--color-hover: var(--steel-600);
	--color-active: var(--steel-650);
	--color-label-bg: var(--steel-600);
	--color-label-hover-bg: var(--steel-550);
	--color-label-active-bg: var(--steel-500);
	--color-label-bg-alt: var(--steel-550);
}

@media (prefers-color-scheme: dark) {
	[data-theme='forgejo-auto'] {
		--color-primary: #72a3ff;
		--color-primary-contrast: #05091a;
		--color-primary-dark-1: #a7c9ff;
		--color-primary-dark-2: #a7c9ff;
		--color-primary-dark-3: #cee3ff;
		--color-primary-dark-4: #cee3ff;
		--color-primary-dark-5: #e4efff;
		--color-primary-dark-6: #e4efff;
		--color-primary-dark-7: #f7faff;
		--color-primary-light-1: #3c6cff;
		--color-primary-light-2: #0029ff;
		--color-primary-light-3: #000fe1;
		--color-primary-light-4: #000cd7;
		--color-primary-light-5: #000cd7;
		--color-primary-light-6: #0511ad;
		--color-primary-light-7: #0511ad;
		--color-primary-alpha-10: #3c6cff19;
		--color-primary-alpha-20: #3c6cff33;
		--color-primary-alpha-30: #3c6cff4b;
		--color-primary-alpha-40: #3c6cff66;
		--color-primary-alpha-50: #3c6cff80;
		--color-primary-alpha-60: #3c6cff99;
		--color-primary-alpha-70: #3c6cffb3;
		--color-primary-alpha-80: #3c6cffcc;
		--color-primary-alpha-90: #3c6cffe1;
		--color-primary-hover: var(--color-primary-dark-1);
		--color-primary-active: var(--color-primary-dark-3);

		--color-header-wrapper-transparent: #0a0b0e00;
		--color-expand-button: #303236;
		--color-highlight-fg: #cee3ff;
		--color-highlight-bg: #0029ff66;


		/* Every one of these is set by the light block, which also matches `forgejo-auto`; without a
		   dark counterpart the light value survives onto a dark page. --color-secondary is Forgejo's
		   border token (~90 uses) and its stock dark value equals --color-box-header exactly, so a box
		   header has no outline at all; one step up is the cockpit's dark hairline. */
		--color-secondary: var(--steel-650);
		--color-body: var(--steel-800);
		--color-box-body: var(--steel-750);
		--color-box-header: var(--steel-700);
		--color-card: var(--steel-700);
		--color-menu: var(--steel-700);
		--color-nav-bg: var(--steel-900);
		--color-secondary-nav-bg: var(--steel-800);
		--color-header-wrapper: var(--steel-850);

		/* --color-primary has to serve link text on a near-black page, so it is a pale blue and a
		   button filled with it needs a dark label, the exact inverse of the light CTA and of the
		   cockpit's. One token cannot do both jobs: white-on-fill wants a fill luminance <= 0.183 and
		   link-text-on-page wants >= 0.2. So the CTA gets its own fill, picked to clear BOTH
		   thresholds it does have to meet (white text 4.5:1, and 3:1 against the page so the button
		   has an edge). Hover darkens, as in light. */
		--ao-cta: #3969ff;
		--ao-cta-fg: #ffffff;
		--ao-cta-hover: #2a55e6;

		/* Counterparts for the light block's --color-footer and --color-secondary: stock dark values,
		   restated because the light block matches forgejo-auto and would otherwise win here. */
		--color-footer: var(--steel-900);
		--color-hover: var(--steel-600);
		--color-active: var(--steel-650);
		--color-label-bg: var(--steel-600);
		--color-label-hover-bg: var(--steel-550);
		--color-label-active-bg: var(--steel-500);
		--color-label-bg-alt: var(--steel-550);
	}
}

/* The one component rule here, and the reason it is not a token: Forgejo draws the active tab
   marker with `border-color: currentColor`, so the "you are here" affordance on every repo,
   settings and explore page is plain black or plain white and the brand colour never appears on
   it. If a future Forgejo renames this selector the marker simply reverts to currentColor, which
   is what it does today, so the rule can rot without breaking a page. */
.ui.secondary.pointing.menu .active.item,
.ui.secondary.pointing.menu .active.item:hover {
	border-color: var(--color-primary);
}

/* Fomantic's own `.ui.primary.button` rule is a flat #2185d0 that the theme overrides; this lands
   after both. Light resolves to exactly what it already was. */
.ui.primary.button,
.ui.primary.buttons .button {
	background: var(--ao-cta);
	color: var(--ao-cta-fg);
}
.ui.primary.button:hover,
.ui.primary.button:focus,
.ui.primary.buttons .button:hover,
.ui.primary.buttons .button:focus {
	background: var(--ao-cta-hover);
	color: var(--ao-cta-fg);
}
