/* === NAV === */
.site-nav {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.nav-container {
  max-width: var(--max-page);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.site-brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text-primary);
  line-height: 1.1;
}
.brand-main {
  font-family: var(--font-serif-latin);
  font-weight: 600;
  font-size: 1.5rem;
  color: var(--brand-primary);
}
.brand-sub {
  font-family: var(--font-serif-cjk);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-tabs-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
/* fade hint on edges to suggest horizontal scrolling */
.nav-tabs-wrap::before,
.nav-tabs-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 1;
}
.nav-tabs-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg-elevated), transparent);
}
.nav-tabs-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg-elevated), transparent);
}
.nav-tabs-wrap.can-scroll-left::before { opacity: 1; }
.nav-tabs-wrap.can-scroll-right::after { opacity: 1; }

.nav-tabs {
  display: flex;
  gap: var(--space-3);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;          /* Firefox: hide */
  -ms-overflow-style: none;       /* legacy IE/Edge */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.nav-tabs::-webkit-scrollbar { display: none; } /* WebKit: hide */

.nav-tab,
.nav-tab:hover,
.nav-tab:focus,
.nav-tab.active {
  /* Lock text color across all states — global a:hover in base.css would
     otherwise swap it to var(--link-hover) gold. */
  color: var(--text-secondary);
}
.nav-tab {
  text-decoration: none;
  font-size: 0.95rem;
  padding: var(--space-1) var(--space-2);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-bottom-color 150ms ease;
}
/* HOVER — only the underline lights up */
@media (hover: hover) {
  .nav-tab:hover { border-bottom-color: var(--brand-accent); }   /* gold #A87C3E */
}
/* ACTIVE — current page indicator */
.nav-tab.active { border-bottom-color: var(--brand-primary); }   /* deep green #1F3A2E */

.nav-actions { display: flex; gap: var(--space-2); }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-light { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-dark { display: inline; }

.nav-toggle {
  display: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
}
.nav-toggle span {
  width: 24px;
  height: 2px;
  background: var(--text-primary);
}

@media (max-width: 767px) {
  .nav-container { flex-wrap: wrap; }
  .nav-toggle { display: flex; }
  .nav-tabs-wrap {
    order: 99;
    flex-basis: 100%;
    overflow: visible;
  }
  /* hide fade hints on mobile (vertical accordion, no scroll) */
  .nav-tabs-wrap::before,
  .nav-tabs-wrap::after { display: none; }
  .nav-tabs {
    flex-direction: column;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    overflow-y: auto;
    transition: max-height 200ms ease;
  }
  .nav-tabs.open {
    max-height: calc(100vh - 80px);
    padding-top: var(--space-2);
  }
  .nav-tab {
    padding: var(--space-2);
    border-bottom: 1px solid var(--border);
    white-space: normal;          /* allow wrap on mobile vertical list */
  }
}

/* === FEATURED === */
.featured {
  margin: 0 0 var(--space-6);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.featured:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
.featured-link { display: block; text-decoration: none; color: inherit; }
.featured-image {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-subtle);
}
.featured-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.featured-overlay { padding: var(--space-5); }
.featured-cat {
  display: inline-block;
  background: var(--cat-color-light);
  color: white;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
  font-family: var(--font-sans-cjk);
}
[data-theme="dark"] .featured-cat { background: var(--cat-color-dark); }
.featured-title {
  font-family: var(--font-serif-cjk);
  font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  line-height: 1.2;
  margin: 0 0 var(--space-3);
  color: var(--text-primary);
}
.featured-summary {
  color: var(--text-secondary);
  font-size: 1.05rem;
  margin: 0 0 var(--space-3);
}
.featured-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.featured-arrow { color: var(--brand-accent); }

/* === LIST SECTION === */
.post-list-section { margin-top: var(--space-6); }
.post-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.section-title {
  font-family: var(--font-serif-cjk);
  margin: 0;
  font-size: 1.5rem;
}
.section-count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 1rem;
}

/* === SORT TOGGLE === */
.sort-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sort-label { color: var(--text-muted); font-size: 0.9rem; }
.sort-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-sans-cjk);
  transition: all 150ms ease;
}
.sort-btn.active, .sort-btn:hover {
  background: var(--brand-primary);
  color: var(--bg-elevated);
  border-color: var(--brand-primary);
}

/* === POST GRID === */
.post-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}
@media (max-width: 1023px) {
  .post-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  .post-grid { grid-template-columns: 1fr; }
}

/* === POST CARD === */
.post-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.post-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.08); }
/* Make card-link a flex column so card-body can stretch and pin footer to bottom.
   Grid auto-stretches all cards in a row to the tallest, so without this the
   shorter card's footer (date / views) would float mid-card. */
.card-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  text-decoration: none;
  color: inherit;
  padding: var(--space-4);
}
.card-body {
  display: flex;
  flex-direction: column;
  flex: 1;                   /* fill remaining vertical space below image */
}
.card-footer { margin-top: auto; }   /* push footer (date + views) to bottom */
.card-cat {
  display: inline-block;
  background: var(--cat-color-light);
  color: #fff;
  font-family: var(--font-sans-cjk);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  /* margin-bottom now lives on .card-header-row (sits next to authorship badge) */
}
[data-theme="dark"] .card-cat { background: var(--cat-color-dark); }
.card-image {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}
.card-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-image-placeholder {
  color: white;
  padding: var(--space-3);
  font-family: var(--font-serif-cjk);
  font-size: 0.95rem;
  text-align: center;
}
.card-body { padding: 0; }
.card-title {
  font-family: var(--font-serif-cjk);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 var(--space-3);
  color: var(--text-primary);
  /* reserve space for up to 2 lines so all cards align even if title is 1 line */
  min-height: calc(1.35rem * 1.35 * 2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-summary {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin: 0 0 var(--space-4);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  /* fix to 3 lines tall regardless of content length → uniform row heights */
  height: calc(0.95rem * 1.7 * 3);
}
.card-date {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}
.card-views {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* === PAGINATION === */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-6) 0;
}
.page-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
}
.page-btn:hover {
  background: var(--brand-primary);
  color: var(--bg-elevated);
  border-color: var(--brand-primary);
}
.page-info { color: var(--text-muted); }

/* === SEARCH === */
.search-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
}
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--space-3) var(--space-3);
}
.search-overlay[hidden] { display: none; }
.search-modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-3) var(--space-3);
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
#search-input {
  width: 100%;
  padding: var(--space-3);
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans-cjk);
}
/* hide browser-native clear button on type="search" — we have our own ✕ */
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}
#search-input::-ms-clear { display: none; }
.search-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: transparent;
  border: 0;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
}
.search-meta {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-2);
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.search-results { list-style: none; padding: 0; margin: var(--space-2) 0 0; }
.search-results li { border-bottom: 1px solid var(--border); }
.search-results a {
  display: block;
  padding: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
}
.search-results a:hover { background: var(--bg-subtle); }
.search-results small { color: var(--text-muted); }

/* === ERROR (404) === */
.error-page {
  text-align: center;
  padding: var(--space-7) var(--space-3);
}
.error-code {
  font-family: var(--font-serif-latin);
  font-size: clamp(4rem, 12vw, 8rem);
  color: var(--brand-accent);
  margin: 0;
  line-height: 1;
}
.error-message {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin: var(--space-3) 0 var(--space-5);
}
.error-back {
  display: inline-block;
  padding: 10px 20px;
  background: var(--brand-primary);
  color: var(--bg-elevated);
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-6);
}
.error-suggestions { text-align: left; max-width: var(--max-page); margin: 0 auto; }
.error-suggestions h3 { font-family: var(--font-serif-cjk); margin-bottom: var(--space-3); }

/* === FOOTER === */
.site-footer {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  margin-top: var(--space-7);
  padding: var(--space-5) var(--space-4);
}
.footer-container {
  max-width: var(--max-page);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.footer-brand .brand-main {
  font-family: var(--font-serif-latin);
  font-size: 1.25rem;
  color: var(--brand-primary);
}
.footer-brand .brand-sub {
  font-family: var(--font-serif-cjk);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.footer-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: right;
}
@media (max-width: 767px) {
  .footer-meta { text-align: left; }
}
