@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800&family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  --bg: #fbf8f1;
  --bg-soft: #f6efe3;
  --surface: #fffdf8;
  --surface-subtle: #f8f3ea;
  --surface-raised: #ffffff;
  --ink: #111827;
  --ink-soft: #263247;
  --muted: #4b5565;
  --muted-2: #6b7280;
  --line: #e5dfd4;
  --line-strong: #cec4b5;
  --accent: #27246f;
  --accent-strong: #17144e;
  --accent-soft: #eeedf8;
  --accent-line: #cbc8ee;
  --warm-red: #7d241f;
  --warm-red-soft: #f8ece9;
  --gold: #6f4a0b;
  --gold-soft: #fbf1d8;
  --sidebar: #101124;
  --sidebar-2: #17152b;
  --sidebar-line: rgba(226, 232, 240, 0.16);
  --code-bg: #0d1117;
  --code-line: #30363d;
  --code-text: #f0f6fc;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 16px 44px rgba(39, 36, 111, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --content: 1560px;
  --font-body: "Noto Sans Thai", "IBM Plex Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: "Noto Sans Thai", "IBM Plex Sans Thai", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% -18%, rgba(251, 241, 216, 0.85), transparent 34rem),
    linear-gradient(180deg, #fffdf8 0%, var(--bg) 100%);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.86;
}

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

a:hover {
  color: var(--accent-strong);
}

img,
svg {
  max-width: 100%;
}

.profile-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 20%;
  border: 3px solid var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  margin: 16px 0;
}

code,
pre {
  font-family: var(--font-mono);
}

::selection {
  background: var(--accent-line);
  color: var(--ink);
}

/* Landing */
.landing {
  min-height: 100vh;
  overflow: hidden;
  background: #fbfbfa;
}

.hero {
  width: min(1420px, calc(100vw - 104px));
  height: 100vh;
  max-height: 1080px;
  min-height: 680px;
  margin: 0 auto;
  padding: 72px 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.62fr) minmax(640px, 1.38fr);
  gap: clamp(56px, 7vw, 112px);
  align-items: center;
}

.hero-panel,
.hero-art {
  min-width: 0;
}

.hero-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  min-height: 480px;
}

.brand-lockup {
  display: grid;
  gap: 22px;
  align-items: start;
}

.hero-psi,
.brand-mark {
  display: grid;
  place-items: center;
  font-family: var(--font-heading);
  font-weight: 800;
  letter-spacing: 0;
}

.hero-psi {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  color: #fff8ea;
  background: #a33c32;
  font-size: 52px;
  box-shadow: 0 16px 34px rgba(163, 60, 50, 0.14);
}

.eyebrow,
.chapter-kicker {
  display: block;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-header .chapter-kicker {
  display: none;
}

.brand-copy h1 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: clamp(2.9rem, 4.8vw, 4.25rem);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: 0;
}

.brand-copy p {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: clamp(1.05rem, 1.5vw, 1.22rem);
  font-weight: 500;
  line-height: 1.55;
}

.hero-actions,
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.86);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.hero-actions,
.pager {
  margin-top: 42px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.button:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.button.primary {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 12px 24px rgba(39, 36, 111, 0.16);
}

.button.primary:hover {
  color: #ffffff;
  background: var(--accent-strong);
}

.button.secondary {
  color: var(--accent-strong);
  background: #ffffff;
  border-color: var(--line-strong);
}

.button.secondary:hover {
  color: var(--accent-strong);
  background: var(--surface-subtle);
}

.hero-art {
  display: flex;
  align-items: center;
}

.toc-shell {
  width: 100%;
  display: block;
}

.chapter-sections {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.chapter-section {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.035);
}

.chapter-section h2,
.chapter-section h3 {
  margin: 0 0 18px;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.35;
}

.chapter-section p {
  display: none;
}

.chapter-list {
  display: grid;
  gap: 0;
}

.chapter-tile {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 46px;
  padding: 8px 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  transition: color 140ms ease, background 140ms ease, transform 140ms ease;
}

.chapter-tile:hover {
  color: var(--accent-strong);
  background: #f8fafc;
  text-decoration: none;
  transform: translateX(2px);
}

.chapter-tile span {
  display: block;
  width: auto;
  height: auto;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.4;
}

.chapter-tile strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.42;
}

/* Chapter layout */
.book-layout {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 14px;
  color: rgba(248, 250, 252, 0.92);
  background:
    radial-gradient(circle at 0 0, rgba(125, 36, 31, 0.22), transparent 15rem),
    linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  border-right: 1px solid rgba(17, 24, 39, 0.9);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(226, 232, 240, 0.24);
  border-radius: 999px;
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 11px;
  align-items: center;
  padding: 8px 10px 18px;
  margin-bottom: 12px;
  color: #ffffff;
  text-decoration: none;
  border-bottom: 1px solid var(--sidebar-line);
}

.brand:hover {
  color: #ffffff;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff8ea;
  background: var(--warm-red);
  font-size: 27px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.2);
}

.brand strong {
  display: block;
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: rgba(226, 232, 240, 0.72);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.side-nav {
  display: grid;
  gap: 3px;
}

.side-nav a {
  display: grid;
  grid-template-columns: 45px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: rgba(226, 232, 240, 0.82);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.34;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.side-nav a span {
  color: rgba(203, 213, 225, 0.78);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.side-nav a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.09);
  text-decoration: none;
}

.side-nav a.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 3px 0 0 #f2d38b;
}

.side-nav a.active span {
  color: #f6e2a8;
}

.sidebar-footer {
  display: none;
}

.reader {
  min-width: 0;
  background: #fffdf8;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
  padding: 0 clamp(28px, 4vw, 60px);
  color: var(--muted);
  background: rgba(255, 253, 248, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar a {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.topbar a:hover {
  color: var(--accent);
}

.topbar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chapter-shell {
  width: min(var(--content), calc(100vw - 276px));
  max-width: var(--content);
  margin: 0;
  padding: 60px clamp(34px, 4.5vw, 72px) 92px;
  min-height: calc(100vh - 56px);
  background: rgba(255, 255, 255, 0.68);
  border-right: 1px solid var(--line);
  box-shadow: 18px 0 44px rgba(17, 24, 39, 0.035);
}

.chapter-header {
  padding-bottom: 34px;
  margin-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.chapter-header h1 {
  margin: 0 0 14px;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1.14;
  letter-spacing: 0;
}

.chapter-lead {
  max-width: 780px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.78;
}

.source-note {
  display: none;
  max-width: 100%;
  margin-top: 18px;
  padding: 7px 10px;
  border: 1px solid var(--accent-line);
  border-radius: 7px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

/* Content typography */
.chapter-content {
  color: var(--ink-soft);
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
  color: var(--ink);
  font-family: var(--font-heading);
  letter-spacing: 0;
}

.chapter-content h1 {
  margin: 48px 0 14px;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.34;
}

.chapter-content h2 {
  margin: 46px 0 14px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  font-size: 27px;
  font-weight: 800;
  line-height: 1.36;
}

.chapter-content h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.chapter-content h3 {
  margin: 32px 0 10px;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.42;
}

.chapter-content h4 {
  margin: 26px 0 8px;
  color: var(--ink-soft);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.5;
}

.chapter-content p {
  max-width: 820px;
  margin: 0 0 18px;
  font-size: 1.09375rem;
  line-height: 1.94;
}

.chapter-content ul,
.chapter-content ol {
  max-width: 820px;
  margin: 0 0 22px 1.35rem;
  padding: 0;
}

.chapter-content li {
  margin: 7px 0;
  padding-left: 4px;
  font-size: 1.09375rem;
  line-height: 1.86;
}

.chapter-content blockquote {
  max-width: 860px;
  margin: 26px 0;
  padding: 18px 20px;
  border: 1px solid var(--accent-line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  color: var(--ink-soft);
  background: var(--accent-soft);
  font-size: 1.09375rem;
  line-height: 1.84;
}

.chapter-content table {
  width: 100%;
  margin: 26px 0 34px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.96875rem;
  line-height: 1.7;
}

.chapter-content th,
.chapter-content td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.chapter-content th {
  color: var(--ink);
  background: #f7f1e8;
  border-bottom-color: var(--line-strong);
  font-size: 13.5px;
  font-weight: 800;
}

.chapter-content tr:last-child td {
  border-bottom: 0;
}

.chapter-content tbody tr:nth-child(even) td {
  background: #fffaf2;
}

.chapter-content tbody tr:hover td {
  background: var(--gold-soft);
}

.chapter-content code {
  padding: 2px 6px;
  border: 1px solid #d8d2e9;
  border-radius: 6px;
  color: var(--accent-strong);
  background: #f7f6ff;
  font-size: 0.9em;
  white-space: nowrap;
}

.chapter-content pre {
  position: relative;
  margin: 24px 0 30px;
  padding: 20px 22px;
  overflow-x: auto;
  border: 1px solid var(--code-line);
  border-radius: var(--radius);
  color: var(--code-text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
    var(--code-bg);
  box-shadow: 0 18px 34px rgba(17, 24, 39, 0.18);
  font-size: 13.5px;
  line-height: 1.7;
  tab-size: 2;
}

.chapter-content pre::before {
  content: "code";
  position: absolute;
  top: 9px;
  right: 12px;
  color: #8b949e;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chapter-content pre code {
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font-size: inherit;
  white-space: pre;
}

.chapter-content hr {
  margin: 42px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.mermaid,
.inline-diagram {
  margin: 26px 0 34px;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.mermaid {
  display: flex;
  justify-content: center;
}

.diagram-caption {
  margin-top: -8px;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  text-align: center;
}

.inline-diagram svg text {
  font-family: var(--font-body);
}

.inline-diagram [fill="#8B1A1A"] {
  fill: var(--warm-red);
}

.inline-diagram [stroke="#8B1A1A"] {
  stroke: var(--accent);
}

.inline-diagram [fill="#FFECD2"] {
  fill: var(--gold-soft);
}

.inline-diagram [stroke="#d8a066"] {
  stroke: var(--line-strong);
}

.inline-diagram [fill="#fff8ed"],
.inline-diagram [fill="#fffdf8"] {
  fill: #ffffff;
}

.inline-diagram stop[stop-color="#8B1A1A"] {
  stop-color: var(--accent);
}

.inline-diagram stop[stop-color="#F5A623"] {
  stop-color: #d59a31;
}

.inline-diagram stop[stop-color="#FFECD2"] {
  stop-color: #fff8ea;
}

.mermaid svg {
  max-width: 100% !important;
  width: min(100%, 960px) !important;
  height: auto;
}

.figure-card {
  margin: 26px 0 34px;
  max-width: 980px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.figure-card .mermaid {
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.figure-card figcaption {
  display: grid;
  gap: 7px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  background: #fffaf2;
  color: var(--ink-soft);
  font-size: 0.9375rem;
  line-height: 1.7;
}

.figure-card figcaption strong {
  color: var(--ink);
  font-weight: 800;
}

.figure-card figcaption em {
  color: var(--accent-strong);
  font-style: normal;
  font-weight: 700;
}

.oracle-map-figure {
  max-width: 900px;
}

.oracle-map-figure .mermaid {
  padding: 18px;
}

.oracle-map-figure .mermaid svg {
  width: min(100%, 760px) !important;
}

.mermaid svg [style*="#FFECD2"],
.mermaid svg [style*="rgb(255, 236, 210)"] {
  fill: var(--gold-soft) !important;
}

.mermaid svg [style*="#8B1A1A"],
.mermaid svg [style*="rgb(139, 26, 26)"] {
  stroke: var(--accent) !important;
}

.callout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 24px 0 30px;
}

.callout {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.callout strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
}

.config-list {
  display: grid;
  gap: 10px;
  margin: 24px 0 30px;
}

.config-item {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 16px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.pager {
  justify-content: space-between;
  padding-top: 34px;
  border-top: 1px solid var(--line);
}

.pager .button {
  min-width: 160px;
}

@media (max-width: 1320px) {
  .hero {
    width: min(1180px, calc(100vw - 56px));
    grid-template-columns: minmax(280px, 0.58fr) minmax(600px, 1.42fr);
    gap: 40px;
  }

  .chapter-sections {
    gap: 14px;
  }

  .chapter-section {
    padding: 20px;
  }

  .chapter-tile {
    grid-template-columns: 40px 1fr;
    gap: 10px;
  }
}

@media (max-width: 1120px) {
  .landing {
    overflow: auto;
  }

  .hero {
    width: min(940px, calc(100vw - 40px));
    height: auto;
    max-height: none;
    min-height: 0;
    padding: 52px 0;
    grid-template-columns: 1fr;
    gap: 44px;
  }

  .hero-panel {
    min-height: auto;
  }

  .chapter-sections {
    grid-template-columns: 1fr;
  }

  .book-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 16px;
  }

  .brand {
    margin-bottom: 10px;
    padding-bottom: 14px;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  .chapter-shell {
    width: auto;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 16px;
  }

  .hero {
    width: min(100% - 32px, 640px);
    padding: 40px 0;
    gap: 34px;
  }

  .brand-copy h1 {
    font-size: 42px;
  }

  .brand-copy p {
    font-size: 17px;
  }

  .hero-actions,
  .pager {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .side-nav {
    grid-template-columns: 1fr;
  }

  .chapter-tile {
    grid-template-columns: 44px 1fr;
  }

  .side-nav a {
    grid-template-columns: 44px 1fr;
  }

  .topbar {
    position: relative;
    padding: 12px 18px;
  }

  .chapter-shell {
    padding: 38px 18px 66px;
  }

  .chapter-header h1 {
    font-size: 34px;
  }

  .chapter-lead,
  .chapter-content p,
  .chapter-content li {
    font-size: 16px;
  }

  .chapter-content h1 {
    font-size: 28px;
  }

  .chapter-content h2 {
    font-size: 23px;
  }

  .chapter-content {
    overflow-x: hidden;
  }

  .chapter-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .chapter-content pre {
    padding: 20px 16px;
  }

  .callout-grid,
  .config-item {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 860px) and (min-width: 1121px) {
  .hero {
    padding: 46px 0;
    gap: 44px;
  }

  .hero-actions {
    margin-top: 30px;
  }

  .chapter-section {
    padding: 14px;
  }

  .chapter-section p {
    min-height: auto;
    margin-bottom: 10px;
  }

  .chapter-tile {
    min-height: 42px;
    padding: 7px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
