@font-face {
  font-family: 'Maple Mono';
  src: url('./assets/fonts/MapleMono/MapleMono-VF.woff2') format('woff2');
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Maple Mono';
  src: url('./assets/fonts/MapleMono/MapleMono-Italic-VF.woff2') format('woff2');
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Retrospective Nerd Icons';
  src: url('./assets/fonts/JetBrainsMono/JetBrainsMonoNerdIcons.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

/* Theme tokens */
:root {
  --font-main: 'Maple Mono', monospace;
  --icon-size: 1.2rem;
  --icon-cell: 3.25rem;
  --page-width: 720px;
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --bg-color: #f2f2f2;
  --border-color: #d8d8d8;
  --link-hover: #5a5a5a;
  --primary-color: #484848;
  --primary-dim: #6e6e6e;
  --accent-color: #383838;
  --accent-dim: #e0e0e0;
  --prompt-user: #2a7d3a;
  --prompt-host: #3366c4;
  --prompt-root: #c04038;
  --code-block-bg: #f5f2f0;
  --math-color: #000;
  --scanline-opacity: 0.06;
  --cursor-outline: #f2f2f2;
  --cursor-glow: rgba(0, 0, 0, 0.14);
}

/* Dark theme tokens */
html.dark {
  --bg-color: #101010;
  --border-color: #303030;
  --link-hover: #b0b0b0;
  --primary-color: #959595;
  --primary-dim: #7a7a7a;
  --accent-color: #b8b8b8;
  --accent-dim: #3a3a3a;
  --prompt-user: #7fc97f;
  --prompt-host: #6fa8dc;
  --prompt-root: #e06c75;
  --code-block-bg: #121212;
  --math-color: #fff;
  --scanline-opacity: 0.1;
  --cursor-outline: #252931;
  --cursor-glow: rgba(255, 255, 255, 0.18);
}

/* Misc */
.nerd-icon {
  font-family: 'Retrospective Nerd Icons';
  font-size: var(--icon-size);
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  margin-right: var(--space-2);
}

.nerd-icon-inline {
  font-family: 'Retrospective Nerd Icons';
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  margin: 0 0.15em;
}

.def-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: calc(var(--space-7) + var(--space-3)) 0 var(--space-4);
  border-radius: 8px;
}

/* Reset and layout */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  cursor: none;
}

@media (pointer: coarse) {
  * {
    cursor: auto;
  }

  .site-cursor {
    display: none;
  }
}

body {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--space-5) calc(var(--icon-cell) + var(--space-4) + var(--space-5));
  font-family: var(--font-main);
  font-weight: 400;
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: 0.01em;
  color: var(--primary-color);
  background-color: var(--bg-color);
}

/* Custom cursor */
.site-cursor {
  width: 24px;
  height: 24px;
  background-image: url('./assets/cursors/default-light.svg');
  background-repeat: no-repeat;
  background-size: contain;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 3000;
  image-rendering: pixelated;
  filter:
    drop-shadow(2px 0 0 var(--cursor-outline))
    drop-shadow(0 2px 0 var(--cursor-outline))
    drop-shadow(-2px 0 0 var(--cursor-outline))
    drop-shadow(0 -2px 0 var(--cursor-outline))
    drop-shadow(0 0 4px var(--cursor-glow));
  pointer-events: none;
}

.site-cursor.is-hovering {
  background-image: url('./assets/cursors/pointer-light.svg');
}

html.dark .site-cursor {
  background-image: url('./assets/cursors/default.svg');
}

html.dark .site-cursor.is-hovering {
  background-image: url('./assets/cursors/pointer.svg');
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
  opacity: var(--scanline-opacity);
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 3px,
    var(--primary-color) 4px
  );
}

header,
.site-nav {
  z-index: 500;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-color);
  box-shadow: 0 0 0 var(--space-4) var(--bg-color);
}

header {
  position: sticky;
  top: var(--space-4);
  margin: var(--space-4) 0 var(--space-5);
}

section {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-color);
}

/* Navbar */
.site-banner {
  display: grid;
  grid-template-columns: 1fr var(--icon-cell);
  gap: 0;
  align-items: stretch;
  padding: 0;
  overflow: hidden;
  color: var(--primary-color);
  text-decoration: none;
  white-space: nowrap;
}

.site-banner > span {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  color: var(--accent-color);
}

.site-banner > .logo {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: var(--icon-cell);
  padding: 0;
  border-left: 1px solid var(--border-color);
}

.logo::before {
  content: '';
  width: 52%;
  height: 52%;
  background-color: var(--accent-color);
  mask: url('./assets/images/logo.svg') center / contain no-repeat;
}

.prompt-user {
  color: var(--prompt-user);
}

.prompt-host {
  color: var(--prompt-host);
}

.prompt-root {
  color: var(--prompt-root);
}

.site-banner,
.site-nav > a,
.grid-label {
  font-size: clamp(0.55rem, 4vw, 1rem);
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

.site-banner {
  font-size: clamp(0.7rem, 4.5vw, 1.15rem);
  letter-spacing: 0;
  text-transform: none;
}

.site-nav {
  position: fixed;
  right: 0;
  bottom: var(--space-4);
  left: 0;
  width: calc(min(var(--page-width), 100%) - 2 * var(--space-5));
  margin: 0 auto;
  gap: 0;
  align-items: stretch;
}

.site-nav > a {
  flex: 1;
  align-self: stretch;
  gap: 1ch;
  padding: var(--space-4) var(--space-4);
}

.site-nav .btn-icon {
  flex: 0 0 var(--icon-cell);
}

.site-nav > a + a {
  border-left: 1px solid var(--border-color);
}

.site-nav > a:hover,
.grid-label[href]:hover {
  background-color: var(--border-color);
  color: var(--accent-color);
}

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

.site-nav > a::before {
  content: '[ ]';
  white-space: pre;
}

.site-nav > a[aria-current="page"]::before {
  content: '[*]';
}

.site-nav .btn-icon {
  width: auto;
  height: auto;
  min-height: var(--icon-cell);
  border: 0;
  border-left: 1px solid var(--border-color);
  border-radius: 0;
}

.grid-label {
  display: grid;
  grid-template-columns: var(--icon-cell) 1fr;
  gap: 0;
  align-items: stretch;
  margin-bottom: var(--space-4);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  text-decoration: none;
}

.grid-label > * {
  display: flex;
  align-items: center;
  min-height: var(--icon-cell);
  padding: var(--space-4) var(--space-4);
}

.grid-label > *:first-child {
  justify-content: center;
  padding: 0;
  font-size: 1.7rem;
  line-height: 1;
}

.grid-label > :first-child {
  justify-content: center;
  padding: 0;
  border-right: 1px solid var(--border-color);
}

#home > section {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

nav {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

nav a {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  color: var(--primary-dim);
  text-decoration: none;
}

a {
  color: var(--primary-dim);
}

a:hover {
  color: var(--accent-color);
}

#posts-list a {
  color: var(--primary-color);
  text-decoration: none;
}

.posts-list-items {
  display: flex;
  flex-direction: column;
}

.posts-list-items .post-meta {
  display: grid;
  grid-template-columns: 5ch minmax(0, 1fr);
  gap: var(--space-4);
}

.posts-list-items article {
  display: block;
  padding: var(--space-1) 0;
  transform-origin: left center;
  transition: transform 0.18s ease, opacity 0.18s ease, color 0.18s ease;
}

.posts-list-items:hover article {
  opacity: 0.7;
}

.posts-list-items article:hover {
  opacity: 1;
}

/* Projects */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--space-3);
}

.project-disk {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-color);
  color: var(--primary-color);
  text-decoration: none;
}

.project-disk-type {
  color: var(--primary-dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Button */
.btn {
  font-family: var(--font-main);
  background: none;
  border: 1px solid var(--border-color);
  color: var(--primary-dim);
  padding: var(--space-2);
  border-radius: 8px;
  font-size: var(--icon-size);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 0;
  line-height: 1;
  padding: 0;
}

.btn-icon svg {
  display: block;
  width: 1.7rem;
  height: 1.7rem;
  flex: none;
}

.btn:hover {
  background-color: var(--border-color);
}

/* Post Content Styling */
h3, h3 a {
  color: var(--primary-dim);
  padding: var(--space-3) 0;
  text-decoration: none;
  font-weight: 400;
}

.post-meta {
  color: var(--primary-dim);
  font-weight: 400;
}

.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: var(--space-6) auto;
  border-radius: 8px;
}

.post-header {
  margin: 0;
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--border-color);
  top: 0;
  background-color: var(--bg-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100
}

.post-header-content {
  flex: 1;
}

.post-header-content h1,
.post-body h2,
.post-body h3,
.post-body h4 {
  font-weight: 400;
  line-height: 1.4;
}

.post-body {
  display: flex;
  flex-direction: column;
}

.post-section {
  display: flow-root;
  margin: 0;
  padding: var(--space-5) 0;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.post-body:has(.post-section:hover) .post-section:not(:hover) {
  opacity: 0.38;
}

.post-body .post-section:hover {
  opacity: 1;
}

.post-body h2 {
  margin: var(--space-6) 0 var(--space-4) 0;
  color: var(--primary-dim);
}

.post-section > :first-child {
  margin-top: 0;
}

.post-section > :last-child {
  margin-bottom: 0;
}

.post-body h2,
.post-body h3,
.post-body h4 {
  position: relative;
  padding-bottom: var(--space-2);
}

.post-body h2::after,
.post-body h3::after,
.post-body h4::after {
  content: '';
  display: block;
  width: 1rem;
  margin-top: var(--space-2);
  border-bottom: 2px solid var(--accent-color);
}

.post-body p {
  margin-bottom: var(--space-4);
}

.post-body blockquote {
  border-left: 4px solid var(--border-color);
  padding-left: var(--space-4);
  margin: var(--space-4) 0;
  font-style: italic;
}

/* Native MathML equations */
.post-body .math-block {
  margin: var(--space-4) 0;
  padding: var(--space-4) var(--space-5);
  overflow-x: auto;
  color: var(--math-color);
  background-color: var(--code-block-bg);
  border-left: 2px solid var(--primary-dim);
  border-radius: 0 8px 8px 0;
}

.post-body .math-block-result {
  border-left-color: var(--accent-color);
}

.post-body .math-block math {
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
  font-family: 'STIX Two Math', 'Cambria Math', 'Times New Roman', serif;
  font-size: 1.15rem;
}

/* Code Styling */
.post-body pre[class*="language-"] {
  border-radius: 8px;
  margin: var(--space-4) 0;
  overflow-x: auto;
}

/* Inline Code (not handled by Prism) */
.post-body p code:not([class*="language-"]) {
  background-color: var(--border-color);
  padding: 0.2rem var(--space-1);
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Copy icon */
div.code-toolbar > .toolbar > .toolbar-item > button {
  background: transparent !important;
  font-size: 0 !important;
  padding: 0 var(--space-2) !important;
  box-shadow: none !important;
}

/* Default copy icon */
div.code-toolbar > .toolbar > .toolbar-item > button::before {
  font-family: 'Retrospective Nerd Icons';
  font-size: var(--icon-size) !important;
  content: '\f018f';
}

/* Dossier */
.dossier-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.dossier-link {
  margin-bottom: 0;
}

/* First-visit archive loader */
html.archive-loading,
html.archive-loading body {
  overflow: hidden;
}

html.archive-loading .site-cursor {
  display: none;
}

.archive-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: clamp(1.25rem, 5vw, 4rem);
  overflow: hidden;
  color: var(--primary-color);
  background: var(--bg-color);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.archive-loader[hidden] {
  display: none;
}

.archive-loader.is-complete {
  opacity: 0;
  transform: scale(0.995);
}

.archive-terminal {
  width: min(100%, 760px);
  text-align: center;
}

.archive-art,
.archive-bar {
  letter-spacing: 0;
  white-space: pre;
}

.archive-art {
  display: inline-block;
  margin: 0 0 var(--space-6);
  font-size: 2rem;
  color: var(--primary-color);
  font-family: inherit;
  line-height: 1;
  text-align: left;
}

.archive-bar {
  color: var(--accent-color);
  font-size: 0.8rem;
  line-height: 1.4;
}

.archive-cursor {
  animation: archive-cursor 0.8s steps(1) infinite;
}

@keyframes archive-cursor {
  50% { opacity: 0; }
}

/* Transitions */
html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

a, nav a, .btn, .font-select {
  transition: color 0.2s ease, background-color 0.2s ease;
}

.page {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  body {
    padding-inline: var(--space-4);
    font-size: 16px;
    line-height: 1.75;
  }

  .site-nav {
    width: calc(100% - 2 * var(--space-4));
  }

  .post-header {
    padding-top: var(--space-4);
  }

  .dossier-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
