/*
 * TOUGHNK — Clean White & Matte Dark Theme
 * Accents & tags: Flexoki palette (github.com/kepano/flexoki)
 * Typography & rhythm: inspired by Tufte CSS & antfu.me
 */

:root {
  /* Crisp White & Solid Ink (Light Mode) */
  --bg: #FFFFFF;
  --bg-subtle: #F5F5F6;
  --bg-card: #FFFFFF;
  --border: #E4E4E7;
  --border-strong: #C9C9CF;
  --text: #100F0F;           /* Flexoki black */
  --text-secondary: #26262A;
  --text-muted: #5C5C63;

  /* Flexoki 600 accents for light background */
  --accent: #BC5215;         /* orange-600 */
  --accent-soft: #F5F5F6;
  --teal: #24837B;           /* cyan-600 */
  --teal-soft: #EEF7F5;
  --amber: #AD8301;          /* yellow-600 */
  --amber-soft: #FBF6E6;

  /* Flexoki tinted tags (light) */
  --tag-fg: #BC5215;
  --tag-bg: #FCECE0;
  --tag-border: #F2CFB6;
  --tag-teal-fg: #1B756D;
  --tag-teal-bg: #E2F3F0;
  --tag-teal-border: #B5DDD7;
  --body-weight: 500;

  /* Clean Inset Code Surface */
  --code-bg: #F5F5F6;
  --code-border: #E4E4E7;
  --code-text: #100F0F;
  --inline-code-bg: #F1F1F3;
  --inline-code-text: #1F1F23;

  --font-heading: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius: 4px;
}

[data-theme="dark"] {
  /* Matte Neutral Dark (Matched to #2C2C2E / #353638 reference) */
  --bg: #2C2C2E;
  --bg-subtle: #353638;
  --bg-card: #2C2C2E;
  --border: #3E3F43;
  --border-strong: #525358;
  --text: #F2F3F5;
  --text-secondary: #D2D3D8;
  --text-muted: #9EA0A6;

  /* Flexoki 400 accents for dark background */
  --accent: #E88648;
  --accent-soft: #353638;
  --teal: #52BFB5;
  --teal-soft: rgba(82, 191, 181, 0.12);
  --amber: #E2B33C;
  --amber-soft: rgba(226, 179, 60, 0.12);

  /* Flexoki tinted tags (dark) */
  --tag-fg: #F0A06B;
  --tag-bg: rgba(232, 134, 72, 0.16);
  --tag-border: rgba(232, 134, 72, 0.30);
  --tag-teal-fg: #6CCBC2;
  --tag-teal-bg: rgba(82, 191, 181, 0.15);
  --tag-teal-border: rgba(82, 191, 181, 0.30);
  --body-weight: 400;

  --code-bg: #353638;
  --code-border: #44454A;
  --code-text: #F2F3F5;
  --inline-code-bg: #38393C;
  --inline-code-text: #EBECEF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.82;
  font-size: 16px;
  font-weight: var(--body-weight);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[data-theme="light"] body { -webkit-font-smoothing: subpixel-antialiased; }

::selection {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text);
}

/* Quiet Editorial Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 58px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1020px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  border: none;
}
.brand:hover { color: var(--accent); border: none; }
.brand-dot {
  display: none;
}
.nav-group {
  display: flex;
  align-items: center;
  gap: 24px;
}
.nav-link {
  font-size: 14px;
  font-weight: 450;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.nav-link:hover {
  color: var(--text);
  border-bottom-color: var(--border-strong);
}
.nav-link.active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.theme-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 9px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.theme-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

/* Page Containers */
.container-narrow {
  max-width: 740px;
  margin: 0 auto;
  padding: 56px 24px 96px;
}
.layout {
  max-width: 1020px;
  margin: 0 auto;
  padding: 48px 24px 96px;
  display: grid;
  grid-template-columns: 200px minmax(0, 720px);
  justify-content: space-between;
  gap: 56px;
}
.layout.no-toc {
  grid-template-columns: minmax(0, 720px);
  justify-content: center;
}

/* Sidebar TOC (Quiet Marginalia) */
.toc {
  position: sticky;
  top: 82px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  font-size: 13px;
  padding-right: 8px;
}
.toc-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.toc a {
  display: block;
  padding: 4px 0 4px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 1px solid var(--border);
  border-bottom: none;
  line-height: 1.5;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.toc a.toc-sub {
  padding-left: 22px;
  font-size: 12.5px;
}
.toc a:hover {
  color: var(--accent);
  border-left-color: var(--accent);
}

/* Typography & Hero */
article { min-width: 0; }
.hero {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
}
.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  padding: 0;
  margin-bottom: 12px;
}
h1 {
  font-family: var(--font-heading);
  font-size: 30px;
  line-height: 1.36;
  letter-spacing: -0.01em;
  font-weight: 800;
  margin-bottom: 14px;
  color: var(--text);
}
.lead {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.8;
}
.meta-row {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Flexoki Tinted Tags */
.tag {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--tag-fg);
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  padding: 1px 8px;
  border-radius: 3px;
  line-height: 1.6;
}
.tag.teal {
  color: var(--tag-teal-fg);
  background: var(--tag-teal-bg);
  border-color: var(--tag-teal-border);
}

article h2 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 46px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--text);
}
.sec-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  padding: 0;
  letter-spacing: 0.04em;
}
article h3 {
  font-family: var(--font-heading);
  font-size: 18.5px;
  font-weight: 750;
  margin: 30px 0 12px;
  color: var(--text);
}
article h4 {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 800;
  margin: 38px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
article h5 {
  font-family: var(--font-heading);
  font-size: 16.5px;
  font-weight: 700;
  margin: 26px 0 10px;
  color: var(--text);
}
p {
  margin-bottom: 16px;
  color: var(--text-secondary);
}
strong {
  color: var(--text);
  font-weight: 700;
}
a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  transition: color 0.15s ease, border-color 0.15s ease;
}
a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
article p a,
article li a,
.refs a,
.post-nav a {
  color: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
article p a:hover,
article li a:hover,
.refs a:hover,
.post-nav a:hover {
  border-bottom-color: var(--accent);
}

ul, ol {
  padding-left: 22px;
  margin-bottom: 18px;
  color: var(--text-secondary);
}
li { margin-bottom: 7px; }
blockquote {
  border-left: 2px solid var(--accent);
  background: var(--bg-subtle);
  padding: 12px 18px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 20px 0 24px;
  color: var(--text-secondary);
}
blockquote p:last-child { margin-bottom: 0; }
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 36px 0;
}
article img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 22px auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Inline & Block Code (Warm Paper Inset) */
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  padding: 1.5px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.code-wrap {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 18px 0 24px;
  overflow-x: auto;
}
.code-wrap pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
}
.code-wrap code {
  background: transparent;
  color: inherit;
  border: none;
  padding: 0;
  font-size: inherit;
}
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.copy-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Callouts, Tables, Cards, Diagrams */
.callout {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 15px 18px;
  margin: 22px 0 26px;
}
.callout.warn, .callout.amber {
  border-left-color: var(--amber);
  background: var(--amber-soft);
}
.callout.teal {
  border-left-color: var(--teal);
  background: var(--teal-soft);
}
.callout-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.callout p:last-child { margin-bottom: 0; }

.table-wrap {
  overflow-x: auto;
  margin: 20px 0 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 18px 0 24px;
}
.table-wrap table { margin: 0; }
th {
  text-align: left;
  background: var(--bg-subtle);
  color: var(--text);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-strong);
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }

.steps-grid, .grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0 28px;
}
.step-card, .pill-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.step-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  padding: 0;
}
.step-cmd {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}
.step-card p, .pill-card p {
  font-size: 13.8px;
  margin-bottom: 0;
  line-height: 1.68;
}
.pill-card h4 {
  font-family: var(--font-heading);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}

.diagram-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 24px 0 28px;
}
.diagram-caption {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 28px;
}
.tl-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: 2px solid var(--teal);
  border-radius: var(--radius);
  padding: 14px;
}
.tl-day {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 6px;
}
.tl-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  margin-bottom: 6px;
}
.tl-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.58;
}

/* Search Bar (Quiet Bottom-Rule Editorial Input) */
.search-bar { margin: 8px 0 24px; }
.search-input {
  width: 100%;
  padding: 10px 2px;
  font-size: 14.5px;
  font-family: var(--font-sans);
  border: none;
  border-bottom: 1px solid var(--border-strong);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-bottom-color: var(--accent); }

/* Editorial Reading List (Replaces Heavy AI Box Cards) */
.section-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 34px 0 12px;
}
.card-list {
  display: flex;
  flex-direction: column;
}
.card {
  display: block;
  text-decoration: none;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  border-radius: 0;
  padding: 22px 0;
  transition: border-color 0.15s ease;
}
.card:last-child { border-bottom: none; }
.card:hover { border-bottom-color: var(--border-strong); }
.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.card-title {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 6px;
  transition: color 0.15s ease;
}
.card:hover .card-title { color: var(--accent); }
.card-desc {
  font-size: 14.5px;
  color: var(--text-secondary);
  line-height: 1.72;
}

/* Archives List */
.year-group { margin-bottom: 36px; }
.year-heading {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 650;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.04em;
}
.archive-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 4px;
  border-bottom: 1px dashed var(--border);
  text-decoration: none;
  transition: color 0.15s ease;
}
.archive-row:last-child { border-bottom: none; }
.archive-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  transition: color 0.15s ease;
}
.archive-row:hover .archive-title { color: var(--accent); }
.archive-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.post-nav {
  margin-top: 52px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 14px;
}
.refs {
  margin-top: 46px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}
.empty {
  display: none;
  text-align: center;
  padding: 48px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

/* About Section */
.about-card {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
}
.about-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
  filter: saturate(0.9);
}
.about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.link-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-decoration: none;
}
.link-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* 404 Page */
.not-found {
  padding: 64px 0 40px;
}
.not-found-code {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 12px;
}

/* Footer */
.site-footer {
  max-width: 1020px;
  margin: 0 auto;
  padding: 24px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 20px; padding-top: 32px; }
  .toc { display: none; }
  .steps-grid, .grid-2, .timeline { grid-template-columns: 1fr; }
  .about-card { flex-direction: column; align-items: center; text-align: center; }
  .about-links { justify-content: center; }
  .archive-row { flex-direction: column; gap: 4px; }
  h1 { font-size: 26px; }
}
