/* Theme tokens: follow system preference by default, overridden by [data-theme] */
:root {
  color-scheme: light dark;
  --page-from: light-dark(#d5d9de, #1e2030);
  --page-to: light-dark(#ccd0d4, #24283b);
  --footer-bg: light-dark(#e5e7eb, #1a1c2a);
  --footer-text: light-dark(#4f5765, #8994c2);
  --footer-hover: light-dark(#2d333d, #a9b8e8);
  --text-primary: light-dark(#1f242d, #c0caf5);
  --text-secondary: light-dark(#374151, #a9b1d6);
  --text-muted: light-dark(#4f5765, #8994c2);
  --link-color: light-dark(#1f242d, #c0caf5);
  --link-hover: light-dark(#2d333d, #a9b8e8);
  --border-subtle: light-dark(rgba(79, 87, 101, 0.25), rgba(137, 148, 194, 0.24));
  --surface-subtle: light-dark(rgba(255, 255, 255, 0.45), rgba(26, 28, 42, 0.5));
  --code-bg: light-dark(rgba(255, 255, 255, 0.6), rgba(26, 28, 42, 0.7));
  --pill-bg: light-dark(rgba(31, 36, 45, 0.07), rgba(192, 202, 245, 0.09));
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

*,
::before,
::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
}

html {
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

button {
  background: transparent;
  font: inherit;
}

a {
  color: inherit;
  text-decoration: inherit;
}

svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.page {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: linear-gradient(to top, var(--page-from), var(--page-to));
  color: var(--text-primary);
}

.page--home main {
  display: flex;
  flex-grow: 1;
  align-items: center;
  justify-content: center;
  padding: 5rem 0 3rem;
}

.page--content main {
  flex-grow: 1;
  width: 100%;
  max-width: 42rem;
  margin-inline: auto;
  padding: 5rem 1.5rem 4rem;
}

/* Header & Navigation */
.site-header {
  position: absolute;
  inset-block-start: 16px;
  inset-inline: 16px;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.site-brand {
  grid-column: 1;
  justify-self: start;
  padding: 8px;
  border-radius: 9999px;
  color: var(--footer-text);
  transition: color 150ms;
}

.site-brand:hover {
  color: var(--footer-hover);
}

.site-brand:focus-visible,
.site-nav a:focus-visible,
.theme-toggle:focus-visible,
.prose a:focus-visible,
.notes-list a:focus-visible,
.rss-link:focus-visible,
.back-link:focus-visible,
.social-links a:focus-visible,
pre.shiki:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.prose a:focus-visible,
.notes-list a:focus-visible,
.rss-link:focus-visible,
.back-link:focus-visible,
.social-links a:focus-visible {
  border-radius: 0.25rem;
}

.site-nav {
  grid-column: 2;
  justify-self: center;
  position: relative;
  display: flex;
  align-items: center;
}

.site-nav a {
  padding: 0.375rem 1rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  color: var(--footer-text);
  transition: color 150ms;
}

/* Hover pill fallback for browsers without anchor positioning */
.site-nav a:hover {
  color: var(--footer-hover);
  background: var(--pill-bg);
}

.site-nav a[aria-current="page"] {
  color: var(--text-primary);
  font-weight: 500;
}

/* With anchor positioning, one pill slides between links. The hovered link
   is the anchor; the nav's ::before draws the rounded pill so the links keep
   rectangular hit boxes with no corner dead zones between them. */
@supports (anchor-name: --x) {
  .site-nav a {
    border-radius: 0;
  }

  .site-nav a:hover,
  .site-nav a:focus-visible {
    anchor-name: --nav-hover;
    background: none;
  }

  .site-nav a:focus-visible {
    border-radius: 9999px;
  }

  .site-nav::before {
    content: "";
    position: absolute;
    position-anchor: --nav-hover;
    inset: anchor(top) anchor(right) anchor(bottom) anchor(left);
    border-radius: 9999px;
    background: var(--pill-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;

    @media (prefers-reduced-motion: no-preference) {
      transition: inset 300ms cubic-bezier(0.22, 1, 0.36, 1), opacity 300ms ease;
    }
  }

  .site-nav:has(a:hover, a:focus-visible)::before {
    opacity: 1;
  }
}

/* Theme toggle */
.theme-toggle {
  grid-column: 3;
  justify-self: end;
  padding: 8px;
  border-radius: 9999px;
  color: var(--footer-text);
  cursor: pointer;
  transition: color 150ms;
  view-transition-name: theme-toggle;
}

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

/* Sun <-> moon morph: the disc grows while a "cutter" circle slides across it
   to carve the crescent, and the rays shrink into the centre. */
.theme-icon .body,
.theme-icon .cutter,
.theme-icon .rays {
  transform-box: view-box;
  transform-origin: 12px 12px;
}

.theme-icon,
.theme-icon .body,
.theme-icon .cutter,
.theme-icon .rays {
  transition: transform 500ms cubic-bezier(0.34, 1.3, 0.5, 1), opacity 300ms ease;
}

/* Constant line weight while scaling */
.theme-icon .disc,
.theme-icon .cutter {
  vector-effect: non-scaling-stroke;
}

.theme-icon {
  transform: rotate(90deg);
}

/* Sun state. The 90deg spin is invisible at rest (sun repeats every 45deg) */
.theme-icon .body {
  transform: scale(0.5);
}

.theme-icon .cutter {
  transform: translate(20px, -20px);
}

.theme-icon .rays {
  transform: rotate(0deg) scale(1);
  opacity: 1;
}

/* Moon state (dark theme) */
:root[data-theme="dark"] .theme-icon {
  transform: rotate(0deg);
}

:root[data-theme="dark"] .theme-icon .body {
  transform: scale(1);
}

:root[data-theme="dark"] .theme-icon .cutter {
  transform: translate(4.5px, -4.5px);
}

:root[data-theme="dark"] .theme-icon .rays {
  transform: rotate(90deg) scale(0);
  opacity: 0;
}

/* Page wipe: disable the default cross-fade (the circle is animated in JS) */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(root) {
  z-index: 0;
}

::view-transition-new(root) {
  z-index: 1;
}

/* Lift the toggle into its own layer so it stays visible above the wipe */
::view-transition-group(theme-toggle) {
  z-index: 2;
}

/* No icon animation for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .theme-icon,
  .theme-icon * {
    transition: none !important;
  }
}

/* Content pages & Prose */
.article-header {
  margin-bottom: 2rem;
}

.article-header h1,
.notes-header h1 {
  font-size: 1.875rem;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-wrap: balance;
}

.page-meta {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.article-header .page-meta:first-child {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.back-link {
  color: var(--text-muted);
  transition: color 150ms;
}

.back-link:hover {
  color: var(--link-hover);
}

.prose {
  color: var(--text-secondary);
  font-size: 1.03125rem;
  line-height: 1.7;
  overflow-wrap: break-word;
}

.prose p,
.prose li,
.prose blockquote {
  text-wrap: pretty;
}

.prose h2 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
  text-wrap: balance;
}

.prose h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  text-wrap: balance;
}

.prose p + p,
.prose ul + p,
.prose ol + p,
.prose pre + p,
.prose blockquote + p,
.prose table + p,
.prose .placeholder-notice + p {
  margin-top: 1.15rem;
}

.prose ul,
.prose ol {
  margin-top: 0.75rem;
  margin-bottom: 1.15rem;
  padding-left: 1.35rem;
}

.prose li + li {
  margin-top: 0.4rem;
}

.prose a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-color: var(--border-subtle);
  text-underline-offset: 0.2em;
  transition: color 150ms, text-decoration-color 150ms;
}

.prose a:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}

.prose blockquote {
  margin-block: 1.25rem;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 2px solid var(--border-subtle);
  color: var(--text-muted);
}

.prose hr {
  border-top: 1px solid var(--border-subtle);
  margin-block: 2rem;
}

.prose :not(pre) > code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.875em;
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
}

.prose pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-block: 1.5rem;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.prose th,
.prose td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}

.prose th:first-child,
.prose td:first-child {
  padding-left: 0;
}

.prose th:last-child,
.prose td:last-child {
  padding-right: 0;
}

.prose th {
  font-weight: 600;
  color: var(--text-primary);
  border-bottom-width: 2px;
  text-wrap: balance;
}

.placeholder-notice {
  padding: 0.875rem 1rem;
  margin-bottom: 1.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
  background: var(--surface-subtle);
  font-size: 0.9375rem;
  color: var(--text-muted);
}

/* Notes index */
.notes-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.rss-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  transition: color 150ms;
}

.rss-link:hover {
  color: var(--footer-hover);
}

.rss-link svg {
  width: 0.875rem;
  height: 0.875rem;
}

.notes-list {
  list-style: none;
  border-top: 1px solid var(--border-subtle);
}

.notes-list li {
  border-bottom: 1px solid var(--border-subtle);
}

.notes-list a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 0;
  transition: color 150ms;
}

@media (min-width: 40rem) {
  .notes-list a {
    flex-direction: row;
    align-items: baseline;
    gap: 1.5rem;
  }
}

.notes-list time {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 6.5rem;
}

.note-title {
  font-weight: 500;
  color: var(--text-primary);
}

.notes-list a:hover .note-title {
  color: var(--footer-hover);
}

/* Shiki dual-theme switching (catppuccin-latte by default, tokyo-night in dark mode) */
pre.shiki {
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.65;
  border: 1px solid var(--border-subtle);
  margin-block: 1.25rem;
}

:root[data-theme="dark"] .shiki,
:root[data-theme="dark"] .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

/* Footer */
.site-footer {
  padding: 2rem 1.5rem;
  background: var(--footer-bg);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  margin-inline: auto;
  text-align: center;
  color: var(--footer-text);
}

.social-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.social-links a {
  padding: 0.5rem;
  transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

@media (min-width: 40rem) {
  .footer-inner {
    max-width: 40rem;
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
}

@media (min-width: 48rem) {
  .footer-inner {
    max-width: 48rem;
  }
}

@media (min-width: 64rem) {
  .footer-inner {
    max-width: 64rem;
  }
}

@media (min-width: 80rem) {
  .footer-inner {
    max-width: 80rem;
  }
}

@media (min-width: 96rem) {
  .footer-inner {
    max-width: 96rem;
  }
}
