/* ==========================================================================
   Editor Theme - Typography-Focused Minimalist Ghost Theme
   ========================================================================== */

/* ==========================================================================
   1. CSS Custom Properties
   ========================================================================== */

:root {
  /* Typography Scale (1.25 modular scale) */
  --font-size-xs: 1.28rem;
  --font-size-sm: 1.6rem;
  --font-size-base: 2rem;
  --font-size-lg: 2.5rem;
  --font-size-xl: 3.125rem;
  --font-size-2xl: 3.9rem;
  --font-size-3xl: 4.88rem;
  --font-size-4xl: 6.1rem;

  /* Font Families */
  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", Times, Georgia, serif;
  --font-heading: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, "Courier New", monospace;

  /* Line Heights */
  --line-height-tight: 1.2;
  --line-height-snug: 1.4;
  --line-height-normal: 1.7;
  --line-height-relaxed: 1.85;

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

  /* Layout */
  --content-width: 65ch;
  --content-width-wide: 90ch;

  /* Light Mode Colors (default) */
  --color-bg: #FDFCFB;
  --color-bg-secondary: #F5F3F0;
  --color-text-primary: #1A1A1A;
  --color-text-secondary: #6B6B6B;
  --color-text-tertiary: #9B9B9B;
  --color-border: #E8E5E1;
  --color-hr: #D4D0CC;
  --color-link-underline: #D4D0CC;
  --color-link-underline-hover: #1A1A1A;
  --color-code-bg: #F5F3F0;
}

/* Dark Mode */
.theme-dark {
  --color-bg: #161616;
  --color-bg-secondary: #1E1E1E;
  --color-text-primary: #E8E6E3;
  --color-text-secondary: #8A8A8A;
  --color-text-tertiary: #5A5A5A;
  --color-border: #2A2A2A;
  --color-hr: #3A3A3A;
  --color-link-underline: #4A4A4A;
  --color-link-underline-hover: #E8E6E3;
  --color-code-bg: #1E1E1E;
}

/* System preference dark mode (when no explicit theme set) */
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-dark) {
    --color-bg: #161616;
    --color-bg-secondary: #1E1E1E;
    --color-text-primary: #E8E6E3;
    --color-text-secondary: #8A8A8A;
    --color-text-tertiary: #5A5A5A;
    --color-border: #2A2A2A;
    --color-hr: #3A3A3A;
    --color-link-underline: #4A4A4A;
    --color-link-underline-hover: #E8E6E3;
    --color-code-bg: #1E1E1E;
  }
}

/* ==========================================================================
   2. Reset / Normalize
   ========================================================================== */

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

html {
  font-size: 62.5%; /* 1rem = 10px */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: var(--line-height-tight);
  margin: 0;
}

p, ul, ol, blockquote, pre, figure, table {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font: inherit;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

/* ==========================================================================
   3. Layout
   ========================================================================== */

.site-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.inner-wide {
  max-width: var(--content-width-wide);
}

/* ==========================================================================
   4. Header
   ========================================================================== */

.site-header {
  padding: var(--space-lg) 0;
}

.site-header .inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-md);
}

.site-title {
  font-family: var(--font-heading);
  font-size: var(--font-size-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-title a {
  color: var(--color-text-primary);
}

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

.site-nav a {
  font-family: var(--font-heading);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  transition: color 0.2s ease;
}

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

/* ==========================================================================
   5. Footer
   ========================================================================== */

.site-footer {
  margin-top: auto;
  padding: var(--space-xl) 0 var(--space-lg);
}

.site-footer .inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-lg);
}

.site-footer-text {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

/* Theme Toggle */
.theme-toggle {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  transition: color 0.2s ease;
}

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

/* ==========================================================================
   6. Index / Post Listing
   ========================================================================== */

.site-main {
  flex: 1;
}

.post-feed {
  list-style: none;
  padding: 0;
}

.post-card {
  margin-bottom: var(--space-lg);
}

.post-card-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.post-card-title a {
  color: var(--color-text-primary);
  background-image: linear-gradient(var(--color-link-underline), var(--color-link-underline));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s ease;
}

.post-card-title a:hover {
  background-size: 100% 1px;
}

.post-card-meta {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
}

/* Featured indicator */
.post-card-featured {
  font-style: italic;
  margin-left: var(--space-sm);
}

/* ==========================================================================
   7. Single Post
   ========================================================================== */

.post-header {
  padding: calc(var(--space-xl) + 2vw) 0 var(--space-lg);
  margin-bottom: var(--space-lg);
}

.post-meta {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
  margin-bottom: var(--space-md);
}

.post-title {
  font-size: var(--font-size-4xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: var(--line-height-tight);
}

/* ==========================================================================
   8. Post Content Typography
   ========================================================================== */

.post-content {
  padding-bottom: var(--space-xl);
}

/* Vertical rhythm - space between elements */
.post-content > * + * {
  margin-top: 1.7em;
}

/* Paragraphs */
.post-content p {
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
}

/* Headings in content */
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
  font-family: var(--font-heading);
  color: var(--color-text-primary);
  text-align: left;
}

.post-content h1 {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  margin-top: 1em;
  margin-bottom: 0.3em;
}

.post-content h2 {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  margin-top: 1em;
  margin-bottom: 0.3em;
}

.post-content h3 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  margin-top: 0.8em;
  margin-bottom: 0.3em;
}

.post-content h4 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-top: 0.8em;
  margin-bottom: 0.3em;
}

.post-content h5,
.post-content h6 {
  font-size: var(--font-size-base);
  font-weight: 600;
  margin-top: 0.6em;
  margin-bottom: 0.2em;
}

/* Links - subtle underline that thickens on hover */
.post-content a {
  color: inherit;
  background-image: linear-gradient(var(--color-link-underline), var(--color-link-underline));
  background-size: 100% 1px;
  background-position: 0 calc(100% - 2px);
  background-repeat: no-repeat;
  transition: background-size 0.2s ease, background-image 0.2s ease;
}

.post-content a:hover {
  background-image: linear-gradient(var(--color-link-underline-hover), var(--color-link-underline-hover));
  background-size: 100% 2px;
}

/* Lists */
.post-content ul,
.post-content ol {
  padding-left: 2.5em;
  margin-left: 0;
}

.post-content li {
  margin-bottom: 0.5em;
  padding-left: 0.5em;
}

.post-content li::marker {
  color: var(--color-text-tertiary);
}

/* Nested lists */
.post-content ul ul,
.post-content ol ol,
.post-content ul ol,
.post-content ol ul {
  margin-top: 0.5em;
  margin-bottom: 0;
}

/* Blockquotes - refined, no border */
.post-content blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: 3em;
  font-style: italic;
  color: var(--color-text-secondary);
  text-align: left;
  font-size: 1.05em;
  line-height: 1.75;
}

.post-content blockquote em {
  font-style: normal;
}

.post-content blockquote p {
  text-align: left;
}

/* Horizontal rules - elegant asterisks */
.post-content hr {
  border: none;
  text-align: center;
  margin: 3em 0;
}

.post-content hr::before {
  content: "* * *";
  letter-spacing: 1em;
  color: var(--color-text-tertiary);
  font-family: var(--font-body);
}

/* Code - inline */
.post-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.2em 0.4em;
  background-color: var(--color-code-bg);
  border-radius: 3px;
}

/* Code - blocks */
.post-content pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  padding: var(--space-md);
  background-color: var(--color-code-bg);
  border-radius: 4px;
  overflow-x: auto;
}

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

/* Images */
.post-content img {
  margin: var(--space-lg) auto;
  border-radius: 2px;
  width: 100%;
  height: auto;
}

.post-content figure {
  margin: var(--space-lg) 0;
}

.post-content figcaption {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  text-align: center;
  margin-top: var(--space-sm);
  font-style: italic;
  letter-spacing: 0.01em;
}

/* Wide images (Ghost editor: /wide) */
.post-content .kg-width-wide,
.post-content .kg-image-card.kg-width-wide {
  width: var(--content-width-wide);
  max-width: calc(100vw - 4rem);
  margin-left: 50%;
  transform: translateX(-50%);
}

.post-content .kg-width-wide img,
.post-content .kg-image-card.kg-width-wide img {
  width: 100%;
}

/* Full-bleed images (Ghost editor: /full) */
.post-content .kg-width-full,
.post-content .kg-image-card.kg-width-full {
  max-width: 100vw;
  margin-left: 50%;
  transform: translateX(-50%);
  width: 100vw;
}

.post-content .kg-width-full img {
  border-radius: 0;
}

/* Image cards (Ghost's native image block) */
.post-content .kg-image-card {
  margin: var(--space-lg) 0;
}

.post-content .kg-image {
  margin: 0 auto;
  display: block;
}

/* Image with caption */
.post-content .kg-image-card figcaption {
  padding: 0 var(--space-md);
  margin-top: var(--space-md);
}

/* Tables */
.post-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

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

.post-content th {
  font-family: var(--font-heading);
  font-weight: 600;
}

/* Drop Cap (optional, enabled via body class) */
.has-drop-cap .post-content > p:first-of-type::first-letter {
  float: left;
  font-size: 4em;
  line-height: 0.8;
  padding-right: 0.1em;
  padding-top: 0.05em;
  font-weight: 400;
  color: var(--color-text-primary);
}

/* ==========================================================================
   9. Post Footer (tags, navigation)
   ========================================================================== */

.post-footer {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-lg);
}

.post-tags {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

.post-tags a {
  color: var(--color-text-secondary);
  transition: color 0.2s ease;
}

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

/* Post navigation */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.post-nav-item {
  flex: 1;
}

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

.post-nav-label {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-xs);
}

.post-nav-title {
  font-family: var(--font-heading);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.post-nav-title a {
  color: var(--color-text-primary);
}

/* ==========================================================================
   10. Pages (Static)
   ========================================================================== */

.page-header {
  padding: calc(var(--space-xl) + 2vw) 0 var(--space-lg);
  margin-bottom: var(--space-lg);
}

.page-title {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ==========================================================================
   11. Author & Tag Archives
   ========================================================================== */

.archive-header {
  padding: var(--space-xl) 0 var(--space-lg);
  margin-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.archive-title {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.archive-description {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  max-width: 50ch;
}

.archive-meta {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin-top: var(--space-md);
}

/* ==========================================================================
   12. Pagination
   ========================================================================== */

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) 0;
  margin-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.pagination a {
  font-family: var(--font-heading);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  transition: color 0.2s ease;
}

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

.pagination-info {
  font-family: var(--font-heading);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

/* ==========================================================================
   13. Error Page
   ========================================================================== */

.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.error-code {
  font-family: var(--font-heading);
  font-size: var(--font-size-4xl);
  font-weight: 700;
  color: var(--color-text-tertiary);
}

.error-message {
  font-size: var(--font-size-lg);
  color: var(--color-text-secondary);
  margin-top: var(--space-md);
}

.error-link {
  font-family: var(--font-heading);
  font-size: var(--font-size-sm);
  margin-top: var(--space-lg);
}

/* ==========================================================================
   14. Ghost Cards & Embeds
   ========================================================================== */

/* Bookmark cards */
.kg-bookmark-card {
  margin: var(--space-lg) 0;
}

.kg-bookmark-container {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

.kg-bookmark-content {
  flex: 1;
  padding: var(--space-md);
}

.kg-bookmark-title {
  font-family: var(--font-heading);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.kg-bookmark-description {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

.kg-bookmark-metadata {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin-top: var(--space-sm);
}

.kg-bookmark-thumbnail {
  width: 160px;
  flex-shrink: 0;
}

.kg-bookmark-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Embed cards */
.kg-embed-card {
  margin: var(--space-lg) 0;
}

.kg-embed-card iframe {
  width: 100%;
  aspect-ratio: 16/9;
}

/* Gallery cards */
.kg-gallery-card {
  margin: var(--space-lg) 0;
}

.kg-gallery-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.kg-gallery-image {
  flex: 1 1 300px;
}

/* ==========================================================================
   15. Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --font-size-base: 1.8rem;
    --font-size-4xl: 4rem;
    --font-size-3xl: 3.5rem;
    --font-size-2xl: 3rem;
  }

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

  .site-nav {
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-md);
  }

  .post-title {
    font-size: var(--font-size-3xl);
  }

  .post-nav {
    flex-direction: column;
  }

  .post-nav-item.next {
    text-align: left;
  }

  .site-footer .inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .kg-bookmark-container {
    flex-direction: column;
  }

  .kg-bookmark-thumbnail {
    width: 100%;
    height: 160px;
    order: -1;
  }
}

@media (max-width: 480px) {
  :root {
    --font-size-base: 1.7rem;
    --font-size-4xl: 3.2rem;
    --font-size-3xl: 2.8rem;
    --space-lg: 3rem;
    --space-xl: 5rem;
  }

  .inner {
    padding: 0 var(--space-sm);
  }

  .post-content blockquote {
    padding-left: 1em;
  }
}

/* ==========================================================================
   16. Print Styles
   ========================================================================== */

@media print {
  body {
    background: white;
    color: black;
    font-size: 12pt;
  }

  .site-header,
  .site-footer,
  .post-nav,
  .theme-toggle {
    display: none;
  }

  .post-content a {
    background: none;
    text-decoration: underline;
  }

  .post-content a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}
