:root {
  /* High-contrast mono: black on white, one accent for links. */
  --color-bg: #FFFFFF;
  --color-bg-alt: #F2F2F2;
  --color-text: #111111;
  --color-text-muted: #555555;
  --color-border: #111111;
  --color-border-muted: #CCCCCC;
  --color-accent: #0645AD;

  --color-primary: var(--color-text);
  --color-secondary: var(--color-accent);
  --color-heading-accent: var(--color-text);
  --color-bg-light: var(--color-bg);
  --color-bg-dark: var(--color-text);
  --color-text-main: var(--color-text);
  --color-link: var(--color-accent);

  --font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --font-size-base: 19px;
  --font-size-sm: 0.875rem;
  --font-size-h1: clamp(1.75rem, 1.1rem + 2.6vw, 2.5rem);
  --font-size-h2: 2.25rem;
  --font-size-h3: 1.75rem;
  --font-size-h4: 1.25rem;

  --space-unit: 8px;
  --space-xs: calc(var(--space-unit) * 1);
  --space-sm: calc(var(--space-unit) * 2);
  --space-md: calc(var(--space-unit) * 4);
  --space-lg: calc(var(--space-unit) * 8);

  --radius-btn: 0px;
  --radius-card: 0px;
  --shadow: none;

  --max-width: 1200px;
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/SpaceGrotesk-Regular.otf") format("opentype");
}

@font-face {
  font-family: "Space Mono";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/SpaceMono-Regular.otf") format("opentype");
}

* {
  box-sizing: border-box;
}

/* Several posts pin an explicit pixel width via org's ATTR_HTML
   (e.g. :width 600px) for a desktop-sized figure. Without a cap those
   overflow the content column on any screen narrower than the pinned
   width — cap at the container instead of the attribute. */
img {
  max-width: 100%;
  height: auto;
}

/* org exports :align center as an align="center" attribute on <img>,
   which browsers ignore for block-level images — center the figure
   wrapper instead. */
.figure {
  text-align: center;
}

html {
  font-size: var(--font-size-base);
  background-color: var(--color-bg);
}

body {
  font-family: var(--font-family);
  line-height: 1.6;
  color: var(--color-text);
  margin: 0;
  padding: var(--space-lg);
  padding-top: calc(70px + var(--space-lg)); /* Space for fixed navbar */
  /* Headings and paragraphs regularly carry one long unbroken token —
     a bare URL, or a =module:function/arity= code span — with no space
     to wrap at. Inherited so it covers every element, not just the
     ones already special-cased (code, pre). */
  overflow-wrap: anywhere;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

#content {
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--color-bg);
  padding: var(--space-lg);
}

/* Headers */
h1, h2, h3, h4 {
  font-weight: 800;
  margin-top: 0;
  margin-bottom: var(--space-sm);
  color: var(--color-text);
  line-height: 1.2;
}

h1.title {
  position: relative;
  font-size: var(--font-size-h1);
  line-height: 1.15;
  color: var(--color-text);
  border-bottom: 3px solid var(--color-border);
  margin-bottom: var(--space-lg);
  padding: 0 0 var(--space-md);
}

.subtitle {
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--color-text-muted);
  display: block;
  margin-top: 0.5rem;
}

h2 {
  font-size: var(--font-size-h2);
  margin-top: var(--space-lg);
  border-bottom: 1px solid var(--color-border-muted);
  padding-bottom: var(--space-xs);
}

h2 a {
  color: inherit !important;
  text-decoration: none !important;
}

h2 a:hover {
  text-decoration: underline !important;
}

/* Floating Navbar */
.navbar-custom {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  z-index: 1000;
  display: flex;
  align-items: center;
  margin-bottom: 0;
  padding: 0;
}

.navbar-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.navbar-brand {
  font-weight: 900;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text);
  flex: 0 0 auto;
}

.navbar-brand a {
  color: inherit !important;
  text-decoration: none !important;
}

.navbar-grid {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  height: 100%;
  flex: 1 1 auto;
  justify-content: center;
}

.navbar-utility {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.rss-link {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border-muted);
  transition: all 0.2s;
}

.rss-link:hover {
  color: var(--color-text);
  border-color: var(--color-text);
  background: var(--color-bg-alt);
}

.navbar-grid a {
  text-decoration: none;
}

.navbar-section {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.navbar-section .navbar-heading {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  color: var(--color-text);
  border: none;
  padding: 0 var(--space-sm);
  cursor: pointer;
  transition: color 0.2s;
}

.navbar-section:hover .navbar-heading {
  color: var(--color-accent);
}

/* Dropdown Logic */
.navbar-tags {
  display: none;
  position: absolute;
  top: 60px;
  left: 0;
  background: var(--color-bg);
  min-width: 280px;
  border: 1px solid var(--color-border);
  border-top: none;
  padding: var(--space-xs);
  flex-direction: column;
  gap: 2px;
}

.navbar-section:hover .navbar-tags {
  display: flex;
}

.navbar-tag {
  font-family: var(--font-family) !important;
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 1rem;
  background: transparent !important;
  color: var(--color-text) !important;
  border: none !important;
  display: block;
  width: 100%;
  transition: background 0.2s, color 0.2s;
}

.navbar-tag:hover {
  background: var(--color-bg-alt) !important;
  color: var(--color-accent) !important;
}

/* Links */
a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

/* Keyboard focus */
a:focus-visible,
.rss-link:focus-visible,
.navbar-tag:focus-visible,
.project-box:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Code */
pre, code {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  background: var(--color-bg-alt);
}

code {
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--color-border-muted);
}

pre {
  padding: 1rem;
  border: 1px solid var(--color-border);
  overflow-x: auto;
  margin: 1.5rem 0;
}

pre code {
  border: none;
  padding: 0;
}

/* Content */
p {
  margin-bottom: 1.5rem;
}

hr {
  border: none;
  height: 1px;
  background: var(--color-border);
  margin: var(--space-lg) 0;
}

/* Projects Grid */
.projects-container {
  margin: var(--space-lg) 0;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-md);
}

.project-box {
  display: block;
  height: 200px;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  border: 1px solid var(--color-border);
  transition: transform 0.15s ease;
  background-color: var(--color-bg-alt);
  background-size: cover;
  background-position: center;
}

.project-box:hover {
  transform: translate(-2px, -2px);
}

.project-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 17, 17, 0.92);
  color: #FFFFFF;
  padding: 12px 16px;
  transition: background 0.3s ease;
  border-top: 2px solid var(--color-accent);
}

.project-box:hover .project-overlay {
  background: rgba(17, 17, 17, 0.98);
}

/*
   Breakpoint covers phones AND the effective viewport of larger phones
   under browser zoom: most mobile visitors read this site at ~125% page
   zoom, which shrinks the CSS/layout viewport by the same factor (e.g. a
   390px-wide phone reports ~312px, a 428px phone ~342px). Design the
   fluid rules below to hold up down to ~300px, not just the raw 390-428px
   device width, or the zoomed-in majority still gets the broken layout.
   Placed last in the file so it wins the cascade against same-specificity
   rules declared earlier (e.g. .project-grid, .navbar-custom).
*/
@media (max-width: 900px) {
  html { font-size: 17px; }

  body {
    padding: var(--space-sm);
    padding-top: var(--space-sm);
  }

  #content {
    padding: var(--space-sm);
  }

  h1.title {
    padding: var(--space-sm) 0;
    margin-bottom: var(--space-md);
  }

  /* The floating/fixed navbar assumes a fixed height and a single
     nowrap row wide enough for brand + 3 dropdown sections + RSS +
     avatar (~900px min-content). Below that it forces horizontal
     scrolling of the bar itself. Drop the fixed positioning in favor
     of a normal-flow sticky bar that can wrap and grow. */
  .navbar-custom {
    position: sticky;
    height: auto;
    min-height: 56px;
  }

  .navbar-container {
    flex-wrap: wrap;
    row-gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
  }

  .navbar-brand {
    font-size: 1rem;
  }

  .navbar-grid {
    order: 3;
    flex-basis: 100%;
    flex-wrap: wrap;
    justify-content: center;
    height: auto;
    gap: var(--space-xs) var(--space-sm);
  }

  .navbar-section {
    height: auto;
  }

  .navbar-section .navbar-heading {
    padding: var(--space-xs) 0;
  }

  /* The submenu only ever opens on :hover, which touch screens don't
     have — it's unreachable here, so stop reserving space/affordance
     for it. Tapping a section heading still navigates to that
     section's own page, which lists the same links as real content. */
  .navbar-section:hover .navbar-tags,
  .navbar-tags {
    display: none !important;
  }

  .navbar-utility {
    order: 2;
  }

  /* auto-fit/minmax(280px,1fr) can't produce even a single column once
     the effective width drops below ~280px + padding, which happens on
     ordinary phones at 125% zoom. Force one column outright instead of
     relying on the grid to infer it. */
  .project-grid {
    grid-template-columns: 1fr;
  }

  .project-box {
    height: 160px;
  }
}

.project-title {
  font-weight: 800;
  font-size: 1.1rem;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.project-desc {
  font-size: 0.85rem;
  margin: 4px 0 0 0;
  opacity: 0.9;
}
