:root{
  /* Fonts: fast system stacks */
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Typography */
  --text-base: 18px;        /* comfortable default */
  --text-small: 14px;
  --lh-body: 1.75;
  --lh-tight: 1.2;

  /* Layout */
  --page-max: 1120px;
  --content-max: 72ch;      /* ideal reading measure */
  --gutter: 20px;

  /* Colors (warm editorial — SAFE UPGRADE) */
  --bg: #f7f5f1;
  --fg: #1c1c1c;
  --muted: rgba(28,28,28,0.62);
  --hairline: rgba(28,28,28,0.10);

  --link: #3e4a52;
  --link-hover: #2c363c;

  /* Radii */
  --r-sm: 10px;
  --r-md: 14px;
}

@media (max-width: 520px){
  :root{ --text-base: 17px; }
}

html, body{
  height: 100%;
}

body{
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--lh-body);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

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

hr{
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 1.25rem 0;
}

.container{
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.site-header{
  padding: 1.25rem 0 0.75rem 0;
}

.brand{
  display: inline-block;
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--fg);
}
.brand:hover{ color: var(--fg); }

.nav{
  margin-top: 0.5rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: var(--text-small);
}
.nav a{
  color: var(--muted);
  text-decoration: none;
}
.nav a:hover{ color: var(--fg); }

main{
  padding: 1.25rem 0 3rem 0;
}

.footer{
  border-top: 1px solid var(--hairline);
  margin-top: 2.5rem;
  padding: 1.25rem 0 2.25rem 0;
  font-size: var(--text-small);
  color: var(--muted);
}

.skip-link{
  position: absolute;
  left: -999px;
  top: 8px;
  padding: 0.5rem 0.75rem;
  background: var(--fg);
  color: var(--bg);
  border-radius: var(--r-sm);
  text-decoration: none;
  font-size: var(--text-small);
}
.skip-link:focus{
  left: 12px;
  z-index: 1000;
}

.muted{ color: var(--muted); }
.small{ font-size: var(--text-small); }

.reading{
  max-width: var(--content-max);
}

.card{
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 1rem 1.05rem;
  background: #ffffff;
  box-shadow: 0 1px 0 rgba(28,28,28,0.04); 
}

.cards{
  display: grid;
  gap: 0.9rem;
}

.pager{
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
  font-size: var(--text-small);
}
.pager a{
  text-decoration: none;
  border: 1px solid var(--hairline);
  padding: 0.35rem 0.6rem;
  border-radius: var(--r-sm);
  color: var(--fg);
}
.pager a:hover{ background: rgba(28,28,28,0.04); }

/* Reading wrappers:
   - reading-wide: page width (for TOC sidebar)
   - prose stays narrow (72ch) */
.reading-wide{
  max-width: var(--page-max);
}

/* --- C7 micro-polish --- */

/* Better selection */
::selection{
  background: rgba(62, 74, 82, 0.18);
}

/* Focus rings: only when keyboard navigating */
:focus{ outline: none; }
:focus-visible{
  outline: 2px solid rgba(62, 74, 82, 0.45);
  outline-offset: 3px;
  border-radius: 8px;
}

/* Softer card hover (desktop only) */
@media (hover: hover){
  .card{
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  }
  .card:hover{
    border-color: rgba(28,28,28,0.16);
    box-shadow: 0 8px 24px rgba(28,28,28,0.06);
    transform: translateY(-1px);
  }
}

/* Clickable area feels better */
.card a:focus-visible{
  outline: 2px solid rgba(62, 74, 82, 0.45);
  outline-offset: 4px;
  border-radius: 10px;
}

/* Better muted contrast in dark-ish monitors */
.muted{ color: var(--muted); }

/* Reduce motion */
@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; scroll-behavior: auto !important; }
}

/* --- Full-card clickable article cards --- */

.card-link{
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-link:hover{
  color: inherit;
  text-decoration: none;
}

.card-link:focus-visible{
  outline: none;
}


/* --- F3 homepage editorial structure --- */

.home-hero .card{
  border-radius: 16px;
}

.home-hero h2 a:hover{
  text-decoration: underline;
}

.home-latest{
  margin-top: 1.5rem;
}

/* --- F3.2 homepage secondary grid --- */

.home-grid{
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px){
  .home-grid{
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.home-grid .card-title{
  margin-bottom: 0.35rem;
}


/* --- F3.3 homepage editorial strip --- */

.home-section-title{
  margin: 0 0 0.85rem 0;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.home-explore{
  margin-top: 2rem;
  margin-bottom: 1.75rem;
}

.home-explore-grid{
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px){
  .home-explore-grid{
    grid-template-columns: repeat(3, 1fr);
  }
}

.home-explore-card{
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 1rem 1.05rem;
  background: rgba(255,255,255,0.72);
  box-shadow: 0 1px 0 rgba(28,28,28,0.03);
}

.home-explore-card:hover{
  border-color: rgba(28,28,28,0.16);
  box-shadow: 0 8px 24px rgba(28,28,28,0.05);
  transform: translateY(-1px);
}

.home-explore-kicker{
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.home-explore-title{
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 1.2;
  margin-bottom: 0.35rem;
  color: var(--fg);
}

.home-explore-text{
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

/* --- F5 theme modes --- */

/* Default = light (already defined in :root) */

:root[data-theme="dim"]{
  --bg: #1d1b19;
  --fg: #ece6db;
  --muted: rgba(236,230,219,0.68);
  --hairline: rgba(236,230,219,0.12);

  --link: #c7d2da;
  --link-hover: #f1ede6;
}

:root[data-theme="sepia"]{
  --bg: #f3eadb;
  --fg: #2b241d;
  --muted: rgba(43,36,29,0.62);
  --hairline: rgba(43,36,29,0.12);

  --link: #5b4f43;
  --link-hover: #3f352d;
}

/* Surfaces adapt too */
:root[data-theme="dim"] .card,
:root[data-theme="dim"] .home-note,
:root[data-theme="dim"] .home-explore-card,
:root[data-theme="dim"] .toc{
  background: rgba(255,255,255,0.04);
}

:root[data-theme="sepia"] .card,
:root[data-theme="sepia"] .home-note,
:root[data-theme="sepia"] .home-explore-card,
:root[data-theme="sepia"] .toc{
  background: rgba(255,255,255,0.42);
}

/* Header / footer adapt */
:root[data-theme="dim"] .site-header,
:root[data-theme="dim"] .footer{
  border-color: var(--hairline);
}

:root[data-theme="sepia"] .site-header,
:root[data-theme="sepia"] .footer{
  border-color: var(--hairline);
}

/* Buttons / switcher */
.theme-switcher{
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.theme-switcher button{
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--muted);
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.theme-switcher button:hover{
  color: var(--fg);
  background: rgba(255,255,255,0.04);
}

.theme-switcher button.is-active{
  color: var(--fg);
  border-color: rgba(28,28,28,0.22);
}

:root[data-theme="dim"] .theme-switcher button.is-active{
  border-color: rgba(236,230,219,0.28);
}

:root[data-theme="sepia"] .theme-switcher button.is-active{
  border-color: rgba(43,36,29,0.22);
}

/* --- Categories block (homepage) --- */

.home-categories{
  margin-bottom: 2rem;
}

.home-categories-grid{
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 700px){
  .home-categories-grid{
    grid-template-columns: repeat(4, 1fr);
  }
}

.home-category-card{
  display: block;
  text-decoration: none;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 0.6rem 0.75rem;
  background: rgba(255,255,255,0.65);
  color: var(--fg);
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.home-category-card:hover{
  border-color: rgba(28,28,28,0.16);
  background: rgba(255,255,255,0.85);
  transform: translateY(-1px);
}

.home-category-name{
  display: block;
}

/* --- Search block --- */

mark{
  background: #fff3a0;
  padding: 0 2px;
  border-radius: 2px;
}

.header-row{
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Nav stays near logo */
.nav{
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Right side container (theme + search) */
.header-right{
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Search */
.search-form input{
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.32rem 0.55rem;
  font-size: 0.85rem;
  background: transparent;
  color: var(--fg);
  width: 130px;
}

.search-form input:focus{
  outline: none;
  border-color: rgba(28,28,28,0.25);
}

/* Improve placeholder */
.search-form input::placeholder{
  color: var(--muted);
}

/* --- Mobile fix --- */

@media (max-width: 720px){

  .header-row{
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .brand{
    text-align: center;
  }

  .nav{
    justify-content: center;
    margin-top: 0.35rem;
  }

  .header-right{
    margin-left: 0;
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
  }

  .theme-switcher{
    justify-content: center;
    margin-top: 0.25rem;
  }

  .search-form{
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .search-form input{
    width: min(280px, 100%);
  }
}

/* --- Tag pills --- */

.tag-list{
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tag-pill{
  display: inline-block;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.82rem;
  background: rgba(255,255,255,0.62);
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.tag-pill:hover{
  color: var(--fg);
  border-color: rgba(28,28,28,0.18);
  background: rgba(255,255,255,0.85);
}

/* --- Fix: tag pills in dim mode --- */

:root[data-theme="dim"] .tag-pill{
  background: rgba(255,255,255,0.06);
  color: #eae4d9;
  border-color: rgba(255,255,255,0.14);
}

:root[data-theme="dim"] .tag-pill:hover{
  background: rgba(255,255,255,0.10);
  color: #ffffff;
  border-color: rgba(255,255,255,0.22);
}


/* --- Fix: category cards in dim mode --- */

:root[data-theme="dim"] .home-category-card{
  background: rgba(255,255,255,0.06);
  color: #ece6db;
  border-color: rgba(255,255,255,0.12);
}

:root[data-theme="dim"] .home-category-card:hover{
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.18);
}
