/* ---------------------------------------------------------------------------
   Theme-independent tokens
   --------------------------------------------------------------------------- */
:root {
  --measure: 42rem;
  --sidebar-w: 14rem;
  --gap: 3rem;

  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------------------------------------------------------------------------
   Colour themes

   Default = light. "auto" (no data-theme attribute) follows the OS via the
   media query below. Explicit choices set data-theme on <html>.
   Keep the dark values in the media query in sync with [data-theme="dark"].
   --------------------------------------------------------------------------- */
:root,
:root[data-theme="light"] {
  --bg: #fdfdfd;
  --fg: #1c1c1c;
  --accent: #7c2fae; /* headings */
  --link: #8a2bb0; /* links */
  --muted: #6b7075;
  --rule: #e3e3e3;
  --code-bg: #f4f4f4;
}

:root[data-theme="dark"] {
  --bg: #1a1815;
  --fg: #f2efe9;
  --accent: #e6b450;
  --link: #e9c06a;
  --muted: #9a938a;
  --rule: #35302a;
  --code-bg: #12100e;
}

:root[data-theme="nord"] {
  --bg: #2e3440;
  --fg: #e5e9f0;
  --accent: #88c0d0;
  --link: #8fbcbb;
  --muted: #9aa4b8;
  --rule: #3b4252;
  --code-bg: #3b4252;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1a1815;
    --fg: #f2efe9;
    --accent: #e6b450;
    --link: #e9c06a;
    --muted: #9a938a;
    --rule: #35302a;
    --code-bg: #12100e;
  }
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--sans);
}

a {
  color: var(--link);
}

a:hover {
  text-decoration: none;
}

h1,
h2,
h3 {
  color: var(--accent);
  line-height: 1.2;
  font-weight: 700;
}

h1 {
  font-size: 2rem;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.4rem;
  margin: 2.5rem 0 0.75rem;
}

h3 {
  font-size: 1.15rem;
  margin: 2rem 0 0.5rem;
}

.page-title {
  font-size: 2.4rem;
  margin-bottom: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Layout: sidebar + content
   --------------------------------------------------------------------------- */
.layout {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  max-width: calc(var(--sidebar-w) + var(--gap) + var(--measure));
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.content {
  flex: 1 1 auto;
  min-width: 0; /* let <pre> scroll instead of stretching the layout */
  max-width: var(--measure);
}

/* ---------------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------------- */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  position: sticky;
  top: 2.5rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

.sidebar .site-title {
  display: block;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  margin-bottom: 0.75rem;
}

.sidebar .site-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  margin-bottom: 1rem;
}

.theme-select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--link);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.1rem 0.25rem;
  margin-bottom: 0.5rem;
}

/* Background-music toggle (hidden until music.js unhides it) */
.music-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.1rem 0.4rem 0.1rem 0.25rem;
  margin-bottom: 1.75rem;
  cursor: pointer;
}

.music-toggle[hidden] {
  display: none;
}

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

.music-toggle .music-toggle-icon {
  font-size: 1.05em;
  line-height: 1;
}

.music-toggle.is-on {
  color: var(--link);
  border-color: currentColor;
}

/* Playing: a gentle pulse on the note. Stilled for reduced-motion. */
.music-toggle.is-on:not(.is-pending) .music-toggle-icon {
  animation: music-pulse 1.8s ease-in-out infinite;
}

.music-toggle.is-pending .music-toggle-icon {
  opacity: 0.55;
}

@keyframes music-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .music-toggle .music-toggle-icon {
    animation: none !important;
  }
}

/* Archive tree */
.archive-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin: 0 0 0.25rem;
}

.archive-year {
  border-top: 1px solid var(--rule);
}

.archive-year > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.4rem 0;
  color: var(--accent);
  font-weight: 700;
}

.archive-year > summary::-webkit-details-marker {
  display: none;
}

.archive-year > summary::before {
  content: "\25B8"; /* ▸ */
  display: inline-block;
  width: 1em;
  color: var(--muted);
  font-weight: 400;
}

.archive-year[open] > summary::before {
  content: "\25BE"; /* ▾ */
}

.archive-month {
  margin: 0.1rem 0 0.6rem 1rem;
}

.archive-month-name {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.archive-month ul {
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
}

.archive-month li {
  padding: 0.12rem 0;
}

.archive-month li[aria-current="page"] a {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}

.archive-empty {
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding-top: 0.5rem;
}

.socials {
  margin-top: 1.75rem;
}

.socials h2 {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.socials ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.socials li {
  padding: 0.12rem 0;
}

.sidebar .webring {
  margin: 1.75rem 0 0;
  font-size: 0.8rem;
}

.sidebar .webring span {
  color: var(--muted);
  margin: 0 0.15rem;
}

.sidebar .colophon {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.8rem;
}

.sidebar .colophon .flag {
  height: 1.4em;
  width: auto;
  vertical-align: -0.35em;
  margin-right: 0.4em;
}

/* ---------------------------------------------------------------------------
   Home
   --------------------------------------------------------------------------- */
.intro {
  margin-bottom: 2.5rem;
  color: var(--muted);
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.post-list time {
  flex: 0 0 8.5rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------------
   Post
   --------------------------------------------------------------------------- */
.post-meta {
  color: var(--muted);
  margin-top: -0.25rem;
}

.post :where(p, ul, ol, pre, blockquote, table) {
  margin: 1rem 0;
}

.post blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--muted);
}

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

/* ---------------------------------------------------------------------------
   Citations & sources (lib/markdown-it-cite.js)
   --------------------------------------------------------------------------- */
.cite {
  font-variant-numeric: tabular-nums;
}

.cite-link {
  text-decoration: none;
}

.cite-missing {
  color: var(--muted);
}

.sources {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}

.sources h2 {
  margin: 0 0 1rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.sources-list {
  padding-left: 1.4rem;
  color: var(--muted);
}

.sources-list li {
  margin: 0.5rem 0;
  scroll-margin-top: 1.5rem;
}

.sources-list li:target {
  color: var(--fg);
}

.source-title {
  color: var(--fg);
}

.source-url {
  word-break: break-word;
}

.source-backref {
  margin-left: 0.3rem;
  text-decoration: none;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Résumé (driven by src/_data/resume.json)
   --------------------------------------------------------------------------- */
.resume-headline {
  color: var(--muted);
  font-size: 1.05rem;
  margin-top: -0.25rem;
}

.resume-location {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
}

.resume-certs {
  margin: 0;
  padding-left: 1.1rem;
}

.resume-certs li {
  margin: 0.25rem 0;
}

.resume-links {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  font-size: 0.9rem;
}

.resume-section {
  margin-top: 2.5rem;
}

.resume-section > h2 {
  margin: 0 0 1.25rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.resume-org {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.resume-org-logo {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--code-bg);
}

.resume-org-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.resume-monogram {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--muted);
}

.resume-org-body {
  flex: 1 1 auto;
  min-width: 0;
}

.resume-org-name {
  margin: 0;
  font-size: 1.1rem;
}

.resume-org-meta {
  margin: 0.15rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.resume-roles {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
}

.resume-role + .resume-role {
  margin-top: 0.9rem;
}

/* Only draw the "promotion" rail when there is more than one role. */
.resume-roles--multi .resume-role {
  padding-left: 0.9rem;
  border-left: 2px solid var(--rule);
}

.resume-role-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 1rem;
}

.resume-role-title {
  font-weight: 700;
}

.resume-role-dates {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.resume-role-summary {
  margin: 0.35rem 0 0;
}

.resume-highlights {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
}

.resume-highlights li {
  margin: 0.2rem 0;
}

.resume-skills {
  margin: 0;
}

.resume-skills > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--rule);
}

.resume-skills dt {
  flex: 0 0 8rem;
  font-weight: 700;
}

.resume-skills dd {
  flex: 1 1 12rem;
  margin: 0;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Code
   --------------------------------------------------------------------------- */
code,
pre {
  font-family: var(--mono);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

:not(pre) > code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border: 1px solid var(--rule);
  font-size: 0.9em;
}

/* Shiki emits a CSS variable per theme on every token; pick one by theme. */
.shiki,
.shiki span {
  color: var(--shiki-light);
}

:root[data-theme="dark"] .shiki,
:root[data-theme="dark"] .shiki span {
  color: var(--shiki-dark);
}

:root[data-theme="nord"] .shiki,
:root[data-theme="nord"] .shiki span {
  color: var(--shiki-nord);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .shiki,
  :root:not([data-theme]) .shiki span {
    color: var(--shiki-dark);
  }
}

/* ---------------------------------------------------------------------------
   Stack the sidebar above the content on narrow screens
   --------------------------------------------------------------------------- */
@media (max-width: 46rem) {
  .layout {
    flex-direction: column;
    gap: 2rem;
    padding-top: 1.75rem;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    flex-basis: auto;
    width: 100%;
  }

  .sidebar .site-nav {
    flex-direction: row;
    gap: 1rem;
  }
}

/* ---------------------------------------------------------------------------
   Page-load indicator
   --------------------------------------------------------------------------- */
.loader {
  position: fixed;
  inset: auto 0 1.25rem 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  pointer-events: none;
  color: var(--muted);
  font-size: 0.8rem;
}

.loader[hidden] {
  display: none;
}

.loader img {
  image-rendering: pixelated;
}

/* ---------------------------------------------------------------------------
   Print — drop the chrome so the résumé (or any page) prints clean
   --------------------------------------------------------------------------- */
@media print {
  .sidebar,
  .loader {
    display: none;
  }

  .layout {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .content {
    max-width: none;
  }

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

  .resume-section,
  .resume-org {
    break-inside: avoid;
  }
}
