/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f6f4ef;
  --bg-card:      #ffffff;
  --bg-header:    #1a1a2e;
  --text:         #1c1c1e;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --border:       #e5e0d8;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --tag-bg:       #e0e7ff;
  --tag-text:     #3730a3;
  --lang-th:      #fef3c7;
  --lang-th-text: #92400e;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --radius:       10px;
  --font-serif:   Georgia, 'Times New Roman', serif;
  --font-sans:    'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'Fira Code', 'Cascadia Code', monospace;
  --max-w:        760px;
  --max-w-wide:   1100px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--accent-hover); }

/* ── Site Header ─────────────────────────────────────────────────────────── */
.site-header {
  background: var(--bg-header);
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.site-header a { color: #e2e8f0; }
.site-header a:hover { color: #fff; text-decoration: none; }

.site-logo {
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: #f8fafc !important;
}
.site-logo span { color: #60a5fa; }

.header-sep { color: rgba(255,255,255,.25); font-size: .85rem; }

.header-crumb {
  font-size: .85rem;
  color: rgba(255,255,255,.55) !important;
}
.header-crumb.active { color: rgba(255,255,255,.85) !important; }

/* ── Page Wrapper ────────────────────────────────────────────────────────── */
.page { padding: 3rem 1.5rem 5rem; }

.container {
  max-width: var(--max-w-wide);
  margin: 0 auto;
}

.container-narrow {
  max-width: var(--max-w);
  margin: 0 auto;
}

/* ── Home Hero ───────────────────────────────────────────────────────────── */
.home-hero {
  padding: 4rem 1.5rem 2.5rem;
  text-align: center;
  max-width: 640px;
  margin: 0 auto;
}

.home-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: .75rem;
}

.home-hero p {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
}

/* ── Section Labels ──────────────────────────────────────────────────────── */
.section-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 1.25rem;
}

/* ── Project Cards (Home) ────────────────────────────────────────────────── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.project-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.project-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.project-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.project-card p {
  font-size: .875rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.project-card-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .75rem;
  color: var(--text-light);
  margin-top: .25rem;
}

.doc-count-badge {
  background: var(--accent-light);
  color: var(--accent);
  font-size: .7rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 20px;
}

/* ── Project Index Page ──────────────────────────────────────────────────── */
.project-header {
  padding: 3rem 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 2.5rem;
}

.project-header-inner {
  max-width: var(--max-w-wide);
  margin: 0 auto;
}

.project-title {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin: .5rem 0;
}

.project-description {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: .5rem;
  max-width: 560px;
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.doc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.doc-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.doc-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.doc-card .doc-subtitle {
  font-size: .82rem;
  color: var(--text-muted);
  font-style: italic;
}

.doc-card .doc-desc {
  font-size: .85rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.doc-card-footer {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .25rem;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: .65rem;
  font-weight: 600;
  padding: .15rem .45rem;
  border-radius: 20px;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.tag.lang-th {
  background: var(--lang-th);
  color: var(--lang-th-text);
}

.arrow-icon {
  margin-left: auto;
  color: var(--text-light);
  font-size: .85rem;
  transition: transform .15s;
}

.doc-card:hover .arrow-icon { transform: translateX(3px); }

/* ── Document Page ───────────────────────────────────────────────────────── */
.doc-layout {
  display: grid;
  grid-template-columns: 1fr min(var(--max-w), 100%) 1fr;
  padding: 2rem 1rem 5rem;
  gap: 0;
}

.doc-layout > * { grid-column: 2; }

.doc-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
}

.doc-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin: .5rem 0 .35rem;
}

.doc-header .subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: .75rem;
}

.doc-header-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  font-size: .78rem;
  color: var(--text-light);
  margin-top: .75rem;
}

/* ── Prose Styling ───────────────────────────────────────────────────────── */
.prose {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.8;
  color: #2c2c2e;
}

.prose h1 {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 700;
  margin: 2.5rem 0 .75rem;
  color: var(--text);
  line-height: 1.25;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.prose h2 {
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 2rem 0 .6rem;
  color: #1d4ed8;
  line-height: 1.3;
}

.prose h3 {
  font-family: var(--font-sans);
  font-size: .95rem;
  font-weight: 600;
  margin: 1.5rem 0 .4rem;
  color: var(--text-muted);
  font-style: italic;
}

.prose p { margin-bottom: 1.1rem; }

.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: .75rem 1.25rem;
  color: #555;
  font-style: italic;
  background: var(--accent-light);
  border-radius: 0 6px 6px 0;
}

.prose blockquote p { margin-bottom: 0; }

.prose strong { font-weight: 700; color: var(--text); }
.prose em { font-style: italic; }

.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.prose a:hover { color: var(--accent-hover); }

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.prose ul, .prose ol {
  margin: .75rem 0 1rem 1.5rem;
}
.prose li { margin-bottom: .35rem; }

.prose code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: #f1f0eb;
  padding: .1em .35em;
  border-radius: 4px;
}

/* ── TOC ─────────────────────────────────────────────────────────────────── */
.toc-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.35rem;
  margin-bottom: 2.5rem;
  font-size: .85rem;
}

.toc-box summary {
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.toc-box summary::-webkit-details-marker { display: none; }

.toc-box ol {
  margin: .75rem 0 0 1rem;
  line-height: 1.7;
}
.toc-box li { color: var(--text-muted); }
.toc-box a { color: var(--accent); font-size: .82rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .site-header { padding: 0 1rem; }
  .home-hero { padding: 2.5rem 1rem 1.5rem; }
  .project-header { padding: 2rem 1rem 1.5rem; }
  .page { padding: 2rem 1rem 4rem; }
  .doc-layout { padding: 1.5rem .75rem 4rem; }
}
