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

/* ─── TOKENS ─────────────────────────────────────── */
:root {
  --bg:           #faf8f5;
  --bg-subtle:    #f5f3ef;
  --text:         #2c2c2c;
  --text-2:       #737373;
  --text-3:       #9a9a9a;
  --accent:       #8a7355;
  --accent-light: #a99478;
  --accent-muted: rgba(138,115,85,.08);
  --border:       #e5e0d8;
  --border-light: #ebe7e0;
  --link:         #6b8a94;
  --link-hover:   #4a6a74;
  --mh:           56px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4,h5,h6 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  letter-spacing: .02em;
  color: var(--text);
}

a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { color: var(--link-hover); }

::selection { background: rgba(138,115,85,.18); }

/* ─── MASTHEAD ───────────────────────────────────── */
.masthead {
  background: var(--bg);
  border-bottom: 1px solid var(--border-light);
  height: var(--mh);
  display: flex;
  align-items: center;
  position: sticky; top: 0; z-index: 100;
}
.masthead__inner-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.75rem;
}
a.site-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  font-size: .85rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text);
}
a.site-title:hover { color: var(--accent); }
.masthead__nav {
  margin-left: auto;
  display: flex;
  gap: 1.25rem;
  align-items: center;
}
.masthead__nav a {
  font-family: 'Crimson Pro', serif;
  font-size: .72rem;
  font-weight: 400;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
  transition: color .2s;
}
.masthead__nav a:hover,
.masthead__nav a.nav-active { color: var(--accent); }

/* ─── PAGE WRAP ──────────────────────────────────── */
.page-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 2.25rem 1.75rem 4rem;
}

/* ─── PAGE HEADER ────────────────────────────────── */
.page-header { margin-bottom: 1.75rem; }

.page-header__title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  font-size: 1.6rem;
  color: var(--accent);
  letter-spacing: .02em;
  margin-bottom: .2rem;
}
.page-header__sub {
  font-size: .88rem;
  color: var(--text-2);
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* Install strip */
.install-strip {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: .3rem .75rem;
}
.install-strip__label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  font-family: 'Crimson Pro', serif;
}
.install-strip__cmd {
  font-family: Monaco, Consolas, monospace;
  font-size: .78rem;
  color: var(--accent);
  background: none; border: none;
  user-select: all;
}
.install-strip__copy {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); font-size: .72rem;
  transition: color .2s; padding: 0; line-height: 1;
}
.install-strip__copy:hover { color: var(--accent); }

/* ─── VIEW COUNTER ───────────────────────────────── */
.view-counter {
  margin-top: .65rem;
  font-family: Monaco, Consolas, monospace;
  font-size: .62rem;
  color: var(--text-3);
  letter-spacing: .04em;
}
.view-counter__num {
  color: var(--accent);
  font-weight: 500;
}

/* ─── SECTION LABEL ──────────────────────────────── */
.section-label {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 400;
  font-size: .68rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 2.5rem 0 1.25rem;
}

/* ─── CONTENT LIST ───────────────────────────────── */
.content-list { list-style: none; padding: 0; margin: 0; }

.list-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
}
.list-item:first-child { border-top: 1px solid var(--border-light); }
.list-item:hover .item-link { color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-light); text-underline-offset: 2px; }
.list-item:hover .list-item__arrow { opacity: 1; }

.list-item__body { flex: 1; min-width: 0; }

.list-item__title { margin-bottom: .2rem; }

.item-link {
  font-family: 'Crimson Pro', Georgia, serif;
  font-weight: 400;
  font-size: .97rem;
  color: var(--text);
  transition: color .2s;
}

.list-item__tag {
  font-size: .62em;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 5px;
  margin-left: 7px;
  vertical-align: middle;
  font-weight: 300;
  font-family: 'Crimson Pro', serif;
}

.item-excerpt {
  font-size: .82rem;
  color: var(--text-3);
  line-height: 1.5;
  font-weight: 300;
  margin-bottom: .35rem;
}

/* KaTeX formula in list */
.item-formula {
  font-size: .8rem;
  color: var(--text-2);
  margin-bottom: .35rem;
  overflow-x: auto;
  line-height: 1.4;
}
.item-formula .katex { font-size: .9em; }

.list-item__chips {
  display: flex; gap: 3px; flex-wrap: wrap;
}
.chip {
  font-size: .6em;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 5px;
  font-weight: 300;
  font-family: 'Crimson Pro', serif;
}

.list-item__arrow {
  font-size: .78rem;
  color: var(--text-3);
  flex-shrink: 0;
  padding-top: .15rem;
  opacity: .4;
  transition: opacity .2s;
}

/* ─── AD BLOCK ───────────────────────────────────── */
.ad-block {
  padding: 0;
  font-size: .85rem;
  color: var(--text-2);
  line-height: 1.65;
}
.ad-block p { margin-bottom: .85rem; }
.ad-features { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .85rem; }
.ad-feature { font-size: .82rem; color: var(--text-2); }
.ad-feature strong { color: var(--text); font-weight: 500; }
.ad-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.ad-btn {
  font-size: .72em;
  color: var(--text) !important;
  font-family: 'Crimson Pro', serif;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 3px 10px;
  transition: color .2s, border-color .2s, background .2s;
}
.ad-btn:hover {
  color: var(--accent) !important;
  border-color: var(--accent-light);
  background: var(--accent-muted);
}

/* ─── ALGORITHM DETAIL ───────────────────────────── */
.back-link {
  display: inline-flex; align-items: center; gap: .3rem;
  font-family: 'Crimson Pro', serif;
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--text-3);
  text-transform: uppercase;
  margin-bottom: 1.25rem;
  transition: color .2s;
}
.back-link:hover { color: var(--accent); }

.impl-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .4rem;
}
.impl-tags { display: flex; gap: .3rem; flex-wrap: wrap; }
.impl-tag {
  font-size: .6em;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 6px;
  font-family: 'Crimson Pro', serif;
  font-weight: 300;
}
.impl-links { display: flex; gap: .85rem; }
.impl-link {
  font-family: 'Crimson Pro', serif;
  font-size: .72rem;
  color: var(--text-3);
  transition: color .2s;
  letter-spacing: .01em;
}
.impl-link:hover { color: var(--accent); }

.detail-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 300;
  font-size: 1.75rem;
  color: var(--accent);
  margin-bottom: .15rem;
}
.detail-subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-size: .9rem;
  font-weight: 300;
  font-style: italic;
  color: var(--text-3);
  margin-bottom: 1rem;
}
.detail-desc {
  font-size: .88rem;
  color: var(--text);
  line-height: 1.75;
  margin-bottom: 1.75rem;
}

/* Detail sections */
.detail-section { margin-bottom: 2rem; }
.detail-section-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 400;
  font-size: .65rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .75rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-light);
}

.intuition-box {
  background: var(--bg-subtle);
  border-left: 2px solid var(--accent-light);
  padding: .75rem 1rem;
  font-size: .85rem;
  color: var(--text-2);
  line-height: 1.7;
  font-style: italic;
}
.intuition-box strong { color: var(--accent); font-style: normal; }

/* Math rows */
.math-row { margin-bottom: .85rem; }
.math-row__label {
  font-size: .62rem;
  font-family: 'Crimson Pro', serif;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .2rem;
}
.math-row__formula {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: 2px;
  padding: .55rem .85rem;
  overflow-x: auto;
  font-size: .85rem;
  line-height: 1.6;
}
.math-row__formula .katex-display { margin: .2em 0; }
.math-row__formula .katex { font-size: 1em; }

/* Code block */
.detail-code {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: 2px;
  padding: .75rem 1rem;
  font-family: Monaco, Consolas, 'Lucida Console', monospace;
  font-size: .78rem;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}
.code-kw  { color: #8a7355; }
.code-fn  { color: #a07855; }
.code-str { color: #6e8c6a; }
.code-num { color: #a07855; }
.code-cm  { color: #b0a28e; font-style: italic; }

/* Playground */
.playground-box {
  background: var(--bg-subtle);
  border: 1px dashed var(--border);
  border-radius: 2px;
  padding: 2rem 1.25rem;
  text-align: center;
}
.playground-box__title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: .3rem;
}
.playground-box__sub { font-size: .8rem; color: var(--text-3); }
.playground-badge {
  display: inline-block;
  margin-top: .6rem;
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 2px 7px;
  font-family: 'Crimson Pro', serif;
}

/* ─── FOOTER ─────────────────────────────────────── */
.page__footer {
  border-top: 1px solid var(--border-light);
  padding: 1.25rem 1.75rem;
  text-align: center;
}
.page__footer-inner {
  font-family: 'Crimson Pro', serif;
  font-size: .72rem;
  color: var(--text-3);
  letter-spacing: .02em;
}
.page__footer-inner a { color: var(--text-3); }
.page__footer-inner a:hover { color: var(--accent); }

/* ─── RESPONSIVE ─────────────────────────────────── */
@media (max-width: 600px) {
  .masthead__inner-wrap {
    padding: 0 1rem;
    gap: .9rem;
  }
  a.site-title {
    flex: 0 0 auto;
  }
  .masthead__nav {
    margin-left: auto;
    gap: .9rem;
  }
  .masthead__nav a {
    padding: .15rem 0;
  }
  .page-wrap { padding: 1.5rem 1rem 3rem; }
  .impl-header { flex-direction: column; }
}
