/* Tomás B. Fiction — Static Mirror */

:root {
  --bg: #fcfbf9;
  --text: #1a1a1a;
  --text-light: #7a7570;
  --accent: #8b4513;
  --border: #e8e4de;
  --sidebar-bg: #f5f2ed;
  --sidebar-width: 260px;
  --active-bg: #ebe7e0;
  --link: #6b3a2e;
  --max-prose: 38rem;
  --serif: Charter, 'Bitstream Charter', 'Noto Serif', 'DejaVu Serif', 'Liberation Serif', Georgia, serif;
  --sans: -apple-system, 'Segoe UI', system-ui, 'Noto Sans', 'DejaVu Sans', 'Liberation Sans', sans-serif;
  --radius: 6px;
}

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

html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--serif);
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  display: flex;
  min-height: 100vh;
}

::selection {
  background: rgba(139, 69, 19, 0.15);
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  position: fixed;
  top: 3rem;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.78rem;
  z-index: 10;
}

.sidebar-header {
  padding: 0 1.4rem 1.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.site-title {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.site-title:hover { color: var(--accent); }

.site-subtitle {
  display: block;
  color: var(--text-light);
  font-size: 0.8rem;
  margin-top: 0.2rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sort-toggle {
  display: flex;
  gap: 0;
  padding: 0.6rem 1.4rem 0.5rem;
}

.sort-btn {
  flex: 1;
  padding: 0.3rem 0;
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sort-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.sort-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.sort-btn.active {
  background: var(--active-bg);
  color: var(--accent);
}
.sort-btn:hover:not(.active) {
  background: var(--active-bg);
}

.nav-section h3 {
  padding: 0.8rem 1.4rem 0.3rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-light);
  font-weight: 600;
}

.nav-section ul {
  list-style: none;
}

.nav-section li a {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  padding: 0.35rem 1.4rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}

.nav-section li a:hover {
  background: var(--active-bg);
  color: var(--accent);
}

.nav-section li a.active {
  background: var(--active-bg);
  font-weight: 600;
  color: var(--accent);
}

.nav-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Top bar --- */
.top-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 3rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 15;
  font-family: var(--sans);
  gap: 1rem;
}

.top-bar-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  display: none;
}

.top-bar-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.top-bar-btn {
  padding: 0.35rem 0.9rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg);
}
.top-bar-btn:hover {
  background: var(--sidebar-bg);
  color: var(--accent);
}

.top-bar-btn-primary {
  background: #a0734f;
  color: #fff;
  border-color: #a0734f;
}
.top-bar-btn-primary:hover {
  background: #8b6243;
  border-color: #8b6243;
  color: #fff;
}

.sidebar-footer {
  padding: 1.5rem 1.4rem 0;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.lw-link {
  font-size: 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  transition: color 0.15s;
}
.lw-link:hover { color: var(--accent); }

/* --- Main --- */
main {
  margin-left: var(--sidebar-width);
  margin-top: 3rem;
  flex: 1;
  padding: 3rem 2.5rem 6rem;
  display: flex;
  justify-content: center;
}

article, .index-page {
  max-width: var(--max-prose);
  width: 100%;
}

/* --- Post --- */
.post-header {
  margin-bottom: 3rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.post-header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 0.6rem;
}

.post-meta {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-light);
  letter-spacing: 0.01em;
}

.post-body p {
  margin-bottom: 1.3em;
  hanging-punctuation: first last;
}

.post-body blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 1.4em;
  margin: 1.8em 0;
  color: var(--text-light);
  font-style: italic;
}

.post-body h2, .post-body h3 {
  margin: 2.2em 0 0.8em;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.post-body h2 { font-size: 1.4rem; }
.post-body h3 { font-size: 1.15rem; }

.post-body a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(107, 58, 46, 0.3);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}
.post-body a:hover {
  text-decoration-color: var(--link);
}

.post-body hr {
  border: none;
  text-align: center;
  margin: 3em 0;
}
.post-body hr::before {
  content: '\2022\2003\2022\2003\2022';
  color: var(--text-light);
  font-size: 0.85rem;
}

.post-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.post-body pre, .post-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.85em;
}

.post-body pre {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  padding: 1.2em;
  overflow-x: auto;
  border-radius: var(--radius);
  margin: 1.8em 0;
}

.post-body code {
  background: var(--sidebar-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.post-body pre code {
  background: none;
  padding: 0;
}

.post-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-light);
}

.post-footer a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(107, 58, 46, 0.3);
  text-underline-offset: 2px;
}
.post-footer a:hover {
  text-decoration-color: var(--link);
}

.post-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.post-nav-link {
  font-size: 0.85rem;
  font-weight: 600;
}

.post-nav-next {
  text-align: right;
}

/* --- Index page --- */
.index-page h1 {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
  letter-spacing: -0.02em;
}

.index-intro {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.index-list {
  list-style: none;
}

.index-item a {
  display: block;
  padding: 1rem 0.8rem;
  margin: 0 -0.8rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.15s;
}

.index-item:first-child a {
  border-top: 1px solid var(--border);
}

.index-item a:hover {
  background: var(--sidebar-bg);
}

.index-title {
  display: block;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}

.index-meta {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.2rem;
}

/* --- Mobile overlay for closing sidebar --- */
.menu-overlay {
  display: none;
}

/* --- Mobile hamburger (in top bar) --- */
.menu-button {
  display: none;
  background: none;
  border: none;
  width: 2rem;
  height: 2rem;
  padding: 0;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 2rem;
  text-align: center;
  color: var(--text);
  flex-shrink: 0;
}
.menu-button:hover {
  color: var(--accent);
}

@media (max-width: 860px) {
  .menu-button { display: block; }
  .top-bar-title { display: block; }

  .top-bar {
    left: 0;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
    top: 3rem;
    height: calc(100vh - 3rem);
  }

  #menu-toggle:checked ~ .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.08);
  }

  #menu-toggle:checked ~ .menu-overlay {
    display: block;
    position: fixed;
    inset: 0;
    top: 3rem;
    z-index: 5;
    background: rgba(0,0,0,0.15);
  }

  main {
    margin-left: 0;
    padding: 2rem 1.5rem 4rem;
  }

  .post-header h1, .index-page h1 {
    font-size: 1.75rem;
  }
}

@media (max-width: 520px) {
  html { font-size: 17px; }

  .top-bar-btn { padding: 0.3rem 0.6rem; font-size: 0.7rem; }

  main {
    padding: 1.5rem 1.2rem 3rem;
  }

  .post-header {
    margin-bottom: 2rem;
  }

  .post-header h1, .index-page h1 {
    font-size: 1.55rem;
  }

  .post-body blockquote {
    margin-left: 0;
    padding-left: 1em;
  }

  .index-item a {
    padding: 0.8rem 0.6rem;
    margin: 0 -0.6rem;
  }
}

/* Low-res screens: swap serif for more legible sans */
@media (max-resolution: 1.5dppx) {
  :root {
    --serif: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', 'DejaVu Sans', 'Liberation Sans', sans-serif;
  }
  body { line-height: 1.7; }
}

/* --- Dark mode --- */
[data-theme="dark"] {
  --bg: #1a1a1e;
  --text: #e0ddd8;
  --text-light: #9a9590;
  --accent: #c8956a;
  --border: #2e2e33;
  --sidebar-bg: #222226;
  --active-bg: #2a2a2f;
  --link: #c8956a;
}

[data-theme="dark"] ::selection {
  background: rgba(200, 149, 106, 0.25);
}

[data-theme="dark"] .top-bar-btn-primary {
  background: #a0734f;
  border-color: #a0734f;
}
[data-theme="dark"] .top-bar-btn-primary:hover {
  background: #8b6243;
  border-color: #8b6243;
}

[data-theme="dark"] .post-body a {
  text-decoration-color: rgba(200, 149, 106, 0.3);
}
[data-theme="dark"] .post-body a:hover {
  text-decoration-color: var(--link);
}
[data-theme="dark"] .post-footer a {
  text-decoration-color: rgba(200, 149, 106, 0.3);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #1a1a1e;
    --text: #e0ddd8;
    --text-light: #9a9590;
    --accent: #c8956a;
    --border: #2e2e33;
    --sidebar-bg: #222226;
    --active-bg: #2a2a2f;
    --link: #c8956a;
  }
  [data-theme="auto"] ::selection {
    background: rgba(200, 149, 106, 0.25);
  }
  [data-theme="auto"] .top-bar-btn-primary {
    background: #a0734f;
    border-color: #a0734f;
  }
  [data-theme="auto"] .top-bar-btn-primary:hover {
    background: #8b6243;
    border-color: #8b6243;
  }
  [data-theme="auto"] .post-body a {
    text-decoration-color: rgba(200, 149, 106, 0.3);
  }
  [data-theme="auto"] .post-body a:hover {
    text-decoration-color: var(--link);
  }
  [data-theme="auto"] .post-footer a {
    text-decoration-color: rgba(200, 149, 106, 0.3);
  }
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover {
  background: var(--sidebar-bg);
  color: var(--accent);
}

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