/* Shared site chrome: theme tokens, navigation, theme switcher and footer.
   Also loaded inside the generated Quartz notes, so every rule stays scoped to
   the shell and never leaks into page content. */

.site-navigation,
.site-navigation *,
.site-footer,
.site-footer * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ffffff;
  --text: #111111;
  --text-body: #374151;
  --text-soft: #4b5563;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --border: #e5e7eb;
  --card-bg: #f9fafb;
  --nav-bg: rgba(255, 255, 255, 0.92);
  --badge-bg: #eff6ff;
  --badge-border: #bfdbfe;
  --email-card-bg: #f4f8ff;
  --email-card-border: #c7dbff;
  --email-card-hover: #93c5fd;
  --email-icon-bg: #dbeafe;
  --email-icon-text: #1e40af;
  --accent-shadow: rgba(37, 99, 235, 0.12);
  --on-accent: #ffffff;
  --max-w: 720px;
  --nav-height: 56px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --text: #e5e7eb;
  --text-body: #d1d5db;
  --text-soft: #9ca3af;
  --muted: #9ca3af;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --border: #1f2937;
  --card-bg: #111827;
  --nav-bg: rgba(11, 18, 32, 0.92);
  --badge-bg: #172554;
  --badge-border: #1d4ed8;
  --email-card-bg: #0f172a;
  --email-card-border: #1e3a8a;
  --email-card-hover: #2563eb;
  --email-icon-bg: #1e3a8a;
  --email-icon-text: #bfdbfe;
  --accent-shadow: rgba(96, 165, 250, 0.18);
  /* The dark accent is a pale blue, so it carries dark text rather than white. */
  --on-accent: #0b1220;
}

/* Never resolved from prefers-color-scheme, only ever chosen by hand. */
html[data-theme="unicorn"] {
  --bg: #fff6fb;
  --text: #4a0f33;
  --text-body: #5d2049;
  --text-soft: #6f3059;
  --muted: #8a4a6e;
  --accent: #c2185b;
  --accent-strong: #94104a;
  --border: #f3d3e4;
  --card-bg: #fffafd;
  --nav-bg: rgba(255, 246, 251, 0.92);
  --badge-bg: #fff5dc;
  --badge-border: #e9c66b;
  --email-card-bg: #fff3f9;
  --email-card-border: #f5c9df;
  --email-card-hover: #d94f8c;
  --email-icon-bg: #ffe3f0;
  --email-icon-text: #94104a;
  --accent-shadow: rgba(194, 24, 91, 0.16);
  --on-accent: #ffffff;
  --gold: #d9a520;
}

html:not([data-theme]) {
  color-scheme: light dark;
}

/* Pages that do not scroll would otherwise lay the navigation out a scrollbar
   further right than the ones that do. */
html {
  scrollbar-gutter: stable;
}

/* ── Navigation ── */
.site-navigation {
  position: sticky;
  top: 0;
  background: var(--nav-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 clamp(0.75rem, 4vw, 2rem);
  height: var(--nav-height);
  z-index: 100;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.7;
}

.nav-name {
  flex: 0 0 auto;
  min-width: max-content;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.site-navigation ul {
  flex: 0 0 auto;
  list-style: none;
  display: flex;
  gap: 2rem;
  align-items: center;
  white-space: nowrap;
}

.site-navigation a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  /* Quartz styles bare links, so the shell states its own metrics rather than
     inheriting whatever the surrounding page happens to set. */
  font-weight: 400;
  line-height: 1.7;
  transition: color 0.15s;
}

.nav-name a {
  font-weight: 600;
  font-size: 0.95rem;
}

.site-navigation a:hover {
  color: var(--text);
}

/* Grows from the left on hover and stays put on the current page. */
.nav-links > li > a {
  position: relative;
}

.nav-links > li > a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.4rem;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.2s ease;
}

.nav-links > li > a:hover::after,
.nav-links > li > a:focus-visible::after,
.nav-links > li > a[aria-current="page"]::after {
  transform: scaleX(1);
}

.nav-links > li > a[aria-current="page"] {
  color: var(--text);
}

html[data-theme="unicorn"] .nav-links > li > a::after {
  background: linear-gradient(90deg, var(--accent) 0%, var(--gold) 100%);
}

@media (prefers-reduced-motion: reduce) {
  .nav-links > li > a::after {
    transition: none;
  }
}

.nav-measurement {
  position: fixed;
  top: 0;
  left: -10000px;
  visibility: hidden;
  pointer-events: none;
}

.nav-measurement > .nav-links {
  width: max-content;
}

.site-navigation.nav-is-collapsed .nav-measurement .theme-switcher {
  margin: 0;
  padding: 0;
  border: 0;
}

.nav-toggle {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.nav-toggle[hidden] {
  display: none;
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
  border-color: var(--accent);
}

.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.15s, background 0.15s;
}

.nav-toggle-icon {
  position: relative;
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
  position: absolute;
  left: 0;
  content: "";
}

.nav-toggle-icon::before {
  top: -6px;
}

.nav-toggle-icon::after {
  top: 6px;
}

.site-navigation.nav-menu-open .nav-toggle-icon {
  background: transparent;
}

.site-navigation.nav-menu-open .nav-toggle-icon::before {
  transform: translateY(6px) rotate(45deg);
}

.site-navigation.nav-menu-open .nav-toggle-icon::after {
  transform: translateY(-6px) rotate(-45deg);
}

.site-navigation.nav-is-collapsed > .nav-links {
  position: absolute;
  top: calc(100% + 1px);
  right: clamp(0.75rem, 4vw, 2rem);
  width: min(18rem, calc(100% - 1.5rem));
  max-height: calc(100vh - var(--nav-height) - 1rem);
  max-height: calc(100dvh - var(--nav-height) - 1rem);
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
  display: grid;
  gap: 0.125rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  white-space: normal;
}

.site-navigation.nav-is-collapsed > .nav-links[hidden] {
  display: none;
}

.site-navigation.nav-is-collapsed > .nav-links > li {
  display: flex;
  width: 100%;
}

.site-navigation.nav-is-collapsed > .nav-links > li > a {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.site-navigation.nav-is-collapsed > .nav-links > li > a:hover,
.site-navigation.nav-is-collapsed > .nav-links > li > a:focus-visible {
  background: var(--email-card-bg);
  color: var(--text);
}

/* The dropdown stacks full width blocks, where an underline reads as a divider. */
.site-navigation.nav-is-collapsed > .nav-links > li > a::after {
  display: none;
}

.site-navigation.nav-is-collapsed > .nav-links > li > a[aria-current="page"] {
  background: var(--email-card-bg);
  color: var(--accent-strong);
  font-weight: 600;
}

.site-navigation.nav-is-collapsed .theme-switcher {
  justify-content: flex-end;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem 0;
  border-top: 1px solid var(--border);
}

/* ── Theme switcher ── */
.theme-switcher {
  position: relative;
  display: inline-flex;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-glyph {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1.5px solid var(--text);
  background: linear-gradient(90deg, var(--text) 50%, transparent 50%);
}

html[data-theme="unicorn"] .theme-glyph {
  border-color: var(--accent);
  background: linear-gradient(135deg, #ff8fc8 0%, var(--gold) 100%);
}

.theme-menu {
  /* A popover, so it renders in the top layer and escapes the collapsed
     navigation's scroll container. Placed against the button from theme.ts.

     The UA sheet anchors [popover] with inset: 0. Safari keeps the right and
     bottom edges once JS sets left and top, which stretches the box into the
     viewport corner and blows up the grid rows, so reset the longhands and pin
     the size explicitly. An explicit size also wins if an edge does survive. */
  position: fixed;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  width: fit-content;
  height: fit-content;
  margin: 0;
  min-width: 120px;
  padding: 0.35rem;
  gap: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.theme-menu:popover-open {
  display: grid;
  align-content: start;
}

.theme-option {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 0.38rem 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.theme-option:hover {
  background: var(--email-card-bg);
}

.theme-option.is-active {
  background: var(--email-card-bg);
  color: var(--accent-strong);
  font-weight: 600;
}

.site-navigation .sr-only,
.site-footer .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Cursor sparkles, unicorn theme only ── */
.sparkle-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 9999;
}

.sparkle {
  position: absolute;
  width: var(--sparkle-size);
  height: var(--sparkle-size);
  background: var(--sparkle-color);
  filter: drop-shadow(0 0 3px rgba(194, 24, 91, 0.4));
  clip-path: polygon(
    50% 0%,
    61% 39%,
    100% 50%,
    61% 61%,
    50% 100%,
    39% 61%,
    0% 50%,
    39% 39%
  );
  will-change: transform, opacity;
}

/* ── Footer ── */
.site-footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.7;
}

.legal-links {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.legal-links a {
  color: var(--muted);
  text-decoration: none;
}

.legal-links a:hover {
  text-decoration: underline;
  color: var(--text);
}

/* Fits the generated Quartz notes inside the site shell.
   Loaded only on /notes/ pages, appended after shell.css. */

/* Quartz sizes the root at 100vw, which is a scrollbar wider than the content
   box and shifts the whole shell right of where it sits on the Astro pages. */
html {
  width: auto;
}

.site-navigation {
  z-index: 1000;
}

/* Quartz pins its sidebars to the viewport top, which the sticky navbar now occupies. */
#quartz-root .sidebar {
  top: var(--nav-height);
  max-height: calc(100vh - var(--nav-height));
}

#quartz-root .page > #quartz-body {
  margin-top: 1rem;
}

/* Quartz paints itself from its own palette, and only ships a light and a dark
   one, so unicorn repaints the light set it inherits. */
html[data-theme="unicorn"] {
  --light: #fff6fb;
  --lightgray: #f3d3e4;
  --gray: #a8698c;
  --darkgray: #5d2049;
  --dark: #4a0f33;
  --secondary: #c2185b;
  --tertiary: #94104a;
  --highlight: rgba(194, 24, 91, 0.1);
  --textHighlight: #ffe08a;
}

/* Sits left of Quartz's reader mode button and matches its metrics. */
.lucky-button {
  position: relative;
  width: 20px;
  height: 32px;
  flex-shrink: 0;
  margin: 0 0.9rem 0 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.lucky-button svg {
  position: absolute;
  top: calc(50% - 10px);
  width: 20px;
  height: 20px;
  stroke: var(--darkgray);
  transition: opacity 0.1s;
}

.lucky-button:hover svg,
.lucky-button:focus-visible svg {
  opacity: 0.7;
}

.lucky-button:disabled {
  cursor: progress;
}

.site-footer {
  margin-top: 2rem;
}
