/* ==========================================================================
   haongo.dev — design tokens
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Light palette (default) */
  --bg:            #ffffff;
  --bg-subtle:     #f7f8fa;
  --bg-elev:       #ffffff;
  --bg-code:       #f4f5f7;
  --text:          #16191d;
  --text-muted:    #565d66;
  --text-faint:    #858d97;
  --border:        #e5e7eb;
  --border-strong: #d3d7dd;
  --accent:        #0d7a6f;
  --accent-hover:  #0a625a;
  --accent-soft:   #e6f4f1;
  --accent-text:   #0a625a;
  --on-accent:     #ffffff;
  --shadow-sm:     0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md:     0 4px 16px rgba(16, 24, 40, .07);

  --radius:    10px;
  --radius-lg: 16px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono",
               Menlo, Consolas, "Liberation Mono", monospace;

  --wrap: 1120px;
  --wrap-narrow: 720px;
  --nav-h: 60px;
}

/* Dark palette — applied for explicit choice and for system-dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0f1115;
    --bg-subtle:     #14171d;
    --bg-elev:       #171b22;
    --bg-code:       #1b1f27;
    --text:          #e8eaed;
    --text-muted:    #a2a9b4;
    --text-faint:    #79808b;
    --border:        #272c35;
    --border-strong: #363c47;
    --accent:        #4ecbb8;
    --accent-hover:  #6fd9c8;
    --accent-soft:   #12302c;
    --accent-text:   #4ecbb8;
    --on-accent:     #06231f;
    --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md:     0 4px 20px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  --bg:            #0f1115;
  --bg-subtle:     #14171d;
  --bg-elev:       #171b22;
  --bg-code:       #1b1f27;
  --text:          #e8eaed;
  --text-muted:    #a2a9b4;
  --text-faint:    #79808b;
  --border:        #272c35;
  --border-strong: #363c47;
  --accent:        #4ecbb8;
  --accent-hover:  #6fd9c8;
  --accent-soft:   #12302c;
  --accent-text:   #4ecbb8;
  --on-accent:     #06231f;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:     0 4px 20px rgba(0, 0, 0, .45);
}

/* ==========================================================================
   Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 16px);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

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

h1, h2, h3, h4 {
  margin: 0 0 .5em;
  line-height: 1.2;
  letter-spacing: -.02em;
  font-weight: 650;
}

h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 3rem); }
h2 { font-size: clamp(1.4rem, 1.15rem + 1vw, 1.85rem); }
h3 { font-size: 1.1rem; }

p { margin: 0 0 1em; }

a {
  color: var(--accent-text);
  text-decoration: none;
  transition: color .15s ease;
}
a:hover { color: var(--accent-hover); }

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

img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

code, pre, kbd { font-family: var(--font-mono); font-size: .875em; }

code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .1em .35em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  line-height: 1.6;
}
pre code { background: none; border: 0; padding: 0; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--on-accent);
  padding: .6rem 1rem;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; color: var(--on-accent); }

/* ==========================================================================
   Layout helpers
   ========================================================================== */

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 24px;
}
.wrap--narrow { max-width: var(--wrap-narrow); }

.section { padding: clamp(3rem, 6vw, 5rem) 0; }
.section--tint { background: var(--bg-subtle); border-block: 1px solid var(--border); }

.section-head { max-width: 640px; margin-bottom: 2.25rem; }
.section-head p { color: var(--text-muted); margin: 0; }

.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin-bottom: .75rem;
}

.grid { display: grid; gap: 1.25rem; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.muted { color: var(--text-muted); }
.lead  { font-size: 1.075rem; color: var(--text-muted); }
.center { text-align: center; }

/* ==========================================================================
   Navigation
   ========================================================================== */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav__inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 680;
  letter-spacing: -.02em;
  color: var(--text);
  font-size: 1rem;
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand__mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 700;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: auto;
  list-style: none;
  padding: 0;
}
.nav__links a {
  display: block;
  padding: .4rem .7rem;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
}
.nav__links a:hover { color: var(--text); background: var(--bg-subtle); }
.nav__links a[aria-current="page"] { color: var(--text); font-weight: 600; }

.nav__actions { display: flex; align-items: center; gap: .35rem; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color .15s ease, border-color .15s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 16px; height: 16px; }

.nav__toggle { display: none; }

/* Theme icon swap */
:root[data-theme="dark"] .icon-sun,
:root:not([data-theme="light"]) .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon,
:root:not([data-theme="light"]) .icon-moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .icon-sun  { display: block; }
  :root:not([data-theme="dark"]) .icon-moon { display: none; }
}
:root[data-theme="light"] .icon-sun  { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }
:root[data-theme="dark"]  .icon-sun  { display: none; }
:root[data-theme="dark"]  .icon-moon { display: block; }

@media (max-width: 820px) {
  .nav__toggle { display: grid; }
  .nav__links {
    position: fixed;
    inset: var(--nav-h) 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: .5rem 24px 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    display: none;
  }
  .nav__links.is-open { display: flex; }
  .nav__links a { padding: .7rem .25rem; font-size: 1rem; }
  .nav__actions { margin-left: auto; }
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: .925rem;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn--primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn--ghost {
  background: var(--bg-elev);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover { border-color: var(--accent); color: var(--accent-text); }
.btn svg { width: 15px; height: 15px; }

/* ==========================================================================
   Hero
   ========================================================================== */

.hero {
  padding: clamp(3rem, 7vw, 5.5rem) 0 clamp(2.5rem, 5vw, 4rem);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: -40% 40% 40% -20%;
  background: radial-gradient(closest-side, var(--accent-soft), transparent);
  opacity: .8;
  pointer-events: none;
}

.hero__inner {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
}
@media (max-width: 780px) {
  .hero__inner { grid-template-columns: 1fr; }
}

.hero h1 { margin-bottom: .35em; }
.hero__role {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-muted);
  letter-spacing: .02em;
  margin-bottom: 1rem;
}
.hero__role b { color: var(--accent-text); font-weight: 600; }
.hero p.lead { max-width: 52ch; }

.hero__cta { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.5rem; }

.avatar {
  width: clamp(150px, 22vw, 200px);
  aspect-ratio: 1;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  object-fit: cover;
  box-shadow: var(--shadow-md);
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: .875rem;
  color: var(--text-muted);
}
.hero__meta span { display: inline-flex; align-items: center; gap: .4rem; }
.hero__meta svg { width: 15px; height: 15px; color: var(--text-faint); }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
a.card:hover,
.card--link:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card h3 { margin-bottom: .4rem; color: var(--text); }
.card p  { margin: 0; color: var(--text-muted); font-size: .925rem; }

.card__num {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--accent-text);
  letter-spacing: .1em;
  display: block;
  margin-bottom: .7rem;
}

.card__icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-text);
  margin-bottom: .9rem;
}
.card__icon svg { width: 18px; height: 18px; }

/* Tag / pill */
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; }
.tag {
  font-family: var(--font-mono);
  font-size: .7rem;
  padding: .2rem .5rem;
  border-radius: 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ==========================================================================
   Stack diagram
   ========================================================================== */

.stack { display: grid; gap: .6rem; }
.stack__layer {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 1.25rem;
  align-items: center;
  padding: 1.1rem 1.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  position: relative;
}
.stack__layer::before {
  content: "";
  position: absolute;
  left: 0; top: 10%; bottom: 10%;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
  opacity: calc(.25 + var(--i, 1) * .25);
}
.stack__name {
  font-weight: 620;
  font-size: .95rem;
}
.stack__name small {
  display: block;
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--text-faint);
  font-weight: 400;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.stack__items {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
@media (max-width: 620px) {
  .stack__layer { grid-template-columns: 1fr; gap: .75rem; }
}

/* ==========================================================================
   Timeline
   ========================================================================== */

.timeline { position: relative; padding-left: 1.75rem; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5px; top: .5rem; bottom: .5rem;
  width: 1px;
  background: var(--border-strong);
}
.timeline__item { position: relative; padding-bottom: 2rem; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before {
  content: "";
  position: absolute;
  left: -1.75rem; top: .45rem;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
}
.timeline__when {
  font-family: var(--font-mono);
  font-size: .74rem;
  color: var(--accent-text);
  letter-spacing: .06em;
}
.timeline__item h3 { margin: .2rem 0 .1rem; font-size: 1.02rem; }
.timeline__where { font-size: .875rem; color: var(--text-faint); margin-bottom: .5rem; }
.timeline__item p { color: var(--text-muted); font-size: .93rem; margin: 0; }
.timeline__item ul {
  margin: .5rem 0 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: .93rem;
}
.timeline__item li { margin-bottom: .3rem; }

/* ==========================================================================
   Post list
   ========================================================================== */

.posts { list-style: none; margin: 0; padding: 0; }
.posts > li { border-top: 1px solid var(--border); }
.posts > li:last-child { border-bottom: 1px solid var(--border); }

.post-row {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 1.5rem;
  padding: 1.35rem .25rem;
  align-items: baseline;
  color: var(--text);
}
.post-row:hover { color: var(--text); background: var(--bg-subtle); }
.post-row:hover .post-row__title { color: var(--accent-text); }
.post-row__date {
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--text-faint);
  letter-spacing: .03em;
  white-space: nowrap;
}
.post-row__title {
  font-weight: 600;
  font-size: 1.02rem;
  display: block;
  margin-bottom: .25rem;
  transition: color .15s ease;
}
.post-row__excerpt { color: var(--text-muted); font-size: .9rem; margin: 0; }
@media (max-width: 620px) {
  .post-row { grid-template-columns: 1fr; gap: .35rem; }
}

/* Filter bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1.5rem;
}
.filter {
  font-size: .82rem;
  font-family: var(--font-mono);
  padding: .3rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s ease;
}
.filter:hover { border-color: var(--border-strong); color: var(--text); }
.filter[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.empty-state {
  padding: 2.5rem 0;
  color: var(--text-faint);
  font-size: .925rem;
}

/* ==========================================================================
   Notes
   ========================================================================== */

.note {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1rem;
}
.note__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: .6rem;
}
.note__head h3 { margin: 0; font-size: 1rem; }
.note__date {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-faint);
  margin-left: auto;
}
.note p:last-child { margin-bottom: 0; }
.note pre { margin: .75rem 0 0; }

/* ==========================================================================
   Article
   ========================================================================== */

.article-head {
  padding: clamp(2.5rem, 5vw, 4rem) 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.article-head .meta {
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.prose { max-width: 72ch; }
.prose h2 { margin-top: 2.5rem; }
.prose h3 { margin-top: 1.75rem; }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li { margin-bottom: .4rem; }
.prose blockquote {
  margin: 1.5rem 0;
  padding: .25rem 0 .25rem 1.15rem;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  margin: 1.5rem 0;
}
.prose th, .prose td {
  text-align: left;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
}
.prose th { font-weight: 600; color: var(--text); }
.prose td { color: var(--text-muted); }

.table-scroll { overflow-x: auto; }

/* ==========================================================================
   Page header (inner pages)
   ========================================================================== */

.page-head {
  padding: clamp(2.5rem, 5vw, 4rem) 0 clamp(1.5rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--border);
  margin-bottom: clamp(2rem, 4vw, 3rem);
}
.page-head h1 { margin-bottom: .3em; }
.page-head p { color: var(--text-muted); max-width: 60ch; margin: 0; }

/* ==========================================================================
   CTA band
   ========================================================================== */

.cta-band {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  padding: clamp(1.75rem, 4vw, 2.75rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}
.cta-band h2 { margin-bottom: .25rem; }
.cta-band p { margin: 0; color: var(--text-muted); }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 3rem 0 2rem;
  margin-top: 4rem;
  font-size: .9rem;
}
.footer__cols {
  display: grid;
  grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: 2rem;
  margin-bottom: 2.5rem;
}
@media (max-width: 780px) {
  .footer__cols { grid-template-columns: 1fr 1fr; gap: 1.75rem; }
  .footer__brand { grid-column: 1 / -1; }
}
.footer__brand p { color: var(--text-muted); max-width: 34ch; margin: .75rem 0 0; font-size: .875rem; }
.footer h4 {
  font-size: .74rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-faint);
  margin-bottom: .9rem;
  font-weight: 500;
}
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin-bottom: .5rem; }
.footer li a { color: var(--text-muted); }
.footer li a:hover { color: var(--accent-text); }

.footer__bottom {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  color: var(--text-faint);
  font-size: .82rem;
}
.social { display: flex; gap: .5rem; }
.social a {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  background: var(--bg-elev);
}
.social a:hover { color: var(--accent-text); border-color: var(--accent); }
.social svg { width: 16px; height: 16px; }

/* ==========================================================================
   404
   ========================================================================== */

.notfound {
  min-height: 58vh;
  display: grid;
  place-content: center;
  text-align: center;
  gap: .5rem;
}
.notfound__code {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 12vw, 6rem);
  color: var(--accent);
  line-height: 1;
  margin: 0;
}
