/* Accessibility-first stylesheet.
   The whole point of this site is to NOT be the cautionary tale it describes,
   so: real focus styles, AAA-ish contrast, no color-only signals, motion opt-out. */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;          /* ~16:1 on white */
  --fg-muted: #4a4a4a;    /* ~8.9:1 on white */
  --link: #00449e;        /* ~8.6:1 on white */
  --link-hover: #002d6b;
  --accent: #00449e;
  --accent-contrast: #ffffff;
  --border: #c9c9c9;
  --surface: #f4f6fa;
  --focus: #b8004f;       /* high-contrast magenta, visible on light + surfaces */
  --error: #b00020;
  --ok-bg: #d6f3df;
  --ok-fg: #0b5132;
  --draft-bg: #fde6c4;
  --draft-fg: #6b4a04;
  --maxw: 42rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --fg: #ececec;
    --fg-muted: #b9c2cc;
    --link: #94c0ff;        /* light blue on dark, high contrast */
    --link-hover: #c5dcff;
    --accent: #94c0ff;
    --accent-contrast: #0f1419;
    --border: #38424d;
    --surface: #182029;
    --focus: #ffd000;       /* bright yellow focus ring on dark */
    --error: #ff9aa6;
    --ok-bg: #11331f;
    --ok-fg: #9be8b8;
    --draft-bg: #3a2c0c;
    --draft-fg: #ffd98a;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1.125rem;
  line-height: 1.6;
}

/* ---- focus: visible, thick, never removed ---- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}
/* fallback for browsers without :focus-visible */
a:focus, button:focus, input:focus, textarea:focus, [tabindex]:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- skip link: hidden until focused, THEN in view (the book's case study) ---- */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  transform: translateY(-200%);
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.75rem 1rem;
  z-index: 100;
  text-decoration: underline;
}
.skip-link:focus {
  transform: translateY(0);
}

main:focus { outline: none; } /* focus moved here by skip link; no need to show a ring on the whole page */

/* ---- layout ---- */
.site-header {
  border-bottom: 2px solid var(--border);
  padding: 1rem;
}
.site-title { margin: 0 0 0.5rem; font-weight: 700; font-size: 1.25rem; }
.site-title a { color: var(--fg); text-decoration: none; }
.site-title a:hover, .site-title a:focus { text-decoration: underline; }

.site-header nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin: 0;
  padding: 0;
}
nav [aria-current="page"] { font-weight: 700; text-decoration: underline; }

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.site-footer {
  border-top: 2px solid var(--border);
  color: var(--fg-muted);
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.95rem;
}

/* ---- links & text ---- */
a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:hover, a:focus { color: var(--link-hover); }

h1 { font-size: 2rem; line-height: 1.2; }
h2 { font-size: 1.5rem; margin-top: 2.5rem; }
h3 { font-size: 1.25rem; }
h1, h2, h3, h4 { scroll-margin-top: 1rem; }

.subtitle { font-size: 1.2rem; color: var(--fg-muted); }
.post-meta, .post-tags { color: var(--fg-muted); font-size: 0.97rem; }

/* ---- post listing ---- */
.post-list ul { list-style: none; padding: 0; }
.post-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background: var(--surface);
}
.post-card h3 { margin: 0 0 0.25rem; }

/* ---- post body / prose ---- */
.post-body { overflow-wrap: break-word; }
.post-body p, .post-body li { line-height: 1.7; }
.post-body pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
}
.post-body code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.95em;
}
.post-body :not(pre) > code {
  background: var(--surface);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.post-body blockquote {
  border-left: 4px solid var(--accent);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--fg-muted);
}
.post-body table { border-collapse: collapse; width: 100%; }
.post-body th, .post-body td { border: 1px solid var(--border); padding: 0.5rem; text-align: left; }
.back-link { margin-top: 2rem; }

/* ---- forms ---- */
.form-wrap { max-width: 28rem; margin: 0 auto; }
.form-wrap-wide { max-width: 48rem; margin: 0 auto; }
.stacked-form .field { margin-bottom: 1.25rem; }
.stacked-form label, .stacked-form legend { display: block; font-weight: 600; margin-bottom: 0.35rem; }
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
textarea { line-height: 1.5; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--error); }

.field-help { color: var(--fg-muted); font-size: 0.95rem; margin: 0 0 0.35rem; }
.field-error { color: var(--error); font-weight: 600; margin: 0 0 0.35rem; }
.field-error::before { content: "⚠ "; } /* icon + text + border: never color alone */
.form-error {
  border: 2px solid var(--error);
  background: var(--surface);
  color: var(--error);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-weight: 600;
}
.form-ok {
  border: 2px solid var(--ok-fg);
  background: var(--ok-bg);
  color: var(--ok-fg);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-weight: 600;
}
.form-ok::before { content: "✓ "; }

fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; }
.radio { display: flex; align-items: center; gap: 0.5rem; margin: 0.4rem 0; }
.radio label { font-weight: 400; margin: 0; }
.radio input { width: auto; }

/* ---- buttons ---- */
.btn-primary, .btn-secondary, button[type="submit"] {
  font: inherit;
  cursor: pointer;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  border: 2px solid var(--accent);
}
.btn-primary, button[type="submit"] { background: var(--accent); color: var(--accent-contrast); }
.btn-secondary { background: var(--bg); color: var(--accent); }
.btn-primary:hover, .btn-secondary:hover, button[type="submit"]:hover { filter: brightness(1.08); }
.btn-link { display: inline-block; padding: 0.6rem 0.5rem; }
.form-buttons { display: flex; gap: 1rem; align-items: center; }
.logout-form { display: inline; margin: 0; }
.logout-form button {
  font: inherit; cursor: pointer; background: none; border: none;
  color: var(--link); text-decoration: underline; padding: 0;
}

/* ---- admin ---- */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.admin-table { border-collapse: collapse; width: 100%; margin-top: 1.5rem; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--border); padding: 0.6rem 0.5rem; text-align: left; }
.badge { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.85rem; font-weight: 700; }
.badge-pub { background: var(--ok-bg); color: var(--ok-fg); }
.badge-draft { background: var(--draft-bg); color: var(--draft-fg); }

.preview-area { margin-top: 2.5rem; border-top: 2px dashed var(--border); padding-top: 1.5rem; }
#preview:empty::after { content: "Aún no hay nada que previsualizar."; color: var(--fg-muted); }

/* ---- utilities ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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