/*
 * Shared design for Markdown tutorials. Shared by every Markdown tutorial -
 * don't edit it per tutorial (set "accent" in kmt.config.json instead).
 *
 * Theme tokens: light by default, dark via the OS preference, and an explicit
 * data-theme="light|dark" (the toggle) wins in both directions.
 */
:root {
  color-scheme: light;
  --accent: #3f7d70;
  --on-accent: #ffffff;
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-muted: #f3f1ed;
  --border: #e6e2da;
  --text: #1d2330;
  --text-muted: #566072;
  --text-faint: #8a92a0;
  --code-inline-bg: #f0ede7;
  --shadow: 0 18px 50px rgba(20, 24, 33, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --header-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --on-accent: #0e1116;
    --bg: #0e1116;
    --surface: #151a21;
    --surface-muted: #1b212a;
    --border: #262e39;
    --text: #e6e9ef;
    --text-muted: #a2acba;
    --text-faint: #6f7a89;
    --code-inline-bg: #1f2630;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --on-accent: #0e1116;
  --bg: #0e1116;
  --surface: #151a21;
  --surface-muted: #1b212a;
  --border: #262e39;
  --text: #e6e9ef;
  --text-muted: #a2acba;
  --text-faint: #6f7a89;
  --code-inline-bg: #1f2630;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.7;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

.wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.wrap.narrow {
  max-width: 720px;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 16px;
  top: 12px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--surface);
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-weight: 500;
  color: var(--text-faint);
}

/* kapmenthoughts -> the site's home page; tutorials -> its Tutorials section. */
.brand a {
  color: var(--text);
  text-decoration: none;
}

.brand-sub a {
  color: var(--text-faint);
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-link {
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
}

.header-link:hover {
  color: var(--text);
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 17px;
  cursor: pointer;
}

/* ---------- Hero ---------- */

.hero {
  padding: 72px 0 56px;
  background:
    radial-gradient(1200px 400px at 10% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent),
    radial-gradient(900px 400px at 100% 0%, color-mix(in srgb, var(--accent) 9%, transparent), transparent);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  max-width: 900px;
  margin: 0 0 18px;
  font-size: clamp(30px, 4.4vw, 50px);
  line-height: 1.12;
  letter-spacing: -0.025em;
}

.lede {
  max-width: 720px;
  margin: 0 0 30px;
  font-size: 20px;
  color: var(--text-muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 40px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 160px));
  gap: 14px;
  margin: 0;
}

.stats div {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stats dt {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.stats dd {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 700;
}

/* ---------- Layout: contents + article ---------- */

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 56px;
  padding-top: 48px;
  padding-bottom: 64px;
}

.toc {
  position: sticky;
  top: calc(var(--header-height) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto;
  font-size: 14px;
}

.toc summary {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  cursor: pointer;
  list-style: none;
}

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

.toc-list,
.toc-sub {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-list > li {
  margin: 2px 0;
}

.toc-sub {
  margin: 2px 0 8px 12px;
  border-left: 1px solid var(--border);
}

.toc a {
  display: block;
  padding: 4px 10px;
  border-radius: 6px;
  line-height: 1.4;
  color: var(--text-muted);
  text-decoration: none;
}

.toc-sub a {
  font-size: 13px;
}

.toc a:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.toc a.active {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ---------- Series: its pages, and previous / next ---------- */

.series-details {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.series-list a {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.series-num {
  flex: none;
  min-width: 1.4em;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.series-list a.current {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.series-list a.current .series-num {
  color: inherit;
}

.pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease;
}

.pager-link:hover {
  border-color: var(--accent);
}

.pager-next {
  grid-column: 2;
  text-align: right;
}

.pager-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.pager-title {
  font-weight: 600;
  line-height: 1.35;
}

/* ---------- Article typography ---------- */

.article {
  max-width: 780px;
  min-width: 0;
}

.article h2,
.article h3,
.article h4 {
  position: relative;
  scroll-margin-top: calc(var(--header-height) + 20px);
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.article h2 {
  margin: 56px 0 18px;
  font-size: 30px;
}

.article h3 {
  margin: 36px 0 12px;
  font-size: 22px;
}

.article h4 {
  margin: 28px 0 10px;
  font-size: 18px;
}

.anchor {
  position: absolute;
  left: -1.1em;
  padding-right: 0.3em;
  color: var(--text-faint);
  text-decoration: none;
  opacity: 0;
}

.article h2:hover .anchor,
.article h3:hover .anchor,
.anchor:focus {
  opacity: 1;
}

.article p,
.article ul,
.article ol {
  margin: 0 0 18px;
}

.article li {
  margin: 6px 0;
}

.article hr {
  margin: 48px 0;
  border: none;
  border-top: 1px solid var(--border);
}

.article blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  color: var(--text);
}

.article blockquote p:last-child {
  margin-bottom: 0;
}

.article :not(pre) > code {
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: var(--code-inline-bg);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

/* ---------- Tables ---------- */

.table-scroll {
  margin: 0 0 24px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.article th,
.article td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.article th {
  background: var(--surface-muted);
  font-weight: 650;
}

.article tr:last-child td {
  border-bottom: none;
}

/* ---------- Code blocks (dark in both themes) ---------- */

.code-block {
  position: relative;
  margin: 0 0 24px;
  border: 1px solid #202834;
  border-radius: var(--radius);
  background: #0d1117;
  box-shadow: var(--shadow);
}

.code-block pre {
  margin: 0;
  padding: 20px 20px 18px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  color: #e6edf3;
}

.code-lang {
  position: absolute;
  top: 0;
  left: 16px;
  transform: translateY(-50%);
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border: 1px solid #30363d;
  border-radius: 7px;
  background: #161b22;
  color: #c9d1d9;
  font: 600 12px var(--font-sans);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease;
}

.code-block:hover .copy-btn,
.copy-btn:focus {
  opacity: 1;
}

.hljs-comment,
.hljs-quote {
  color: #8b949e;
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-meta .hljs-keyword,
.hljs-doctag {
  color: #ff7b72;
}

.hljs-string,
.hljs-regexp,
.hljs-meta .hljs-string {
  color: #a5d6ff;
}

.hljs-title,
.hljs-title.class_,
.hljs-title.function_,
.hljs-section {
  color: #d2a8ff;
}

.hljs-type,
.hljs-built_in,
.hljs-selector-class,
.hljs-selector-id {
  color: #ffa657;
}

.hljs-number,
.hljs-literal,
.hljs-symbol,
.hljs-bullet,
.hljs-attr,
.hljs-attribute,
.hljs-variable,
.hljs-template-variable,
.hljs-property {
  color: #79c0ff;
}

.hljs-meta,
.hljs-name,
.hljs-tag {
  color: #7ee787;
}

.hljs-params {
  color: #e6edf3;
}

/* ---------- Contact ---------- */

.contact {
  padding: 64px 0;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

.contact h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.contact-intro {
  margin: 0 0 24px;
  color: var(--text-muted);
}

.contact-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.contact-form label {
  font-size: 14px;
  font-weight: 650;
}

.contact-form textarea {
  min-height: 120px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.contact-form textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}

.contact-form .btn {
  align-self: flex-start;
}

.field-hint {
  font-size: 13px;
  color: var(--text-faint);
}

.field-hint.over-limit,
.form-status.error {
  color: #d1453b;
}

.form-status {
  margin: 0;
  font-size: 14px;
}

.form-status.ok {
  color: var(--accent);
}

/* ---------- Footer ---------- */

.site-footer {
  padding: 28px 0 40px;
  font-size: 14px;
  color: var(--text-faint);
}

.site-footer a {
  color: var(--text-muted);
}

/* ---------- Small screens ---------- */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    padding-top: 28px;
  }

  .toc {
    position: static;
    max-height: none;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .toc summary {
    margin: 0;
  }

  .toc-details[open] summary {
    margin-bottom: 10px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .anchor {
    display: none;
  }
}

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

  .hero {
    padding: 48px 0 40px;
  }

  .lede {
    font-size: 18px;
  }

  .article h2 {
    font-size: 25px;
  }

  .header-link {
    display: none;
  }

  .pager {
    grid-template-columns: minmax(0, 1fr);
  }

  .pager-next {
    grid-column: auto;
  }
}
