/* ==========================================================================
   1. VARIABLES & RESETS
   ========================================================================== */
:root {
  --max-width: 798px;
  --sidebar-width: 140px;
  --gap: 40px;
  
  /* Modern Typographic Scale & Colors */
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --color-text: #1f2937;
  --color-text-muted: #4b5563;
  --color-link: #2563eb;
  --color-border: #e5e7eb;
  --color-bg-alt: #f9fafb;
}

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

html {
  scroll-behavior: smooth; /* Smooth scroll when clicking Archives link */
}

body {
  font-family: var(--font-main);
  color: var(--color-text);
  line-height: 1.6;
  background-color: #ffffff;
}

/* ==========================================================================
   2. GLOBAL / BASE STYLES
   ========================================================================== */
a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4, h5, h6 {
  color: #111827;
  font-weight: 700;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

h1:first-child, h2:first-child, h3:first-child {
  margin-top: 0;
}

/* Base Lists for Content Areas */
ul, ol {
  margin-bottom: 1.25rem;
  padding-left: 1.25rem;
}

ul {
  list-style: disc;
}

ol {
  list-style: decimal;
}

li {
  margin-bottom: 0.35rem;
}

p {
  margin-bottom: 1.25rem;
}

p:last-child,
ul:last-child,
ol:last-child {
  margin-bottom: 0;
}

blockquote {
  margin: 1.5rem 30px;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ==========================================================================
   3. LAYOUT / CONTAINERS
   ========================================================================== */
body {
  display: grid;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 20px;
  
  grid-template-areas: 
    "header  header"
    "content sidebar"
    "footer  footer";
    
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  column-gap: var(--gap);
  row-gap: 40px;
  width: 100%;
}

.site-header {
  grid-area: header;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 12px;       /* Reduced bottom padding */
  display: flex;
  flex-direction: column;
  gap: 4px;                   /* Tightened gap between site title and nav */
}

.site-title {
  margin-bottom: 0;           /* Resets bottom margin on title heading */
}

.site-title a {
  color: #111827;
  text-decoration: none;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;           /* Tightens line height to pull nav closer */
}

main {
  grid-area: content;
}

.site-sidebar {
  grid-area: sidebar;
  padding-top: 10px;
}

.site-footer {
  grid-area: footer;
  border-top: 1px solid var(--color-border);
  padding-top: 20px;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  text-align: center;
}

/* ==========================================================================
   4. BUCKETS & ENTRIES (Common Core)
   ========================================================================== */

/* --- Buckets --- */
.calendar-stream {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.bucket {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Bucket Headers & Titles */
.bucket header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.calendar-stream header h2,
.bucket header h2 {
  font-size: 1.85rem;
  line-height: 1.2;
  color: #111827;
  letter-spacing: -0.02em;
}

.calendar-stream header h2 a,
.bucket header h2 a {
  color: inherit;
  text-decoration: none;
}

.calendar-stream header h2 a:hover,
.bucket header h2 a:hover {
  color: var(--color-link);
}

.bucket header h3 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.bucket-body {
  display: flex;
  flex-direction: column;
  gap: 30px;
  list-style: none;
  padding-left: 0;
}

.bucket-body--list a {
  padding-left: 5px;
}

/* --- Agnostic Entries --- */
.entry {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.entry-title {
  font-size: 1.9rem;
}

.entry-title a {
  font-size: 1.6rem;
  line-height: 1.3;
  color: #111827;
  font-weight: 600;
}

.entry-content {
  font-size: 1.05rem;
}

.entry-content p + p {
  margin-top: 1rem;
}

.entry-content a {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entry-content img {
  width: 92%;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px; 
}

/* Default for images inside <details>: Left-aligned and sized correctly */
.entry-content details img {
  width: auto;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.75rem 0; /* Left aligned (no auto margins) */
  border-radius: 4px;
}

/* Utility class to explicitly center any image */
.entry-content img.align-center,
.entry-content details img.align-center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* --- Entry List Item Tweaks --- */
.entry-list-date {
  color: var(--color-text-muted);
}

.bucket--list .bucket-body > *:not(:last-child) {
  position: relative;
}

.bucket--list .bucket-body > *:not(:last-child)::after {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 0px;
  right: 16px;
  border-bottom: 1px solid var(--color-border);
}

/* --- Entry Footer & Metadata --- */
.entry-footer {
  margin-top: 12px;
  display: flex;
  flex-direction: column;   /* Stacks meta and tags on separate lines */
  align-items: flex-end;    /* Aligns both blocks to the right */
  gap: 6px;                 /* Spacing between the date line and tag line */
  text-align: right;
}

.entry-meta {
  color: var(--color-text-muted);
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end; /* Ensures tags align right if they wrap */
  gap: 8px;
}

.entry-tag {
  font-size: 0.85rem;
  font-weight: 500;
  color: #374151;
  background-color: #f3f4f6;
  padding: 2px 10px;
  border-radius: 4px;
}

.index-status {
  margin-top: 60px;
  padding: 20px;
  background-color: var(--color-bg-alt);
  border-radius: 6px;
  font-size: 0.95rem;
}

/* ==========================================================================
   5. NAVIGATION COMPONENTS
   ========================================================================== */

/* --- Header Navigation --- */
.header-nav {
  margin-top: 0;
}

.header-nav-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.header-nav-list li {
  margin-bottom: 0;
  list-style: none;
}

.header-nav-list a {
  font-weight: 600;
  color: var(--color-text);
  font-size: 0.95rem;
}

.header-nav-list a:hover {
  color: var(--color-link);
}

/* Hidden on desktop/large screens by default */
.header-nav-link--archives {
  display: none;
  color: var(--color-link);
}

/* --- Sidebar Navigation --- */
.sidebar-nav-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 18px;
}

.sidebar-nav-body ul {
  display: flex;
  flex-direction: column;
  gap: 12px;
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.sidebar-nav-body li {
  margin-bottom: 0;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
}

.sidebar-nav-body a {
  display: inline-block;
  padding: 4px 0;
  color: var(--color-text);
  transition: color 0.15s ease-in-out;
}

.sidebar-nav-body a:hover {
  color: var(--color-link);
  text-decoration: none;
}

/* Sub-items (Calendar Tree) Indentation */
.sidebar-nav-body ul ul,
.sidebar-nav-body ul.nav-tree,
.sidebar-nav-body ul.nav-months,
.sidebar-nav-body ul.nav-days {
  margin-top: 8px;
  margin-bottom: 4px;
  padding-left: 16px;
  gap: 8px;
  border-left: 2px solid var(--color-border);
}

.sidebar-nav-body li.is-active > a {
  font-weight: 700;
  color: var(--color-link);
}

.sidebar-back-to-top {
  display: none;
  margin-top: 24px;
  padding-top: 16px;
  text-align: center; /* Centers the link when displayed */
}

.back-to-top-link {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-link);
  display: inline-block; /* Helps with clean touch target alignment */
}

/* ==========================================================================
   6. RESPONSIVE LAYOUT OVERRIDES
   ========================================================================== */

/* --- Tablet & Mobile: Stack Layout --- */
@media (max-width: 850px) {
  body {
    grid-template-areas: 
      "header"
      "content"
      "sidebar"
      "footer";
    grid-template-columns: 1fr;
    row-gap: 40px;
    padding: 30px 20px;
  }

  /* Center the main site header title and top nav items */
  .site-title {
    text-align: center;
  }

  .header-nav-list {
    justify-content: center;
  }

  main, 
  .site-sidebar {
    grid-column: 1 / -1;
  }
  
  main {
    order: 1;
  }
  
  .site-sidebar {
    order: 2; 
    border-top: 2px solid var(--color-border);
    padding-top: 30px;
  }

  /* --- Center Sidebar Heading & Main Menu Items --- */
  .sidebar-nav-header {
    text-align: center;
  }

  /* Centers the primary top-level navigation list */
  .sidebar-nav-body > section > ul {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-left: 0;
  }

  .sidebar-nav-body > section > ul > li {
    text-align: center;
    width: 100%;
  }

  /* --- Preserve Tree Hierarchy for Nested Sub-Lists --- */
  .sidebar-nav-body ul ul,
  .sidebar-nav-body ul.nav-tree,
  .sidebar-nav-body ul.nav-months,
  .sidebar-nav-body ul.nav-days {
    display: flex;
    flex-direction: column;
    align-items: flex-start;  /* Keeps sub-items left-aligned */
    text-align: left;
    margin-left: auto;
    margin-right: auto;
    max-width: max-content;   /* Keeps the left border snugly attached to the nested list */
  }

  /* Show Archives jump link when sidebar collapses to bottom */
  .header-nav-link--archives {
    display: inline;
  }

  .sidebar-back-to-top {
    display: block;
    text-align: center;
  }
}

/* --- Micro-Screens (Under 450px): Fine-Tuning --- */
@media (max-width: 450px) {
  body {
    padding: 15px 12px;
  }

  .site-title a {
    font-size: 1.85rem;
  }

  .entry-title {
    font-size: 1.35rem;
  }
}
