/* ============================================================
   hiltsu-clean — Polished minimalism
   --------------------------------------------------------------
   System-font typography with intentional restraint.
   Warm neutral palette (stone family) with a refined indigo accent.
   Modular type scale (1.250 — major third) and 4px spacing rhythm.
   No external resources: privacy-first by design.
   ============================================================ */

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

:root {
  /* Neutrals — warm stone family */
  --c-bg:           #f9f8f6;
  --c-surface:      #ffffff;
  --c-surface-2:    #f5f5f4;
  --c-text:         #1c1917;
  --c-text-2:       #44403c;
  --c-text-muted:   #78716c;
  --c-text-subtle:  #a8a29e;
  --c-border:       #e7e5e4;
  --c-border-soft:  #f1efed;

  /* Accent — refined indigo */
  --c-accent:       #4338ca;
  --c-accent-hover: #3730a3;
  --c-accent-soft:  #eef2ff;
  --c-accent-on:    #ffffff;

  /* Semantic surfaces */
  --c-code-bg:      #f4f2ee;
  --c-tag-bg:       #f4f2ee;
  --c-tag-bg-hover: #eef2ff;
  --c-tag-text:     #44403c;
  --c-tag-text-hover: #4338ca;
  --c-selection:    #fef3c7;
  --c-selection-text: #1c1917;

  /* Type stack — system fonts only (privacy + performance) */
  --font-sans:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-mono:
    ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
    "JetBrains Mono", Menlo, Consolas, monospace;

  /* Type scale — modular (1.250 ratio, base 17px) */
  --fs-xs:   0.78125rem;   /* ~13.3px  */
  --fs-sm:   0.875rem;     /* ~15px    */
  --fs-base: 1rem;         /* ~17px    */
  --fs-md:   1.0625rem;    /* ~18px    */
  --fs-lg:   1.25rem;      /* ~21.25px */
  --fs-xl:   1.5625rem;    /* ~26.5px  */
  --fs-2xl:  1.953125rem;  /* ~33px    */

  /* Line heights — paired to size */
  --lh-tight: 1.2;
  --lh-snug:  1.4;
  --lh-base:  1.7;

  /* Spacing scale — 4px base */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Layout — narrow column for optimal reading line length (~70 chars) */
  --w-content: 660px;
  --w-wide:    820px;
  --pad-x:     1.5rem;

  /* Form */
  --radius-xs:   3px;
  --radius-sm:   5px;
  --radius:      8px;
  --radius-pill: 9999px;

  /* Motion */
  --ease:        cubic-bezier(0.32, 0.72, 0, 1);
  --t-fast:      120ms;
  --t-base:      200ms;
  --t-slow:      400ms;

  /* Elevation — used very sparingly */
  --shadow-sm: 0 1px 2px 0 rgb(28 25 23 / 0.04);
  --shadow:    0 1px 3px 0 rgb(28 25 23 / 0.06), 0 1px 2px -1px rgb(28 25 23 / 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:           #0c0a09;
    --c-surface:      #1c1917;
    --c-surface-2:    #292524;
    --c-text:         #f5f5f4;
    --c-text-2:       #d6d3d1;
    --c-text-muted:   #a8a29e;
    --c-text-subtle:  #78716c;
    --c-border:       #292524;
    --c-border-soft:  #1f1d1c;

    --c-accent:       #a5b4fc;
    --c-accent-hover: #c7d2fe;
    --c-accent-soft:  #1e1b4b;
    --c-accent-on:    #0c0a09;

    --c-code-bg:      #1c1917;
    --c-tag-bg:       #292524;
    --c-tag-bg-hover: #1e1b4b;
    --c-tag-text:     #d6d3d1;
    --c-tag-text-hover: #c7d2fe;
    --c-selection:    #4338ca;
    --c-selection-text: #f5f5f4;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow:    0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  }
}

/* --- Reset ---------------------------------------------------- */

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

* { margin: 0; padding: 0; }

html {
  font-size: 17px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Prevent layout shift from scrollbar appearing */
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--c-text);
  background: var(--c-bg);
  font-feature-settings: "kern", "liga", "calt", "ss01";
  text-underline-offset: 2px;
  /* Subtle fade-in on first paint */
  animation: app-fade-in var(--t-slow) var(--ease) both;
}

@keyframes app-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

::selection {
  background: var(--c-selection);
  color: var(--c-selection-text);
}

img, svg, video {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}

/* --- Focus ring — accessible & refined ----------------------- */

:focus { outline: none; }

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

/* --- Links ---------------------------------------------------- */

a {
  color: var(--c-accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--c-accent) 28%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition:
    color var(--t-fast) var(--ease),
    text-decoration-color var(--t-fast) var(--ease);
}

a:hover {
  color: var(--c-accent-hover);
  text-decoration-color: currentColor;
}

/* --- Layout --------------------------------------------------- */

.site-wrapper {
  max-width: var(--w-content);
  margin: 0 auto;
  padding: 0 var(--pad-x);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

main {
  flex: 1 0 auto;
  padding-bottom: var(--sp-16);
}

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

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  padding: var(--sp-10) 0 var(--sp-6);
  margin-bottom: var(--sp-12);
  border-bottom: 1px solid var(--c-border-soft);
}

.site-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.site-brand__name {
  color: var(--c-text);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.022em;
  text-decoration: none;
  line-height: 1.2;
}
.site-brand__name:hover {
  color: var(--c-text);
  text-decoration: none;
}

.site-brand__subtitle {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  font-feature-settings: "tnum";
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  font-size: var(--fs-sm);
}

.site-nav a {
  color: var(--c-text-2);
  font-weight: 500;
  text-decoration: none;
  position: relative;
  transition: color var(--t-fast) var(--ease);
}

.site-nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 1px;
  background: var(--c-text);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--t-base) var(--ease);
}

.site-nav a:hover {
  color: var(--c-text);
}
.site-nav a:hover::after {
  transform: scaleX(1);
}

.lang-switch {
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  color: var(--c-text-muted);
  background: transparent;
  transition:
    color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease);
}
.lang-switch:hover {
  color: var(--c-accent);
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
  text-decoration: none;
}
.lang-switch::after { display: none; }

/* --- Page descriptions / list titles ------------------------- */

.page-description {
  font-size: var(--fs-md);
  color: var(--c-text-2);
  margin-bottom: var(--sp-10);
  max-width: 56ch;
  line-height: 1.6;
}

.list-title {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: var(--lh-tight);
  margin-bottom: var(--sp-8);
}

/* --- Post list ----------------------------------------------- */

.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.post-item {
  padding: var(--sp-8) 0;
  border-bottom: 1px solid var(--c-border-soft);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.post-item:first-child { padding-top: 0; }
.post-item:last-child  { border-bottom: none; }

.post-item__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.018em;
  line-height: var(--lh-snug);
}
.post-item__title a {
  color: var(--c-text);
  text-decoration: none;
}
.post-item__title a:hover {
  color: var(--c-accent);
  text-decoration: none;
}

.post-meta {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  font-feature-settings: "tnum";
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.post-meta-divider { color: var(--c-text-subtle); }

.post-summary {
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  line-height: 1.65;
  max-width: 60ch;
}

/* --- Single post --------------------------------------------- */

.post {
  display: flex;
  flex-direction: column;
}

.post-header {
  margin-bottom: var(--sp-10);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.post-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.028em;
  text-wrap: balance;
}

.post-content {
  /* Slightly larger body for the article view */
  font-size: var(--fs-md);
  line-height: 1.75;
  color: var(--c-text);
}

.post-content > * + * { margin-top: var(--sp-5); }
.post-content > h2     { margin-top: var(--sp-12); }
.post-content > h3     { margin-top: var(--sp-10); }
.post-content > h2 + * { margin-top: var(--sp-3); }
.post-content > h3 + * { margin-top: var(--sp-3); }

.post-content h2 {
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: var(--lh-snug);
  text-wrap: balance;
}
.post-content h3 {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: var(--lh-snug);
}
.post-content h4 {
  font-size: var(--fs-md);
  font-weight: 600;
}

.post-content ul,
.post-content ol {
  padding-left: 1.4rem;
}
.post-content li + li { margin-top: var(--sp-2); }
.post-content li::marker { color: var(--c-text-subtle); }

.post-content blockquote {
  border-left: 2px solid var(--c-accent);
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-5);
  color: var(--c-text-2);
  font-style: italic;
  /* Hanging quote-mark */
  position: relative;
}

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--c-code-bg);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--c-border-soft);
}

.post-content pre {
  background: var(--c-code-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  overflow-x: auto;
  font-size: var(--fs-sm);
  line-height: 1.6;
  /* Subtle scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--c-text-subtle) transparent;
}
.post-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
}

.post-content hr {
  border: none;
  height: 1px;
  background: var(--c-border);
  margin-block: var(--sp-10);
}

.post-content img {
  margin-block: var(--sp-2);
  border-radius: var(--radius);
}

.post-content figure {
  margin-block: var(--sp-6);
}
.post-content figure figcaption {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  margin-top: var(--sp-2);
  text-align: center;
}

.post-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-sm);
}
.post-content th,
.post-content td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
}
.post-content th {
  font-weight: 600;
  color: var(--c-text-2);
}

/* --- Tags ---------------------------------------------------- */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: var(--fs-xs);
  font-weight: 500;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  padding: 3px 10px;
  background: var(--c-tag-bg);
  color: var(--c-tag-text);
  border-radius: var(--radius-pill);
  text-decoration: none;
  border: 1px solid transparent;
  transition:
    background var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}
.tag:hover {
  background: var(--c-tag-bg-hover);
  color: var(--c-tag-text-hover);
  border-color: color-mix(in oklab, var(--c-accent) 20%, transparent);
  transform: translateY(-1px);
  text-decoration: none;
}

/* --- Pagination ---------------------------------------------- */

.pagination,
nav.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-12);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--c-border-soft);
  font-size: var(--fs-sm);
  list-style: none;
}

.pagination a,
.pagination span,
.pagination .page-item {
  text-decoration: none;
}

.pagination .page-item {
  display: inline-flex;
}

.pagination .page-link {
  color: var(--c-text-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  transition:
    border-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease);
}
.pagination .page-link:hover {
  color: var(--c-accent);
  border-color: var(--c-accent);
  text-decoration: none;
}
.pagination .page-item.active .page-link {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-accent-on);
}
.pagination .page-item.disabled .page-link {
  color: var(--c-text-subtle);
  border-color: var(--c-border-soft);
  background: transparent;
  cursor: not-allowed;
}

/* --- Post footer (single page) ------------------------------- */

.post-footer {
  margin-top: var(--sp-16);
  padding-top: var(--sp-8);
  border-top: 1px solid var(--c-border-soft);
  display: flex;
  flex-direction: column;
  gap: var(--sp-10);
}

.back-link {
  font-size: var(--fs-sm);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.back-link a {
  color: var(--c-text-muted);
  text-decoration: none;
}
.back-link a:hover {
  color: var(--c-accent);
  text-decoration: none;
}

/* --- Previous / Next post navigation ------------------------- */

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.post-nav__link {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  text-decoration: none;
  color: var(--c-text);
  transition:
    border-color var(--t-base) var(--ease),
    transform var(--t-base) var(--ease),
    box-shadow var(--t-base) var(--ease);
}
.post-nav__link:hover {
  border-color: var(--c-accent);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.post-nav__link--prev { text-align: left; }
.post-nav__link--next { text-align: right; }

.post-nav__direction {
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

.post-nav__title {
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: var(--lh-snug);
  color: var(--c-text);
  /* Truncate at 2 lines for tidy cards */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-nav__placeholder { /* Empty cell to keep grid balanced */ }

/* --- Related posts ------------------------------------------- */

.related-posts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.related-posts__heading {
  font-size: var(--fs-xs);
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--c-border-soft);
}

.related-posts__list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.related-posts__item {
  border-bottom: 1px solid var(--c-border-soft);
}
.related-posts__item:last-child { border-bottom: none; }

.related-posts__link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-4);
  padding: var(--sp-3) 0;
  text-decoration: none;
  color: var(--c-text);
  transition: color var(--t-fast) var(--ease);
}
.related-posts__link:hover {
  color: var(--c-accent);
  text-decoration: none;
}

.related-posts__title {
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: var(--lh-snug);
  flex: 1 1 auto;
}

.related-posts__date {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  font-feature-settings: "tnum";
  flex: 0 0 auto;
  white-space: nowrap;
}

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

.site-footer {
  flex: 0 0 auto;
  padding: var(--sp-8) 0;
  margin-top: var(--sp-12);
  border-top: 1px solid var(--c-border-soft);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.7;
}

.site-footer a {
  color: var(--c-text-2);
  text-decoration: none;
}
.site-footer a:hover {
  color: var(--c-accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--c-accent) 40%, transparent);
}

.site-footer__sep {
  margin: 0 var(--sp-2);
  color: var(--c-text-subtle);
}

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

@media (max-width: 640px) {
  html { font-size: 16px; }

  :root {
    --pad-x: 1.25rem;
  }

  .site-header {
    padding: var(--sp-6) 0 var(--sp-4);
    margin-bottom: var(--sp-8);
    align-items: flex-start;
  }

  .site-nav {
    gap: var(--sp-4);
  }

  .post-title { font-size: 1.625rem; }
  .list-title { font-size: 1.625rem; }

  .post-nav {
    grid-template-columns: 1fr;
  }
  .post-nav__link--next { text-align: left; }

  .post-content > h2 { margin-top: var(--sp-10); }
  .post-content > h3 { margin-top: var(--sp-8); }
}

/* --- Print ---------------------------------------------------- */

@media print {
  body { background: white; color: black; }
  .site-header, .site-footer, .post-nav, .related-posts, .pagination { display: none; }
  a { color: black; text-decoration: underline; }
  .post-content pre, .post-content code { background: #f5f5f5; }
}
