@layer reset, base, layout, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p { margin: 0; }
  button, input { font: inherit; }
  img { max-width: 100%; height: auto; }
  button, summary { cursor: pointer; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    color-scheme: light dark;
    --ink: light-dark(#292722, #eee9de);
    --muted: light-dark(#716e64, #b7b1a5);
    --paper: light-dark(#fffefa, #1e1f1b);
    --canvas: light-dark(#f6f4ec, #171815);
    --line: light-dark(#dedbd1, #3a3c33);
    --soft: light-dark(#efede4, #2c2e26);
    --accent: light-dark(#966400, #f3c65c);
    --link: light-dark(#805700, #f3c65c);
    --field: light-dark(#ffffff, #23251f);
    --active: light-dark(#e9e5d8, #303228);
    --note: light-dark(#fff5d6, #302a1d);
    --note-border: light-dark(#e3d49b, #665332);
    --row-hover: light-dark(#faf8f0, #272922);
    --number: light-dark(#aaa18c, #a79c83);
    --marker: light-dark(#ffce4f, #785b1c);
    --quote: light-dark(#faf7ec, #28271f);
    --selection: light-dark(#ffe49a, #72551d);
    --focus: light-dark(#826000, #ffce4f);
    --gold: #ffbf19;
    --on-gold: #292722;
  }
  :root[data-theme=light] { color-scheme: light; }
  :root[data-theme=dark] { color-scheme: dark; }
  html { scroll-behavior: smooth; scroll-padding-top: 2rem; }
  body { background: var(--canvas); color: var(--ink); font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
  a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
  button, input { color: inherit; }
  button { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: .65rem 1rem; }
  button:hover { border-color: var(--ink); background: var(--soft); }
  :focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
  h1, h2, h3, .wordmark { font-family: "Trebuchet MS", "Arial Rounded MT Bold", sans-serif; line-height: 1.12; letter-spacing: -.045em; }
  h1 { font-size: clamp(2.4rem, 4.5vw, 4.5rem); }
  h2 { font-size: clamp(1.6rem, 2.2vw, 2.1rem); }
  h3 { font-size: 1.27rem; letter-spacing: -.025em; }
  ::selection { background: var(--selection); }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
  .muted { color: var(--muted); }
  .gold { color: var(--accent); }
  .skip-link { position: absolute; top: -100px; left: 1rem; background: var(--gold); padding: 1rem; z-index: 10; }
  .skip-link:focus { top: .5rem; }
}

@layer layout {
  .site-header { max-width: 1500px; margin: auto; min-height: 100px; padding: 1.5rem 3.5rem; display: flex; align-items: center; gap: 2rem; border-bottom: 1px solid var(--line); }
  .workspace { max-width: 1500px; margin: auto; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
  .sidebar { padding: 3rem 1.7rem 3rem 3.5rem; border-right: 1px solid var(--line); }
  main { min-width: 0; padding: 3rem 3.5rem 4rem; background: var(--paper); }
  .site-footer { max-width: 1500px; margin: auto; padding: 2.4rem 3.5rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 2rem; }
  .site-footer nav { display: flex; flex-wrap: wrap; align-content: flex-start; gap: .8rem 1.4rem; font-size: .8rem; }
  .site-footer p { color: var(--muted); font-size: .8rem; margin-top: .4rem; }
}

@layer components {
  .wordmark { display: inline-flex; align-items: center; font-size: 1.65rem; font-weight: 900; text-decoration: none; white-space: nowrap; letter-spacing: -.065em; }
  .wordmark > span:not(.brand-symbol) { color: var(--accent); }
  .brand-symbol { background: var(--gold); color: var(--on-gold); font-family: sans-serif; border-radius: 50%; font-size: 1.6rem; width: 34px; height: 34px; display: grid; place-items: center; margin-right: .5rem; }
  .header-nav { display: flex; gap: 1.6rem; margin-left: auto; font-size: .85rem; font-weight: 600; }
  .header-nav a { text-decoration: none; padding: .4rem 0; }
  .header-nav a[aria-current] { box-shadow: 0 2px var(--ink); }
  .header-tools { display: flex; align-items: center; gap: .65rem; margin-left: .8rem; }
  .theme-toggle { display: none; width: 40px; height: 40px; padding: 0; flex: 0 0 auto; place-items: center; }
  [data-theme] .theme-toggle { display: grid; }
  .theme-toggle .theme-moon, [data-theme=dark] .theme-toggle .theme-sun { display: none; }
  [data-theme=dark] .theme-toggle .theme-moon { display: block; }
  .language { position: relative; font-size: .8rem; }
  .language summary { padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 6px; list-style: none; white-space: nowrap; }
  .language summary::-webkit-details-marker { display: none; }
  .language nav { position: absolute; right: 0; top: calc(100% + .5rem); min-width: 130px; padding: .4rem; background: var(--paper); box-shadow: 0 6px 25px #29272220; border: 1px solid var(--line); border-radius: 8px; z-index: 4; }
  .language a { display: block; padding: .45rem .65rem; border-radius: 4px; text-decoration: none; }
  .language a:hover, .language a[aria-current] { background: var(--soft); }
  .sidebar-label, .eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: .65rem; font-weight: 750; }
  .sidebar nav { margin: 1rem -.65rem 0; display: grid; gap: .4rem; }
  .sidebar nav a { display: flex; align-items: center; gap: .8rem; padding: .65rem; text-decoration: none; border-radius: 6px; font-size: .85rem; }
  .sidebar nav a span { font-size: 1.2rem; line-height: 1; width: 20px; text-align: center; }
  .sidebar nav a[aria-current], .sidebar nav a:hover { background: var(--active); }
  .sidebar nav a[aria-current] { font-weight: 700; }
  .desk-note { margin-top: 4rem; padding: 1.2rem .95rem; border: 1px solid var(--note-border); border-radius: 3px 12px 12px 12px; background: var(--note); transform: rotate(-2deg); }
  .desk-note strong { display: block; font: 700 1.05rem/1.2 "Trebuchet MS", sans-serif; margin: .6rem 0; }
  .desk-note p { font-size: .75rem; line-height: 1.6; }
  .desk-note a { display: inline-block; font-weight: 650; font-size: .7rem; margin-top: 1rem; }
  .note-star { font-size: 1.8rem; line-height: 1; }
  .sidebar-signature { margin-top: 2rem; font-family: Georgia, serif; font-style: italic; font-size: .8rem; color: var(--muted); }
  .hero { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1.8rem; align-items: center; padding: .5rem 0 2.5rem; }
  .hero .eyebrow { margin-bottom: 1.4rem; display: flex; align-items: center; gap: .5rem; }
  .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
  .hero h1 { max-width: 700px; font-size: clamp(2.4rem, 4.15vw, 4.3rem); line-height: 1.1; }
  .marker { background: linear-gradient(transparent 72%, var(--marker) 72%, var(--marker) 96%, transparent 96%); padding-bottom: .06em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
  .hero-intro { color: var(--muted); max-width: 450px; margin-top: 1.5rem; line-height: 1.7; font-size: .98rem; }
  .text-link { display: inline-flex; align-items: center; gap: 1.6rem; font-weight: 700; margin-top: 1.3rem; font-size: .85rem; }
  .maestro-card { color: var(--on-gold); background: #fff2c3; border: 1px solid #e9d99c; border-radius: 45% 45% 8px 8px; transform: rotate(3deg); padding: .6rem .6rem 1.1rem; position: relative; box-shadow: 5px 6px 0 #f3efde; }
  .maestro-card img { display: block; width: 100%; mix-blend-mode: multiply; }
  .card-caption { display: block; font-family: Georgia, serif; font-style: italic; text-align: center; font-size: .72rem; }
  .card-spark { position: absolute; top: 1rem; right: .2rem; font-size: 1.7rem; color: var(--accent); }
  .search-form { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line); padding: .45rem; border-radius: 10px; background: var(--field); }
  .search-form:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
  .search-icon { margin-left: .7rem; font-size: 1.8rem; line-height: 1; }
  .search-form input { border: 0; background: transparent; outline: none; width: 100%; min-width: 0; padding: .7rem .4rem; font-size: .9rem; }
  .search-form input::placeholder { color: var(--muted); opacity: 1; }
  .search-form button { background: var(--gold); color: var(--on-gold); border-color: #e5aa10; white-space: nowrap; font-weight: 650; font-size: .8rem; padding: .8rem 1.1rem; }
  .search-form button:hover { background: #ffd055; }
  .guide-section { margin-top: 2.8rem; }
  .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; }
  .section-heading .eyebrow { margin-bottom: .45rem; font-size: .6rem; }
  .count { font-size: .7rem; white-space: nowrap; padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 20px; }
  .topic-tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .3rem; border-bottom: 1px solid var(--line); padding-bottom: .75rem; }
  .topic-tabs a { text-decoration: none; font-size: .75rem; padding: .45rem .9rem; border-radius: 5px; }
  .topic-tabs a[aria-current] { background: var(--ink); color: var(--paper); font-weight: 600; }
  .topic-tabs a:hover { background: var(--soft); color: var(--ink); }
  .subcategories { display: flex; flex-wrap: wrap; gap: .5rem; padding: 1rem 0; border-bottom: 1px solid var(--line); }
  .subcategories a { border: 1px solid var(--line); border-radius: 6px; padding: .4rem .7rem; font-size: .75rem; text-decoration: none; }
  .subcategories a:hover { background: var(--soft); }
  .subcategories span { margin-left: .5rem; }
  .guide-list { padding: 0; margin: 0; list-style: none; }
  .guide-row { border-bottom: 1px solid var(--line); }
  .guide-row > a { display: grid; grid-template-columns: 36px 1fr 28px; gap: 1rem; padding: 1.5rem .35rem; text-decoration: none; }
  .guide-row:hover { background: var(--row-hover); }
  .guide-row:hover .row-arrow { transform: translate(2px, -2px); }
  .guide-number { font: italic 1.1rem Georgia, serif; color: var(--number); padding-top: .2rem; }
  .guide-meta { display: block; font-size: .65rem; letter-spacing: .035em; color: var(--muted); margin-bottom: .45rem; }
  .guide-meta > span { color: var(--muted); padding: 0 .4rem; }
  .guide-row p { margin-top: .55rem; font-size: .8rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 680px; line-height: 1.6; }
  .row-arrow { font-size: 1.4rem; align-self: center; transition: transform .15s; }
  .pagination { display: flex; align-items: center; justify-content: center; gap: 1.5rem; margin-top: 1.5rem; font-size: .8rem; }
  .pagination button:disabled { cursor: default; opacity: .35; }
  .page-heading { margin: .5rem 0 2rem; max-width: 800px; }
  .page-heading h1 { margin: 1rem 0; }
  .page-heading > p:not(.eyebrow) { color: var(--muted); }
  .empty { padding: 2rem 0; color: var(--muted); }
  .result-count { color: var(--muted); font-size: .8rem; margin-bottom: 1rem; }
  .article-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .75rem; color: var(--muted); margin-bottom: 2.5rem; }
  .article-heading { max-width: 850px; }
  .article-category { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
  .article-category a { text-decoration: none; }
  .article-category a:hover { text-decoration: underline; }
  .article-heading h1 { font-size: clamp(2rem, 3.6vw, 3.6rem); margin: 1rem 0; }
  .article-deck { color: var(--muted); font-size: 1.05rem; line-height: 1.7; }
  .article-meta { display: flex; gap: .75rem; align-items: center; font-size: .75rem; margin-top: 1.8rem; }
  .author-avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--gold); color: var(--on-gold); font: bold 1.2rem Georgia, serif; }
  .article-actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.5rem; padding-bottom: 1.8rem; border-bottom: 1px solid var(--line); }
  .article-actions button { font-size: .75rem; }
  .article-actions [aria-pressed=true] { background: var(--note); border-color: var(--note-border); }
  .article-layout { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 2rem; margin-top: 2rem; }
  .prose { max-width: 720px; overflow-wrap: anywhere; line-height: 1.8; }
  .prose > :first-child { margin-top: 0; }
  .prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose .table-wrap { margin: 1.2rem 0; }
  .prose h2 { margin-top: 2.6rem; margin-bottom: 1rem; font-size: 1.75rem; }
  .prose h3 { margin-top: 2rem; margin-bottom: .8rem; font-size: 1.3rem; }
  .prose h4 { font-size: 1.05rem; margin: 1.5rem 0 .7rem; }
  .prose li { margin: .5rem 0; padding-left: .15rem; }
  .prose li > p { margin: .5rem 0; }
  .prose a { color: var(--link); }
  .prose img { display: block; border-radius: 8px; margin: 1.5rem 0; background: var(--soft); }
  .prose blockquote { padding: .25rem 1.3rem; border-left: 3px solid var(--gold); background: var(--quote); }
  .prose code { background: var(--soft); padding: .15rem .3rem; border-radius: 3px; font-size: .88em; }
  .prose pre { overflow: auto; padding: 1rem; background: var(--soft); border-radius: 6px; }
  .prose pre code { padding: 0; }
  .prose hr { margin: 2rem 0; border: 0; border-top: 1px solid var(--line); }
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: .85rem; }
  th, td { border: 1px solid var(--line); padding: .6rem; text-align: left; }
  th { background: var(--soft); }
  .toc { font-size: .75rem; }
  .toc details { position: sticky; top: 2rem; border-left: 1px solid var(--line); padding-left: 1.1rem; }
  .toc summary { font-weight: 700; }
  .toc ol { list-style: none; padding: 0; margin-top: 1rem; }
  .toc li { margin-bottom: .7rem; }
  .toc a { color: var(--muted); text-decoration: none; }
  .toc a:hover { color: var(--ink); text-decoration: underline; }
  .standalone { margin-top: 2rem; }
  .related { border-top: 1px solid var(--line); padding-top: 2rem; }
  .footer-brand { text-decoration: none; font-weight: 800; letter-spacing: -.04em; }
  .footer-brand span { color: var(--accent); }
  .toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .75rem 1.2rem; border-radius: 8px; font-size: .85rem; z-index: 5; }
  .toast:empty { display: none; }
}

@media (min-width: 1450px) { .hero { grid-template-columns: 1fr 310px; } }
@media (max-width: 1100px) {
  .site-header, .site-footer { padding-left: 2rem; padding-right: 2rem; }
  .workspace { grid-template-columns: 185px minmax(0, 1fr); }
  .sidebar { padding-left: 2rem; padding-right: 1.2rem; }
  main { padding: 2.5rem 2rem; }
  .hero { grid-template-columns: 1fr 200px; }
  .hero h1 { font-size: 2.7rem; }
  .article-layout { grid-template-columns: minmax(0,1fr); }
  .toc { grid-row: 1; }
  .toc details { position: static; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 8px; }
  .toc ol { columns: 2; }
}
@media (max-width: 760px) {
  .site-header { min-height: 80px; padding: 1rem 1.25rem; gap: .8rem; flex-wrap: wrap; }
  .wordmark { font-size: 1.4rem; }
  .brand-symbol { font-size: 1.3rem; width: 28px; height: 28px; }
  .header-nav { display: none; }
  .header-tools { margin-left: auto; gap: .4rem; }
  .language { font-size: .7rem; }
  .workspace { display: block; }
  .sidebar { padding: .75rem 1.25rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-label, .desk-note, .sidebar-signature { display: none; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .2rem .7rem; margin: 0; }
  .sidebar nav a { font-size: .72rem; padding: .5rem .35rem; gap: .3rem; }
  .sidebar nav a span { width: 16px; font-size: 1rem; }
  main { padding: 2rem 1.25rem 3rem; }
  .hero { gap: 1rem; padding: .2rem 0 2rem; grid-template-columns: minmax(0,1fr) 130px; }
  .hero h1 { font-size: clamp(1.85rem, 6vw, 2.7rem); }
  .hero .eyebrow { font-size: .53rem; line-height: 1.5; margin-bottom: 1rem; }
  .hero-intro { font-size: .85rem; margin-top: 1.1rem; }
  .maestro-card { padding-bottom: .7rem; }
  .card-caption { font-size: .5rem; }
  .card-spark { font-size: 1.2rem; }
  .text-link { font-size: .75rem; gap: .6rem; }
  .search-form { gap: .2rem; }
  .search-form button { width: 44px; min-width: 44px; height: 44px; padding: .5rem; font-size: 0; }
  .search-form button span { display: inline; font-size: 1.2rem; }
  .search-form input { font-size: 16px; }
  .search-icon { font-size: 1.4rem; margin-left: .3rem; }
  .guide-section { margin-top: 2rem; }
  .guide-row > a { gap: .6rem; grid-template-columns: 23px minmax(0,1fr) 20px; padding: 1.2rem 0; }
  .guide-row h3 { font-size: 1.13rem; line-height: 1.25; }
  .guide-row p { font-size: .75rem; }
  .topic-tabs a { font-size: .68rem; padding: .4rem .6rem; }
  .article-heading h1 { font-size: 2.2rem; }
  .article-deck { font-size: .95rem; }
  .prose { font-size: .95rem; }
  .toc ol { columns: 1; }
  .site-footer { padding: 1.75rem 1.25rem; flex-direction: column; gap: 1.2rem; }
  .site-footer nav { gap: .6rem 1rem; }
}
@media (max-width: 400px) {
  .hero { grid-template-columns: minmax(0,1fr); }
  .maestro-card { display: none; }
  .hero h1 { font-size: 2.4rem; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; } }
@media print {
  :root { color-scheme: light; }
  .site-header, .sidebar, .site-footer, .toc, .article-actions, .related { display: none; }
  .workspace, .article-layout { display: block; }
  main { padding: 0; }
  body { background: white; }
}
