/* ═══════════════════════════════════════════════════════════
   bits & bytes — programmer blog
   3-state theme · typewriter · hover-raise · smooth transitions
   ═══════════════════════════════════════════════════════════ */

/* ── theme tokens (3 states) ── */
:root, html[data-theme="dark"] {
  --bg: #0E1116;
  --bg-soft: #161B22;
  --bg-code: #0A0D12;
  --surface: #161B22;
  --text: #E6EDF3;
  --text-soft: #9DA7B3;
  --muted: #6E7681;
  --line: #21262D;
  --accent: #58A6FF;
  --accent-2: #7EE787;
  --accent-3: #F0883E;
  --code: #A5D6FF;
  --shadow: 0 18px 40px -22px rgba(0,0,0,0.55);
}
html[data-theme="light"] {
  --bg: #F6F8FA;
  --bg-soft: #FFFFFF;
  --bg-code: #F0F3F6;
  --surface: #FFFFFF;
  --text: #1F2328;
  --text-soft: #57606A;
  --muted: #8C959F;
  --line: #D0D7DE;
  --accent: #0969DA;
  --accent-2: #1A7F37;
  --accent-3: #BC4C00;
  --code: #24292F;
  --shadow: 0 18px 40px -24px rgba(31,35,40,0.25);
}
html[data-theme="sepia"] {
  --bg: #F4ECD8;
  --bg-soft: #FBF6E9;
  --bg-code: #EDE2C6;
  --surface: #FBF6E9;
  --text: #3A3226;
  --text-soft: #6B5F4C;
  --muted: #98896F;
  --line: #DCCFB2;
  --accent: #A0522D;
  --accent-2: #5B6B3C;
  --accent-3: #B86B2F;
  --code: #4A3B28;
  --shadow: 0 18px 40px -24px rgba(58,50,38,0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* smooth theme transition */
  transition: background 0.5s ease, color 0.5s ease;
}
.mono { font-family: 'IBM Plex Mono', monospace; }
::selection { background: var(--accent); color: var(--bg); }
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* smooth transitions for themed elements */
body, .site-header, .post-card, .code-block, .hero, .about-card, .stack-item,
.tag, .hero-repo, .theme-toggle, .site-footer, .featured-body pre, .featured-body {
  transition: background 0.5s ease, color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}

/* reading progress bar */
.progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 300;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform: scaleX(0); transform-origin: left;
}

/* ═══════════ HEADER ═══════════ */
.site-header {
  position: sticky; top: 0; z-index: 200;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1080px; margin: 0 auto; padding: 0.8rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.logo {
  font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 1.1rem;
  text-decoration: none; color: var(--text);
}
.logo-cursor { color: var(--accent-3); }
.logo-amp { color: var(--accent-2); }
.logo-caret { color: var(--accent); animation: caret 1.06s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.nav-links { display: flex; align-items: center; gap: 1.4rem; }
.nav-links a {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.82rem;
  color: var(--text-soft); text-decoration: none;
  border-bottom: 2px solid transparent; padding-bottom: 0.2rem;
  transition: color 0.3s ease, border-color 0.3s ease;
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.nav-links a:hover { color: var(--text); border-bottom-color: var(--accent); }
.nav-links a svg { width: 15px; height: 15px; }
.nav-gh:hover { color: var(--accent) !important; }

/* ═══════════ THEME TOGGLE · 3 states ═══════════ */
.theme-toggle {
  position: relative;
  display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); padding: 3px; gap: 2px;
  cursor: pointer;
}
.tt-seg {
  width: 28px; height: 26px; border-radius: 999px;
  display: grid; place-items: center;
  font-size: 14px; color: var(--muted);
  transition: color 0.4s ease;
  position: relative; z-index: 2;
}
.tt-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 28px; height: 26px; border-radius: 999px;
  background: var(--accent);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), background 0.45s ease;
  z-index: 1;
}
.theme-toggle[data-pos="1"] .tt-thumb { transform: translateX(30px); background: var(--accent-2); }
.theme-toggle[data-pos="2"] .tt-thumb { transform: translateX(60px); background: var(--accent-3); }
.theme-toggle[data-pos="0"] .tt-seg:nth-child(1),
.theme-toggle[data-pos="1"] .tt-seg:nth-child(2),
.theme-toggle[data-pos="2"] .tt-seg:nth-child(3) { color: var(--bg); }

/* ═══════════ HERO · typewriter ═══════════ */
.hero {
  max-width: 1080px; margin: 0 auto;
  padding: clamp(4rem, 12vh, 7rem) 1.4rem 3rem;
}
.hero-kicker {
  color: var(--accent); font-size: 0.82rem; letter-spacing: 0.18em;
  text-transform: uppercase; margin-bottom: 1.4rem;
}
.hero-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  font-size: clamp(2.2rem, 6vw, 4.2rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
}
.hero-title em { font-style: italic; color: var(--accent-3); }
.hero-title .tw-line { display: inline-block; }
.tw-caret {
  display: inline-block; color: var(--accent);
  animation: caret 1.06s steps(1) infinite;
  font-weight: 400;
}
.hero-sub {
  margin-top: 1.2rem; color: var(--text-soft); font-size: 0.9rem;
}
.hero-repo {
  margin-top: 2rem; display: flex; gap: 1.6rem; flex-wrap: wrap;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.8rem 1.1rem; font-size: 0.82rem; color: var(--text-soft);
}
.hero-repo b { color: var(--accent); font-weight: 600; }
.repo-name { color: var(--muted); margin-left: auto; }

/* ═══════════ SECTIONS ═══════════ */
.posts, .featured, .about { max-width: 1080px; margin: 0 auto; padding: 2.5rem 1.4rem 3.5rem; }
.sec-head { margin-bottom: 1.8rem; }
.sec-index { color: var(--accent); font-size: 0.8rem; letter-spacing: 0.16em; text-transform: uppercase; margin-bottom: 0.5rem; }
.sec-head h2 { font-family: 'Source Serif 4', serif; font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 600; }
.sec-head .date { color: var(--muted); font-size: 0.78rem; margin-top: 0.4rem; display: block; }

/* ═══════════ POST CARDS · hover-raise ═══════════ */
.post-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem;
}
.post-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.4rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.8rem;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease, border-color 0.35s ease, background 0.5s ease;
}
.post-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.card-top { display: flex; justify-content: space-between; align-items: center; }
.tag {
  font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 999px;
  padding: 0.18rem 0.6rem;
}
.date { color: var(--muted); font-size: 0.72rem; }
.post-card h3 { font-size: 1.18rem; line-height: 1.35; font-weight: 600; }
.post-card h3 a { text-decoration: none; color: var(--text); }
.post-card h3 a:hover { color: var(--accent); }
.card-excerpt { font-size: 0.95rem; color: var(--text-soft); flex: 1; }
.card-foot {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--line); padding-top: 0.7rem;
}
.read { color: var(--muted); font-size: 0.72rem; }
.arrow { color: var(--accent); font-size: 1rem; transition: transform 0.3s ease; }
.post-card:hover .arrow { transform: translateX(4px); }

/* ═══════════ FEATURED POST + CODE BLOCK ═══════════ */
.featured { border-top: 1px solid var(--line); }
.featured-body { max-width: 70ch; }
.featured-body p { font-size: 1.05rem; color: var(--text-soft); margin-bottom: 1.2rem; }
.featured-body p strong { color: var(--text); }
.code-block {
  background: var(--bg-code); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; margin: 1.4rem 0;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.code-head .mono { font-size: 0.72rem; color: var(--text-soft); }
.copy-btn {
  font-family: 'IBM Plex Mono', monospace; font-size: 0.7rem;
  color: var(--accent); background: transparent; border: 1px solid var(--line);
  border-radius: 6px; padding: 0.25rem 0.7rem; cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.copy-btn:hover { border-color: var(--accent); }
.copy-btn.flash { background: var(--accent-2); color: var(--bg); border-color: var(--accent-2); }
.code-block pre {
  padding: 1.1rem 1.2rem; overflow-x: auto;
  font-family: 'IBM Plex Mono', monospace; font-size: 0.86rem; line-height: 1.6;
  color: var(--code);
}

/* ═══════════ ABOUT ═══════════ */
.about { border-top: 1px solid var(--line); }
.about-grid {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.6rem; align-items: start;
}
.about-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.5rem 1.6rem;
}
.about-card p { font-size: 1.08rem; color: var(--text-soft); margin-bottom: 1rem; }
.about-card strong { color: var(--text); }
.about-sign { color: var(--muted) !important; font-size: 0.8rem !important; }
.about-stack { display: flex; flex-direction: column; gap: 0.6rem; }
.stack-item {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.8rem 1rem; display: flex; justify-content: space-between; gap: 0.8rem;
  font-size: 0.78rem;
}
.stack-k { color: var(--accent); }
.stack-item .mono:last-child { color: var(--text-soft); text-align: right; }

/* ═══════════ FOOTER ═══════════ */
.site-footer {
  border-top: 1px solid var(--line); background: var(--bg-soft);
  padding: 1.4rem 1.4rem;
}
.footer-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--muted);
}
.footer-inner a { color: var(--text-soft); text-decoration: none; }
.footer-inner a:hover { color: var(--accent); }
.heart { color: var(--accent-3); }

/* ═══════════ responsive ═══════════ */
@media (max-width: 820px) {
  .post-grid { grid-template-columns: 1fr; }
  .about-grid { grid-template-columns: 1fr; }
  .hero-repo .repo-name { display: none; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .nav-links .nav-gh span { display: none; }
  .hero-title { font-size: 2rem; }
  .theme-toggle { display: none; }
}

/* ═══════════ reduced motion ═══════════ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
  .post-card:hover { transform: none; }
}
