/* ---------- Design tokens ---------- */
:root {
  --bg: #f6f5f1;
  --bg-elevated: #ffffff;
  --bg-subtle: #eeece5;
  --text: #1c1d1b;
  --text-muted: #5c5d58;
  --text-faint: #8a8b85;
  --border: #e2e0d8;
  --accent: #0f6d5c;
  --accent-strong: #0a4f42;
  --accent-soft: #e2f1ed;
  --accent-contrast: #ffffff;
  --chip-bg: #ffffff;
  --chip-active-bg: #0f6d5c;
  --chip-active-text: #ffffff;
  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.06), 0 1px 1px rgba(20, 20, 15, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 20, 15, 0.08), 0 2px 6px rgba(20, 20, 15, 0.05);
  --shadow-lg: 0 20px 50px rgba(20, 20, 15, 0.16);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --font-display: 'Space Grotesk', 'Sarabun', sans-serif;
  --font-body: 'Sarabun', 'Noto Sans Thai', sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-elevated: #1c1f24;
  --bg-subtle: #21242a;
  --text: #ecece7;
  --text-muted: #a3a59d;
  --text-faint: #6f716b;
  --border: #2b2e34;
  --accent: #3ecfaa;
  --accent-strong: #6ee6c6;
  --accent-soft: #17332c;
  --accent-contrast: #08201a;
  --chip-bg: #1c1f24;
  --chip-active-bg: #3ecfaa;
  --chip-active-text: #08201a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --bg-elevated: #1c1f24;
    --bg-subtle: #21242a;
    --text: #ecece7;
    --text-muted: #a3a59d;
    --text-faint: #6f716b;
    --border: #2b2e34;
    --accent: #3ecfaa;
    --accent-strong: #6ee6c6;
    --accent-soft: #17332c;
    --accent-contrast: #08201a;
    --chip-bg: #1c1f24;
    --chip-active-bg: #3ecfaa;
    --chip-active-text: #08201a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
select, input { font-family: inherit; }
a { color: var(--accent-strong); }

h1, h2, h3, .brand-text h1, .hero h2 {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand-text { min-width: 0; }
.brand-mark {
  font-size: 26px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 700; }
.brand-text p { margin: 0; font-size: 12.5px; color: var(--text-muted); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--bg-subtle); }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-sun { display: block; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; fill: currentColor; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; fill: currentColor; }
}

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(ellipse 900px 400px at 15% 0%, var(--accent-soft), transparent 60%),
    var(--bg);
  border-bottom: 1px solid var(--border);
}
.hero-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 56px 24px 40px;
}
.hero h2 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 700;
  max-width: 18ch;
}
.hero-sub {
  margin: 0 0 28px;
  color: var(--text-muted);
  font-size: 17px;
  max-width: 58ch;
}
.hero-stats { display: flex; gap: 32px; flex-wrap: wrap; }
.stat-item .stat-num {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-strong);
  line-height: 1.1;
}
.stat-item .stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Main / controls ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 36px 24px 80px; }

.controls {
  padding: 14px 0 16px;
  margin-bottom: 8px;
}

/* Only the search row stays pinned while scrolling. Keeping the whole
   filter block (including the topic/year chip rows) sticky let it
   grow tall enough — especially once chips wrap onto several lines —
   to cover the card grid as it scrolled underneath it. */
.search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  top: 78px;
  z-index: 30;
  margin: 0 0 14px;
  padding: 10px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.search-box {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  box-shadow: var(--shadow-sm);
}
.search-box svg { fill: none; stroke: var(--text-faint); stroke-width: 2; flex-shrink: 0; }
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  padding: 11px 0;
  width: 100%;
  font-size: 15px;
}
.search-box input::placeholder { color: var(--text-faint); }

.view-toggle {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.view-toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
}
.view-toggle-btn.active { background: var(--accent); color: var(--accent-contrast); }

#sort-select {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.filter-group { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-text);
  border-color: var(--chip-active-bg);
}
.chip .chip-count { opacity: 0.7; font-size: 11.5px; }
.chip.active .chip-count { opacity: 0.85; }

.year-row .chip { font-family: var(--font-display); font-weight: 600; }

.active-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.active-filters:empty { display: none; }
.clear-filters-btn {
  border: 1px dashed var(--text-faint);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
}
.clear-filters-btn:hover { color: var(--text); border-color: var(--text); }

.result-count {
  color: var(--text-faint);
  font-size: 13.5px;
  margin: 18px 2px 18px;
}

/* ---------- Card grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  text-align: left;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  color: inherit;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.card-thumb {
  aspect-ratio: 16/10;
  background: var(--bg-subtle);
  overflow: hidden;
  position: relative;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-thumb.no-image {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  font-family: var(--font-display);
  font-size: 13px;
}
.card-date-badge {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(20,20,15,0.68);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  backdrop-filter: blur(3px);
}
.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-hook {
  font-size: 13.5px;
  color: var(--text-muted);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; }
.tag-pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 15px;
}

/* ---------- Timeline view ---------- */
.timeline { display: flex; flex-direction: column; gap: 36px; }
.timeline-year { position: relative; }
.timeline-year-label {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-strong);
  margin: 0 0 14px;
  position: sticky;
  top: 158px;
}
.timeline-items { display: flex; flex-direction: column; gap: 2px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline-item {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 9px 0 9px 20px;
  position: relative;
  text-decoration: none;
  color: inherit;
  border-radius: 0 8px 8px 0;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -6px; top: 15px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg);
}
.timeline-item:hover { background: var(--bg-subtle); }
.timeline-item:hover::before { background: var(--accent); }
.timeline-date { flex-shrink: 0; font-size: 12.5px; color: var(--text-faint); font-family: var(--font-display); width: 78px; }
.timeline-title { font-size: 14.5px; font-weight: 500; flex: 1; }
.timeline-tags { display: none; }
@media (min-width: 720px) {
  .timeline-tags { display: flex; gap: 5px; flex-shrink: 0; }
}

/* ---------- Post detail ---------- */
.back-btn {
  border: none;
  background: transparent;
  color: var(--accent-strong);
  font-size: 14.5px;
  font-weight: 600;
  padding: 8px 0;
  margin-bottom: 20px;
}
.back-btn:hover { text-decoration: underline; }

.post-detail {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 48px);
  box-shadow: var(--shadow-sm);
}
.post-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-faint);
}
.post-week-badge {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-display);
}
.post-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 3.4vw, 32px);
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 18px;
}
.post-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 26px; }
.post-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.post-images img {
  width: 100%;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  border: 1px solid var(--border);
  object-fit: cover;
  max-height: 420px;
}
.post-images.single img { max-height: 520px; }
.post-body {
  font-size: 16.5px;
  line-height: 1.85;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
}
.post-nav-link {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.post-nav-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.post-nav-link.next { text-align: right; }
.post-nav-dir { display: block; font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.post-nav-title { font-size: 14px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-nav-spacer { flex: 1; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(10,10,8,0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 30px;
}
.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 6px; }
.lightbox-close {
  position: absolute; top: 20px; right: 24px;
  background: transparent; border: none; color: #fff;
  font-size: 34px; line-height: 1;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 28px 24px 40px;
  text-align: center;
}
.site-footer p { margin: 0; color: var(--text-faint); font-size: 13px; max-width: 60ch; margin: 0 auto; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  /* Keep the header to one line so its height is predictable — the
     sticky search row below needs to know exactly where it ends. */
  .brand-text p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Bleed the sticky search row edge-to-edge and let it sit flush
     against the screen edges on narrow viewports; chips scroll
     horizontally in a single row instead of wrapping, since wrapped
     chips would otherwise fill most of a small screen. */
  .controls { padding-top: 0; }
  .search-row {
    margin: 0 -16px 10px;
    padding: 10px 16px;
  }
  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -16px 8px;
    padding: 0 16px 4px;
  }
  .filter-row::-webkit-scrollbar { display: none; }
  .filter-group { flex-wrap: nowrap; }
  .chip { flex-shrink: 0; }
}

@media (max-width: 600px) {
  .hero-inner { padding: 40px 20px 32px; }
  main { padding: 24px 16px 60px; }
  .post-nav { flex-direction: column; }
}
