/* ========================================
   CSS VARIABLES & THEME CONFIGURATION
   ======================================== */

:root {
  --background-color: #faf8f4;
  --text-color: #201e1a;
  --text-secondary: #8a8478;
  --border-color: #e7e2d9;
  --code-background-color: #efece4;
  --accent-color: #c0362a;
  --link-underline: #c0362a;
  --bg-gray-focus: rgba(0, 0, 0, 0.06);
  --selection-color: rgba(192, 54, 42, 0.18);
  --diagram-infra: #e6ecf3;
  --diagram-user: #fbf1cf;
  /* Shared monospace stack for code blocks and inline code. ui-monospace
     resolves to the platform's UI monospace (SF Mono on macOS). */
  --mono-font:
    ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

[data-theme='dark'] {
  --background-color: #161513;
  --text-color: #ece7dd;
  --text-secondary: #928b7f;
  --border-color: #2a2823;
  --code-background-color: #26241f;
  --accent-color: #ff7364;
  --link-underline: #b0564a;
  --bg-gray-focus: rgba(255, 255, 255, 0.08);
  --selection-color: rgba(255, 115, 100, 0.26);
  --diagram-infra: #1c2630;
  --diagram-user: #2e2814;
}

/* ========================================
   RESPONSIVE TYPOGRAPHY & BASE LAYOUT
   ======================================== */

html {
  font-size: 22px;
}

body > * {
  font-size: 100%;
  margin-left: 7.5rem;
  margin-right: 7.5rem;
}

@media all and (max-width: 840px) {
  html {
    font-size: 20px;
  }

  body > * {
    margin-left: 5.5rem;
    margin-right: 5.5rem;
  }
}

@media all and (max-width: 760px) {
  body > * {
    margin-left: 2.5rem;
    margin-right: 2.5rem;
  }
}

@media all and (max-width: 580px) {
  html {
    font-size: 18px;
  }

  body > * {
    margin: 0.7rem 1.5rem 0 1.5rem;
  }
}

/* ========================================
   HTML & BODY RESETS
   ======================================== */

html {
  height: 100%;
}

body {
  background-color: var(--background-color);
  color: var(--text-color);
  font-family: 'New York', Georgia, 'Noto Serif', 'Liberation Serif', 'Times New Roman', serif;
  padding: 0;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: 1200px;
  min-height: 100%;
  text-rendering: optimizeLegibility;
  font-feature-settings:
    'kern' 1,
    'liga' 1;
}

* {
  margin: 0;
  padding: 0;
}

::selection {
  background: var(--selection-color);
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

p {
  margin-bottom: 1em;
  line-height: 1.6;
  max-width: 62ch;
}

p:has(img),
p:has(svg.diagram) {
  text-align: center;
}

img {
  max-width: 100%;
  height: auto;
}

/* Inline diagrams (SVG inlined at generation time).

   Each diagram SVG is self-contained: it ships its own <style> with light-mode
   defaults (geometry + colors) so it also renders correctly on its own and in
   the Atom feed. Here we override only the colors with the theme variables so
   the diagrams adapt to the light/dark theme, including the manual toggle.
   These rules win by specificity over the SVG's own bare-class rules. */
svg.diagram {
  display: block;
  width: 100%;
  height: auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

svg.diagram text {
  fill: var(--text-color);
}

svg.diagram .d-call,
svg.diagram .d-arrow-call {
  stroke: var(--text-color);
  fill: var(--text-color);
}

svg.diagram .d-return,
svg.diagram .d-lifeline,
svg.diagram .d-frame,
svg.diagram .d-panel,
svg.diagram .d-frame-tab {
  stroke: var(--text-secondary);
}

svg.diagram .d-panel,
svg.diagram .d-frame-tab {
  fill: var(--code-background-color);
}

svg.diagram .d-return,
svg.diagram .d-arrow-return,
svg.diagram .d-muted,
svg.diagram .d-frame-label {
  fill: var(--text-secondary);
}

svg.diagram .d-box {
  fill: none;
  stroke: var(--text-secondary);
}

svg.diagram .d-infra {
  fill: var(--diagram-infra);
  stroke: var(--text-secondary);
}

svg.diagram .d-user {
  fill: var(--diagram-user);
  stroke: var(--text-secondary);
}

h1 {
  display: block;
  font-size: 170%;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-top: 1rem;
  margin-bottom: 1.5rem;
  padding-top: 0.02em;
  hyphens: none;
  text-wrap: balance;
}

h2 {
  padding-top: 0.02em;
  margin-top: 0.7rem;
  margin-bottom: 1.1rem;
  text-wrap: balance;
}

h3 {
  padding-top: 0.02em;
  margin-top: 0.7rem;
  margin-bottom: 1.1rem;
  text-wrap: balance;
}

aside {
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

aside em {
  font-size: 0.7rem;
}

/* ========================================
   LISTS & LINKS
   ======================================== */

ul,
ol {
  margin-bottom: 1em;
  padding-left: 1em;
}

li {
  line-height: 1.75;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-thickness 0.15s ease;
}

a:visited {
  text-decoration-color: var(--text-secondary);
}

a:hover {
  text-decoration-thickness: 2.5px;
}

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

/* ========================================
   CODE BLOCKS & INLINE CODE
   ======================================== */

pre {
  font-size: 0.8rem;
  font-family: var(--mono-font);
  line-height: 1.55;
  margin-bottom: 1em;
  background-color: var(--code-background-color);
  padding: 1em;
  border-radius: 5px;
}

pre > code {
  white-space: pre-wrap;
}

:not(pre) > code {
  hyphens: none;
  border-radius: 5px;
  font-family: var(--mono-font);
  font-size: 0.85em;
  background-color: var(--code-background-color);
  color: inherit;
  padding: 0.12em 0.38em;
  white-space: pre-wrap;
}

/* ========================================
   MAIN LAYOUT & CONTAINER
   ======================================== */

.container {
  display: grid;
  grid-template-columns: auto;
  grid-template-rows: auto auto 30px;
  grid-template-areas: 'header' 'content' 'footer';
  row-gap: 1em;
  margin-left: auto;
  margin-right: auto;
  padding-left: 0.7em;
  padding-right: 0.7em;
}

.container > header {
  margin-top: 1em;
}

@media all and (max-width: 520px) {
  .container > header {
    margin-top: 0;
  }
}

.container .content {
  grid-area: content;
  display: grid;
  grid-auto-flow: row;
  row-gap: 0.6em;
}

@media all and (max-width: 520px) {
  .content {
    padding: 0;
  }
}

.container > footer {
  grid-area: footer;
}

.container > footer > ul {
  display: grid;
  grid-auto-flow: column;
  padding: 0;
  margin: 0;
  gap: 10px;
  justify-content: center;
}

.container > footer > ul > li {
  list-style-type: none;
  line-height: normal;
}

.container > footer > ul > li > a {
  color: var(--text-color);
  text-decoration: none;
}

.container > footer > ul > li > a:hover {
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 3px;
}

.container > footer > ul > li > a::after {
  position: relative;
  content: '\FEFF°';
  margin-left: 0.1em;
  font-size: 80%;
  top: -0.3em;
  left: -0.1em;
  color: var(--accent-color);
}

[data-theme='dark'] .icon-feed {
  filter: invert(1);
}

/* ========================================
   NAVIGATION & HAMBURGER MENU
   ======================================== */

.main-nav {
  display: grid;
  grid-template-columns: max-content auto;
  padding: 0 0 0.6em 0;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
}

/* Theme toggle button positioned after nav links on desktop */
.main-nav > #theme-toggle {
  order: 1;
}

.nav-links {
  display: grid;
  grid-template-columns: repeat(4, max-content) max-content 1fr;
  column-gap: 1.3em;
  margin: 0;
  align-items: center;
  padding: 0;
}

/* Theme toggle button styling */
#theme-toggle {
  background: none;
  border: none;
  padding: 0.2em;
  font-size: 1.1em;
  transition:
    background 0.18s,
    color 0.18s;
  justify-self: end;
}

#theme-toggle:hover,
#theme-toggle:focus {
  background: var(--bg-gray-focus);
  color: var(--accent-color);
  outline: none;
}

.theme-icon {
  display: block;
  font-size: 1em;
}

.nav-links > li {
  list-style-type: none;
  line-height: normal;
}

.nav-links > li > a {
  max-width: fit-content;
  text-transform: lowercase;
  font-weight: bold;
  color: var(--text-color);
  text-decoration: none;
}

.nav-links > li > a:hover {
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 3px;
}

.nav-links > li > a:after {
  position: relative;
  content: '\FEFF°';
  margin-left: 0.1em;
  font-size: 80%;
  top: -0.3em;
  left: -0.1em;
  color: var(--accent-color);
}

/* Hamburger menu button */
.hamburger {
  display: none;
  grid-auto-flow: row;
  width: 20px;
  height: 25px;
  justify-self: end;
  background: none;
  border: none;
  cursor: pointer;
}

.hamburger span {
  display: block;
  height: 3px;
  width: 100%;
  background-color: var(--text-color);
  border-radius: 5px;
  transition: all 0.3s ease-in-out;
}

/* Mobile navigation */
@media all and (max-width: 520px) {
  .hamburger {
    display: grid;
  }

  .main-nav > #theme-toggle {
    order: -1;
    padding: 0;
    justify-self: start;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 0;
    margin-top: 50px;
    left: 0;
    width: 100%;
    background-color: var(--background-color);
    grid-template-columns: auto;
    grid-auto-flow: row;
  }

  .main-nav.nav-open .nav-links {
    display: grid;
  }

  .main-nav.nav-open .hamburger span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 4px);
  }

  .main-nav.nav-open .hamburger span:nth-child(2) {
    opacity: 0;
  }

  .main-nav.nav-open .hamburger span:nth-child(3) {
    transform: rotate(-45deg) translate(8px, -4px);
  }

  .nav-links > li {
    display: flex;
    padding: 1em;
    border-bottom: 1px solid var(--border-color);
    justify-content: center;
    align-content: center;
  }
}

/* ========================================
   BLOG STYLES
   ======================================== */

/* Blog index page */
.blog-month > ul {
  padding: 0;
}

.blog-month > ul > li {
  list-style-type: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.blog-month > ul > li > a {
  grid-column: 1;
  max-width: fit-content;
}

.blog-month > ul > li > span {
  grid-column: 2;
  max-width: fit-content;
  justify-self: end;
}

/* Blog entry page */
.article-header {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: 'title date';
  align-items: center;
}

.article-header > h1 {
  grid-area: title;
  margin: 0;
  padding: 0;
}

.article-header > h2 {
  grid-area: date;
  align-self: center;
  justify-self: right;
  font-size: 18px;
  margin: 0;
  padding: 0;
}

@media all and (max-width: 840px) {
  .article-header {
    grid-template-rows: auto auto;
    grid-template-areas:
      'title'
      'date';
  }
  .article-header > h2 {
    justify-self: left;
    margin-top: 0.7em;
  }
}

/* Blog table of contents */
nav.blog-toc ul {
  margin-bottom: 0;
}
