/*
 * Styles for the Astro-only enhancements. Tuned to the hugo-coder palette so
 * the visual identity is unchanged: accent = theme link colour, surfaces match
 * the dark/light backgrounds.
 */

/* The theme uppercases the top-left site title via `.navigation .navigation-title`
 * (specificity 0,2,0); match that specificity so the title shows exactly as set. */
.navigation .navigation-title {
  text-transform: none;
}

body {
  --accent: #1565c0;
  --surface: #fafafa;
  --surface-alt: #e0e0e0;
  --fg-soft: #5a5a5a;
  /* Full-strength body text per scheme (matches the theme's own body color),
   * used where `inherit` would resolve to a dimmed value (e.g. Pagefind). */
  --fg-strong: #212121;
  --toc-width: 30rem;
}
body.colorscheme-dark {
  --accent: #42a5f5;
  --surface: #2b2b2b;
  --surface-alt: #424242;
  --fg-soft: #9e9e9e;
  --fg-strong: #dadada;
}
@media (prefers-color-scheme: dark) {
  body.colorscheme-auto {
    --accent: #42a5f5;
    --surface: #2b2b2b;
    --surface-alt: #424242;
    --fg-soft: #9e9e9e;
    --fg-strong: #dadada;
  }
}

/* --- Code blocks: reconcile Shiki vs theme backgrounds ---
 * Shiki paints the <pre> (#24292e, inline style); the ported theme paints the
 * inner <code> (#0d1117), which is only as wide as the text — leaving a mismatched
 * inner box. Force one uniform near-black background, matching the original. */
pre.astro-code {
  background-color: #0d1117 !important;
}
pre.astro-code > code {
  background-color: transparent;
  color: inherit;
}

/* --- Images: keep aspect ratio ---
 * Astro adds explicit width/height attributes (good — reserves space, no layout
 * shift). The theme only sets `max-width: 100%`, so a constrained image keeps its
 * attribute height and distorts. Pairing with height:auto scales it correctly. */
.content img,
.post-content img {
  height: auto;
}

/* Only standalone (non-linked) post images are click-to-zoom. */
.post-content img.lb-zoom {
  cursor: zoom-in;
}

/* --- Responsive tables ---
 * Markdown tables are wrapped in `.table-wrap` (rehype-table-wrap.mjs). The
 * wrapper scrolls horizontally so a wide table stays inside the content column
 * instead of stretching the page past the viewport on phones. The table fills
 * the width when it fits and grows (scrolling the wrapper) when it doesn't. */
.table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 2rem 0;
}
.table-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.post-content .table-wrap table,
.content .table-wrap table {
  width: auto;
  min-width: 100%;
  margin: 0;
}
/* Theme-aware borders (the base theme hardcodes solid black, harsh in dark). */
.post-content .table-wrap td,
.post-content .table-wrap th,
.content .table-wrap td,
.content .table-wrap th {
  border-color: var(--surface-alt);
}

/* --- Long content never forces a horizontal page scroll on mobile ---
 * Long words, URLs and inline commands wrap instead of overflowing. Code
 * blocks (<pre>) keep their own horizontal scroll. */
.post-content {
  overflow-wrap: break-word;
}
.post-content :not(pre) > code {
  overflow-wrap: break-word;
  word-break: break-word;
}

@media only screen and (max-width: 768px) {
  /* The theme's 1.6rem cell padding is too generous on narrow screens. */
  .post-content .table-wrap th,
  .post-content .table-wrap td,
  .content .table-wrap th,
  .content .table-wrap td {
    padding: 0.7rem 1rem;
  }
}

/* --- Draft / unlisted post badges --- */
.post-flag {
  display: inline-block;
  vertical-align: middle;
  margin-left: 1rem;
  padding: 0.2rem 0.8rem;
  border-radius: 0.4rem;
  font-size: 1.3rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
  line-height: 1.6;
}
.flag-draft {
  color: #ffb300;
  background: rgba(255, 179, 0, 0.13);
  border: 1px solid rgba(255, 179, 0, 0.35);
}
.flag-unlisted {
  color: var(--fg-soft);
  background: rgba(158, 158, 158, 0.13);
  border: 1px solid rgba(158, 158, 158, 0.35);
}

/* --- Skip to content (a11y) --- */
.skip-link {
  position: fixed;
  left: -9999px;
  top: 0;
  z-index: 1100;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 0.4rem;
  font-size: 1.5rem;
}

/* --- Reading progress bar --- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 1000;
  pointer-events: none;
  background: transparent;
}
.reading-progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* --- Inline Table Of Contents + scrollspy --- */
/* dot separators between meta items (authors / categories / tags): give the
   bullet balanced room so it doesn't hug the item on its right, and mute it */
.post-meta .separator {
  margin: 0 0.45rem;
  opacity: 0.5;
}

.toc {
  border-left: 3px solid var(--accent);
  background: rgba(127, 127, 127, 0.06);
  border-radius: 0.4rem;
  padding: 0.4rem 1.8rem 1.2rem;
  margin: 2.5rem 0;
}
.toc h2 {
  font-size: 2.2rem;
  line-height: 2.6rem;
  margin: 1.6rem 0 0.4rem;
}
#TableOfContents ul {
  margin: 0;
  padding-left: 1.6rem;
  list-style: none;
}
#TableOfContents > ul {
  padding-left: 0;
}
#TableOfContents a {
  display: block;
  padding: 0.3rem 0;
  color: inherit;
  transition: color 0.15s ease;
}
#TableOfContents a:hover,
#TableOfContents a.active {
  color: var(--accent);
  font-weight: 700;
}
/* h3 sub-sections: tie each group to its parent h2 with an indented guide
   line, and mute/shrink the labels a touch so the hierarchy reads clearly */
#TableOfContents li > ul {
  margin: 0.1rem 0 0.5rem 0.4rem;
  padding-left: 1.2rem;
  border-left: 1px solid rgba(127, 127, 127, 0.25);
}
#TableOfContents li > ul a {
  padding: 0.22rem 0;
  font-size: 0.94em;
  opacity: 0.8;
}
#TableOfContents li > ul a:hover,
#TableOfContents li > ul a.active {
  opacity: 1;
}

/* --- Lateral (toggleable) Table Of Contents --- */
.toc-fab {
  position: fixed;
  right: 1.6rem;
  bottom: 2rem;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.9rem;
  cursor: pointer;
  box-shadow: 0 0.4rem 1.6rem rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, background-color 0.15s ease,
    color 0.15s ease;
}
.toc-fab.visible {
  display: flex;
}
.toc-fab:hover,
.toc-fab[aria-expanded='true'] {
  background: var(--accent);
  color: var(--surface);
}
.toc-fab:hover {
  transform: translateY(-0.2rem);
}

.toc-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: var(--toc-width);
  max-width: 85vw;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--surface-alt);
  transform: translateX(100%);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  box-shadow: none;
}
.toc-panel.open {
  transform: translateX(0);
}

/* The page content shifts to make room so both are visible at once (docked).
 * The whole site lives in .wrapper; reserving right padding shifts the centred
 * content left without it sliding under the panel. */
.wrapper {
  transition: padding-right 0.25s ease;
}

@media (min-width: 1024px) {
  body.toc-docked .wrapper {
    padding-right: var(--toc-width);
  }
  /* Keep the toggle button beside the panel, not under it. */
  body.toc-docked .toc-fab {
    right: calc(var(--toc-width) + 1.6rem);
  }
  /* Progress bar spans only the content area, not under the panel. */
  body.toc-docked .reading-progress {
    width: calc(100% - var(--toc-width));
  }
}

/* Narrow screens can't show both side by side — fall back to an overlay with a
 * soft shadow, and let the panel's own close button dismiss it. */
@media (max-width: 1023px) {
  .toc-panel.open {
    box-shadow: -1rem 0 3rem rgba(0, 0, 0, 0.35);
  }
  body.toc-docked .toc-fab.visible {
    display: none;
  }
}
.toc-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.6rem 2rem;
  border-bottom: 1px solid var(--surface-alt);
  font-weight: 700;
  font-size: 1.7rem;
}
.toc-panel-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 2.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.4rem;
}
.toc-panel-close:hover {
  color: var(--accent);
}
.toc-panel-nav {
  overflow-y: auto;
  padding: 1rem 2rem 3rem;
}
.toc-panel-nav ul {
  list-style: none;
  margin: 0.3rem 0;
  padding-left: 1.6rem;
}
.toc-panel-nav .toc-panel-toc > ul {
  padding-left: 0;
}
.toc-panel-nav a {
  display: block;
  padding: 0.35rem 0;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1.4;
}
.toc-panel-nav a:hover,
.toc-panel-nav a.active {
  color: var(--accent);
  font-weight: 700;
}

/* --- Image lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: zoom-out;
  padding: 2rem;
}
.lightbox.open {
  display: flex;
}
.lightbox img {
  width: auto;
  height: auto;
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 0.4rem;
  box-shadow: 0 0 4rem rgba(0, 0, 0, 0.6);
}

/* --- Prev / next post navigation --- */
.post-nav {
  display: flex;
  gap: 1.5rem;
  margin: 3.2rem 0 0;
  font-size: 1.6rem;
}
.post-nav a {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 1.2rem 1.6rem;
  border: 1px solid var(--surface-alt);
  border-radius: 0.6rem;
  text-decoration: none;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.post-nav a:hover {
  border-color: var(--accent);
  transform: translateY(-0.2rem);
  text-decoration: none;
}
.post-nav .nav-dir {
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
  color: var(--fg-soft);
}
.post-nav .nav-next {
  text-align: right;
  align-items: flex-end;
}
@media only screen and (max-width: 768px) {
  .post-nav {
    flex-direction: column;
  }
}

/* --- Homepage: latest posts + CTAs ---
 * Selectors are scoped under `.centered .about` to out-specify the theme's
 * social-row rules (`.centered .about ul li a`) that would otherwise force
 * uppercase, muted links on these lists. */
.centered .about .home-latest {
  width: 100%;
  max-width: 64rem;
  margin: 3.5rem auto 0;
  text-align: left;
}
.centered .about .home-latest h2 {
  text-align: center;
  font-size: 2.2rem;
  margin: 0 0 1.5rem;
}
.centered .about .home-latest ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.centered .about .home-latest ul li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.5rem 0;
}
.centered .about .home-latest ul li a {
  display: inline;
  margin: 0;
  text-transform: none;
  font-size: 1.6rem;
}
.centered .about .home-latest ul li a.post-link {
  font-weight: 700;
  color: var(--accent);
}
.centered .about .home-latest .post-date {
  color: var(--fg-soft);
  font-size: 1.5rem;
  white-space: nowrap;
}
.centered .about .home-latest .home-all {
  display: block;
  text-align: center;
  margin-top: 1.5rem;
  font-size: 1.6rem;
  text-transform: none;
}
.centered .about .home-cta {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 3rem 0 0.5rem;
}
.centered .about .home-cta a {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0;
  padding: 0.85rem 1.9rem;
  border: 1px solid var(--accent);
  border-radius: 0.8rem;
  background: rgba(66, 165, 245, 0.1);
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 600;
  text-transform: none;
  white-space: nowrap;
  transition: transform 0.18s ease, background-color 0.18s ease,
    color 0.18s ease, box-shadow 0.18s ease;
}
.centered .about .home-cta a i {
  font-size: 1.4rem;
  opacity: 0.9;
}
.centered .about .home-cta a:hover {
  background: var(--accent);
  color: var(--surface);
  transform: translateY(-0.2rem);
  box-shadow: 0 0.6rem 1.8rem rgba(0, 0, 0, 0.28);
  text-decoration: none;
}
/* Primary call-to-action is filled to establish hierarchy. */
.centered .about .home-cta a.cta-primary {
  background: var(--accent);
  color: var(--surface);
}
.centered .about .home-cta a.cta-primary:hover {
  box-shadow: 0 0.8rem 2rem rgba(66, 165, 245, 0.35);
  filter: brightness(1.06);
}
@media only screen and (max-width: 768px) {
  .centered .about .home-latest ul li {
    flex-direction: column;
    gap: 0;
  }
}

/* --- Nav search icon --- */
.nav-search {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.7rem;
  color: inherit;
  padding: 0;
}

/* --- Search page (Pagefind UI themed to match) --- */
.search-wrap {
  --pagefind-ui-scale: 0.85;
  --pagefind-ui-primary: var(--accent);
  /* Full-strength text, not `inherit` (which resolved to a dimmed colour and
   * made result titles/excerpts almost invisible in dark mode). */
  --pagefind-ui-text: var(--fg-strong);
  --pagefind-ui-background: var(--surface);
  --pagefind-ui-border: var(--surface-alt);
  --pagefind-ui-tag: var(--surface-alt);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 0.6rem;
  --pagefind-ui-font: inherit;
  margin-top: 2rem;
}
/* Belt-and-braces: force legible colours on the actual result elements in case
 * the theme variable is overridden in the result context. */
.search-wrap .pagefind-ui__result-title,
.search-wrap .pagefind-ui__result-link {
  color: var(--fg-strong);
}
.search-wrap .pagefind-ui__result-excerpt {
  color: var(--fg-strong);
  opacity: 1;
}
/* Result link/title is the primary action — tint it like other links. */
.search-wrap .pagefind-ui__result-title .pagefind-ui__result-link {
  color: var(--accent);
}
.search-note {
  color: var(--fg-soft);
  font-size: 1.5rem;
}

/* --- Archive --- */
.archive .archive-year {
  margin: 3rem 0 1rem;
}
.archive ul {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
}
.archive li {
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  padding: 0.4rem 0;
}
.archive .archive-date {
  color: var(--fg-soft);
  font-size: 1.5rem;
  width: 9rem;
  flex-shrink: 0;
}

/* --- whoami page --- */
.whoami-hero {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
  margin: 1rem 0 3rem;
}
/* Higher specificity than `.content img { height: auto }` so the avatar stays
 * a fixed square and the 50% radius renders a true circle. */
.content img.whoami-avatar {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 6px rgba(66, 165, 245, 0.12);
}
.whoami-intro {
  flex: 1;
  min-width: 18rem;
}
.whoami-name {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}
.whoami-name span {
  font-family: 'Fira Mono', 'Courier New', monospace;
  color: var(--accent);
}
.whoami-role {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.05rem;
  text-transform: uppercase;
  color: var(--fg-soft);
  margin: 0.6rem 0 0;
}
.whoami-tagline {
  margin: 0.9rem 0 0;
  line-height: 1.6;
  opacity: 0.92;
}
.cert-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  list-style: none;
  padding: 0;
  margin: 1rem 0 2rem;
}
.cert-list li {
  margin: 0;
}
.cert-list a {
  display: inline-block;
  padding: 0.4rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.6rem;
  background: rgba(66, 165, 245, 0.1);
  color: var(--accent);
  font-weight: 600;
  font-size: 1.5rem;
  text-decoration: none;
  transition: background-color 0.18s ease, color 0.18s ease,
    transform 0.18s ease;
}
.cert-list a:hover {
  background: var(--accent);
  color: var(--surface);
  transform: translateY(-0.2rem);
  text-decoration: none;
}
.gh-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: center;
  margin: 1rem 0 2rem;
}
.content .gh-badges img {
  height: 28px;
  width: auto;
  margin: 0;
}
@media only screen and (max-width: 768px) {
  .whoami-hero {
    flex-direction: column;
    text-align: center;
  }
  .cert-list {
    justify-content: center;
  }
}
