/* ===========================
   Cleartext — Custom Theme
   Matches luisepastor.me design
   =========================== */

/* --- CSS Custom Properties --- */
:root {
  --max-width: 700px;
  --page-padding: 24px;
  --section-spacing: 48px;
  --post-gap: 32px;

  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  --font-size-body: 18px;
  --font-size-body-mobile: 16px;
  --line-height: 1.7;

  /* Light mode (default) */
  --bg-primary: #f5f5f5;
  --bg-secondary: #ebebeb;
  --text-primary: #1a1a1a;
  --text-secondary: #6b7280;
  --accent: #2a5298;
  --border: #e5e7eb;
  --code-bg: #e8e8e8;
}

[data-theme="dark"] {
  --bg-primary: #343434;
  --bg-secondary: #2a2a2a;
  --text-primary: #e5e5e5;
  --text-secondary: #9ca3af;
  --accent: #667eea;
  --border: #4a4a4a;
  --code-bg: #2a2a2a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #343434;
    --bg-secondary: #2a2a2a;
    --text-primary: #e5e5e5;
    --text-secondary: #9ca3af;
    --accent: #667eea;
    --border: #4a4a4a;
    --code-bg: #2a2a2a;
  }
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size-body);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color 0.2s ease, color 0.2s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--page-padding);
  width: 100%;
}

main {
  flex: 1;
  padding: var(--section-spacing) 0;
}

/* --- Links --- */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

h1 { font-size: 1.78rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.17rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 1.5em; }

blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1.2em;
  margin: 1.5em 0;
  color: var(--text-secondary);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--section-spacing) 0;
}

ul, ol {
  padding-left: 1.5em;
  margin-bottom: 1.5em;
}

li { margin-bottom: 0.4em; }

img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* --- Code --- */
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1.2em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5em 0;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.83rem;
}

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  transition: background 0.2s ease, border-color 0.2s ease;
}

[data-theme="dark"] .site-header {
  background: rgba(29, 29, 29, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-header {
    background: rgba(29, 29, 29, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-brand a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
  text-decoration: none;
  transition: opacity 0.2s;
}

.site-brand a:hover {
  opacity: 0.8;
  text-decoration: none;
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.site-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  line-height: 1;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-nav a {
  font-size: 0.88rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s;
  font-weight: 500;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--text-primary);
  text-decoration: none;
}

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.theme-toggle:hover { color: var(--text-primary); }

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

[data-theme="dark"] .theme-toggle .icon-sun  { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun  { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: inline; }

:root:not([data-theme]) .theme-toggle .icon-sun  { display: none; }
:root:not([data-theme]) .theme-toggle .icon-moon { display: inline; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun  { display: inline; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
}

/* --- Mobile Menu --- */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.5rem;
  padding: 4px;
  line-height: 1;
}

@media (max-width: 640px) {
  .header-container {
    flex-wrap: wrap;
    padding: 1rem 1.5rem;
  }

  .menu-toggle { display: block; }

  .site-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
  }

  .site-nav.open { display: flex; }
  .site-nav a { font-size: 1rem; }

  html { font-size: var(--font-size-body-mobile); }
}

@media (min-width: 641px) {
  :root { --page-padding: 32px; }
}

/* --- Post Feed --- */
.post-feed {
  list-style: none;
  padding: 0;
}

.post-entry {
  padding: var(--post-gap) 0;
  border-bottom: 1px solid var(--border);
}

.post-entry:first-child { padding-top: 0; }
.post-entry:last-child  { border-bottom: none; }

.post-entry-title {
  font-size: 1.11rem;
  font-weight: 600;
  margin: 0 0 0.3em;
  line-height: 1.3;
}

.post-entry-title a {
  color: var(--text-primary);
  text-decoration: none;
}

.post-entry-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.post-entry-excerpt {
  color: var(--text-secondary);
  font-size: 0.89rem;
  margin-bottom: 0.5em;
  line-height: 1.5;
}

.post-entry-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

/* --- Single Post --- */
.post-header { margin-bottom: 2rem; }

.post-title {
  font-size: 1.78rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

.post-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.post-meta .separator { color: var(--border); }

.post-content { margin-bottom: var(--section-spacing); }

.post-content h1 { font-size: 1.56rem; }
.post-content h2 { font-size: 1.33rem; margin-top: 2.5em; }
.post-content h3 { font-size: 1.11rem; margin-top: 2em; }

.post-content a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.post-content a:hover { color: var(--text-primary); }

/* --- Post Tags --- */
.post-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 2rem 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.post-tags a {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 3px 10px;
  border-radius: 3px;
  text-decoration: none;
  transition: color 0.15s;
}

.post-tags a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* --- Post Navigation --- */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  font-size: 0.89rem;
}

.post-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  max-width: 48%;
}

.post-nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

.post-nav .nav-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 4px;
}

/* --- Subscribe CTA --- */
.subscribe-cta {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 2rem;
  margin: var(--section-spacing) 0;
  text-align: center;
}

.subscribe-cta p {
  color: var(--text-secondary);
  font-size: 0.89rem;
  margin-bottom: 1rem;
}

.subscribe-cta a {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1.5rem;
  border-radius: 5px;
  font-size: 0.89rem;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

.subscribe-cta a:hover {
  opacity: 0.9;
  text-decoration: none;
}

/* --- Archive --- */
.archive-year { margin-bottom: 2.5rem; }

.archive-year h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 0;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.archive-list {
  list-style: none;
  padding: 0;
}

.archive-item {
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.89rem;
}

.archive-item:last-child { border-bottom: none; }

.archive-date {
  color: var(--text-secondary);
  font-size: 0.75rem;
  white-space: nowrap;
  min-width: 60px;
}

.archive-title a {
  color: var(--text-primary);
  text-decoration: none;
}

.archive-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: space-between;
  padding-top: 2rem;
  font-size: 0.89rem;
}

.pagination a { color: var(--text-secondary); }
.pagination a:hover { color: var(--accent); }

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 4rem 0 2rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  background-color: var(--bg-secondary);
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.footer-columns {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 3rem;
  margin-bottom: 3rem;
}

.footer-col h4 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 1rem;
}

.footer-col p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin: 0;
  line-height: 1.6;
}

.footer-col a {
  display: block;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
  transition: color 0.15s;
}

.footer-col a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.footer-bottom {
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-bottom p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .footer-columns {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .footer-container {
    padding: 0 1.5rem;
  }
}
