/* layout.css — site header, footer, post-controls, posts list */

/* ── Site header ──────────────────────────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 10rem;
  display: flex;
  align-items: center;
}

.site-logo {
  position: absolute;
  top: 50%;
  right: calc(100% - 2rem);
  transform: translateY(-50%);
  width: 10rem;
  height: 10rem;
  flex-shrink: 0;
}

.site-logo img {
  width: 100%;
  height: 100%;
  display: block;
}

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

.brand-text {
  display: flex;
  flex-direction: column;
  margin-right: auto;
}

.wordmark {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.025em;
}

.wordmark a {
  color: var(--color-text);
  text-decoration: none;
}

.wordmark .dot {
  color: var(--color-accent);
}

.subtitle {
  font-size: 0.72rem;
  line-height: 1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-muted);
  font-weight: 500;
  margin-top: 0.35rem;
}

#site-search {
  background: var(--color-bg-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.42rem 0.8rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
  width: 200px;
}

#site-search::placeholder {
  color: var(--color-muted);
}

#site-search:focus {
  outline: none;
  border-color: var(--color-accent);
}

.header-inner > button,
.header-inner > a.button {
  background: var(--color-bg-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.42rem 0.8rem;
  color: var(--color-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.header-inner > button:hover,
.header-inner > a.button:hover {
  color: var(--color-text);
  border-color: var(--color-text);
  opacity: 1;
}

#theme-toggle {
  position: absolute;
  top: 50%;
  left: calc(100% - 2rem + 0.8rem);
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.42rem 0.4rem;
}

#theme-toggle:hover {
  background: none;
  border-color: transparent;
}

/* ── Main container ───────────────────────────────────────────────────── */

main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 4rem 2rem 0rem;
  width: 100%;
  box-sizing: border-box;
}

/* ── Index controls (sort + tag filter) ───────────────────────────────── */

.post-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: flex-start;
  margin-bottom: 1.6rem;
}

#post-sort {
  background: var(--color-bg-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.42rem 0.8rem;
  color: var(--color-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

#post-sort:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

.tag-filter {
  position: relative;
  flex: 0 0 auto;
}

.tag-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: var(--color-bg-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.42rem 0.8rem;
}

.tag-filter-toggle::-webkit-details-marker { display: none; }

.tag-filter-toggle::after {
  content: "▾";
  font-size: 0.85em;
  transition: transform 0.15s;
}

.tag-filter[open] .tag-filter-toggle::after {
  transform: rotate(180deg);
}

.tag-filter-toggle:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

/* Active-tag indicator — standalone row between .post-controls and
   .posts-head, populated by _search_script.html with one .tag-filter-chip
   per checked checkbox so the user always sees what's filtered. The row
   collapses entirely when no tags are selected (`:empty`). */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.4rem;
}

.active-filters:empty {
  display: none;
}

.active-filters::before {
  content: "Filtering by";
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-muted);
  margin-right: 0.4rem;
}

.tag-filter-chip {
  background: var(--color-accent);
  color: var(--color-bg);
  padding: 0.18rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.tag-filter-bar {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  width: max-content;
  max-width: min(640px, calc(100vw - 4rem));
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.7rem 0.8rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.tag-filter-bar label {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  padding: 0.25em 0.7em;
  border-radius: 3px;
  background: var(--color-bg-2);
  color: var(--color-muted);
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: background 0.1s, color 0.1s;
}

.tag-filter-bar label:hover {
  color: var(--color-text);
}

.tag-filter-bar label:has(input:checked) {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
}

.tag-filter-bar input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* ── Posts list ───────────────────────────────────────────────────────── */

.posts-head {
  display: grid;
  grid-template-columns: 200px 60px 1fr 40px;
  gap: 2rem;
  padding: 0 1.5rem 0.8rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.posts-head .right { text-align: right; }

.post {
  display: grid;
  grid-template-columns: 200px 60px 1fr 40px;
  gap: 2rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  align-items: center;
  text-decoration: none;
  color: inherit;
  height: 150px;
}

.post:hover {
  background: var(--color-bg-2);
  opacity: 1;
}

.post:hover .arrow {
  transform: translateX(4px);
  color: var(--color-accent);
}

.post .thumb {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.post .thumb.thumb-empty {
  background: linear-gradient(135deg, var(--color-bg-2), var(--color-border));
}

.post .num {
  font-feature-settings: "tnum";
  font-size: 0.82rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  align-self: center;
}

.post-body {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
  overflow: hidden;
}

.post .title {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post .title em {
  font-style: italic;
  color: var(--color-muted);
  font-weight: 400;
}

.post .desc {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.92rem;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-foot {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
  margin-top: 0.2rem;
}

.post-foot .author + .date::before {
  content: "·";
  margin-right: 0.6rem;
  color: var(--color-border);
}

.post .arrow {
  display: inline-block;
  font-size: 1.1rem;
  text-align: right;
  align-self: center;
  color: var(--color-accent);
  transition: transform 0.15s, color 0.15s;
}

.no-results {
  display: none;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
  font-style: italic;
  font-size: 1rem;
}

.no-results.visible { display: block; }

/* ── Footer ───────────────────────────────────────────────────────────── */

footer.site {
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  padding: 1.6rem 2rem;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.82rem;
}

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 1380px) {
  .site-logo {
    position: static;
    transform: none;
    width: 6rem;
    height: 6rem;
    margin-right: 1.2rem;
  }
  #theme-toggle {
    position: static;
    transform: none;
    margin-left: 1rem;
  }
  .header-inner {
    height: auto;
    padding: 1.2rem 2rem;
  }
}

@media (max-width: 900px) {
  .header-inner {
    flex-wrap: wrap;
    padding: 1rem 1.4rem;
    gap: 0.6rem;
  }
  #site-search {
    flex: 1 1 200px;
    min-width: 0;
    margin-left: 5rem;
    width: auto;
  }
  .site-logo {
    width: 5rem;
    height: 5rem;
  }
  .wordmark { font-size: 1.4rem; }
  main { padding: 2.6rem 1.4rem 1rem; }

  /* Post list: simplified 2-col layout starting at tablet width. The
     desktop 4-col grid (cover / № / body / arrow) is too cramped once
     the cover column shrinks below ~150px, so we drop the № and arrow
     columns entirely and lock the thumb to a fixed square. The post
     row grows in height with longer titles, but the thumb stays the
     same size on every row. */
  .posts-head { display: none; }
  .post {
    grid-template-columns: 100px 1fr;
    gap: 1rem;
    padding: 0.8rem 1rem;
    height: auto;
    min-height: 116px;
  }
  .post .thumb {
    width: 100px;
    height: 100px;
    align-self: center;
  }
  .post .num,
  .post .arrow { display: none; }
  .post .title {
    font-size: 1.1rem;
    line-height: 1.25;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .post .desc {
    -webkit-line-clamp: 1;
  }
}

@media (max-width: 600px) {
  .header-inner {
    padding: 0.9rem 1rem;
    gap: 0.45rem 0.7rem;
    align-items: center;
  }
  .site-logo {
    width: 5rem;
    height: 5rem;
    margin-right: 0.8rem;
  }
  .wordmark { font-size: 1.2rem; }
  .subtitle {
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    margin-top: 0.25rem;
  }
  /* All header buttons (theme toggle + post-page ← Index) share the
     same compact box so they read as a paired control set. Explicit
     line-height + min-width prevents the moon/arrow glyphs from
     rendering at a different visual height than the surrounding text. */
  .header-inner > button,
  .header-inner > a.button {
    padding: 0.4rem 0.55rem;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 2rem;
    text-align: center;
  }
  /* Hide the " Index" label inside the post page's back button so it
     collapses to just "←", matching the theme toggle's footprint. */
  .header-inner > button .btn-label { display: none; }
  #theme-toggle {
    margin-left: 0;
    background: none;
    border: none;
    padding: 0.4rem;
    min-width: 0;
  }
  #site-search {
    order: 99;
    flex: 1 1 100%;
    width: 100%;
    padding: 0.5rem 0.8rem;
    margin-left: 0;
    font-size: 0.85rem;
  }

  main { padding: 1.6rem 1rem 1rem; }

  /* Sort + filter share an identical box (font, padding, line-height) so
     the <select> and the <summary> button line up at the same height. */
  .post-controls {
    position: relative;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }
  #post-sort,
  .tag-filter-toggle {
    padding: 0.42rem 0.7rem;
    font-size: 0.78rem;
    line-height: 1.15;
    border-radius: 4px;
  }
  .tag-filter-toggle {
    text-transform: none;
    letter-spacing: 0;
    gap: 0.35em;
  }
  /* Anchor the dropdown to the controls row instead of the toggle, so it
     stretches the full row width and never overflows the viewport. */
  .tag-filter { position: static; }
  .tag-filter-bar {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    padding: 0.55rem 0.65rem;
  }

  /* Phone-specific overrides on top of the 900px 2-col post layout. */
  .post {
    grid-template-columns: 76px 1fr;
    gap: 0.8rem;
    padding: 0.7rem 0.6rem;
    min-height: 92px;
  }
  .post .thumb {
    width: 76px;
    height: 76px;
  }
  .post .title {
    font-size: 0.9rem;
    line-height: 1.25;
    -webkit-line-clamp: 3;
  }
  .post .desc {
    font-size: 0.78rem;
  }
  .post-body { gap: 0.25rem; }
  .post-foot { font-size: 0.7rem; gap: 0.4rem; margin-top: 0.1rem; }
  .post-foot .author + .date::before { margin-right: 0.4rem; }

  footer.site {
    padding: 1.2rem 1rem;
    font-size: 0.75rem;
  }
}
