/* ==========================================================================
   MOSS - Typography-first design for Writers & Publishers
   ========================================================================== */

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

:root {
  /* Color System - Warm, paper-inspired */
  --moss-text-primary: #2c2825;
  --moss-text-secondary: #5d5853;
  --moss-text-muted: #8a8580;
  --moss-background: #faf8f5;
  --moss-background-alt: #f4f1ec;
  --moss-accent: #2d5a2d;
  --moss-accent-hover: #1e3d1e;
  --moss-accent-light: rgba(45, 90, 45, 0.15);
  --moss-border-light: #e6e2db;
  --moss-border-medium: #d1cdc4;

  /* Code Block Colors */
  --moss-code-background: #f8f6f3;
  --moss-code-border: #e0ddd6;
  --moss-code-accent-primary: #2d5a2d; /* moss green - systems/primary */
  --moss-code-accent-secondary: #5d5853; /* warm gray - web languages */
  --moss-code-accent-tertiary: #8a8580; /* muted brown - scripting */
  --moss-code-accent-quaternary: #6b5b4f; /* deeper brown - config/data */

  /* Typography Scale - Optimized for long-form reading */
  --moss-font-base: 1.125rem; /* 18px */
  --moss-font-sm: 1rem; /* 16px */
  --moss-font-lg: 1.25rem; /* 20px */
  --moss-font-xl: 1.375rem; /* 22px */
  --moss-font-2xl: 1.625rem; /* 26px */
  --moss-font-3xl: 2rem; /* 32px */

  /* Spacing Scale (8pt grid) */
  --moss-space-xs: 0.5rem; /* 8px */
  --moss-space-sm: 1rem; /* 16px */
  --moss-space-md: 1.5rem; /* 24px */
  --moss-space-lg: 2rem; /* 32px */
  --moss-space-xl: 3rem; /* 48px */
  --moss-space-2xl: 4rem; /* 64px */

  /* Layout */
  --moss-content-width: 65ch;
  --moss-site-max-width: 1200px;
  --moss-container-padding: clamp(1rem, 5vw, 2rem);
}

/* Dark mode - explicit toggle */
[data-theme="dark"] {
  --moss-text-primary: #e8e6e3;
  --moss-text-secondary: #b8b5b0;
  --moss-text-muted: #8a8580;
  --moss-background: #1a1816;
  --moss-background-alt: #242018;
  --moss-border-light: #3a362f;
  --moss-border-medium: #4a453c;
  --moss-accent: #4a7c4a;
  --moss-accent-hover: #5a8c5a;
  --moss-accent-light: rgba(74, 124, 74, 0.2);

  --moss-code-background: #1e1e1e;
  --moss-code-border: #3a3a3a;
  --moss-code-accent-primary: #4a7c4a;
  --moss-code-accent-secondary: #b8b5b0;
  --moss-code-accent-tertiary: #a8a19a;
  --moss-code-accent-quaternary: #9b8b7f;
}

/* Dark mode - system preference (when no explicit theme set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --moss-text-primary: #e8e6e3;
    --moss-text-secondary: #b8b5b0;
    --moss-text-muted: #8a8580;
    --moss-background: #1a1816;
    --moss-background-alt: #242018;
    --moss-border-light: #3a362f;
    --moss-border-medium: #4a453c;
    --moss-accent: #4a7c4a;
    --moss-accent-hover: #5a8c5a;
    --moss-accent-light: rgba(74, 124, 74, 0.2);

    --moss-code-background: #1e1e1e;
    --moss-code-border: #3a3a3a;
    --moss-code-accent-primary: #4a7c4a;
    --moss-code-accent-secondary: #b8b5b0;
    --moss-code-accent-tertiary: #a8a19a;
    --moss-code-accent-quaternary: #9b8b7f;
  }
}

/* ==========================================================================
   2. Base & Reset
   ========================================================================== */

* {
  box-sizing: border-box;
}

/* Text selection - moss green tint */
::selection {
  background: rgba(45, 90, 45, 0.15);
}

[data-theme="dark"] ::selection {
  background: rgba(74, 124, 74, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) ::selection {
    background: rgba(74, 124, 74, 0.25);
  }
}

/* Smooth transitions for theme changes */
* {
  transition: background-color 0.2s ease, color 0.2s ease,
    border-color 0.2s ease;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Inter",
    system-ui, sans-serif;
  font-size: var(--moss-font-base);
  font-weight: 320;
  line-height: 1.7;
  color: var(--moss-text-primary);
  background: var(--moss-background);
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;  /* Prevent horizontal scroll - content should be responsive */
}

strong,
b {
  font-weight: 480;
}

/* ==========================================================================
   3. Typography
   ========================================================================== */

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 480;
  line-height: 1.3;
  color: var(--moss-text-primary);
  margin: var(--moss-space-xl) 0 var(--moss-space-md) 0;
}

h1 {
  font-size: var(--moss-font-2xl);
  font-weight: 300;
  margin-top: 0;
  border-bottom: none;
  padding-bottom: 0;
}

h2 {
  font-size: var(--moss-font-xl);
}

h3 {
  font-size: var(--moss-font-xl);
}

h4 {
  font-size: var(--moss-font-lg);
}

h5,
h6 {
  font-size: var(--moss-font-base);
}

/* Paragraphs */
p {
  margin: 0 0 var(--moss-space-md) 0;
  max-width: var(--moss-content-width);
}

/* Shrink article body paragraphs to content width for tighter selection highlight */
article > p {
  width: fit-content;
}

p + p {
  margin-top: var(--moss-space-md);
}

/* Lists */
ul,
ol {
  margin: var(--moss-space-md) 0;
  padding-left: var(--moss-space-lg);
}

li {
  margin-bottom: var(--moss-space-xs);
  line-height: 1.6;
}

li > ul,
li > ol {
  margin-top: var(--moss-space-xs);
  margin-bottom: var(--moss-space-xs);
}

/* Links */
a {
  color: var(--moss-accent);
  text-decoration: none;
  transition: background-color 0.15s ease;
}

a:hover,
a:focus {
  color: var(--moss-accent-hover);
}

/* ==========================================================================
   4. Layout
   ========================================================================== */

.container {
  max-width: var(--moss-site-max-width);
  margin: 0 auto;
  padding: 0 var(--moss-container-padding);
}

header {
  padding-top: var(--moss-space-lg);
}

main {
  background: transparent;
  padding: 0;
  padding-bottom: 60px;
  flex: 1;
}

/* ==========================================================================
   SIMPLIFIED LAYOUT SYSTEM

   Hero is placed outside <main> at body level for natural full-width display.
   No complex subgrid chain needed - hero naturally spans viewport width.

   HTML Structure:
     <header>...</header>
     {hero_section}           <!-- Full-width hero at body level -->
     <main class="{main_class}">
       {latest_sidebar}       <!-- Optional sidebar -->
       <article class="container">
         {content}            <!-- Centered content -->
       </article>
     </main>
   ========================================================================== */

/* Main layout - simple block container */
main {
  background: transparent;
  padding: 0;
  padding-bottom: 60px;
  flex: 1;
}

/* Article container - centered content */
main > article.container {
  max-width: var(--moss-content-width);
  margin: 0 auto;
  padding: 0 var(--moss-container-padding);
}

/* Sidebar layout - flexbox-based */
main.has-sidebar {
  display: flex;
  gap: var(--moss-space-lg);
  max-width: var(--moss-site-max-width, 1400px);
  margin: 0 auto;
  padding: 0 var(--moss-container-padding);
}

main.has-sidebar > article.container {
  flex: 1;
  max-width: var(--moss-content-width);
  margin: 0;
  padding: 0;
}

main.has-sidebar > .latest-sidebar {
  width: clamp(200px, 22vw, 320px);
  flex-shrink: 0;
  position: sticky;
  top: var(--moss-space-lg);
  max-height: calc(100vh - var(--moss-space-2xl));
  overflow-y: auto;
  align-self: flex-start;
}

footer {
  width: 100%;
  flex-shrink: 0;
  margin-top: var(--moss-space-2xl);
}

footer.container {
  max-width: var(--moss-content-width);
  margin: var(--moss-space-2xl) auto 0 auto;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--moss-border-light);
  padding-top: var(--moss-space-lg);
  padding-bottom: var(--moss-space-2xl);
}

.footer-label {
  color: var(--moss-text-muted);
  margin: 0;
  font-size: var(--moss-font-base);
}

.footer-link {
  color: var(--moss-text-primary);
  text-decoration: none;
  font-size: var(--moss-font-base);
}

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

/* Email subscribe form injected by email plugin enhance hook */
.footer-subscribe-form {
  display: flex;
  gap: var(--moss-space-sm);
  align-items: center;
}

.footer-subscribe-form input[type="email"] {
  font-size: var(--moss-font-base);
  padding: var(--moss-space-xs) var(--moss-space-sm);
  border: 1px solid var(--moss-border-light);
  border-radius: 4px;
  background: transparent;
  color: var(--moss-text-primary);
}

.footer-subscribe-form button {
  font-size: var(--moss-font-base);
  padding: var(--moss-space-xs) var(--moss-space-sm);
  background: transparent;
  border: 1px solid var(--moss-border-light);
  border-radius: 4px;
  color: var(--moss-text-primary);
  cursor: pointer;
}

.footer-subscribe-form button:hover {
  color: var(--moss-accent);
  border-color: var(--moss-accent);
}

/* ==========================================================================
   5. Navigation
   ========================================================================== */

/* Main Nav */
.main-nav {
  max-width: var(--moss-content-width);
  margin: 0 auto var(--moss-space-sm) auto;
}

.main-nav a {
  color: var(--moss-text-secondary);
  border-bottom: none;
  text-decoration: none;
  white-space: nowrap;
}

.main-nav a:hover {
  color: var(--moss-accent);
}

.main-nav a.active {
  color: var(--moss-accent);
  border-bottom: 2px solid var(--moss-accent);
  padding-bottom: 2px;
}

.main-nav a.active:hover {
  color: var(--moss-accent-hover);
  border-bottom-color: var(--moss-accent-hover);
}

/* Nav Content - Flexible layout that wraps only when needed
   Default: all items on one row (site-name | nav-links | toggle)
   When overflow: site-name + toggle on row 1, nav-links on row 2 */
.nav-content {
  border-bottom: 1px solid var(--moss-border-light);
  padding-bottom: var(--moss-space-md);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--moss-space-md);
}

/* When hero follows header, remove nav border (hero visually replaces it)
   Keep padding-bottom so nav links have breathing room */
header:has(+ .moss-hero) .nav-content {
  border-bottom: none;
}

header:has(+ .moss-hero) .main-nav {
  margin-bottom: 0;
}

.nav-left {
  font-weight: 600;
}

.nav-right {
  display: flex;
  align-items: center;
  flex: 1;
  justify-content: flex-end;
  gap: var(--moss-space-md);
}

/* Site Name */
.site-name {
  color: var(--moss-text-primary);
  font-size: var(--moss-font-lg);
  font-weight: 600;
}

.site-name:hover {
  color: var(--moss-accent);
}

/* Nav Links & Icons */
.nav-links {
  display: flex;
  align-items: center;
  gap: var(--moss-space-md);
}

.nav-icons {
  display: flex;
  align-items: center;
  gap: var(--moss-space-md);
  margin-left: auto;  /* Push to far right, even when nav-links wrap */
}

.nav-divider {
  width: 1px;
  height: 24px;
  background-color: var(--moss-border-light);
  margin: 0 var(--moss-space-sm);
}

/* Article Header */
.article-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 1.5em;
  gap: var(--moss-space-sm);
}

.article-date {
  color: var(--moss-text-muted);
  font-size: 1.1em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Theme Toggle - Classic from toggles.dev */
.theme-toggle {
  --theme-toggle__classic--duration: 500ms;
  background: none;
  border: none;
  border-radius: 4px;
  padding: 0.375rem;
  cursor: pointer;
  color: var(--moss-text-secondary);
  position: relative;
  transition: all 0.2s ease;
  font-size: 18px; /* Controls SVG size since it uses 1em */
}

.theme-toggle:hover {
  background: var(--moss-background-alt);
  color: var(--moss-text-primary);
}

.theme-toggle:focus {
  outline: 2px solid var(--moss-accent);
  outline-offset: 2px;
}

.theme-toggle svg {
  display: block;
  stroke-width: 1;
  opacity: 0.7;
}

.theme-toggle__classic path {
  transition-timing-function: cubic-bezier(0, 0, 0.15, 1.25);
  transform-origin: center;
  transition-duration: calc(var(--theme-toggle__classic--duration) * 0.8);
}

.theme-toggle__classic g path {
  transition-property: opacity, transform;
  transition-delay: calc(var(--theme-toggle__classic--duration) * 0.2);
}

.theme-toggle__classic :first-child path {
  transition-property: transform, d;
}

/* Toggled state (dark mode active) */
.theme-toggle--toggled .theme-toggle__classic g path {
  transform: scale(0.5) rotate(45deg);
  opacity: 0;
  transition-delay: 0s;
}

.theme-toggle--toggled .theme-toggle__classic :first-child path {
  d: path("M-12 5h30a1 1 0 0 0 9 13v24h-39Z");
  transition-delay: calc(var(--theme-toggle__classic--duration) * 0.2);
}

/* Fallback for browsers without d: path() support */
@supports not (d: path("")) {
  .theme-toggle--toggled .theme-toggle__classic :first-child path {
    transform: translate3d(-12px, 10px, 0);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle:not(.theme-toggle--force-motion) * {
    transition: none !important;
  }
}

/* GitHub Link */
.github-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  color: var(--moss-text-secondary);
  border-bottom: none;
  transition: all 0.2s ease;
}

.github-link:hover {
  background: var(--moss-background-alt);
  color: var(--moss-accent);
}

.github-link svg {
  display: block;
}

/* Mobile Menu Button */
.mobile-menu-button {
  display: none;
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--moss-text-secondary);
  transition: all 0.2s ease;
}

.mobile-menu-button:hover {
  background: var(--moss-background-alt);
  color: var(--moss-text-primary);
}

.mobile-menu-button svg {
  display: block;
}

/* ==========================================================================
   6. Lists
   ========================================================================== */

.topic-articles .date,
.year-group .date {
  margin-right: 0.5rem;
}

/* Consistent article link styles across all listing contexts */
.topic-articles a,
.year-group a,
.article-listing a {
  color: var(--moss-text-primary);
}

.topic-articles a:hover,
.year-group a:hover,
.article-listing a:hover {
  color: var(--moss-accent);
}

/* ==========================================================================
   Shared Prefix-Link Pattern
   Used by article-item and series-nav for consistent styling:
   - Flexbox with baseline alignment
   - Prefix (date/arrow) stays fixed, doesn't wrap
   - Title wraps independently
   - Only title changes color on hover
   ========================================================================== */

.prefix-link {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.prefix-link-prefix {
  flex-shrink: 0;
  color: var(--moss-text-muted);
}

/* Prefix doesn't change color on hover - stays muted */
.prefix-link:hover .prefix-link-prefix {
  color: var(--moss-text-muted);
}

.prefix-link-title {
  color: var(--moss-text-primary);
}

.prefix-link:hover .prefix-link-title {
  color: var(--moss-accent);
  text-decoration: underline;  /* Underline only title on hover */
}

/* Article item: uses prefix-link pattern */
article .article-item a,
.article-item a {
  text-decoration: none;  /* Override article a default */
  color: inherit;
}

/* Keep backward compatibility with existing .date and .title classes */
.article-item .title {
  color: var(--moss-text-primary);
}

.article-item a:hover .title {
  color: var(--moss-accent);
  text-decoration: underline;  /* Underline only title on hover */
}

/* Year Groups */
.year-group {
  margin-bottom: var(--moss-space-md);
}

.year-group h2 {
  font-size: var(--moss-font-lg);
  color: var(--moss-text-secondary);
  border-bottom: 1px solid var(--moss-border-light);
  padding-bottom: var(--moss-space-xs);
  margin-top: 0;
  margin-bottom: var(--moss-space-sm);
  font-weight: 500;
}

.year-group p {
  margin-bottom: 0.25rem;
  margin-top: 0;
}

/* Article Listing */
.article-listing {
  max-width: var(--moss-content-width);
}

.latest-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.latest-list li {
  margin-bottom: 0.25rem;
}

.latest-list .entry-date {
  display: block;
  font-size: var(--moss-font-sm);
  color: var(--moss-text-muted);
  margin-bottom: 0.25rem;
}

.latest-list a {
  color: var(--moss-text-secondary);
  text-decoration: none;
  font-size: var(--moss-font-sm);
  line-height: 1.5;
  display: block;
}

.latest-list a:hover {
  color: var(--moss-accent);
}

.no-posts {
  color: var(--moss-text-muted);
  font-style: italic;
  margin: 0;
}

/* ==========================================================================
   7. Content Elements
   ========================================================================== */

/* Article */
article {
  max-width: var(--moss-content-width);
  margin-bottom: var(--moss-space-2xl);
}

/* Article Metadata */
.article-meta {
  margin-bottom: var(--moss-space-md);
}

.article-meta time {
  color: var(--moss-text-muted);
  font-size: var(--moss-font-base);
}

.date {
  color: var(--moss-text-muted);
}

/* Blog Feed */
.blog-feed {
  max-width: var(--moss-content-width);
}

.blog-entry {
  margin-bottom: var(--moss-space-2xl);
  padding-bottom: var(--moss-space-xl);
  border-bottom: 1px solid var(--moss-border-light);
}

.blog-entry:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.blog-entry-header {
  margin-bottom: var(--moss-space-md);
}

.blog-entry-title {
  margin: 0 0 var(--moss-space-xs) 0;
  font-size: var(--moss-font-xl);
  line-height: 1.3;
}

.blog-entry-title a {
  color: var(--moss-text-primary);
  text-decoration: none;
  border-bottom: none;
}

.blog-entry-title a:hover {
  color: var(--moss-accent);
}

.blog-entry-date {
  font-size: var(--moss-font-sm);
  color: var(--moss-text-secondary);
  font-weight: 500;
  display: block;
  margin-bottom: var(--moss-space-sm);
}

.blog-entry-excerpt {
  color: var(--moss-text-secondary);
  line-height: 1.6;
}

.blog-entry-excerpt p {
  margin-bottom: var(--moss-space-sm);
}

.read-more {
  font-weight: 500;
  color: var(--moss-accent) !important;
  border-bottom: 1px solid transparent !important;
}

.read-more:hover {
  border-bottom-color: var(--moss-accent-hover) !important;
}

/* Content Table */
.content-table {
  margin: var(--moss-space-xl) 0;
}

.content-table h1,
.content-table h2 {
  margin-bottom: var(--moss-space-lg);
  color: var(--moss-text-primary);
}

.content-table table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--moss-space-md);
}

.content-table th {
  background: var(--moss-background-alt);
  padding: var(--moss-space-sm) var(--moss-space-md);
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--moss-border-medium);
}

.content-table td {
  padding: var(--moss-space-sm) var(--moss-space-md);
  border-bottom: 1px solid var(--moss-border-light);
}

.content-table tr:hover {
  background: var(--moss-background-alt);
}

.content-table a {
  color: var(--moss-text-primary);
  font-weight: 500;
}

.content-table a:hover {
  color: var(--moss-accent);
}

/* Post Metadata */
.post-meta {
  margin-bottom: var(--moss-space-lg);
  padding: var(--moss-space-sm) 0;
  border-bottom: 1px solid var(--moss-border-light);
}

.post-meta .meta {
  font-size: var(--moss-font-sm);
  color: var(--moss-text-secondary);
  display: flex;
  align-items: center;
  gap: var(--moss-space-sm);
  flex-wrap: wrap;
}

.post-meta .topic {
  background: var(--moss-background-alt);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: var(--moss-font-sm);
  color: var(--moss-accent);
  border: 1px solid var(--moss-border-light);
}

/* ==========================================================================
   8. UI Components
   ========================================================================== */

/* Code */
code {
  font-family: "SF Mono", "Monaco", "Cascadia Code", "Roboto Mono", monospace;
  font-size: 0.9em;
  background: var(--moss-background-alt);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  color: var(--moss-text-primary);
}

pre {
  background: var(--moss-code-background);
  border: 1px solid var(--moss-code-border);
  border-radius: 6px;
  padding: 1.5rem;
  overflow-x: auto;
  position: relative;
  margin: 1.5rem 0;
  line-height: 1.5;
  max-width: 100%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
}

/* Language-specific code borders */
pre:has(code[class*="language-rust"]),
pre:has(code[class*="language-c"]),
pre:has(code[class*="language-cpp"]),
pre:has(code[class*="language-c++"]),
pre:has(code[class*="language-go"]) {
  border-left: 3px solid var(--moss-code-accent-primary);
}

pre:has(code[class*="language-css"]),
pre:has(code[class*="language-scss"]),
pre:has(code[class*="language-sass"]),
pre:has(code[class*="language-html"]),
pre:has(code[class*="language-xml"]),
pre:has(code[class*="language-javascript"]),
pre:has(code[class*="language-js"]),
pre:has(code[class*="language-typescript"]),
pre:has(code[class*="language-ts"]) {
  border-left: 3px solid var(--moss-code-accent-secondary);
}

pre:has(code[class*="language-python"]),
pre:has(code[class*="language-py"]),
pre:has(code[class*="language-ruby"]),
pre:has(code[class*="language-rb"]),
pre:has(code[class*="language-php"]),
pre:has(code[class*="language-bash"]),
pre:has(code[class*="language-sh"]),
pre:has(code[class*="language-shell"]) {
  border-left: 3px solid var(--moss-code-accent-tertiary);
}

pre:has(code[class*="language-json"]),
pre:has(code[class*="language-yaml"]),
pre:has(code[class*="language-yml"]),
pre:has(code[class*="language-toml"]),
pre:has(code[class*="language-ini"]) {
  border-left: 3px solid var(--moss-code-accent-quaternary);
}

/* Blockquotes */
blockquote {
  border-left: 4px solid var(--moss-accent);
  margin: var(--moss-space-lg) 0;
  padding-left: var(--moss-space-lg);
  color: var(--moss-text-secondary);
  font-style: italic;
  font-size: var(--moss-font-lg);
}

blockquote p {
  margin: var(--moss-space-sm) 0;
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: var(--moss-space-lg) 0;
}

/* Reduce gap between consecutive images in paragraphs */
p:has(> img:only-child) {
  margin-bottom: var(--moss-space-xs);
}

p:has(> img:only-child) + p:has(> img:only-child) {
  margin-top: 0;
}

p:has(> img:only-child) > img {
  margin: var(--moss-space-xs) 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--moss-space-lg) 0;
  border: 1px solid var(--moss-border-medium);
  border-radius: 6px;
  overflow: hidden;
}

th,
td {
  padding: var(--moss-space-sm) var(--moss-space-md);
  text-align: left;
  border-bottom: 1px solid var(--moss-border-light);
}

th {
  background: var(--moss-background-alt);
  font-weight: 600;
  color: var(--moss-text-primary);
}

tr:last-child td {
  border-bottom: none;
}

/* Horizontal Rule */
hr {
  border: none;
  height: 1px;
  background: var(--moss-border-light);
  margin: var(--moss-space-2xl) 0;
}

/* ==========================================================================
   9. Forms
   ========================================================================== */

.email-subscription form {
  display: flex;
  gap: var(--moss-space-sm);
  justify-content: flex-end;
  align-items: center;
}

.email-subscription input[type="email"] {
  flex: 0 0 auto;
  width: 240px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--moss-border-medium);
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--moss-background);
  color: var(--moss-text-primary);
}

.email-subscription input[type="email"]:focus {
  outline: 2px solid var(--moss-accent);
  outline-offset: 2px;
  border-color: var(--moss-accent);
}

.email-subscription button[type="submit"] {
  padding: 0.5rem 1rem;
  background: var(--moss-accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.email-subscription button[type="submit"]:hover {
  background: var(--moss-accent-hover);
}

.email-subscription iframe {
  width: 100%;
  max-width: 100%;
  border: none;
  min-height: 120px;
}

/* ==========================================================================
   10. Layout Variants - Minimal Layout
   ========================================================================== */

/* Year headings: keep visible but remove underline */
.year-group.minimal h2 {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: var(--moss-space-xs);
}

/* Article item as clickable link */
.year-group.minimal .article-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  text-decoration: none;
  border-bottom: none;
  color: inherit;
}

.year-group.minimal .article-item .date {
  flex-shrink: 0;
  min-width: 2ch;
  color: var(--moss-text-secondary);
}

.year-group.minimal .article-item .title {
  flex: 1;
  color: var(--moss-text-primary);
  transition: color 0.2s ease;
}

.year-group.minimal .article-item:hover .title {
  color: var(--moss-accent);
}

/* Article title styling */
.article-title {
  font-size: 1.5rem;
  font-weight: 400;
  margin-top: 0;
  margin-bottom: var(--moss-space-xs);
  line-height: 1.3;
}

/* Article content links: blend with text, underlined, green on hover */
article a {
  color: var(--moss-text-primary);
  text-decoration: underline;
}

article a:hover,
article a:focus {
  color: var(--moss-accent);
}

/* ==========================================================================
   11. Responsive - Desktop (min-width: 48rem)
   ========================================================================== */

@media (min-width: 48rem) {
  /* Desktop: nav stays flex, content stays centered */
}

/* ==========================================================================
   12. Responsive - Mobile (max-width: 48rem)
   ========================================================================== */

@media (max-width: 48rem) {
  :root {
    --moss-font-base: 1rem;
    --moss-font-2xl: 1.5rem;
    --moss-font-3xl: 1.75rem;
    /* Slightly larger container padding on mobile for better margins */
    --moss-container-padding: 1.5rem;
  }

  header {
    padding-top: var(--moss-space-md);
  }

  .footer-content {
    padding-bottom: var(--moss-space-lg);
  }

  .article-date {
    font-size: 1em;
  }

  /* Navigation mobile styles */
  .nav-right {
    gap: 0.5rem;
  }

  .nav-icons {
    gap: 0.5rem;
  }

  .nav-divider {
    margin: 0 0.25rem;
  }

  .theme-toggle,
  .github-link {
    padding: 0.25rem;
  }

  /* Email form mobile */
  .email-subscription form {
    justify-content: center;
  }

  .email-subscription input[type="email"],
  .email-subscription button[type="submit"] {
    max-width: 320px;
  }

  .email-subscription iframe {
    min-height: 150px;
  }
}

/* Mobile menu button - hidden by default, shown only on narrow screens */
.mobile-menu-button {
  display: none;
}

/* ==========================================================================
   12b. Responsive - Narrow (<20rem): Hamburger with natural expand
   ========================================================================== */

@media (max-width: 20rem) {
  .nav-content {
    position: relative;
  }

  .mobile-menu-button {
    display: block;
  }

  .nav-links {
    /* Absolute positioning removes from flex flow */
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;

    /* Hidden by default */
    display: flex;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out;

    /* Vertical stack */
    flex-direction: column;
    align-items: flex-start;
    gap: 0;

    /* Clean appearance */
    background: var(--moss-background);
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .nav-links.mobile-open {
    max-height: 200px;
    opacity: 1;
    padding-top: var(--moss-space-sm);
  }

  .nav-links a {
    padding: var(--moss-space-sm) 0;
    border-bottom: none;
  }

  .nav-links a:hover {
    background: transparent;
    color: var(--moss-accent);
  }
}

/* ==========================================================================
   12. Collection Listing (Homepage)
   ========================================================================== */

.collection-listing {
  margin: var(--moss-space-xl) 0;
  padding: var(--moss-space-lg) 0;
  border-top: 1px solid var(--moss-border-light);
  border-bottom: 1px solid var(--moss-border-light);
}

.collection-item {
  margin-bottom: var(--moss-space-md);
}

.collection-item:last-child {
  margin-bottom: 0;
}

.collection-item a {
  display: block;
  padding: var(--moss-space-sm) var(--moss-space-md);
  border-radius: 4px;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.15s ease;
}

.collection-item a:hover {
  background-color: var(--moss-background-alt);
}

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

.collection-name {
  font-size: var(--moss-font-lg);
  font-weight: 500;
  color: var(--moss-text-primary);
}

.collection-count {
  font-size: var(--moss-font-sm);
  color: var(--moss-text-muted);
  white-space: nowrap;
}

.collection-description {
  margin-top: var(--moss-space-xs);
  font-size: var(--moss-font-sm);
  color: var(--moss-text-secondary);
  line-height: 1.5;
}

/* Dark mode */
.dark .collection-listing {
  border-color: var(--moss-border-light);
}

.dark .collection-item a:hover {
  background-color: var(--moss-background-alt);
}

.dark .collection-name {
  color: var(--moss-text-primary);
}

/* Collection Grid (Card-based layout for homepage) */
.collection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--moss-space-md);
  margin: var(--moss-space-lg) 0;
}

@media (max-width: 768px) {
  .collection-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .collection-grid {
    grid-template-columns: 1fr;
  }
}

.collection-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  overflow: hidden;
  background: var(--moss-background-alt);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.collection-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.collection-card-cover {
  aspect-ratio: 4 / 3;
  background-size: cover;
  background-position: center;
  background-color: var(--moss-background-alt);
}

.collection-card-no-cover {
  background: linear-gradient(135deg, var(--moss-background-alt) 0%, var(--moss-border-light) 100%);
}

.collection-card-content {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--moss-space-sm);
  background: var(--moss-background-alt);
  gap: var(--moss-space-sm);
}

.collection-card-title {
  font-size: var(--moss-font-sm);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collection-card-count {
  font-size: var(--moss-font-xs);
  color: var(--moss-text-muted);
  white-space: nowrap;
}

/* Dark mode for collection cards */
[data-theme="dark"] .collection-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .collection-card-no-cover {
  background: linear-gradient(135deg, var(--moss-background-alt) 0%, rgba(255, 255, 255, 0.05) 100%);
}

/* ==========================================================================
   Hero Section (:::hero directive)

   Usage: :::hero <image-url>
          overlay text here
          :::

   Full-width hero image with optional text overlay.

   Full-bleed is achieved by placing the hero at body level (outside <main>)
   in the HTML template. The base styles here define appearance, not layout.
   ========================================================================== */

.moss-hero {
  width: 100%;  /* Explicit width for flex child */
  height: 50vh;
  background-image:
    linear-gradient(135deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.2) 50%, transparent 100%),
    var(--hero-image);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: flex-end;
  position: relative;
  margin-bottom: var(--moss-space-lg);
}

.moss-hero-content {
  padding: var(--moss-space-xl);
  max-width: 600px;
}

.moss-hero-content p {
  color: #ffffff;
  font-size: var(--moss-font-lg);
  line-height: 1.5;
  margin: 0;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Mobile: auto height based on image aspect ratio */
@media (max-width: 64rem) {
  .moss-hero {
    height: auto;
    min-height: 40vh;
    aspect-ratio: 16/9;
  }

  .moss-hero-content {
    padding: var(--moss-space-md);
  }

  .moss-hero-content p {
    font-size: var(--moss-font-base);
  }
}

/* ==========================================================================
   Flexible Grid Layout ({{grid}} shortcode)

   Usage: {{grid N [ratio]}}...{{/grid}}
   - N: number of columns (1, 2, 3, etc.)
   - ratio: optional column width ratios like "1:3"
   - Content between --- separators becomes cards
   ========================================================================== */

.moss-grid {
  display: grid;
  gap: var(--moss-space-sm);
  margin: var(--moss-space-lg) 0;
}

/* Column configurations */
.moss-grid[data-columns="1"] {
  grid-template-columns: 1fr;
}

.moss-grid[data-columns="2"] {
  grid-template-columns: repeat(2, 1fr);
}

.moss-grid[data-columns="3"] {
  grid-template-columns: repeat(3, 1fr);
}

.moss-grid[data-columns="4"] {
  grid-template-columns: repeat(4, 1fr);
}

/* Ratio configurations for 2-column grids */
.moss-grid[data-columns="2"][data-ratio="1:2"] {
  grid-template-columns: 1fr 2fr;
}

.moss-grid[data-columns="2"][data-ratio="1:3"] {
  grid-template-columns: 1fr 3fr;
}

.moss-grid[data-columns="2"][data-ratio="2:1"] {
  grid-template-columns: 2fr 1fr;
}

.moss-grid[data-columns="2"][data-ratio="3:1"] {
  grid-template-columns: 3fr 1fr;
}

/* Grid card styling */
.moss-grid-card {
  /* Cards are transparent by default, letting content style itself */
}

.moss-grid-card img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
}

.moss-grid-card h2 {
  margin-top: 0;
  color: var(--moss-accent);
}

/* Responsive: collapse to single column on mobile */
@media (max-width: 768px) {
  .moss-grid {
    grid-template-columns: 1fr !important;
  }

  .moss-grid-card img {
    max-width: 200px;
    margin: 0 auto;
    display: block;
  }
}

/* ==========================================================================
   13. Series Navigation (Article Page)
   Unified clickable cards:
     Row 1: [← Prev Title]  [Next Title →] (unified clickable cards, side by side)
     Row 2: Collection Name (centered link)
   ========================================================================== */

.series-nav {
  margin-top: var(--moss-space-xl);
  margin-bottom: 60px;
  padding-top: var(--moss-space-lg);
  border-top: 1px solid var(--moss-border-light);
}

/* Row 1: Navigation cards - always side by side */
.series-nav-links {
  display: flex;
  justify-content: space-between;
  gap: var(--moss-space-sm);  /* Small gap between titles */
}

/* Navigation link - flexbox keeps arrow fixed, title wraps */
.series-nav-link {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  width: 50%;
  font-size: var(--moss-font-sm);
  line-height: 1.4;
  color: var(--moss-text-muted);
  text-decoration: none;  /* Override article a default */
}

/* Next link: flex-end to align arrow to right edge */
.series-nav-next {
  justify-content: flex-end;
  text-align: right;
}

/* Arrow stays fixed, doesn't wrap */
.series-nav-arrow {
  flex-shrink: 0;
}

/* Title can wrap to multiple lines */
.series-nav-title {
  /* inherits line-height from parent */
}

/* Hover: only underline the title, not the arrow */
.series-nav-link:hover .series-nav-title {
  text-decoration: underline;
}

/* Empty placeholder to maintain layout */
.series-nav-link.empty {
  visibility: hidden;
}

/* Row 2: Collection link centered (below nav links) */
.series-nav-collection-row {
  text-align: center;
  margin-top: var(--moss-space-md);
}

.series-nav-collection {
  color: var(--moss-text-secondary);  /* Darker than muted for differentiation */
  font-size: var(--moss-font-sm);
  text-decoration: none;  /* Override article a default */
}

.series-nav-collection:hover {
  text-decoration: underline;
}

/* Dark mode */
.dark .series-nav {
  border-color: var(--moss-border-light);
}

/* Mobile: keep same layout, just ensure touch targets */
@media (max-width: 600px) {
  .collection-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--moss-space-xs);
  }
}

/* ==========================================================================
   14. Media Collections
   ========================================================================== */

/* Media Grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--moss-space-md);
  margin: var(--moss-space-xl) 0;
}

.media-item {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  border-radius: 6px;
  cursor: pointer;
  background: var(--moss-background-alt);
}

.media-item img,
.media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.media-item:hover img,
.media-item:hover video,
.media-item:focus img,
.media-item:focus video {
  transform: scale(1.03);
}

.media-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--moss-space-sm) var(--moss-space-md);
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: #fff;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.media-item:hover .media-overlay,
.media-item:focus .media-overlay {
  opacity: 1;
}

.media-title {
  font-size: var(--moss-font-sm);
  font-weight: 400;
  margin: 0;
}

/* Video play indicator */
.media-item[data-type="video"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  opacity: 0.9;
  transition: opacity 0.2s ease;
  z-index: 1;
}

.media-item[data-type="video"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-40%, -50%);
  border-left: 16px solid #fff;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  z-index: 2;
}

.media-item[data-type="video"]:hover::before {
  opacity: 1;
  background: rgba(0,0,0,0.7);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--moss-space-lg);
}

.lightbox[hidden] {
  display: none;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 75vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-image,
.lightbox-video {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 4px;
  object-fit: contain;
}

.lightbox-iframe {
  width: 80vw;
  height: 60vh;
  border: none;
  border-radius: 4px;
  background: #fff;
}

.lightbox-caption {
  text-align: center;
  color: #fff;
  margin-top: var(--moss-space-md);
  max-width: 600px;
}

.lightbox-title {
  font-size: var(--moss-font-lg);
  font-weight: 400;
  margin: 0 0 var(--moss-space-sm) 0;
}

.lightbox-article-link {
  color: var(--moss-accent);
  text-decoration: none;
  font-size: var(--moss-font-sm);
}

.lightbox-article-link:hover {
  text-decoration: underline;
}

.lightbox-close {
  position: absolute;
  top: var(--moss-space-md);
  right: var(--moss-space-md);
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  line-height: 1;
  padding: var(--moss-space-xs);
}

.lightbox-close:hover {
  opacity: 1;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #fff;
  font-size: 2.5rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: var(--moss-space-md);
}

.lightbox-nav:hover {
  opacity: 1;
}

.lightbox-prev {
  left: var(--moss-space-sm);
}

.lightbox-next {
  right: var(--moss-space-sm);
}

/* Video figure styling */
.video-figure {
  margin: var(--moss-space-lg) 0;
}

.video-figure video {
  max-width: 100%;
  border-radius: 6px;
}

.video-figure figcaption {
  margin-top: var(--moss-space-sm);
  color: var(--moss-text-secondary);
  font-size: var(--moss-font-sm);
}

/* ==========================================================================
   Video in Article Content
   Videos embedded via markdown are wrapped in <p> tags by pulldown-cmark.
   Apply responsive styling to ensure proper aspect ratio and controls overlay.
   ========================================================================== */

/* Video paragraph container - treat like video-figure */
article p:has(> video:only-child) {
  margin: var(--moss-space-lg) 0;
}

/* Video element styling */
article p > video,
article video {
  max-width: 100%;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: var(--moss-background-alt);
  object-fit: contain;
}

/* Override inline height attribute for percentage-width videos */
article p > video[height],
article video[height] {
  height: auto !important;
  aspect-ratio: 16 / 9;
}

/* Mobile adjustments for media grid */
@media (max-width: 48rem) {
  .media-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--moss-space-sm);
  }

  .lightbox-nav {
    display: none;
  }

  .lightbox-iframe {
    width: 95vw;
    height: 50vh;
  }
}

@media (max-width: 30rem) {
  .media-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   15. Latest Sidebar (list_style: sidebar)

   Design: Centered content with absolutely positioned sidebar.

   Layout diagram (desktop):
   |<------------------ viewport ------------------>|
   |              |<-- 65ch centered -->|           |
   | [sidebar]   |     [container]     |           |
   |     ↑       |                     |           |
   | absolute    |                     |           |
   | positioned  |                     |           |

   Key principles:
   - Container stays centered exactly like non-sidebar pages (65ch, margin: 0 auto)
   Sidebar is sticky-positioned on desktop, below content on mobile.
   ========================================================================== */

/* Sidebar styles defined in main.has-sidebar section above */

.latest-sidebar h3 {
  font-size: var(--moss-font-xl);
  font-weight: 600;
  margin: 0 0 var(--moss-space-md) 0;
  color: var(--moss-text-primary);
}

.latest-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.latest-sidebar li {
  margin-bottom: var(--moss-space-xs);
}

.latest-sidebar .prefix-link {
  display: flex;
  gap: var(--moss-space-sm);
  padding: var(--moss-space-xs) 0;
  color: var(--moss-text-secondary);
  text-decoration: none;
  font-size: var(--moss-font-base);
  line-height: 1.4;
}

.latest-sidebar .prefix-link:hover {
  color: var(--moss-text-primary);
}

.latest-sidebar .prefix-link-prefix {
  flex-shrink: 0;
  color: var(--moss-text-tertiary);
  font-variant-numeric: tabular-nums;
}

.latest-sidebar .prefix-link-title {
  color: inherit;
}

/* Tablet/Mobile (max-width: 64rem): sidebar below content, nav grid layout */
@media (max-width: 64rem) {
  /* Sidebar layout: stack vertically on mobile */
  main.has-sidebar {
    flex-direction: column;
  }

  main.has-sidebar > .latest-sidebar {
    width: 100%;
    max-width: var(--moss-content-width);
    margin: 0 auto;
    order: 2;  /* Sidebar comes after content */
    position: static;
  }

  /* Nav: CSS Grid for clean 2-row layout
     Row 1: [site-name] ... [toggle]
     Row 2: [nav-links spanning full width] */
  .nav-content {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "name icons"
      "links links";
    gap: var(--moss-space-sm) var(--moss-space-md);
  }

  .nav-left {
    grid-area: name;
  }

  .nav-right {
    display: contents;  /* Children participate directly in parent grid */
  }

  .nav-links {
    grid-area: links;
    display: flex;
    justify-content: space-between;
  }

  .nav-icons {
    grid-area: icons;
  }

  /* Hide hamburger on tablet - only for narrow screens */
  .mobile-menu-button {
    display: none;
  }
}

/* ==========================================================================
   16. Immersive Mode - FLIP-Based Click-Triggered Fullscreen Toggle

   When body has class "immersive-ready" (set when article contains local iframe),
   JavaScript wraps the iframe in a container with a floating fullscreen button.
   Clicking toggles true fullscreen using the FLIP technique for smooth animation.

   States:
   - Normal: iframe inline with description, fullscreen button at lower-right
   - Fullscreen: iframe covers entire viewport, all chrome hidden, exit button visible
   ========================================================================== */

/* ==========================================================================
   16.1 Iframe Wrapper
   Relative container created by JS to position the fullscreen button
   and serve as the FLIP animation target.
   ========================================================================== */

.immersive-ready main > article.container > .immersive-iframe-wrapper {
  position: relative;
  display: block;
}

.immersive-ready main > article.container > .immersive-iframe-wrapper > iframe {
  width: 100%;
  height: 60vh;
  border: none;
  border-radius: 8px;
  background: var(--moss-background-alt);
  margin-top: var(--moss-space-lg);
  display: block;
}

/* ==========================================================================
   16.2 Fullscreen Toggle Button
   Always visible at lower-right of iframe. Semi-transparent with blur.
   ========================================================================== */

.immersive-fullscreen-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  z-index: 210;
  transition: background 0.15s ease, transform 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.immersive-fullscreen-btn:hover {
  background: rgba(0, 0, 0, 0.6);
  transform: scale(1.08);
}

.immersive-fullscreen-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

/* ==========================================================================
   16.3 Fullscreen Active State
   Body class added by JS. Hides all chrome, iframe wrapper covers viewport.
   ========================================================================== */

.immersive-fs-active {
  overflow: hidden;
}

.immersive-fs-active main > article.container > .immersive-iframe-wrapper {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.immersive-fs-active main > article.container > .immersive-iframe-wrapper > iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

/* Hide all chrome in fullscreen */
.immersive-fs-active > header,
.immersive-fs-active > footer {
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.immersive-fs-active main > article.container > *:not(.immersive-iframe-wrapper) {
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

/* Chrome fade-in when exiting */
body:not(.immersive-fs-active) > header,
body:not(.immersive-fs-active) > footer {
  transition: opacity 200ms ease 100ms;
}

body:not(.immersive-fs-active) main > article.container > *:not(.immersive-iframe-wrapper) {
  transition: opacity 200ms ease 100ms;
}

/* Button repositioned in fullscreen */
.immersive-fs-active .immersive-fullscreen-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  background: rgba(128, 128, 128, 0.3);
}

.immersive-fs-active .immersive-fullscreen-btn:hover {
  background: rgba(128, 128, 128, 0.5);
}

/* WebKit (Safari + Tauri WKWebView): match native video player convention.
   hanging-punctuation is Safari/WebKit-only (not Chrome/Firefox/Edge).
   Placed after fullscreen-active rules so @supports overrides take precedence. */
@supports (hanging-punctuation: first) {
  .immersive-fullscreen-btn {
    bottom: auto;
    right: auto;
    top: 16px;
    left: 16px;
  }

  .immersive-fs-active .immersive-fullscreen-btn {
    bottom: auto;
    right: auto;
    top: 24px;
    left: 24px;
  }
}

/* ==========================================================================
   16.4 FLIP Animation Classes
   Applied by JS during enter/exit transitions.
   transform-origin: top left is required for FLIP math to work correctly.
   ========================================================================== */

.immersive-iframe-wrapper.fs-animating-enter {
  transform-origin: top left;
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.immersive-iframe-wrapper.fs-animating-exit {
  transform-origin: top left;
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   16.5 Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .immersive-iframe-wrapper.fs-animating-enter,
  .immersive-iframe-wrapper.fs-animating-exit {
    transition: none !important;
  }

  .immersive-fs-active > header,
  .immersive-fs-active > footer,
  .immersive-fs-active main > article.container > *:not(.immersive-iframe-wrapper) {
    transition: none !important;
  }

  .immersive-fullscreen-btn {
    transition: none !important;
  }
}

/* ==========================================================================
   16.6 Print Styles
   ========================================================================== */

@media print {
  .immersive-ready main > article.container > .immersive-iframe-wrapper > iframe {
    width: 100% !important;
    height: auto !important;
    min-height: 400px;
    page-break-inside: avoid;
  }

  .immersive-fullscreen-btn {
    display: none !important;
  }
}

/* ==========================================================================
   16.9 Mobile Adjustments
   ========================================================================== */

@media (max-width: 48rem) {
  .immersive-ready main > article.container {
    padding-bottom: 150vh;
  }

  .immersive-ready main > article.container > iframe {
    min-height: 50vh;
  }
}
