/* ==========================================================================
   Modern dev/mono theme, layered on bamboo.css
   - Tokyo Night-inspired palette
   - Auto (system) light/dark + manual toggle via html[data-theme]
   ========================================================================== */

/* --- Design tokens -------------------------------------------------------- */

:root,
html[data-theme="light"] {
  --bg: #fbfbfd;
  --bg-soft: #f1f2f6;
  --txt: #2c3043;
  --muted: #6c7086;
  --line: #e3e4ec;
  --accent: #2e7de9;
  --accent-soft: rgba(46, 125, 233, 0.1);
  --code-2: #9854f1;

  --hl-red: #f52a65;
  --hl-green: #587539;
  --hl-yellow: #8c6c3e;
  --hl-blue: #2e7de9;
  --hl-cyan: #007197;
  --hl-magenta: #9854f1;
  --hl-comment: #9aa0b3;
}

/* Dark when the OS prefers it (unless the user forced light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1b26;
    --bg-soft: #1f2335;
    --txt: #c0caf5;
    --muted: #787c99;
    --line: #2a2e42;
    --accent: #7aa2f7;
    --accent-soft: rgba(122, 162, 247, 0.14);
    --code-2: #bb9af7;

    --hl-red: #f7768e;
    --hl-green: #9ece6a;
    --hl-yellow: #e0af68;
    --hl-blue: #7aa2f7;
    --hl-cyan: #7dcfff;
    --hl-magenta: #bb9af7;
    --hl-comment: #565f89;
  }
}

/* Dark when explicitly toggled */
html[data-theme="dark"] {
  --bg: #1a1b26;
  --bg-soft: #1f2335;
  --txt: #c0caf5;
  --muted: #787c99;
  --line: #2a2e42;
  --accent: #7aa2f7;
  --accent-soft: rgba(122, 162, 247, 0.14);
  --code-2: #bb9af7;

  --hl-red: #f7768e;
  --hl-green: #9ece6a;
  --hl-yellow: #e0af68;
  --hl-blue: #7aa2f7;
  --hl-cyan: #7dcfff;
  --hl-magenta: #bb9af7;
  --hl-comment: #565f89;
}

/* Map bamboo.css variables onto our tokens (resolved per active theme) */
:root {
  --b-txt: var(--txt);
  --b-bg-1: var(--bg);
  --b-bg-2: var(--bg-soft);
  --b-line: var(--line);
  --b-link: var(--accent);
  --b-focus: var(--accent);
  --b-font-main: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --b-font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Monaco,
    Consolas, "Liberation Mono", monospace;
}

/* --- Base layout ---------------------------------------------------------- */

html {
  scroll-behavior: smooth;
}

body {
  max-width: 52rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  background: var(--bg);
  color: var(--txt);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent-soft);
}

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

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

.site-header {
  margin-bottom: 3.5rem;
}

.site-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-brand {
  font-family: var(--b-font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--txt);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

.site-prompt {
  font-size: 1.25rem;
  filter: grayscale(0.1);
}

.site-tagline {
  font-family: var(--b-font-mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}

/* Theme toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.theme-icon {
  display: none;
  line-height: 1;
}

/* light shows "go dark" icon; dark shows "go light" icon */
.theme-icon-dark { display: inline; }
.theme-icon-light { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-dark { display: none; }
  :root:not([data-theme="light"]) .theme-icon-light { display: inline; }
}

html[data-theme="dark"] .theme-icon-dark { display: none; }
html[data-theme="dark"] .theme-icon-light { display: inline; }
html[data-theme="light"] .theme-icon-dark { display: inline; }
html[data-theme="light"] .theme-icon-light { display: none; }

/* --- Navigation ----------------------------------------------------------- */

.site-header nav {
  display: flex;
  gap: 1.5rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-family: var(--b-font-mono);
  font-size: 0.875rem;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.site-header nav a:hover {
  color: var(--accent);
}

.site-header nav a[aria-current="true"] {
  color: var(--txt);
  text-decoration: none;
  position: relative;
}

.site-header nav a[aria-current="true"]::before {
  content: "→ ";
  color: var(--accent);
}

/* --- Home: posts list ----------------------------------------------------- */

.all-posts {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.year-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.year-heading {
  font-family: var(--b-font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  padding: 0;
}

.year-heading::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.posts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.post-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid transparent;
}

.post-link {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--txt);
}

.post-arrow {
  color: var(--muted);
  font-family: var(--b-font-mono);
  transition: transform 0.15s ease, color 0.15s ease;
}

.post-title {
  font-weight: 500;
  flex: 1;
  transition: color 0.15s ease;
}

.post-meta {
  font-family: var(--b-font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.post-link:hover .post-title {
  color: var(--accent);
}

.post-link:hover .post-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

.post-description {
  margin: 0.15rem 0 0 1.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* --- Post page ------------------------------------------------------------ */

.post-back {
  display: inline-block;
  font-family: var(--b-font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 2rem;
  transition: color 0.15s ease;
}

.post-back:hover {
  color: var(--accent);
}

.post-head {
  margin-bottom: 2.5rem;
}

.post-head h1 {
  margin: 0 0 0.75rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.post-meta-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-family: var(--b-font-mono);
  font-size: 0.82rem;
  color: var(--muted);
}

.post-meta-sep {
  opacity: 0.5;
}

.post-tags {
  display: inline-flex;
  gap: 0.5rem;
  margin-left: 0.25rem;
}

.post-tag {
  color: var(--accent);
}

.draft-badge {
  display: inline-block;
  font-family: var(--b-font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 0.2em 0.5em;
  border-radius: 4px;
  color: var(--hl-yellow);
  border: 1px solid var(--hl-yellow);
}

.post p,
.post li {
  line-height: 1.75;
}

.post h2,
.post h3 {
  margin-top: 2.5rem;
  letter-spacing: -0.01em;
}

.post img {
  border-radius: 8px;
  border: 1px solid var(--line);
}

.post blockquote {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: normal;
}

/* --- Code ----------------------------------------------------------------- */

pre {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.6;
}

:not(pre) > code {
  background: var(--accent-soft);
  color: var(--code-2);
  border-radius: 5px;
  padding: 0.12em 0.4em;
  font-size: 0.875em;
}

/* Syntax highlighting (highlight.js) */
.hljs-keyword,
.hljs-selector-tag,
.hljs-section,
.hljs-link { color: var(--hl-magenta); }

.hljs-string,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-addition,
.hljs-template-tag { color: var(--hl-green); }

.hljs-title,
.hljs-name,
.hljs-function .hljs-title,
.hljs-type { color: var(--hl-blue); }

.hljs-variable,
.hljs-template-variable,
.hljs-attr,
.hljs-property { color: var(--hl-cyan); }

.hljs-number,
.hljs-regexp,
.hljs-literal { color: var(--hl-yellow); }

.hljs-built_in,
.hljs-class .hljs-title,
.hljs-params { color: var(--hl-red); }

.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta { color: var(--hl-comment); font-style: italic; }

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

.site-footer {
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--b-font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

/* --- Responsive ----------------------------------------------------------- */

@media (max-width: 540px) {
  body {
    padding: 1.75rem 1.1rem 3rem;
  }

  .post-link {
    flex-wrap: wrap;
  }

  .post-meta {
    margin-left: 1.45rem;
  }
}
