/* =============================================================================
   Fearful Odds — main.css

   Contents
   --------
   1.  Fonts
   2.  Design tokens (light / dark)
   3.  Base & layout
   4.  Typography (headings, text, links, lists, rules)
   5.  Code & tables
   6.  Header & navigation
   7.  Theme toggle
   8.  Social links (used in embedded post content)
   9.  Content: blog entries, contact channels
   10. Webring
   11. Footer
   12. Responsive
   ============================================================================= */

/* 1. Fonts ------------------------------------------------------------------ */
@font-face {
  font-family: "Primary";
  src: url("../fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Primary";
  src: url("../fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Secondary";
  src: url("../fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* 2. Design tokens ---------------------------------------------------------- */
:root,
:root[data-theme="light"] {
  --primary-font:
    "Primary", "JetBrains Mono Nerd Font", ui-monospace, monospace;
  --secondary-font:
    "Secondary", "JetBrains Mono Nerd Font", ui-monospace, monospace;

  /* Warm "paper" light theme with a racing-red accent. */
  --text-color: #2b2924;
  --heading-color: #15130f;
  --text-muted: #6f6a61;

  --background-color: #fdfcf9;
  --card-bg: #ffffff;
  --accent-bg: #f3efe8;
  --border-color: #e7e1d6;

  --accent-color: #c4362b;
  --accent-strong: #9e271e;
  --link-color: #b23227;
  --link-hover-color: #871d15;

  --blockquote-bg: rgba(196, 54, 43, 0.05);
  --footer-bg: #f6f3ed;
  --footer-text: #2b2924;

  /* Retained for backward-compatibility with older markup / highlight.css. */
  --hero-overlay: rgba(0, 0, 0, 0.5);
  --content-bg: rgba(21, 19, 15, 0.04);

  --shadow-sm: 0 1px 2px rgba(21, 19, 15, 0.06);
  --shadow-md: 0 6px 20px rgba(21, 19, 15, 0.1);

  --content-max-width: 720px;
  --content-padding: 1.5rem;
  --radius: 10px;
  --radius-sm: 6px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --text-color: #e4e0d8;
  --heading-color: #faf7f1;
  --text-muted: #968f83;

  --background-color: #131210;
  --card-bg: #1c1a17;
  --accent-bg: #1c1a17;
  --border-color: #2e2a25;

  --accent-color: #ff6a5c;
  --accent-strong: #ff8b80;
  --link-color: #ff7d70;
  --link-hover-color: #ffa399;

  --blockquote-bg: rgba(255, 106, 92, 0.08);
  --footer-bg: #1a1815;
  --footer-text: #e4e0d8;

  --hero-overlay: rgba(0, 0, 0, 0.7);
  --content-bg: rgba(255, 255, 255, 0.05);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

/* No-JS fallback (odoc-style): when scripts never set data-theme, follow the
   system preference. Must mirror the :root[data-theme="dark"] block above. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --text-color: #e4e0d8;
    --heading-color: #faf7f1;
    --text-muted: #968f83;

    --background-color: #131210;
    --card-bg: #1c1a17;
    --accent-bg: #1c1a17;
    --border-color: #2e2a25;

    --accent-color: #ff6a5c;
    --accent-strong: #ff8b80;
    --link-color: #ff7d70;
    --link-hover-color: #ffa399;

    --blockquote-bg: rgba(255, 106, 92, 0.08);
    --footer-bg: #1a1815;
    --footer-text: #e4e0d8;

    --hero-overlay: rgba(0, 0, 0, 0.7);
    --content-bg: rgba(255, 255, 255, 0.05);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);

    color-scheme: dark;
  }
}

/* The toggle is inert without JS — hide it rather than show a dead button. */
@media (scripting: none) {
  .theme-toggle {
    display: none;
  }
}

/* 3. Base & layout ---------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  /* Reserve the scrollbar's space on every page so short pages (no scrollbar)
     and tall pages (scrollbar) are centered against the same width — otherwise
     navigating between them nudges the centered layout sideways. */
  scrollbar-gutter: stable;
  /* Paint the root canvas in the theme color so cross-page navigation
     doesn't flash white (most visible in dark mode on mobile). */
  background-color: var(--background-color);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--primary-font);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text-color);
  background: var(--background-color);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

main {
  flex: 1;
  width: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem 2.5rem;
}

main > * {
  width: 100%;
  max-width: var(--content-max-width);
}

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

::selection {
  background: var(--accent-color);
  color: #fff;
}

/* 4. Typography ------------------------------------------------------------- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--secondary-font);
  color: var(--heading-color);
  line-height: 1.25;
  letter-spacing: -0.01em;
  transition: color 0.3s ease;
}

h1 {
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 800;
  margin: 0.5rem 0 1.5rem;
}

h1::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 3px;
  margin-top: 0.9rem;
  background: var(--accent-color);
  border-radius: 2px;
}

h2 {
  font-size: clamp(1.5rem, 3.5vw, 1.9rem);
  font-weight: 700;
  margin: 2.75rem 0 1rem;
}

h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
}

h4,
h5,
h6 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

p {
  margin: 0 0 1.15rem;
}

a {
  color: var(--link-color);
  text-decoration: none;
  text-decoration-color: color-mix(in srgb, var(--link-color) 35%, transparent);
  text-underline-offset: 0.18em;
  transition:
    color 0.2s ease,
    text-decoration-color 0.2s ease;
}

p a,
li a {
  text-decoration: underline;
}

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

strong {
  color: var(--heading-color);
  font-weight: 700;
}

hr {
  border: none;
  height: 1px;
  margin: 2.5rem 0;
  background: linear-gradient(
    to right,
    transparent,
    var(--border-color) 20%,
    var(--border-color) 80%,
    transparent
  );
}

img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

blockquote {
  margin: 1.75rem 0;
  padding: 1rem 1.5rem;
  border-left: 3px solid var(--accent-color);
  background: var(--blockquote-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--text-color);
  transition:
    background 0.3s ease,
    border-color 0.3s ease;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Lists with custom arrow markers (scoped to content via main). */
ul,
ol {
  padding-left: 1.5rem;
  margin: 0 0 1.15rem;
}

li {
  margin-bottom: 0.4rem;
}

main ul:not(.social-nav) {
  list-style: none;
  padding-left: 1.4rem;
}

main ul:not(.social-nav) > li {
  position: relative;
  padding-left: 0.4rem;
}

main ul:not(.social-nav) > li::before {
  content: "→";
  position: absolute;
  left: -1rem;
  color: var(--accent-color);
  font-weight: bold;
}

main ol {
  list-style: decimal;
}

/* 5. Code & tables ---------------------------------------------------------- */
pre,
code {
  font-family: var(--primary-font);
}

code {
  font-size: 0.9em;
  color: var(--text-color);
}

:not(pre) > code {
  background: var(--accent-bg);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  word-break: break-word;
}

pre {
  margin: 1.5rem 0;
  padding: 1rem 1.15rem;
  max-width: 100%;
  overflow-x: auto;
  background: var(--accent-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.9em;
  line-height: 1.6;
  white-space: pre;
  box-shadow: var(--shadow-sm);
}

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

.table-container {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

thead th {
  background: var(--accent-bg);
  color: var(--heading-color);
  font-weight: 700;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* 6. Header & navigation ---------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 0.6rem 0;
  background: color-mix(in srgb, var(--background-color) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-color);
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.site-logo {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.05;
  font-family: var(--primary-font);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: var(--heading-color);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.site-logo:hover {
  color: var(--accent-color);
}

.site-logo .logo-l2 {
  padding-left: 2ch;
}

.site-navigation {
  display: flex;
  align-items: center;
}

.nav-list {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  margin: 0;
}

.nav-item a {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  transition:
    color 0.2s ease,
    background 0.2s ease;
}

.nav-item a:hover {
  color: var(--heading-color);
  background: var(--accent-bg);
}

.nav-item.active a,
.nav-item a[aria-current="page"] {
  color: var(--accent-color);
  font-weight: 700;
}

/* Mobile toggle (hidden on desktop) */
.mobile-nav-toggle {
  display: none;
  position: relative;
  z-index: 1001;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger {
  display: block;
  position: relative;
  width: 24px;
  height: 2px;
  background: var(--heading-color);
  border-radius: 2px;
  transition: background 0.2s ease;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--heading-color);
  border-radius: 2px;
  transition:
    transform 0.3s ease,
    top 0.3s ease;
}

.hamburger::before {
  top: -7px;
}

.hamburger::after {
  top: 7px;
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger {
  background: transparent;
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger::before {
  top: 0;
  transform: rotate(45deg);
}

.mobile-nav-toggle[aria-expanded="true"] .hamburger::after {
  top: 0;
  transform: rotate(-45deg);
}

.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;
}

/* 7. Theme toggle ----------------------------------------------------------- */
.theme-toggle {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1100;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  transition:
    transform 0.15s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--accent-color);
}

/* Default (light) shows the moon (switch-to-dark); [data-theme] flips it. */
.sun-icon {
  display: none;
}

.moon-icon {
  display: block;
}

[data-theme="dark"] .sun-icon {
  display: block;
}

[data-theme="dark"] .moon-icon {
  display: none;
}

/* 8. Social links (used in embedded post content) -------------------------- */
.nav-right {
  display: flex;
  align-items: center;
}

.social-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}

.social-nav li {
  margin: 0;
}

.social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--text-color);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

.social-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.social-link:hover .social-icon {
  transform: scale(1.1);
}

.social-link[href*="github"]:hover {
  background: #24292f;
  border-color: #24292f;
  color: #fff;
}

.social-link[href*="twitter"]:hover,
.social-link[href*="x.com"]:hover {
  background: #1da1f2;
  border-color: #1da1f2;
  color: #fff;
}

.social-link[href*="linkedin"]:hover {
  background: #0077b5;
  border-color: #0077b5;
  color: #fff;
}

.social-icon {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

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

/* 9. Content: blog entries -------------------------------------------------- */
.blog-entries {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin: 2rem 0;
  width: 100%;
}

/* Scoped to the listing container: "blog-entry" is also a frontmatter layout
   value that becomes the <body> class of a post page, so an unscoped selector
   would style an entire page as a hover-card. */
.blog-entries .blog-entry {
  padding: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.blog-entries .blog-entry:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(
    in srgb,
    var(--accent-color) 45%,
    var(--border-color)
  );
}

.blog-entries .blog-entry h3 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.blog-entries .blog-entry h3 a {
  color: var(--heading-color);
  text-decoration: none;
}

.blog-entries .blog-entry h3 a:hover {
  color: var(--accent-color);
}

.blog-entry-date {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.blog-entry-description {
  margin: 0;
  color: var(--text-color);
  line-height: 1.6;
}

/* Section headings in page content (contact channels, project titles, …).
   Scoped to direct children of <main> so blog card titles are exempt. */
.page main > h3 {
  position: relative;
  padding-left: 0.85rem;
}

.page main > h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.15em;
  bottom: 0.15em;
  width: 3px;
  border-radius: 2px;
  background: var(--accent-color);
}

/* 10. Webring --------------------------------------------------------------- */
.webring-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  margin: 2.5rem 0 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--accent-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.webring-nav .prev {
  flex: 0 0 auto;
  text-align: left;
}

.webring-nav .center {
  flex: 1;
  margin: 0;
  text-align: center;
  color: var(--text-muted);
}

.webring-nav .next {
  flex: 0 0 auto;
  text-align: right;
}

.webring-description {
  margin: 0;
  font-size: inherit;
  line-height: 1.4;
}

.webring-link {
  color: var(--accent-color);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.webring-link:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

/* 11. Footer ---------------------------------------------------------------- */
.site-footer {
  margin-top: auto;
  padding: 0.5rem 1rem;
  text-align: center;
  background: var(--footer-bg);
  color: var(--footer-text);
  border-top: 1px solid var(--border-color);
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.footer-bottom {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.copyright {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* 12. Responsive ------------------------------------------------------------ */
@media (max-width: 768px) {
  .mobile-nav-toggle {
    display: block;
  }

  .header-inner {
    padding: 0 1rem;
  }

  .nav-list {
    position: fixed;
    inset: 0;
    height: 100dvh;
    flex-direction: column;
    justify-content: center;
    gap: 1.25rem;
    padding: 2rem;
    background: var(--background-color);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
  }

  .nav-list[data-visible="true"] {
    transform: translateX(0);
  }

  .nav-item a {
    font-size: 1.25rem;
    padding: 0.75rem 1.5rem;
  }

  body.nav-open {
    overflow: hidden;
  }

  h2 {
    margin-top: 2rem;
  }

  .webring-nav {
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.72rem;
  }

  .webring-nav .center {
    order: -1;
    flex-basis: 100%;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 16px;
  }

  main {
    padding: 1rem 0.85rem 2rem;
  }

  .blog-entries .blog-entry {
    padding: 1.15rem;
  }

  .theme-toggle {
    right: 1rem;
    bottom: 1rem;
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* RSS subscribe icon (footer) */
.rss-link {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

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

.rss-icon {
  display: block;
}

/* Hacker News / Lobsters share row on blog posts */
.post-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.post-share-label {
  color: var(--text-muted);
}

.post-share-link {
  font-weight: 600;
}

.post-share-sep {
  color: var(--text-muted);
}

/* Home "Latest writing" teaser */
.latest-date {
  font-size: 0.82rem;
  color: var(--text-muted);
}
