/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ========================================
   THEME SYSTEM — Three swappable themes
   ======================================== */

/* Theme A: Warm Light (default) */
:root,
[data-theme="warm"] {
  --primary-color: #1a1a1a;
  --text-color: #2d2d2d;
  --light-gray: #666666;
  --lighter-gray: #888888;
  --border-color: #e0ddd8;
  --background: #faf8f5;
  --link-color: #2d2d2d;
  --link-hover: #000000;
  --internal-link-color: #1a5c3a;
  --accent-bg: #f0ede8;
  --accent-bg-hover: #e8e4de;
  --max-width: 720px;
  --font-heading: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Crimson Pro', Georgia, serif;
  --font-weight-heading: 600;
  --heading-tracking: -0.01em;
  --body-size: 16px;
  --body-size-mobile: 15px;
  --code-bg: rgba(0, 0, 0, 0.04);
  --blockquote-border: #c8c4be;
  --selection-bg: #1a5c3a;
  --selection-text: #ffffff;
  --theme-switcher-bg: var(--accent-bg);
  --theme-switcher-active: var(--internal-link-color);
  --details-bg: rgba(0, 0, 0, 0.02);
}

/* Theme B: Deep Navy */
[data-theme="navy"] {
  --primary-color: #f0ece7;
  --text-color: #e8e4df;
  --light-gray: #9a9590;
  --lighter-gray: #7a7570;
  --border-color: #1e3050;
  --background: #0d1b2a;
  --link-color: #e8e4df;
  --link-hover: #ffffff;
  --internal-link-color: #c17f59;
  --accent-bg: #142238;
  --accent-bg-hover: #1a2d48;
  --max-width: 720px;
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-weight-heading: 700;
  --heading-tracking: -0.02em;
  --body-size: 15px;
  --body-size-mobile: 14px;
  --code-bg: rgba(255, 255, 255, 0.06);
  --blockquote-border: #2a4060;
  --selection-bg: #c17f59;
  --selection-text: #0d1b2a;
  --theme-switcher-bg: var(--accent-bg);
  --theme-switcher-active: var(--internal-link-color);
  --details-bg: rgba(255, 255, 255, 0.02);
}

/* Theme C: Soft Sage */
[data-theme="sage"] {
  --primary-color: #2a2f1e;
  --text-color: #3a3f2e;
  --light-gray: #6b7060;
  --lighter-gray: #8a8f80;
  --border-color: #d5d9ce;
  --background: #f2f4ef;
  --link-color: #3a3f2e;
  --link-hover: #1a1f0e;
  --internal-link-color: #c4704a;
  --accent-bg: #e8ebe3;
  --accent-bg-hover: #dde1d5;
  --max-width: 720px;
  --font-heading: 'Libre Baskerville', Georgia, serif;
  --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-weight-heading: 700;
  --heading-tracking: -0.01em;
  --body-size: 15px;
  --body-size-mobile: 14px;
  --code-bg: rgba(0, 0, 0, 0.04);
  --blockquote-border: #b8bfae;
  --selection-bg: #c4704a;
  --selection-text: #ffffff;
  --theme-switcher-bg: var(--accent-bg);
  --theme-switcher-active: var(--internal-link-color);
  --details-bg: rgba(0, 0, 0, 0.02);
}

/* ========================================
   GLOBAL STYLES
   ======================================== */

::selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}

/* Content wrapper */
.content-wrapper {
  position: relative;
  min-height: 100vh;
}

/* Typography */
html, body {
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: 1.7;
  color: var(--text-color);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-weight-heading);
  color: var(--primary-color);
  line-height: 1.25;
  letter-spacing: var(--heading-tracking);
  margin-top: 1.8em;
  margin-bottom: 0.6em;
}

h1 { font-size: 2.2em; }
h2 { font-size: 1.7em; }
h3 { font-size: 1.35em; }
h4 { font-size: 1.15em; }

p {
  margin-bottom: 1.1em;
}

a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  opacity: 0.85;
}

/* Internal links */
a[href^="/"],
a[href^="https://www.mossjing.com"] {
  color: var(--internal-link-color);
}

a[href^="/"]:hover,
a[href^="https://www.mossjing.com"]:hover {
  color: var(--internal-link-color);
  opacity: 0.75;
}

/* Layout */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* ========================================
   HEADER
   ======================================== */

.site-header {
  padding: 2em 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 3em;
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title a,
.site-title a[href^="/"] {
  font-family: var(--font-heading);
  font-size: 1.4em;
  font-weight: var(--font-weight-heading);
  color: var(--primary-color);
  text-decoration: none;
  letter-spacing: var(--heading-tracking);
}

/* Theme Switcher */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-switcher-label {
  font-size: 0.75em;
  color: var(--lighter-gray);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 4px;
  font-family: var(--font-heading);
}

.theme-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  position: relative;
}

.theme-btn:hover {
  transform: scale(1.15);
}

.theme-btn.active {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--primary-color);
}

.theme-btn[data-theme="warm"] {
  background: #faf8f5;
  border-color: #e0ddd8;
}

.theme-btn[data-theme="navy"] {
  background: #0d1b2a;
  border-color: #1e3050;
}

.theme-btn[data-theme="sage"] {
  background: #f2f4ef;
  border-color: #d5d9ce;
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content {
  min-height: calc(100vh - 300px);
  margin-bottom: 4em;
}

/* Home Page */
.home {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.simple-list {
  list-style: none;
  margin: 1em 0;
}

.simple-list li {
  margin-bottom: 0.5em;
}

.simple-list .date {
  color: var(--lighter-gray);
  font-size: 0.9em;
  font-family: var(--font-heading);
}

.intro h1 {
  margin-top: 0;
  margin-bottom: 0.3em;
}

.lead {
  font-size: 1.15em;
  color: var(--light-gray);
  margin-bottom: 3em;
}

/* Post list */
.recent-posts {
  margin-bottom: 3em;
}

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

.post-list li {
  margin-bottom: 2em;
  padding-bottom: 2em;
  border-bottom: 1px solid var(--border-color);
}

.post-list li:last-child {
  border-bottom: none;
}

.post-meta {
  color: var(--lighter-gray);
  font-size: 0.9em;
}

.post-list h3 {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
  font-size: 1.3em;
}

.more-posts {
  text-align: center;
  margin-top: 2em;
}

/* Highlight Cards */
.highlight-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2em;
  margin-top: 1.5em;
}

.card {
  padding: 1.5em;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  transition: border-color 0.2s ease;
}

.card:hover {
  border-color: var(--light-gray);
}

.card h3 {
  margin-top: 0;
  margin-bottom: 0.5em;
  font-size: 1.2em;
}

.card p {
  margin-bottom: 0;
  color: var(--light-gray);
  font-size: 0.95em;
}

/* ========================================
   BLOG ARCHIVE
   ======================================== */

.blog-archive {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.year-section {
  margin-bottom: 3em;
}

.year-heading {
  color: var(--lighter-gray);
  font-size: 1.3em;
  margin-bottom: 1em;
}

/* ========================================
   POST & PAGE
   ======================================== */

.post, .page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.post-header, .page-header {
  margin-bottom: 2em;
}

.post-title, .page-title {
  margin-top: 0;
}

.post-date {
  color: var(--lighter-gray);
  font-size: 0.95em;
  font-family: var(--font-heading);
}

/* Tags */
.post-tags {
  margin-top: 0.5em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
}

.tag {
  font-size: 0.78em;
  color: var(--lighter-gray);
  background: var(--accent-bg);
  padding: 0.2em 0.65em;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  font-weight: 400;
  display: inline-block;
  font-family: var(--font-heading);
}

a.tag-link,
a.tag-link[href^="/"] {
  text-decoration: none;
  color: var(--lighter-gray);
}

a.tag-link:hover {
  background: var(--accent-bg-hover);
  color: var(--light-gray);
  text-decoration: none;
  transform: translateY(-1px);
}

/* Tags page */
.tags-page {
  max-width: var(--max-width);
  margin: 0 auto;
}

.tag-cloud {
  margin-bottom: 3em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
}

.tag-section {
  margin-bottom: 2.5em;
  scroll-margin-top: 2em;
}

.tag-section h2 {
  color: var(--link-color);
  font-size: 1.3em;
  margin-bottom: 0.5em;
}

/* Inline tags in post lists */
.post-tags-inline {
  margin-left: 0.5em;
}

.tag-small {
  font-size: 0.7em;
  padding: 0.15em 0.5em;
}

/* Post / Page content */
.post-content, .page-content {
  font-size: 1.05em;
}

.post-content h2,
.page-content h2 {
  margin-top: 2.2em;
}

.post-content h3,
.page-content h3 {
  margin-top: 1.6em;
}

.post-content ul,
.post-content ol,
.page-content ul,
.page-content ol {
  margin-bottom: 1em;
  margin-left: 1.5em;
}

.post-content li,
.page-content li {
  margin-bottom: 0.3em;
}

.post-content blockquote,
.page-content blockquote {
  margin: 1.5em 0;
  padding-left: 1.5em;
  border-left: 3px solid var(--blockquote-border);
  color: var(--light-gray);
  font-style: italic;
}

.post-content code,
.page-content code {
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-size: 0.88em;
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.post-content pre,
.page-content pre {
  background: var(--accent-bg);
  padding: 1.2em;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 1.2em;
  border: 1px solid var(--border-color);
}

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

/* Images */
.post-content img,
.page-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
  border-radius: 4px;
}

/* Prevent horizontal scrolling */
html, body {
  overflow-x: hidden;
  width: 100%;
}

/* ========================================
   COLLAPSIBLE SECTIONS
   ======================================== */

.post-content details,
.page-content details {
  margin: 0.5em 0;
  padding: 0.3em 0.6em;
  border: none;
  border-left: 2px solid var(--border-color);
  border-radius: 0 2px 2px 0;
  background: var(--details-bg);
}

.post-content details summary,
.page-content details summary {
  cursor: pointer;
  padding: 0.2em 0;
  font-weight: 400;
  font-size: 0.85em;
  color: var(--lighter-gray);
  transition: color 0.2s ease;
  list-style: none;
  display: flex;
  align-items: center;
}

.post-content details summary::-webkit-details-marker,
.page-content details summary::-webkit-details-marker {
  display: none;
}

.post-content details summary::before,
.page-content details summary::before {
  content: '\25B8';
  font-size: 0.7em;
  margin-right: 0.5em;
  transition: transform 0.2s ease;
  display: inline-block;
  color: var(--lighter-gray);
}

.post-content details[open] summary::before,
.page-content details[open] summary::before {
  transform: rotate(90deg);
}

.post-content details summary:hover,
.page-content details summary:hover {
  color: var(--light-gray);
}

.post-content details[open] summary,
.page-content details[open] summary {
  margin-bottom: 0.3em;
}

.post-content details p:first-of-type,
.page-content details p:first-of-type {
  margin-top: 0.3em;
  font-size: 0.9em;
}

/* ========================================
   POST NAVIGATION
   ======================================== */

.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3em;
  padding-top: 2em;
  border-top: 1px solid var(--border-color);
}

.post-nav .prev,
.post-nav .next {
  max-width: 45%;
}

.post-nav a[href^="/"] {
  color: var(--link-color);
}

/* ========================================
   FOOTER
   ======================================== */

.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 2em 0;
  margin-top: 4em;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  color: var(--lighter-gray);
  font-size: 0.9em;
}

.footer-section a,
.footer-section a[href^="/"] {
  margin-left: 1.5em;
  color: var(--lighter-gray);
}

.footer-section a:hover {
  color: var(--light-gray);
}

/* ========================================
   SIDEBAR ANNOTATIONS
   ======================================== */

.sidebar {
  position: fixed;
  top: 0;
  right: -350px;
  width: 320px;
  height: 100vh;
  background: var(--accent-bg);
  border-left: 2px solid var(--border-color);
  padding: 20px;
  transition: right 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
}

.sidebar.active {
  right: 0;
}

.sidebar-content {
  color: var(--text-color);
  font-size: 0.9em;
  line-height: 1.5;
}

.sidebar-title {
  font-weight: bold;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--primary-color);
}

.sidebar-note {
  margin-bottom: 15px;
  padding: 10px;
  background: var(--accent-bg-hover);
  border-radius: 4px;
  border-left: 3px solid var(--border-color);
}

.sidebar-annotation {
  margin-bottom: 20px;
  padding: 12px;
  background: var(--accent-bg-hover);
  border-radius: 4px;
  border-left: 3px solid var(--border-color);
  transition: all 0.3s ease;
}

.sidebar-annotation.highlighted {
  background: var(--accent-bg);
  border-left-color: var(--primary-color);
}

.annotation-text {
  font-size: 0.85em;
  color: var(--lighter-gray);
  font-style: italic;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.annotation-note {
  font-size: 0.9em;
  line-height: 1.4;
  color: var(--text-color);
}

.hoverable-text {
  position: relative;
  cursor: help;
  transition: background-color 0.2s ease;
}

.hoverable-text:hover {
  background-color: var(--details-bg);
  border-radius: 2px;
}

/* ========================================
   COLLAPSIBLE JS SECTIONS
   ======================================== */

.collapsible-section {
  margin: 1em 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--accent-bg);
}

.collapsible-header {
  cursor: pointer;
  padding: 0.8em;
  font-weight: 500;
  color: var(--link-color);
  transition: all 0.2s ease;
  user-select: none;
}

.collapsible-header:hover {
  background: var(--accent-bg-hover);
  color: var(--link-hover);
}

.toggle-icon {
  display: inline-block;
  transition: transform 0.3s ease;
  margin-right: 0.5em;
}

.collapsible-section.expanded .toggle-icon {
  transform: rotate(90deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 0.8em;
}

.collapsible-section.expanded .collapsible-content {
  max-height: 1000px;
  padding: 0.8em;
  border-top: 1px solid var(--border-color);
}

/* ========================================
   404
   ======================================== */

.error-page {
  text-align: center;
  padding: 2em 0;
}

.error-image {
  max-width: 400px;
  width: 100%;
  height: auto;
  margin: 0 auto 2em;
  display: block;
  border-radius: 8px;
  opacity: 0.9;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  html, body {
    font-size: var(--body-size-mobile);
  }

  .site-header .container {
    flex-direction: column;
    gap: 1em;
  }

  .highlight-cards {
    grid-template-columns: 1fr;
  }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }

  .footer-section {
    margin-top: 1em;
  }

  .footer-section a:first-child {
    margin-left: 0;
  }

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

  .post-nav .prev,
  .post-nav .next {
    max-width: 100%;
    margin-bottom: 1em;
  }

  .sidebar {
    width: 100%;
    right: -100%;
  }
}
