/* ============================================================
   extras.css - extra polish layered on top of global.css.
   Driven by /scripts/extras.js. Nothing here changes page layout;
   every addition is an overlay, an accent, or an injected strip.
   ============================================================ */

html { scroll-behavior: smooth; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--fg); }

/* themed scrollbar */
html { scrollbar-color: var(--accent-dark) var(--bg); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* page entrance */
@keyframes x-enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
main { animation: x-enter 0.7s cubic-bezier(0.16, 1, 0.3, 1) both; }
header { animation: x-enter 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* ---------- Scroll progress bar ---------- */
.x-progress {
	position: fixed; top: 0; left: 0; height: 3px; width: 100%;
	transform-origin: 0 50%; transform: scaleX(0);
	background: linear-gradient(90deg, var(--accent-dark), var(--accent), var(--fg));
	box-shadow: 0 0 12px var(--accent);
	z-index: 10002; pointer-events: none;
}

/* ---------- Glow parallax ---------- */
.bg-fx .glow { transition: translate 0.9s cubic-bezier(0.16, 1, 0.3, 1); will-change: translate; }
@keyframes x-float { 0%,100% { margin-top: 0; } 50% { margin-top: -26px; } }
.bg-fx .glow-blue { animation: x-float 11s ease-in-out infinite; }
.bg-fx .glow-teal { animation: x-float 14s ease-in-out infinite reverse; }
.bg-fx .glow-pink { animation: x-float 13s ease-in-out infinite; }
.bg-fx .glow-purple { animation: x-float 16s ease-in-out infinite reverse; }

/* ---------- Hero ---------- */
.x-h { position: relative; display: inline-block; }
.x-grad { background: linear-gradient(100deg, var(--fg) 30%, var(--accent) 60%, var(--fg) 90%); background-size: 220% 100%;
	-webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
	animation: x-shimmer 7s linear infinite; }
@keyframes x-shimmer { to { background-position: -220% 0; } }
.x-wave { display: inline-block; margin-left: 0.25em; transform-origin: 70% 70%; animation: x-wave 2.6s ease-in-out infinite; }
@keyframes x-wave {
	0%,60%,100% { transform: rotate(0); }
	10%,30% { transform: rotate(16deg); }
	20%,40% { transform: rotate(-10deg); }
	50% { transform: rotate(8deg); }
}
.hero-type { margin: -0.9em auto 1.4em; font-size: 1.05em; color: var(--muted); min-height: 1.6em;
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.hero-type .x-prompt { color: var(--accent); margin-right: 0.5em; }
.hero-type .x-word { color: var(--fg); }
.hero-type .x-caret { display: inline-block; width: 0.55em; height: 1.05em; margin-left: 2px; vertical-align: -0.18em;
	background: var(--accent); animation: x-blink 1s steps(1) infinite; }
@keyframes x-blink { 50% { opacity: 0; } }

/* buttons: shine + ripple */
.button { position: relative; overflow: hidden; isolation: isolate; }
.button::after { content: ""; position: absolute; top: 0; left: -80%; width: 50%; height: 100%;
	background: linear-gradient(100deg, transparent, rgba(255,255,255,0.35), transparent);
	transform: skewX(-20deg); transition: left 0.6s ease; z-index: -1; pointer-events: none; }
.button:hover::after { left: 130%; }
.x-ripple { position: absolute; border-radius: 50%; background: rgba(255,255,255,0.45); transform: scale(0);
	animation: x-ripple 0.65s ease-out forwards; pointer-events: none; z-index: -1; }
@keyframes x-ripple { to { transform: scale(1); opacity: 0; } }

/* ---------- Ticker ---------- */
.x-ticker { position: relative; overflow: hidden; margin: -1.6em 0 3em; padding: 0.85em 0;
	border-block: 1px solid var(--border); -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
	mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); }
.x-ticker-track { display: flex; width: max-content; animation: x-marquee 38s linear infinite; }
.x-ticker span { position: relative; display: inline-flex; align-items: center; white-space: nowrap;
	/* letter-spacing adds trailing space after the last letter, so the right
	   padding is reduced by the same amount to keep the dots truly centred. */
	padding: 0 calc(1.7em - 0.12em) 0 1.7em;
	font-size: 0.78em; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
	font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; transition: color 0.2s; }
.x-ticker span::after { content: ""; position: absolute; right: 0; top: 50%; width: 4px; height: 4px; border-radius: 50%;
	background: var(--accent-dark); transform: translate(50%, -50%); }
.x-ticker span:hover { color: var(--accent); }
@keyframes x-marquee { to { transform: translateX(-50%); } }

/* ---------- Cards: spotlight + glare + tilt ---------- */
.card { position: relative; transform-style: preserve-3d; will-change: transform; }
.card::before { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit;
	opacity: 0; transition: opacity 0.3s ease;
	background: radial-gradient(380px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 12%, transparent), transparent 55%); }
.card:hover::before { opacity: 1; }
.card::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit; padding: 1px;
	background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 60%, transparent), transparent 60%);
	-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
	mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); opacity: 0; transition: opacity 0.3s ease; }
.card:hover::after { opacity: 1; }
.card .img-slot img { transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
.card:hover .img-slot img { transform: scale(1.06); }
.card .tag { transition: border-color 0.2s, color 0.2s; }
.card:hover .tag { border-color: var(--accent-dark); color: var(--fg); }

/* heading count badge */
.x-count { display: inline-block; margin-left: 0.5em; padding: 0.1em 0.65em; font-size: 0.5em; font-weight: 700; vertical-align: 0.35em;
	border: 1px solid var(--accent-dark); border-radius: 999px; color: var(--accent); background: rgba(90,160,220,0.08);
	font-variant-numeric: tabular-nums; }
.featured-heading { position: relative; }
.featured-heading::after { content: ""; position: absolute; left: 0; bottom: -1px; height: 1px; width: var(--lw, 0%);
	background: linear-gradient(90deg, var(--accent), transparent); transition: width 1.2s cubic-bezier(0.16, 1, 0.3, 1); }
.featured-heading.is-lit::after { width: 100%; }

/* generic reveal for headings on inner pages */
.x-reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1); }
.x-reveal.is-visible { opacity: 1; transform: none; }

/* code copy */
pre { position: relative; }
.x-copy { position: absolute; top: 0.6em; right: 0.6em; padding: 0.2em 0.7em; font: 600 0.65em/1.6 inherit; font-family: inherit;
	background: var(--bg); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
	opacity: 0; transition: opacity 0.2s, color 0.2s, border-color 0.2s; }
pre:hover .x-copy, .x-copy:focus-visible { opacity: 1; }
.x-copy:hover { color: var(--accent); border-color: var(--accent-dark); }

/* ---------- Floating dock (palette + back to top) ---------- */
.x-dock { position: fixed; right: 1.2em; bottom: 1.2em; z-index: 9000; display: flex; flex-direction: column; gap: 0.6em; align-items: flex-end; }
.x-fab { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border);
	background: color-mix(in srgb, var(--bg-raised) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
	color: var(--fg); cursor: pointer; position: relative; transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), border-color 0.2s, opacity 0.3s; font: inherit; }
.x-fab:hover { transform: translateY(-3px) scale(1.06); border-color: var(--accent); }
.x-fab svg { width: 18px; height: 18px; }
.x-top { opacity: 0; transform: translateY(14px) scale(0.8); pointer-events: none; }
.x-top.is-on { opacity: 1; transform: none; pointer-events: auto; }
.x-top.is-on:hover { transform: translateY(-3px) scale(1.06); }
.x-fab svg.x-ring { position: absolute; left: -1px; top: -1px; width: 46px; height: 46px; transform: rotate(-90deg); pointer-events: none; }
.x-ring circle { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.x-kbd { font-size: 0.7em; font-weight: 700; letter-spacing: 0.02em; }

/* ---------- Command palette ---------- */
.x-pal { position: fixed; inset: 0; z-index: 10005; display: flex; align-items: flex-start; justify-content: center; padding: 14vh 1em 1em;
	background: var(--pal-dim, rgba(5,5,5,0.62)); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.x-pal.is-open { opacity: 1; pointer-events: auto; }
.x-pal-box { width: min(560px, 100%); background: var(--bg-raised); border: 1px solid var(--border); border-radius: 16px;
	box-shadow: 0 30px 80px var(--pal-shadow, rgba(0,0,0,0.6)), 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent); overflow: hidden;
	transform: translateY(-12px) scale(0.97); transition: transform 0.25s cubic-bezier(0.16,1,0.3,1); }
.x-pal.is-open .x-pal-box { transform: none; }
.x-pal input { width: 100%; padding: 1em 1.2em; font-size: 16px; color: var(--fg); background: transparent; border: 0; border-bottom: 1px solid var(--border); outline: none; font-family: inherit; }
.x-pal ul { list-style: none; margin: 0; padding: 0.4em; max-height: 46vh; overflow-y: auto; }
.x-pal li { display: flex; align-items: center; justify-content: space-between; gap: 1em; margin: 0; padding: 0.65em 0.9em; border-radius: 10px;
	color: var(--fg); font-size: 0.9em; cursor: pointer; line-height: 1.3; }
.x-pal li small { color: var(--muted-dim); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.08em; }
.x-pal li.is-sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.x-pal-foot { display: flex; gap: 1.2em; padding: 0.6em 1em; border-top: 1px solid var(--border); color: var(--muted-dim); font-size: 0.7em; }
.x-pal-empty { padding: 1.2em; color: var(--muted); font-size: 0.9em; text-align: center; }
html.has-custom-cursor .x-pal li, html.has-custom-cursor .x-fab, html.has-custom-cursor .x-copy { cursor: none; }

/* ---------- Toast ---------- */
.x-toast { position: fixed; left: 50%; bottom: 1.6em; z-index: 10010; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
	padding: 0.7em 1.3em; border-radius: 999px; background: var(--bg-raised); color: var(--fg); border: 1px solid var(--accent-dark);
	font-size: 0.85em; box-shadow: var(--box-shadow); transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s; max-width: calc(100% - 2em); text-align: center; }
.x-toast.is-on { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Easter egg ---------- */
.x-party { animation: x-hue 3s linear infinite; }
@keyframes x-hue { to { filter: hue-rotate(360deg); } }
.x-confetti { position: fixed; top: -12px; width: 8px; height: 14px; z-index: 10020; pointer-events: none; animation: x-fall linear forwards; }
@keyframes x-fall { to { transform: translate3d(var(--dx), 108vh, 0) rotate(var(--rot)); opacity: 0.9; } }

@media (max-width: 520px) {
	.x-dock { right: 0.8em; bottom: 0.8em; }
	.x-fab { width: 42px; height: 42px; }
	.x-fab svg.x-ring { width: 42px; height: 42px; }
	.hero-type { font-size: 0.9em; }
}

/* ---------- Reduced motion: keep it calm ---------- */
@media (prefers-reduced-motion: reduce) {
	html { scroll-behavior: auto; }
	main, header { animation: none; }
	.x-grad { animation: none; }
	.x-wave, .x-ticker-track, .bg-fx .glow { animation: none !important; }
	.x-ticker { overflow-x: auto; }
	.x-reveal { opacity: 1; transform: none; transition: none; }
	.hero-type .x-caret { animation: none; }
}

/* ---------- Cursor fixes (custom-cursor devices only) ---------- */
/* Keep the circle cursor above the palette's blurred backdrop and toasts. */
html body > .custom-cursor { z-index: 20000; }
/* No native arrow/I-beam anywhere inside the palette. */
html.has-custom-cursor .x-pal,
html.has-custom-cursor .x-pal * { cursor: none; }
/* Browsers always draw the native arrow over a scrollbar, and CSS can't
   change that. With the circle cursor active, hide scrollbars instead; the
   progress bar at the top and the back-to-top ring replace them. */
html.has-custom-cursor { scrollbar-width: none; }
html.has-custom-cursor::-webkit-scrollbar,
html.has-custom-cursor *::-webkit-scrollbar { display: none; width: 0; height: 0; }
html.has-custom-cursor * { scrollbar-width: none; }

/* ---------- Custom draggable scroll bar ---------- */
/* Shown only where the native scrollbar is hidden (circle-cursor devices). */
.x-sb { position: fixed; top: 10px; bottom: 10px; right: 2px; width: 22px; z-index: 10006; /* above the palette backdrop (10005), below the cursor */ display: none; touch-action: none; }
html.has-custom-cursor .x-sb.is-needed { display: block; }
.x-sb-thumb { position: absolute; right: 5px; top: 0; width: 5px; min-height: 36px; border-radius: 999px;
	background: var(--accent); opacity: 0.32; transform-origin: 100% 50%;
	transition: width 0.22s cubic-bezier(0.34,1.56,0.64,1), right 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease, box-shadow 0.3s ease; }
.x-sb.is-active .x-sb-thumb, .x-sb:hover .x-sb-thumb { width: 9px; right: 3px; opacity: 0.95; box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 55%, transparent); }
.x-sb.is-scrolling .x-sb-thumb { opacity: 0.8; }
.x-sb.is-drag .x-sb-thumb { opacity: 1; }
html.has-custom-cursor .x-sb, html.has-custom-cursor .x-sb * { cursor: none; }
/* Hidden until the intro starts, so it doesn't sit there and then vanish. */
.x-sb.is-pre .x-sb-thumb { opacity: 0; translate: 26px 0; transition: none; }
/* intro nudge: slides in from the edge and bobs once so people notice it.
   Uses the separate `translate` property so it never fights the inline
   transform that positions the thumb. */
@keyframes x-sb-peek {
	0% { translate: 26px 0; opacity: 0; }
	35% { translate: 0 0; opacity: 1; }
	55% { translate: 0 14px; }
	75% { translate: 0 0; }
	100% { translate: 0 0; opacity: 0.32; }
}
.x-sb.is-intro .x-sb-thumb { animation: x-sb-peek 2.4s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* Palette list bar: sits inside the palette box, right of the GO TO / LINK labels. */
.x-pal-scroll { position: relative; }
.x-sb.x-sb-list { position: absolute; top: 6px; bottom: 6px; right: 2px; width: 16px; z-index: 2; }

/* Keep list items (and the selected highlight) clear of the palette's scroll bar. */
html.has-custom-cursor .x-pal ul { padding-right: 24px; }

/* ============================================================
   Portfolio additions
   ============================================================ */

/* skip link (keyboard users) */
.x-skip { position: fixed; left: 1em; top: -60px; z-index: 20001; padding: 0.6em 1em; border-radius: 999px;
	background: var(--accent); color: #0a0a0a; font-weight: 700; font-size: 0.85em; transition: top 0.2s ease; }
.x-skip:focus { top: 1em; color: #0a0a0a; }

.x-gone { display: none !important; }

/* filter chips */
.x-chips { display: flex; flex-wrap: wrap; gap: 0.5em; margin: -0.4em 0 1.4em; }
.x-chip { display: inline-flex; align-items: center; gap: 0.5em; padding: 0.4em 0.95em; font: inherit; font-size: 0.8em; color: var(--muted);
	background: transparent; border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
	transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s cubic-bezier(0.34,1.56,0.64,1); }
.x-chip span { font-size: 0.85em; color: var(--muted-dim); font-variant-numeric: tabular-nums; }
.x-chip:hover { color: var(--fg); border-color: var(--accent-dark); transform: translateY(-1px); }
.x-chip.is-on { color: var(--bg); background: var(--fg); border-color: var(--fg); font-weight: 700; }
.x-chip.is-on span { color: var(--bg); opacity: 0.6; }
html.has-custom-cursor .x-chip { cursor: none; }

/* project page: sticky "On this page" bar */
.x-toc { position: sticky; top: 10px; z-index: 30; margin: 1.6em 0 0; }
.x-toc-track { display: flex; gap: 0.3em; overflow-x: auto; padding: 0.35em; border: 1px solid var(--border); border-radius: 999px;
	background: color-mix(in srgb, var(--bg-raised) 82%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
	box-shadow: 0 8px 30px rgba(0,0,0,0.35); scrollbar-width: none; }
.x-toc-track::-webkit-scrollbar { display: none; }
.x-toc-a { flex: none; padding: 0.35em 0.9em; border-radius: 999px; color: var(--muted); font-size: 0.78em; white-space: nowrap;
	transition: color 0.2s, background 0.2s; }
.x-toc-a:hover { color: var(--fg); }
.x-toc-a.is-on { color: var(--fg); background: color-mix(in srgb, var(--accent) 22%, transparent); }
.prose h2 { scroll-margin-top: 90px; }
html.has-custom-cursor .x-toc-a { cursor: none; }

/* smooth page-to-page fade where the browser supports it */
@media (prefers-reduced-motion: no-preference) {
	@view-transition { navigation: auto; }
	::view-transition-old(root) { animation: 0.18s ease-in both x-vt-out; }
	::view-transition-new(root) { animation: 0.28s ease-out both x-vt-in; }
	@keyframes x-vt-out { to { opacity: 0; } }
	@keyframes x-vt-in { from { opacity: 0; } }
}

/* ---------- Day mode tweaks ---------- */
:root[data-mode="light"] { --pal-dim: rgba(30,40,55,0.32); --pal-shadow: rgba(30,50,80,0.28); }
/* sun <-> moon: both icons sit on top of each other and swap with a spin */
.x-mode { overflow: hidden; }
.x-ico { position: absolute; inset: 0; display: grid; place-items: center;
	transition: transform 0.6s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.35s ease; }
.x-mode svg { width: 20px; height: 20px; }
.x-mode .x-moon { opacity: 0; transform: rotate(-120deg) scale(0.3); }
:root[data-mode="light"] .x-mode .x-sun { opacity: 0; transform: rotate(120deg) scale(0.3); }
:root[data-mode="light"] .x-mode .x-moon { opacity: 1; transform: none; }
.x-mode:hover .x-sun svg { animation: x-spin 6s linear infinite; }
@keyframes x-spin { to { transform: rotate(360deg); } }
.x-mode:active { transform: scale(0.92); }

/* the circle reveal when switching day / night */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }
