/* Layout shell */
:root {
  --side-rail-width: 12rem;
  --icon-rail-width: 4.5rem;
}

.site-shell {
  position: relative;
}

.site-content {
  min-width: 0;
}

/* Compact: in-flow wrapping row. Wide: left text column. */
.site-header {
  position: relative;
  z-index: 100;
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  align-content: flex-start;
  gap: 1rem;
  padding: max(0.8rem, env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px)) 0.8rem
    max(1rem, env(safe-area-inset-left, 0px));
  background: transparent;
  font-size: 1rem;
}

.site-logo {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
}

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

/* Flatten so logo, links, and buttons wrap as one row */
.site-nav,
.site-rail {
  display: contents;
}

.site-nav a {
  flex: 0 0 auto;
  color: var(--color-text-muted);
}

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

/* Shared icon buttons (theme + compact search + RSS) */
.icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.15rem;
  min-height: 2.15rem;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  color: var(--color-text);
  font-size: 1rem;
  line-height: 1;
}

a.icon-btn {
  color: var(--color-text);
  text-decoration: none;
  box-sizing: border-box;
}

a.icon-btn:hover {
  color: var(--color-text);
  text-decoration: none;
}

.rss-btn {
  order: 2;
}

.rss-btn svg {
  width: 1em;
  height: 1em;
}

.search-toggle-icon {
  display: flex;
}

.search-toggle-icon svg {
  width: 1em;
  height: 1em;
}

/* Search */
.search-wrapper {
  position: relative;
  flex: 0 0 auto;
  order: 1;
}

/* Compact: input lives in a popover opened by the search button */
.search-popover {
  display: none;
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  width: min(18rem, calc(100vw - 2rem));
  z-index: 51;
}

.search-wrapper.is-open .search-popover {
  display: block;
}

#search-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-secondary);
  color: var(--color-text);
  outline: none;
}

#search-input:focus {
  border-color: var(--color-accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  width: 100%;
  max-height: min(26rem, 60vh);
  overflow-y: auto;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 50;
}

.search-results:not([hidden]) {
  display: block;
}

.search-result-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  color: var(--color-text);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--color-bg-secondary);
  text-decoration: none;
}

.search-result-item .result-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.search-result-item .result-excerpt {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.search-no-results {
  padding: 1rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Theme toggle */

.theme-toggle svg {
  width: 1em;
  height: 1em;
}

.theme-icon-light {
  display: flex;
}

.theme-icon-dark {
  display: none;
}

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

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-light {
    display: none;
  }

  :root:not([data-theme="light"]) .theme-icon-dark {
    display: flex;
  }

  :root[data-theme="light"] .theme-icon-light {
    display: flex;
  }

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

/* Wide screens — left text nav, right icon stack */
@media (min-width: 1024px) {
  .site-shell {
    min-height: 100dvh;
  }

  .site-content {
    /* Equal insets so the reading column sits in the viewport center. */
    padding-left: var(--side-rail-width);
    padding-right: var(--side-rail-width);
  }

  .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: var(--side-rail-width);
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 1.5rem;
    padding: 2rem 1.5rem;
    font-size: 1.15rem;
    /* Full-bleed pages show through the rail, so only its contents take the pointer. */
    pointer-events: none;
  }

  .site-header > * {
    pointer-events: auto;
  }

  .site-nav {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
  }

  .search-wrapper,
  .rss-btn {
    order: 0;
  }

  .site-rail {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.85rem;
    padding: 2rem 1.5rem;
    z-index: 101;
  }

  .site-rail .icon-btn {
    font-size: 1.15rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
  }

  .search-popover {
    top: 0;
    right: calc(100% + 0.4rem);
    left: auto;
    width: min(22rem, calc(100vw - 6rem));
  }
}

/* Main content */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem calc(2rem + env(safe-area-inset-bottom, 0px));
  min-width: 0;
}

/* Compact header is inset 1rem; keep the feed flush with the logo. */
@media (max-width: 1023px) {
  .home-page {
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }
}

main.custom-page {
  max-width: none;
  padding: 0;
  /* Clip, not hidden: hidden would make main a scroll container, and scroll-linked
     effects inside it would track main instead of the page. */
  overflow-x: clip;
}

@media (min-width: 1024px) {
  /* Break out of the side insets so full-bleed pages can paint edge to edge. */
  main.custom-page {
    margin-left: calc(var(--side-rail-width) * -1);
    margin-right: calc(var(--side-rail-width) * -1);
  }
}

.article-page .article,
.static-page .page,
.home-page .page {
  max-width: 720px;
  margin: 0 auto;
  min-width: 0;
}

/* Homepage */
.post-list {
  display: grid;
  gap: 1.5rem;
}

/* Article cards */
.article-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--color-card-bg);
  transform: scale(1);
  transform-origin: center;
  transition:
    transform 0.2s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease;
}

.article-card[hidden] {
  display: none;
}

.article-card:hover {
  transform: scale(0.985);
  border-color: color-mix(
    in srgb,
    var(--color-accent) 35%,
    var(--color-border)
  );
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--color-accent) 22%, transparent),
    0 0 28px color-mix(in srgb, var(--color-accent) 20%, transparent);
}

.article-card:active {
  transform: scale(0.965);
  transition-duration: 0.1s;
}

.card-link {
  display: flex;
  flex: 1;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

.card-link:hover {
  text-decoration: none;
}

.card-body {
  padding: 1.25rem 1.25rem 0.5rem;
}

.card-body h2 {
  font-size: 1.625rem;
  margin: 0 0 0.35em;
  color: var(--color-text);
}

.card-description {
  font-size: 1.25rem;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.45;
}

.card-meta {
  display: flex;
  justify-content: flex-end;
  padding: 0 1.25rem 1rem;
}

.card-date {
  font-size: 1rem;
  color: var(--color-text-muted);
  opacity: 0.75;
}

.tag-filter-note {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0 0 1.25rem;
}

.tag-filter-note a {
  color: var(--color-text-muted);
}

/* Intro line above the post list */
.posts-intro {
  margin: 0 0 2rem;
  font-size: 1.125rem;
  line-height: 1.55;
  color: var(--color-text-muted);
}

.posts-intro p {
  margin: 0 0 0.75rem;
}

.posts-intro p:last-child {
  margin-bottom: 0;
}

/* Article */
.article-header {
  margin-bottom: 2rem;
}

.article-header h1 {
  font-size: 2.25rem;
}

:is(.article-content, .page-content) :is(h2, h3, h4, h5, h6) {
  scroll-margin-top: 1.25rem;
}

:is(.article-content, .page-content) .header-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0;
  height: 0.75em;
  margin-left: 0;
  overflow: hidden;
  vertical-align: middle;
  position: relative;
  top: -0.06em;
  color: var(--color-text-muted);
  text-decoration: none;
  opacity: 0;
}

:is(.article-content, .page-content) .header-anchor svg {
  width: 0.75em;
  height: 0.75em;
  flex: none;
}

:is(.article-content, .page-content) :is(h2, h3, h4, h5, h6):hover .header-anchor,
:is(.article-content, .page-content) .header-anchor:focus {
  width: 0.75em;
  margin-left: 0.4rem;
  overflow: visible;
  opacity: 1;
  text-decoration: none;
}

:is(.article-content, .page-content) .header-anchor:hover,
:is(.article-content, .page-content) .header-anchor:focus {
  color: var(--color-accent);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  margin-top: 0.75rem;
}

.article-meta time {
  opacity: 0.8;
}

.article .tag,
.essay .tag {
  opacity: 0.8;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  display: inline-block;
  padding: 0.15em 0.6em;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  border-radius: 4px;
  font-size: 0.8125rem;
  text-decoration: none;
}

.tag:hover {
  text-decoration: none;
  opacity: 0.85;
}

/*
 * Cloaked text: names, contact values and external hrefs ship base64-encoded
 * in data-n / data-h. app.js decodes names into data-name, rendered here
 * through ::before so crawlers see no name text, and sets each href only on
 * human interaction. Encode a new value in the browser console: btoa("Name").
 */
[data-name]::before {
  content: attr(data-name);
}

a[data-h] {
  cursor: pointer;
}

/* Contacts (components/contacts.html) */
.contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.75rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
  font-size: 0.9375rem;
}

.contacts li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
}

.contact-label {
  color: var(--color-text-muted);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Code blocks (Shiki) */
.code-block {
  position: relative;
  margin: 1.5em 0;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}

.code-block pre,
.code-block .shiki {
  background-color: var(--color-bg) !important;
}

.code-block .shiki span {
  background-color: transparent !important;
}

.code-block pre {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
}

.code-copy {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.code-copy svg {
  width: 14px;
  height: 14px;
  display: block;
}

.code-copy:hover,
.code-copy.is-copied {
  color: var(--color-text);
}

.code-copy:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.code-block:hover .code-copy,
.code-block:focus-within .code-copy {
  opacity: 1;
}

@media (hover: none) {
  .code-copy {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .code-copy {
    transition: none;
  }
}

/* Shiki dual themes: switch token colors with site theme */
[data-theme="dark"] .code-block .shiki span {
  color: var(--shiki-dark) !important;
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .code-block .shiki span {
    color: var(--shiki-dark) !important;
    font-style: var(--shiki-dark-font-style) !important;
    font-weight: var(--shiki-dark-font-weight) !important;
    text-decoration: var(--shiki-dark-text-decoration) !important;
  }
}

