/* miedo.org — stylesheet principal */

:root {
  --bg: #faf7f2;
  --bg-elev: #f2ece2;
  --fg: #1a1614;
  --muted: #5a534d;
  --accent: #7a1f2b;
  --accent-hover: #5c1620;
  --line: #e6e0d8;
  --code-bg: #efe9df;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(26, 22, 20, .06), 0 2px 8px rgba(26, 22, 20, .04);
  --font-serif: ui-serif, Georgia, "Iowan Old Style", "Apple Garamond", Baskerville, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --max-content: 68ch;
  --max-wide: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13110f;
    --bg-elev: #1c1917;
    --fg: #ebe5dc;
    --muted: #9a948c;
    --accent: #c44a5a;
    --accent-hover: #d96071;
    --line: #2a2622;
    --code-bg: #1f1c19;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
  }
}

:root[data-theme="dark"] {
  --bg: #13110f;
  --bg-elev: #1c1917;
  --fg: #ebe5dc;
  --muted: #9a948c;
  --accent: #c44a5a;
  --accent-hover: #d96071;
  --line: #2a2622;
  --code-bg: #1f1c19;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
}

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

html {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.65;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

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

@media (min-width: 900px) {
  html { font-size: 19px; }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: -.015em;
  line-height: 1.25;
  margin: 2.2em 0 .6em;
  color: var(--fg);
}

h1 { font-size: clamp(1.9rem, 4.5vw, 2.6rem); margin-top: 0; letter-spacing: -.025em; }
h2 { font-size: clamp(1.45rem, 3vw, 1.75rem); border-bottom: 1px solid var(--line); padding-bottom: .3em; }
h3 { font-size: clamp(1.2rem, 2.2vw, 1.35rem); }
h4 { font-size: 1.08rem; }

p, ul, ol, blockquote, figure, pre, table { margin: 0 0 1.1em; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color .15s ease;
}
a:hover, a:focus-visible { color: var(--accent-hover); text-decoration-thickness: 2px; }

a:focus-visible, button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

strong { font-weight: 700; }
em { font-style: italic; }

blockquote {
  border-left: 3px solid var(--accent);
  padding: .1em 0 .1em 1.2em;
  color: var(--muted);
  font-style: italic;
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: .92em;
  background: var(--code-bg);
  padding: .12em .4em;
  border-radius: 3px;
}

pre { background: var(--code-bg); padding: 1em; overflow-x: auto; border-radius: var(--radius); }
pre code { background: transparent; padding: 0; }

ul, ol { padding-left: 1.4em; }
li { margin-bottom: .35em; }
li > ul, li > ol { margin-top: .35em; margin-bottom: .5em; }

hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }

figure { margin: 1.5em 0; }
figcaption { color: var(--muted); font-size: .88em; margin-top: .5em; text-align: center; font-style: italic; }

img, svg, video { max-width: 100%; height: auto; display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .94em;
}
th, td { padding: .6em .8em; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 700; }

/* --- Skip link --- */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: .6em 1em;
  z-index: 100;
  text-decoration: none;
}
.skip:focus { left: 1em; top: 1em; }

/* --- Layout --- */
.wrap { width: 100%; max-width: var(--max-wide); margin: 0 auto; padding: 0 1.1em; }
.prose { max-width: var(--max-content); margin: 0 auto; }

main { flex: 1 0 auto; padding: 1.5em 0 4em; }

/* --- Header --- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(1.4) blur(6px);
  -webkit-backdrop-filter: saturate(1.4) blur(6px);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 1em;
  padding: .75em 1.1em;
}
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--fg);
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand:hover { color: var(--accent); }
.brand span { color: var(--accent); }

.nav {
  display: flex;
  gap: 1.1em;
  align-items: center;
  margin-left: auto;
}
.nav a {
  color: var(--fg);
  text-decoration: none;
  font-size: .96rem;
  padding: .25em 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover, .nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.nav-tools { display: flex; gap: .5em; align-items: center; }
.icon-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--fg);
  width: 36px; height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem;
  padding: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.hamburger { display: none; }

@media (max-width: 820px) {
  .hamburger { display: inline-flex; }
  .nav {
    position: fixed;
    inset: 56px 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 1em 1.3em;
    gap: .6em;
    margin-left: 0;
    transform: translateY(-120%);
    transition: transform .2s ease;
  }
  .nav.is-open { transform: translateY(0); box-shadow: var(--shadow); }
  .nav a { padding: .5em 0; border-bottom: 1px solid var(--line); }
  .nav a:last-of-type { border-bottom: 0; }
  .nav-tools { margin-left: auto; }
}

/* --- Hero / home --- */
.hero {
  padding: 3em 0 2.5em;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2.5em;
}
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.2rem); margin-bottom: .4em; }
.hero p.lede { font-size: 1.15rem; color: var(--muted); max-width: 60ch; }

/* --- Section grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.3em;
}
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2em 1.3em;
  background: var(--bg-elev);
  transition: border-color .15s ease, transform .15s ease;
  display: block;
  text-decoration: none;
  color: var(--fg);
}
.card:hover { border-color: var(--accent); color: var(--fg); }
.card h3 { margin: 0 0 .35em; font-size: 1.12rem; }
.card h3 a { text-decoration: none; color: inherit; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.card-tag {
  display: inline-block;
  font-size: .78rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .3em;
}

/* --- Breadcrumbs --- */
.breadcrumbs {
  font-size: .88rem;
  color: var(--muted);
  margin: 0 0 1.5em;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .4em;
}
.breadcrumbs li { margin: 0; }
.breadcrumbs li + li::before {
  content: "›";
  margin-right: .4em;
  color: var(--muted);
}
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs [aria-current="page"] { color: var(--fg); }

/* --- Article --- */
.article-meta {
  color: var(--muted);
  font-size: .9rem;
  margin: -.5em 0 1.8em;
}
.article-meta span + span::before { content: " · "; margin: 0 .3em; }

.article h2 + p,
.article h3 + p { margin-top: 0; }

.lede { font-size: 1.12rem; color: var(--muted); }

.callout {
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  padding: 1em 1.2em;
  margin: 1.6em 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout p:last-child { margin-bottom: 0; }
.callout strong { color: var(--accent); }

/* --- TOC --- */
.toc {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1em 1.3em;
  margin: 1.5em 0 2em;
  font-size: .94rem;
}
.toc-title {
  font-weight: 700;
  margin-bottom: .4em;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.toc ol, .toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { margin: .2em 0; }
.toc ol ol, .toc ul ul { padding-left: 1.1em; font-size: .95em; }
.toc a { color: var(--fg); text-decoration: none; }
.toc a:hover, .toc a.is-active { color: var(--accent); }

@media (min-width: 1080px) {
  .layout-with-toc {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 3em;
    align-items: start;
  }
  .toc-sticky {
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    font-size: .88rem;
    border: 0;
    background: transparent;
    padding: 0;
  }
  .toc-sticky .toc-title { margin-bottom: .7em; }
}

/* --- Related --- */
.related {
  margin-top: 3.5em;
  padding-top: 2em;
  border-top: 1px solid var(--line);
}
.related h2 { border: 0; padding: 0; margin: 0 0 1em; font-size: 1.2rem; }

/* --- References --- */
.references {
  margin-top: 2.5em;
  padding-top: 1.5em;
  border-top: 1px solid var(--line);
  font-size: .92rem;
}
.references h2 { font-size: 1.1rem; border: 0; padding: 0; margin: 0 0 .7em; }
.references ol { padding-left: 1.3em; color: var(--muted); }
.references li { margin-bottom: .4em; }
.references a { color: var(--muted); }
.references a:hover { color: var(--accent); }

/* --- FAQ --- */
.faq details {
  border-bottom: 1px solid var(--line);
  padding: .9em 0;
}
.faq details[open] summary { color: var(--accent); }
.faq summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  padding-right: 1.5em;
  position: relative;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  position: absolute;
  right: 0;
  font-weight: 400;
  font-size: 1.4em;
  line-height: 1;
  top: -.1em;
  transition: transform .15s ease;
}
.faq details[open] summary::after { content: "−"; }

/* --- Search --- */
.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 280px;
  margin: 0 .5em;
}
.search input {
  width: 100%;
  padding: .45em .7em;
  font-family: var(--font-mono);
  font-size: .85rem;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.search input:focus { border-color: var(--accent); outline: none; }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
  display: none;
  z-index: 60;
}
.search-results.is-open { display: block; }
.search-results a {
  display: block;
  padding: .7em 1em;
  text-decoration: none;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
}
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a.is-focused { background: var(--bg-elev); color: var(--accent); }
.search-results .sr-title { font-weight: 700; font-size: .95rem; }
.search-results .sr-snippet { color: var(--muted); font-size: .85rem; margin-top: .15em; }
.search-results .sr-empty { padding: 1em; color: var(--muted); text-align: center; }

@media (max-width: 820px) {
  .search { max-width: none; margin: 0; order: 3; flex-basis: 100%; }
}

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 2.5em 0 2em;
  margin-top: 3em;
  color: var(--muted);
  font-size: .92rem;
  background: var(--bg-elev);
}
.site-footer .wrap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2em;
}
.site-footer h4 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--fg);
  margin: 0 0 .7em;
}
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: .3em; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.site-footer .footer-bottom {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 1.2em;
  font-size: .85rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1em;
}

/* --- Index lists (section hubs) --- */
.index-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1em;
}
.index-list li {
  padding: .9em 1.1em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0;
  transition: border-color .15s ease;
}
.index-list li:hover { border-color: var(--accent); }
.index-list a { text-decoration: none; display: block; color: var(--fg); }
.index-list a:hover { color: var(--accent); }
.index-list strong { display: block; margin-bottom: .15em; }
.index-list span { color: var(--muted); font-size: .9rem; }

/* --- Glosario --- */
.glossary dt { font-weight: 700; margin-top: 1.3em; font-size: 1.05rem; }
.glossary dd { margin: .2em 0 0; color: var(--fg); }
.glossary-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .3em;
  margin: 1em 0 2em;
  padding: .8em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.glossary-nav a {
  display: inline-block;
  padding: .2em .5em;
  text-decoration: none;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: .9rem;
}
.glossary-nav a:hover { color: var(--accent); }

/* --- Utility --- */
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.hide-sm { display: none; }
@media (min-width: 700px) { .hide-sm { display: inline; } }

/* 404 */
.error-page { text-align: center; padding: 4em 0; }
.error-page h1 { font-size: 6rem; margin: 0; color: var(--accent); letter-spacing: -.05em; }
.error-page h2 { border: 0; padding: 0; font-size: 1.5rem; font-weight: 400; }
