@import url("https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&display=swap");

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ffffff;
  --muted: #999999;
  --line: #333333;
  --canvas: #1e1e1e;
  --subtle: #252525;
  --surface: #2a2a2a;
  --accent: #6bff77;
  --accent-hover: #ffffff;
  --nav: #ffffff;
  --nav-accent: #58a6ff;
  --header: rgba(15, 15, 15, 0.92);
  --tag: #333333;
  --tag-hover: #444444;
  --date: #777777;
  --prose: #cccccc;
  --code-bg: rgba(107, 255, 119, 0.12);
  --page: 980px;
  --read: 740px;
  --shadow: none;
  --font: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --ink: #161616;
  --muted: #5c6166;
  --line: #d9d9d9;
  --canvas: #ffffff;
  --subtle: #f5f5f5;
  --surface: #ececec;
  --accent: #0c7a34;
  --accent-hover: #085626;
  --nav: #161616;
  --nav-accent: #0969da;
  --header: rgba(255, 255, 255, 0.94);
  --tag: #e7f6eb;
  --tag-hover: #d3eedb;
  --date: #6a6a6a;
  --prose: #333333;
  --code-bg: rgba(12, 122, 52, 0.12);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

main { flex: 1 0 auto; }

img, video, iframe { max-width: 100%; height: auto; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -120%);
  background: #111;
  color: #fff;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  z-index: 5;
}
.skip:focus { transform: translate(-50%, 0.6rem); color: #fff; }

.wrap {
  width: min(var(--page), calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(180%) blur(8px);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  color: inherit;
  text-decoration: none;
}

.logo {
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
}
.logo span { color: var(--accent); }

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem 0.15rem;
}
.nav a {
  color: var(--nav);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
}
.nav a:hover,
.nav a[aria-current="page"] {
  background: var(--subtle);
  color: var(--nav-accent);
}
.theme-toggle {
  border: 1px solid var(--line);
  background: var(--subtle);
  color: var(--nav);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 0.2rem;
}
.theme-toggle:hover {
  color: var(--nav-accent);
  border-color: var(--nav-accent);
}

.writeups-container {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto 3rem;
  padding-top: 20px;
  text-align: left;
}
.writeups-header { margin-bottom: 20px; text-align: center; }
.writeups-header h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.search-container {
  position: relative;
  max-width: 500px;
  margin: 20px auto;
}
#articleSearch {
  width: 100%;
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--subtle);
  color: var(--ink);
  font: inherit;
  font-size: 0.85em;
}
#articleSearch:focus {
  outline: none;
  border-color: var(--accent);
}
.result-count {
  margin: 0 0 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85em;
}
.empty-search {
  text-align: center;
  color: var(--muted);
}

.article-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}
.article-item {
  min-width: 0;
  background: var(--subtle);
  padding: 15px;
  border-radius: 5px;
  border-left: 3px solid var(--accent);
}
.article-item:hover { background: var(--surface); }
.article-item[hidden] { display: none; }
.article-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.45;
}
.article-title a {
  color: var(--accent);
  text-decoration: none;
}
.article-title a:hover { color: var(--accent); text-decoration: underline; }
.article-meta {
  font-size: 0.8em;
  color: var(--muted);
}
.article-date { color: var(--date); }
.article-excerpt { display: none; }
.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}
.article-tag {
  border: 0;
  background: var(--tag);
  font: inherit;
  font-size: 0.75em;
  padding: 2px 8px;
  border-radius: 12px;
  color: var(--accent);
  cursor: pointer;
}
.article-tag:hover { background: var(--tag-hover); color: var(--accent); }

.article {
  width: min(var(--read), 100%);
  margin: 0 auto 4rem;
}
.article > h1 {
  margin: 0.35rem auto 0.75rem;
  font-size: clamp(1.7rem, 4vw, 2.15rem);
  line-height: 1.2;
  letter-spacing: -0.03em;
  font-weight: 650;
  text-align: left;
}
.article > .meta { text-align: left; margin-bottom: 1.5rem; }
.back { text-align: center; margin: 1.6rem 0 0.2rem; }
.back a { color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.back a:hover { color: var(--accent); }

.lead {
  color: var(--prose);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.65;
}

.about { width: min(860px, 100%); padding-top: 0.4rem; }
.profile {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 1.4rem;
  align-items: center;
  background: var(--subtle);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 1.15rem 1.25rem;
}
.portrait {
  width: 200px;
  height: auto;
  border-radius: 6px;
  display: block;
}
.profile h1 {
  margin: 0;
  text-align: left;
  font-size: clamp(1.45rem, 3vw, 1.85rem);
}
.profile .handle {
  margin: 0.35rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.socials {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.socials a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--tag);
  color: var(--accent);
  text-decoration: none;
  border-radius: 12px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
}
.socials a:hover { background: var(--tag-hover); color: var(--accent); }
.socials svg { width: 14px; height: 14px; display: block; fill: currentColor; }

.content { overflow-wrap: anywhere; }
.content h1,
.content h2,
.content h3,
.content h4 {
  line-height: 1.3;
  letter-spacing: -0.02em;
  scroll-margin-top: 5rem;
}
.content h2 {
  margin-top: 2rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
  font-size: 1.45rem;
}
.content h3 { margin-top: 1.5rem; font-size: 1.2rem; }
.content h4 { margin-top: 1.25rem; }
.content p,
.content ul,
.content ol { margin: 0.9rem 0; }
.content ul,
.content ol { padding-left: 1.4rem; }
.content li + li { margin-top: 0.25rem; }
.content hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.5rem auto;
}

.content img,
.content video {
  display: block;
  height: auto;
  margin-inline: auto;
}
.content > img { margin: 1.2rem auto; border-radius: 8px; }
.content figure,
.content .kg-card {
  margin: 1.35rem auto;
  text-align: center;
}
.content figure img,
.content .kg-image,
.content figure video,
.content .kg-video-container video {
  margin-inline: auto;
  border-radius: 8px;
}
.content figcaption,
.content figcaption p {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.45rem;
}
.kg-video-container {
  display: flex;
  justify-content: center;
}
.kg-embed-card {
  display: flex;
  justify-content: center;
}
.twitter-tweet { margin-inline: auto !important; }

.content pre {
  background: var(--subtle);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.05rem;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.86rem;
  text-align: left;
}
.content code { font-family: var(--mono); font-size: 0.88em; }
.content :not(pre) > code {
  background: var(--code-bg);
  color: var(--accent);
  padding: 0.15em 0.35em;
  border-radius: 4px;
}
.content pre code { background: transparent; padding: 0; font-size: inherit; color: inherit; }
.content blockquote {
  margin: 1.15rem 0;
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 0.25em solid var(--line);
  color: var(--muted);
}

.content iframe {
  display: block;
  width: min(100%, 640px);
  aspect-ratio: 16 / 9;
  height: auto;
  margin: 1.2rem auto;
  border: 0;
  border-radius: 8px;
}

.content table,
.content table.styled-table {
  width: 100% !important;
  max-width: 100% !important;
  margin: 1.25rem auto !important;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--subtle) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  box-shadow: none !important;
  border-radius: 8px;
  overflow: hidden;
  display: table;
}
.content table th,
.content table td,
.content table.styled-table th,
.content table.styled-table td {
  border: 1px solid var(--line) !important;
  padding: 0.55rem 0.65rem !important;
  text-align: left !important;
  background: var(--subtle) !important;
  color: var(--ink) !important;
  font-size: 0.86rem !important;
  word-break: break-word;
}
.content table th,
.content table.styled-table th {
  background: var(--subtle) !important;
  font-weight: 650 !important;
  text-transform: none !important;
}
.content table tr,
.content table thead,
.content table tbody {
  background: transparent !important;
}

.kg-bookmark-card { max-width: 100%; }
.kg-bookmark-container {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: var(--subtle);
  text-align: left;
}
.kg-bookmark-container:hover { border-color: var(--accent); }
.kg-bookmark-content { padding: 0.85rem 1rem; }
.kg-bookmark-title { font-weight: 650; color: var(--accent); }
.kg-bookmark-description { color: var(--muted); font-size: 0.9rem; }
.kg-bookmark-thumbnail img {
  width: 120px;
  height: 100%;
  object-fit: cover;
  margin: 0;
  border-radius: 0;
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 1.6rem 0 2.4rem;
  font-size: 0.92rem;
  text-align: center;
}
.site-footer p { margin: 0.2rem 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

@media (max-width: 720px) {
  .wrap { width: min(var(--page), calc(100% - 1.5rem)); }
  .site-header .wrap {
    flex-direction: column;
    justify-content: center;
    padding: 0.7rem 0 0.8rem;
    gap: 0.35rem;
  }
  .nav { justify-content: center; }
  .writeups-container { width: min(1100px, calc(100% - 1.5rem)); }
  .profile {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .profile h1,
  .profile .handle,
  .profile .lead { text-align: center; }
  .socials { justify-content: center; }
  .kg-bookmark-thumbnail { display: none; }
}
