/* ==========================================================================
   style.css — Main stylesheet for the Flask blog
   ==========================================================================
   Structure:
     1. CSS custom properties (design tokens)
     2. Reset & base styles
     3. Layout utilities
     4. Site header
     5. Site footer
     6. Home page — post list & cards
     7. Post page — full article
     8. 404 page
     9. Responsive adjustments
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. CSS Custom Properties
   These variables make it easy to change the colour palette or typography
   in one place and have the changes cascade through the whole stylesheet.
   -------------------------------------------------------------------------- */
:root {
  /* Colours */
  --color-bg:          #fafaf8;   /* warm off-white page background          */
  --color-surface:     #ffffff;   /* card / post backgrounds                 */
  --color-border:      #e8e6e0;   /* subtle divider lines                    */
  --color-text:        #2c2c2c;   /* primary body text                       */
  --color-muted:       #6b6b6b;   /* secondary / metadata text               */
  --color-accent:      #2563eb;   /* links and interactive elements (blue)   */
  --color-accent-dark: #1d4ed8;   /* hover state for links                   */
  --color-heading:     #1a1a1a;   /* headings                                */

  /* Typography */
  --font-sans:   'Georgia', 'Times New Roman', serif; /* body / reading font */
  --font-ui:     system-ui, -apple-system, sans-serif; /* UI chrome          */
  --font-mono:   'Courier New', Courier, monospace;    /* code blocks        */

  --text-base:   1.125rem;   /* 18px — comfortable reading size              */
  --text-sm:     0.9rem;
  --text-xs:     0.8rem;
  --line-height: 1.75;       /* generous line-height for long-form reading   */

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  2rem;
  --space-xl:  4rem;

  /* Layout */
  --max-width:  700px;   /* keeps line lengths comfortable for reading       */
  --radius:     6px;     /* border-radius for cards and code blocks          */
}


/* --------------------------------------------------------------------------
   2. Reset & Base Styles
   Minimal reset so we start from a consistent baseline across browsers.
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px; /* 1rem = 16px */
  scroll-behavior: smooth;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height);
  min-height: 100vh;
  /* Stack the layout: header → main → footer */
  display: flex;
  flex-direction: column;
}

/* Make the main content grow to push the footer to the bottom */
main {
  flex: 1;
}

/* Base link styles */
a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--color-accent-dark);
  text-decoration: underline;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-heading);
  font-family: var(--font-ui);
  line-height: 1.3;
}

/* Images should never overflow their container */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Inline code */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-border);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}


/* --------------------------------------------------------------------------
   3. Layout Utilities
   .container centres content and caps its width at --max-width.
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;          /* horizontally centres the container */
  padding-inline: var(--space-lg);
}


/* --------------------------------------------------------------------------
   4. Site Header
   -------------------------------------------------------------------------- */
.site-header {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding-block: var(--space-md);

  /* Keep the header sticky at the top as the user scrolls */
  position: sticky;
  top: 0;
  z-index: 10;
}

/* The .container inside the header uses flexbox to space the logo and nav */
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

/* Blog name / logo */
.site-title {
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-heading);
  text-decoration: none;
  letter-spacing: -0.02em;
}

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

/* Navigation links */
.site-nav {
  display: flex;
  gap: var(--space-lg);
}

.site-nav a {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-muted);
}

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


/* --------------------------------------------------------------------------
   5. Site Footer
   -------------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding-block: var(--space-lg);
  margin-top: var(--space-xl);
}

.site-footer p {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-muted);
  text-align: center;
}


/* --------------------------------------------------------------------------
   6. Home Page — Post List & Cards
   -------------------------------------------------------------------------- */

/* Page heading area */
.page-header {
  padding-block: var(--space-xl) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-xl);
}

.page-header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-sm);
}

/* A short intro paragraph below the heading */
.lead {
  font-size: 1.1rem;
  color: var(--color-muted);
}

/* Vertical list of post cards */
.post-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  padding-bottom: var(--space-xl);
}

/* Individual post card */
.post-card {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-xl);
}

.post-card:last-child {
  border-bottom: none; /* remove divider after the final card */
}

/* Post title on the card */
.post-card__title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-xs);
}

.post-card__title a {
  color: var(--color-heading);
  text-decoration: none;
}

.post-card__title a:hover {
  color: var(--color-accent);
}

/* Publication date */
.post-card__date {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-bottom: var(--space-sm);
}

/* Short description / excerpt */
.post-card__description {
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

/* "Read more →" link */
.read-more {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-accent);
}

/* Empty-state message when there are no posts */
.empty-state {
  color: var(--color-muted);
  font-style: italic;
  padding-block: var(--space-xl);
  text-align: center;
}


/* --------------------------------------------------------------------------
   7. Post Page — Full Article
   -------------------------------------------------------------------------- */
.post {
  padding-block: var(--space-xl);
}

/* Post header section */
.post__header {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.post__title {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-sm);
}

.post__date {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-bottom: var(--space-sm);
}

.post__description {
  font-size: 1.1rem;
  color: var(--color-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Post body typography
   These styles apply to the HTML that the markdown library generates, so
   we scope them under .post__body.
   -------------------------------------------------------------------------- */
.post__body {
  /* Add vertical rhythm between all direct children */
}

.post__body > * + * {
  margin-top: var(--space-md);
}

/* Paragraphs */
.post__body p {
  margin-top: var(--space-md);
}

/* Headings inside the post body */
.post__body h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
}

.post__body h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-xs);
}

/* Lists */
.post__body ul,
.post__body ol {
  padding-left: 1.5rem;
  margin-top: var(--space-md);
}

.post__body li + li {
  margin-top: var(--space-xs);
}

/* Block quotes */
.post__body blockquote {
  border-left: 4px solid var(--color-accent);
  padding: var(--space-sm) var(--space-lg);
  margin-block: var(--space-lg);
  color: var(--color-muted);
  font-style: italic;
  background: var(--color-border);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* Fenced code blocks */
.post__body pre {
  background: #1e1e1e;           /* dark background for code contrast        */
  color: #d4d4d4;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  padding: var(--space-lg);
  border-radius: var(--radius);
  overflow-x: auto;              /* horizontal scroll for long lines         */
  margin-block: var(--space-lg);
}

/* Reset the inline code style inside a pre block */
.post__body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Horizontal rules */
.post__body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin-block: var(--space-xl);
}

/* Tables */
.post__body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  margin-block: var(--space-lg);
}

.post__body th,
.post__body td {
  border: 1px solid var(--color-border);
  padding: var(--space-sm) var(--space-md);
  text-align: left;
}

.post__body th {
  background: var(--color-border);
  font-weight: 600;
}

.post__body tr:nth-child(even) {
  background: #f5f5f3; /* subtle row striping for readability */
}

/* Post footer — "← Back" link */
.post__footer {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.back-link {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-muted);
}

.back-link:hover {
  color: var(--color-accent);
}


/* --------------------------------------------------------------------------
   8. 404 Page
   -------------------------------------------------------------------------- */
.error-page {
  text-align: center;
  padding-block: var(--space-xl);
}

.error-page h1 {
  font-size: 6rem;
  font-weight: 700;
  color: var(--color-border);
  line-height: 1;
  margin-bottom: var(--space-md);
}

.error-page p {
  color: var(--color-muted);
  margin-bottom: var(--space-lg);
}


/* --------------------------------------------------------------------------
   9. Responsive Adjustments
   Shrink font sizes and spacing on smaller screens.
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root {
    --text-base: 1rem;
  }

  .container {
    padding-inline: var(--space-md);
  }

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

  .post__title {
    font-size: 1.75rem;
  }

  .post-card__title {
    font-size: 1.3rem;
  }

  .site-header .container {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }
}
