/* ==========================================================================
   Layer 2: Long-Form Article Template Stylesheet (pages/article.css)
   Imported via native CSS Module Script in pages/article.js:
     import articleStyles from './article.css' with { type: 'css' };
     document.adoptedStyleSheets = [...document.adoptedStyleSheets, articleStyles];
   ========================================================================== */

@layer bivens.page {
  :host {
    display: block;
  }

  .editorial-shell {
    background-color: light-dark(
      var(--md-sys-color-surface-container-lowest),
      var(--md-sys-color-surface)
    );
    color: var(--md-sys-color-on-surface);
    min-block-size: calc(100dvh - 4rem);
  }

  .editorial-hero {
    background-color: light-dark(
      var(--md-ref-palette-primary-18),
      var(--md-ref-palette-primary-22)
    );
    color: var(--md-ref-palette-primary-97);
    padding: clamp(2.75rem, 5vw, 4.5rem) clamp(1.25rem, 4vw, 3rem);
    border-block-end: 1px solid var(--md-sys-color-outline-variant);
  }

  .editorial-hero-inner {
    max-inline-size: 72rem;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
  }

  .editorial-kicker {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--md-ref-palette-primary-80);
    margin: 0;
  }

  .editorial-title {
    font-family: var(--md-ref-typeface-brand, "Playfair Display", Georgia, serif);
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 700;
    line-height: 1.12;
    letter-spacing: -0.015em;
    color: var(--md-ref-palette-primary-97);
    margin: 0;
    max-inline-size: 48rem;
  }

  .editorial-subtitle {
    font-size: clamp(1rem, 1.35vw, 1.15rem);
    line-height: 1.6;
    color: var(--md-ref-palette-primary-80);
    max-inline-size: 46rem;
    margin: 0;
  }

  .article-breadcrumb {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--md-ref-palette-primary-80);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-block-end: 0.25rem;
  }

  .article-breadcrumb:hover {
    color: var(--md-ref-palette-primary-97);
  }

  .article-byline-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-block-start: 0.75rem;
    padding-block-start: 1rem;
    border-block-start: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.8125rem;
    color: var(--md-ref-palette-primary-80);
  }

  .article-byline-author strong {
    color: var(--md-ref-palette-primary-97);
  }

  .article-layout {
    max-inline-size: 72rem;
    margin-inline: auto;
    padding: clamp(2.25rem, 4vw, 3.75rem) clamp(1.25rem, 4vw, 3rem);
    display: grid;
    grid-template-columns: 16.5rem minmax(0, 44rem);
    justify-content: space-between;
    gap: 3rem;
    align-items: start;
  }

  @media (max-width: 960px) {
    .article-layout {
      grid-template-columns: 1fr;
      gap: 2rem;
    }
  }

  /* Sticky Left Table of Contents & Key Takeaways Rail */
  .article-rail {
    position: sticky;
    inset-block-start: 5.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
  }

  @media (max-width: 960px) {
    .article-rail {
      position: static;
    }
  }

  .rail-box {
    padding: 1.25rem;
    background-color: light-dark(
      var(--md-sys-color-surface-container-low),
      var(--md-sys-color-surface-container)
    );
    border: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .rail-title {
    font-size: 0.71875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--md-sys-color-outline);
    margin: 0;
  }

  .toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.8125rem;
  }

  .toc-list a {
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    font-weight: 600;
    display: block;
    padding-block: 0.15rem;
  }

  .toc-list a:hover {
    color: var(--md-sys-color-primary);
  }

  .toc-list .toc-upcoming {
    color: var(--md-sys-color-outline);
    font-weight: 500;
    display: block;
    padding-block: 0.15rem;
  }

  .rail-takeaways {
    margin: 0;
    padding-inline-start: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--md-sys-color-on-surface-variant);
  }

  .rail-takeaways strong {
    color: var(--md-sys-color-on-surface);
  }

  /* Main Long-Form Editorial Prose */
  .article-prose {
    font-size: 1.0625rem;
    line-height: 1.75;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
  }

  .article-prose > * {
    margin: 0;
  }

  .article-prose p.lead {
    font-size: 1.2rem;
    line-height: 1.65;
    color: var(--md-sys-color-on-surface);
    font-weight: 500;
  }

  .article-prose h2 {
    font-family: var(--md-ref-typeface-brand, "Playfair Display", Georgia, serif);
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--md-sys-color-on-surface);
    margin-block-start: 1.25rem;
    padding-block-start: 0.5rem;
    border-block-start: 1px solid var(--md-sys-color-outline-variant);
  }

  .article-prose h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin-block-start: 0.5rem;
  }

  .article-prose strong {
    color: var(--md-sys-color-on-surface);
  }

  .article-prose ul,
  .article-prose ol {
    padding-inline-start: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .prose-callout {
    padding: 1.25rem 1.5rem;
    background-color: light-dark(
      var(--md-sys-color-surface-container-low),
      var(--md-sys-color-surface-container)
    );
    border: 1px solid var(--md-sys-color-outline-variant);
    border-inline-start: 3.5px solid var(--md-sys-color-primary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .prose-callout-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--md-sys-color-primary);
    margin: 0;
  }

  .prose-callout p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--md-sys-color-on-surface);
    margin: 0;
  }

  .prose-pullquote {
    font-family: var(--md-ref-typeface-brand, "Playfair Display", Georgia, serif);
    font-size: 1.35rem;
    font-style: italic;
    line-height: 1.45;
    color: var(--md-sys-color-on-surface);
    padding: 1rem 0 1rem 1.5rem;
    border-inline-start: 3px solid var(--md-sys-color-primary);
  }

  /* Editorial Data Table */
  .prose-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--md-sys-color-outline-variant);
  }

  .prose-table {
    inline-size: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    font-variant-numeric: lining-nums tabular-nums;
  }

  .prose-table th,
  .prose-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-block-end: 1px solid var(--md-sys-color-outline-variant);
  }

  .prose-table th {
    background-color: light-dark(
      var(--md-sys-color-surface-container-low),
      var(--md-sys-color-surface-container)
    );
    color: var(--md-sys-color-on-surface);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .prose-table td {
    color: var(--md-sys-color-on-surface-variant);
  }

  .prose-table tr:last-child td {
    border-block-end: 0;
  }

  /* Code Blocks & MicroLighter Syntax Highlighting (CSS Custom Highlight API) */
  :root,
  micro-lighter,
  .prose-code {
    --syntax-background: light-dark(
      var(--md-ref-palette-primary-18),
      var(--md-ref-palette-primary-15)
    );
    --syntax-foreground: var(--md-ref-palette-primary-97);
    --syntax-comment: var(--md-ref-palette-primary-68);
    --syntax-keyword: #bb9af7;
    --syntax-operator: #c0caf5;
    --syntax-string: #9ece6a;
    --syntax-constant: #ff9e64;
    --syntax-function: #7aa2f7;
    --syntax-type: #bb9af7;
    --syntax-variable: #e0af68;
    --syntax-property: #7dcfff;
    --syntax-tag: #f7768e;
    --syntax-selector: #7aa2f7;
    --syntax-inserted: #73daca;
    --syntax-deleted: #f7768e;
  }

  micro-lighter {
    display: grid;
    position: relative;
  }

  micro-lighter[controls*="copy"] > .prose-code {
    padding-inline-end: 4.75rem;
  }

  micro-lighter::part(copy-button) {
    font-family: var(--md-ref-typeface-mono, "JetBrains Mono", ui-monospace, monospace);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background-color: light-dark(
      var(--md-ref-palette-primary-24),
      var(--md-ref-palette-primary-21)
    );
    color: var(--md-ref-palette-primary-95);
    border: 1px solid var(--md-ref-palette-primary-42);
    border-radius: 2px;
    margin: 0.65rem;
    padding: 0.35rem 0.6rem;
    transition: background-color 120ms ease, border-color 120ms ease;
  }

  micro-lighter::part(copy-button):hover {
    background-color: var(--md-ref-palette-primary-31);
    border-color: var(--md-ref-palette-primary-68);
  }

  .prose-code {
    background-color: var(--syntax-background);
    color: var(--syntax-foreground);
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--md-sys-color-outline-variant);
    overflow-x: auto;
    font-family: var(--md-ref-typeface-mono, "JetBrains Mono", ui-monospace, monospace);
    font-size: 0.84375rem;
    line-height: 1.6;
  }

  ::highlight(comment),
  ::highlight(quote) {
    color: var(--syntax-comment);
  }

  ::highlight(keyword),
  ::highlight(storage),
  ::highlight(at-rule),
  ::highlight(doctype),
  ::highlight(important),
  ::highlight(section) {
    color: var(--syntax-keyword);
  }

  ::highlight(operator),
  ::highlight(punctuation) {
    color: var(--syntax-operator);
  }

  ::highlight(string),
  ::highlight(regexp),
  ::highlight(attribute-value),
  ::highlight(link),
  ::highlight(raw) {
    color: var(--syntax-string);
  }

  ::highlight(numeric),
  ::highlight(boolean),
  ::highlight(constant),
  ::highlight(symbol),
  ::highlight(character-entity),
  ::highlight(anchor),
  ::highlight(entity) {
    color: var(--syntax-constant);
  }

  ::highlight(function),
  ::highlight(decorator),
  ::highlight(animation) {
    color: var(--syntax-function);
  }

  ::highlight(type),
  ::highlight(support) {
    color: var(--syntax-type);
  }

  ::highlight(variable),
  ::highlight(interpolation) {
    color: var(--syntax-variable);
  }

  ::highlight(property),
  ::highlight(key),
  ::highlight(attribute-name) {
    color: var(--syntax-property);
  }

  ::highlight(tag) {
    color: var(--syntax-tag);
  }

  ::highlight(selector) {
    color: var(--syntax-selector);
  }

  ::highlight(inserted) {
    color: var(--syntax-inserted);
  }

  ::highlight(deleted) {
    color: var(--syntax-deleted);
  }

  /* Editorial Figures & Network Diagrams */
  .prose-figure {
    margin: 0.5rem 0;
    border: 1px solid var(--md-sys-color-outline-variant);
    background-color: light-dark(
      var(--md-sys-color-surface-container-lowest, #ffffff),
      var(--md-sys-color-surface-container-low)
    );
    overflow: hidden;
  }

  .prose-figure img {
    display: block;
    inline-size: 100%;
    max-inline-size: 100%;
    block-size: auto;
  }

  .prose-figcaption {
    padding: 0.875rem 1.25rem;
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--md-sys-color-on-surface-variant);
    border-block-start: 1px solid var(--md-sys-color-outline-variant);
    background-color: light-dark(
      var(--md-sys-color-surface-container-low),
      var(--md-sys-color-surface-container)
    );
  }

  .article-author-box {
    margin-block-start: 2rem;
    padding: 1.75rem;
    background-color: light-dark(
      var(--md-sys-color-surface-container-low),
      var(--md-sys-color-surface-container)
    );
    border: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
  }

  .author-bio-col {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-inline-size: 32rem;
  }

  .author-bio-name {
    font-family: var(--md-ref-typeface-brand, "Playfair Display", Georgia, serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin: 0;
  }

  .author-bio-text {
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--md-sys-color-on-surface-variant);
    margin: 0;
  }
}
