@layer base, layout, components, markdown, responsive;

@layer base {
  :root {
    --bg: #f5f5f0; --surface: #fff; --surface-soft: #f0f1ed; --text: #252a30;
    --muted: #646a71; --border: #e1e3dc; --accent: #f3d454; --accent-ink: #393013;
    --link: #876710; --code-bg: #f5f6f1; --shadow: 0 16px 60px #26301b18;
    --header-height: 76px; --radius: 10px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px; color-scheme: light;
  }
  :root[data-theme="dark"] {
    --bg: #151a21; --surface: #1e252e; --surface-soft: #29323d; --text: #eeeee9;
    --muted: #aab2be; --border: #37424e; --accent: #f3d454; --accent-ink: #393013;
    --link: #f3d454; --code-bg: #19202a; --shadow: 0 16px 60px #0006; color-scheme: dark;
  }
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.65; -webkit-font-smoothing: antialiased; }
  a { color: var(--link); text-decoration: none; }
  button, input { font: inherit; }
  button { cursor: pointer; }
  button, input { color: inherit; }
  svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 3px solid var(--link); outline-offset: 4px; border-radius: 3px; }
  ::selection { background: var(--accent); color: var(--accent-ink); }
  kbd { font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; border: 1px solid var(--border); border-radius: 4px; padding: 3px 5px; }
  html { scroll-padding-top: calc(var(--header-height) + 30px); }
}

@layer layout {
  .topbar { height: var(--header-height); position: sticky; top: 0; z-index: 40; background: var(--bg); border-bottom: 1px solid var(--border); }
  .topbar-inner { max-width: 1560px; height: 100%; margin: auto; padding: 0 36px; display: flex; align-items: center; gap: 24px; }
  .brand { display: flex; align-items: center; gap: 11px; color: var(--text); white-space: nowrap; }
  .brand-symbol { display: flex; align-items: center; justify-content: center; width: 39px; height: 39px; background: #252a30; border-radius: 7px; font-size: 22px; letter-spacing: -2px; font-weight: 700; color: #fff; }
  .brand-symbol span { color: var(--accent); padding-left: 1px; }
  .brand-name { font-size: 21px; font-weight: 730; line-height: 1.05; letter-spacing: -.6px; }
  .brand-suffix { font-weight: 450; color: var(--muted); }
  .brand-name small { display: block; font-size: 8px; letter-spacing: 1.6px; font-weight: 650; margin-top: 5px; color: var(--muted); }
  .header-divider { width: 1px; height: 25px; background: var(--border); }
  .sdk-label { color: var(--muted); font-size: 12px; font-weight: 550; }
  .header-actions { display: flex; align-items: center; gap: 20px; margin-left: auto; }
  .docs-layout { max-width: 1560px; margin: auto; display: grid; grid-template-columns: 258px minmax(0, 1fr) 214px; align-items: start; }
  .sidebar { position: sticky; top: var(--header-height); max-height: calc(100dvh - var(--header-height)); overflow-y: auto; padding: 32px 20px 24px 30px; scrollbar-width: thin; }
  .sidebar-intro { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; letter-spacing: .15px; margin: 0 0 27px 9px; }
  .status-dot { width: 6px; height: 6px; background: #b58f21; border-radius: 50%; }
  .main-content { min-width: 0; min-height: calc(100dvh - var(--header-height)); background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); padding: 44px clamp(28px, 4.4vw, 68px) 26px; }
  .page-meta { display: flex; justify-content: space-between; gap: 16px; font-size: 10px; text-transform: uppercase; letter-spacing: 1.6px; color: var(--muted); margin-bottom: 23px; }
  .reading-time { text-transform: none; letter-spacing: 0; white-space: nowrap; }
  .toc-sidebar { position: sticky; top: calc(var(--header-height) + 35px); padding: 0 24px; max-height: calc(100dvh - var(--header-height) - 65px); overflow: auto; scrollbar-width: thin; }
  .toc-title { font-size: 9px; font-weight: 650; letter-spacing: 1.8px; color: var(--muted); margin: 0 0 17px; }
  .article-footer { border-top: 1px solid var(--border); padding-top: 20px; margin-top: 35px; display: flex; justify-content: space-between; gap: 16px; font-size: 11px; color: var(--muted); }
  .article-footer a { color: var(--muted); }
}

@layer components {
  .skip-link { position: fixed; z-index: 100; top: 10px; left: 10px; transform: translateY(-180%); padding: 8px 14px; background: var(--accent); color: var(--accent-ink); border-radius: 6px; }
  .skip-link:focus { transform: none; }
  .icon-button { border: 0; background: transparent; display: inline-flex; justify-content: center; align-items: center; width: 36px; height: 36px; border-radius: 8px; color: var(--muted); }
  .icon-button:hover { background: var(--surface-soft); color: var(--text); }
  .menu-toggle { display: none; }
  .package-link { font-size: 12px; color: var(--muted); white-space: nowrap; }
  .gallery-link { padding: 7px 12px; font-size: 12px; font-weight: 650; background: var(--accent); color: var(--accent-ink); border-radius: 6px; white-space: nowrap; }
  .gallery-link:hover { filter: brightness(.97); }
  .package-link span { margin-left: 4px; }
  .search-trigger { display: flex; align-items: center; gap: 10px; width: 286px; height: 36px; padding: 0 10px; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; text-align: left; }
  .search-trigger svg { width: 16px; height: 16px; }
  .search-trigger kbd { margin-left: auto; }
  [data-theme="light"] .sun-icon, [data-theme="dark"] .moon-icon { display: none; }
  .nav-section { margin-bottom: 23px; }
  .nav-group-title { margin: 0 0 8px 10px; font-size: 9px; letter-spacing: 1.6px; text-transform: uppercase; font-weight: 650; color: var(--muted); }
  .nav-page { display: flex; align-items: center; color: var(--muted); font-size: 12px; line-height: 1.35; padding: 10px 12px; margin: 2px 0; border-radius: 6px; transition: background .12s; }
  .nav-page:hover { background: var(--surface-soft); color: var(--text); }
  .nav-page[aria-current="page"] { color: var(--accent-ink); background: var(--accent); font-weight: 650; }
  .nav-page[aria-current="page"]::after { content: "↗"; margin-left: auto; font-size: 12px; }
  .sidebar-foot { display: flex; flex-direction: column; margin: 22px 10px 0; border-top: 1px solid var(--border); padding-top: 20px; font-size: 10px; line-height: 1.9; color: var(--muted); }
  .toc-link { display: block; border-left: 1px solid var(--border); padding: 7px 0 7px 13px; font-size: 10px; line-height: 1.55; color: var(--muted); }
  .toc-link.subheading { padding-left: 22px; }
  .toc-link:hover, .toc-link.active { color: var(--link); border-left-color: var(--link); }
  .back-to-top { display: block; font-size: 10px; color: var(--muted); margin-top: 24px; }
  .page-pagination { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 50px; }
  .pagination-link { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); padding: 17px 20px; color: var(--text); min-width: 0; }
  .pagination-link:hover { background: var(--surface-soft); border-color: var(--link); }
  .pagination-link small { font-size: 9px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
  .pagination-link span { font-size: 12px; font-weight: 550; }
  .pagination-link.next { text-align: right; grid-column: 2; }
  .loading-state { min-height: 280px; color: var(--muted); padding-top: 15px; }
  .loading-bar { display: block; width: 65%; height: 36px; border-radius: 5px; background: var(--surface-soft); animation: pulse 1.2s infinite alternate; }
  @keyframes pulse { to { opacity: .4; } }
  .error-state { padding: 18px 22px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
  .error-state button { padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
  .search-dialog { width: min(670px, calc(100% - 32px)); max-height: min(720px, calc(100dvh - 80px)); margin: 8vh auto auto; padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .search-dialog::backdrop { background: #111b1380; backdrop-filter: blur(3px); }
  .search-heading { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
  .search-heading h2 { margin: 0; font-size: 15px; font-weight: 620; }
  .search-input-wrap { display: flex; align-items: center; gap: 12px; margin: 8px 20px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; }
  .search-input-wrap:focus-within { border-color: var(--link); }
  .search-input-wrap svg { color: var(--muted); }
  .search-input-wrap input { width: 100%; min-width: 0; border: none; background: transparent; padding: 13px 0; font-size: 13px; outline: none; }
  .search-status { margin: 12px 22px; font-size: 11px; color: var(--muted); }
  .search-results { max-height: 400px; overflow: auto; padding: 0 12px 8px; }
  .search-result { display: block; border: 1px solid transparent; padding: 13px 12px; border-radius: 8px; color: var(--text); margin-bottom: 4px; }
  .search-result:hover, .search-result.selected { background: var(--surface-soft); border-color: var(--border); }
  .search-result strong { display: block; font-size: 13px; font-weight: 620; }
  .search-result small { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 3px; }
  .search-result p { font-size: 11px; color: var(--muted); margin: 5px 0 0; }
  .search-result mark { background: var(--accent); color: var(--accent-ink); padding: 0 2px; border-radius: 2px; }
  .search-footer { display: flex; justify-content: space-between; gap: 15px; padding: 14px 20px; border-top: 1px solid var(--border); font-size: 10px; color: var(--muted); }
  .toast { position: fixed; bottom: 25px; left: 50%; transform: translateX(-50%); z-index: 100; background: var(--text); color: var(--surface); border-radius: 8px; padding: 10px 16px; font-size: 12px; box-shadow: var(--shadow); }
  .noscript-message { margin: 30px; padding: 20px; background: var(--surface); border: 1px solid var(--border); }
}

@layer markdown {
  .markdown-body { overflow-wrap: anywhere; }
  .markdown-body h1 { font-size: clamp(30px, 3.1vw, 44px); line-height: 1.16; letter-spacing: -1.6px; font-weight: 650; margin: 0 0 22px; }
  .markdown-body h2 { font-size: 22px; line-height: 1.35; letter-spacing: -.5px; font-weight: 620; margin: 46px 0 18px; padding-top: 8px; }
  .markdown-body h3 { font-size: 16px; line-height: 1.5; font-weight: 630; margin: 28px 0 12px; }
  .markdown-body h4 { font-size: 14px; font-weight: 650; margin: 24px 0 10px; }
  .markdown-body p { font-size: 14px; margin: 0 0 18px; line-height: 1.85; }
  .markdown-body h1 + p { color: var(--muted); font-size: 16px; line-height: 1.8; margin-bottom: 28px; }
  .markdown-body a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent); }
  .markdown-body a:hover { text-decoration-color: var(--link); }
  .markdown-body li { font-size: 14px; line-height: 1.8; padding-left: 5px; margin: 8px 0; }
  .markdown-body ul, .markdown-body ol { margin: 16px 0 24px; padding-left: 24px; }
  .markdown-body li p { margin: 6px 0 12px; }
  .markdown-body strong { font-weight: 630; }
  .markdown-body code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .85em; background: var(--surface-soft); color: var(--link); border-radius: 4px; padding: 3px 5px; box-decoration-break: clone; }
  .markdown-body pre { margin: 22px 0 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--code-bg); overflow: auto; padding: 20px 21px; font-size: 12px; line-height: 1.75; tab-size: 4; }
  .markdown-body pre code { display: block; font-size: 12px; background: none; color: var(--text); padding: 0; border-radius: 0; overflow-wrap: normal; white-space: pre; }
  .code-block { margin: 22px 0 28px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
  .code-block .code-toolbar { display: flex; align-items: center; justify-content: space-between; background: var(--surface-soft); border-bottom: 1px solid var(--border); padding: 7px 12px; font-size: 10px; color: var(--muted); }
  .code-block .copy-button { background: transparent; border: 0; padding: 3px 7px; color: var(--muted); font-size: 10px; border-radius: 4px; }
  .code-block .copy-button:hover { background: var(--surface); color: var(--text); }
  .code-block pre { margin: 0; border: 0; border-radius: 0; }
  .markdown-body blockquote { border-left: 3px solid #c5a02c; background: var(--surface-soft); padding: 18px 22px; border-radius: 0 8px 8px 0; margin: 26px 0; color: var(--muted); }
  .markdown-body blockquote p { font-size: 13px; margin: 0; }
  .markdown-body hr { margin: 32px 0; border: 0; border-top: 1px solid var(--border); }
  .markdown-body img { max-width: 100%; height: auto; border-radius: 8px; }
  .preview-link { display: block; }
  .preview-link img { display: block; width: 100%; border: 1px solid var(--border); }
  .gallery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 24px 0 36px; }
  .gallery-card { margin: 0; min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-soft); }
  .gallery-card .preview-link { padding: 12px; }
  .gallery-card .preview-link img { width: 100%; height: 220px; object-fit: contain; border: 0; border-radius: 3px; }
  .gallery-card .preview-link:hover { background: var(--bg); }
  .gallery-card figcaption { padding: 12px 15px; font-size: 12px; font-weight: 600; border-top: 1px solid var(--border); color: var(--text); }
  .app-screenshot { width: 100%; max-width: 360px; margin: 24px auto 30px; padding: 12px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: var(--radius); }
  .app-screenshot a { display: block; }
  .app-screenshot img { display: block; width: 100%; height: auto; }
  .app-screenshot figcaption { margin-top: 11px; font-size: 11px; line-height: 1.7; color: var(--muted); }
  .screenshot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 24px 0 30px; }
  .screenshot-grid .app-screenshot { max-width: none; margin: 0; }
  .table-wrapper { overflow-x: auto; margin: 20px 0; }
  .markdown-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .markdown-body th, .markdown-body td { border-bottom: 1px solid var(--border); padding: 11px 14px; text-align: left; }
  .markdown-body th { background: var(--surface-soft); font-weight: 600; }
  .heading-anchor { opacity: 0; margin-left: 8px; font-size: .75em; font-weight: 400; text-decoration: none !important; }
  .markdown-body :is(h2,h3):hover .heading-anchor, .heading-anchor:focus-visible { opacity: 1; }
  .hljs-keyword, .hljs-selector-tag, .hljs-built_in { color: #6b5797; }
  .hljs-string, .hljs-attr { color: #4f7132; }
  .hljs-comment { color: #84917d; }
  .hljs-number, .hljs-literal { color: #a56537; }
  .hljs-title, .hljs-function { color: #356886; }
  [data-theme="dark"] .hljs-keyword, [data-theme="dark"] .hljs-built_in { color: #c3abe9; }
  [data-theme="dark"] .hljs-string, [data-theme="dark"] .hljs-attr { color: #bfd889; }
  [data-theme="dark"] .hljs-number, [data-theme="dark"] .hljs-literal { color: #e2b178; }
  [data-theme="dark"] .hljs-title, [data-theme="dark"] .hljs-function { color: #95c6de; }
}

@layer responsive {
  @media (min-width: 1600px) { .docs-layout { grid-template-columns: 278px minmax(0, 1fr) 240px; } }
  @media (max-width: 1180px) {
    .docs-layout { grid-template-columns: 240px minmax(0, 1fr); max-width: 1180px; }
    .toc-sidebar { display: none; }
    .main-content { border-right: none; padding-left: 45px; padding-right: 45px; }
    .sidebar { padding-left: 20px; }
    .sdk-label, .header-divider { display: none; }
  }
  @media (max-width: 860px) {
    :root { --header-height: 66px; }
    .topbar-inner { padding: 0 20px; gap: 13px; }
    .menu-toggle { display: inline-flex; }
    .brand-symbol { width: 34px; height: 34px; font-size: 20px; border-radius: 8px; }
    .brand-name { font-size: 19px; }
    .brand-name small { font-size: 7px; }
    .header-actions { gap: 12px; }
    .search-trigger { width: 36px; padding: 0; justify-content: center; background: transparent; border: none; }
    .search-trigger svg { width: 19px; height: 19px; }
    .search-trigger span, .search-trigger kbd { display: none; }
    .gallery-link { display: none; }
    .docs-layout { display: block; }
    .sidebar { display: none; position: fixed; z-index: 60; top: var(--header-height); left: 0; bottom: 0; width: min(310px, calc(100vw - 48px)); background: var(--bg); border-right: 1px solid var(--border); padding: 27px 23px; box-shadow: var(--shadow); }
    body.menu-open .sidebar { display: block; }
    .sidebar-backdrop { position: fixed; z-index: 50; inset: var(--header-height) 0 0; background: #0b170c66; }
    body.menu-open { overflow: hidden; }
    .sidebar-intro { font-size: 11px; }
    .nav-page { font-size: 14px; padding-top: 12px; padding-bottom: 12px; }
    .nav-group-title { font-size: 10px; }
    .main-content { border-left: none; padding: 32px clamp(20px, 6vw, 54px) 25px; }
    .markdown-body h1 { font-size: 34px; }
    .markdown-body h1 + p { font-size: 15px; }
    .page-meta { font-size: 9px; margin-bottom: 22px; }
  }
  @media (max-width: 440px) {
    .topbar-inner { padding: 0 12px; gap: 8px; }
    .brand { gap: 8px; }
    .package-link { display: none; }
    .header-actions { gap: 5px; }
    .main-content { padding-left: 21px; padding-right: 21px; }
    .markdown-body h1 { font-size: 30px; letter-spacing: -.9px; }
    .markdown-body h2 { font-size: 21px; }
    .markdown-body p, .markdown-body li { font-size: 13px; }
    .code-block pre { padding: 16px; }
    .page-pagination { gap: 10px; }
    .pagination-link { padding: 14px 12px; }
    .pagination-link span { font-size: 11px; }
    .article-footer { font-size: 10px; }
    .search-footer { font-size: 9px; padding-left: 16px; padding-right: 16px; }
    .search-dialog { margin-top: 20px; max-height: calc(100dvh - 40px); }
  }
  @media (max-width: 640px) {
    .screenshot-grid { grid-template-columns: minmax(0, 1fr); }
    .screenshot-grid .app-screenshot { max-width: 360px; margin-inline: auto; }
    .gallery-grid { grid-template-columns: minmax(0, 1fr); }
    .gallery-card .preview-link img { height: 260px; }
  }
  @media (max-width: 360px) {
    .topbar-inner { padding-inline: 8px; gap: 4px; }
    .brand-symbol { display: none; }
    .brand-name { font-size: 16px; }
    .icon-button, .search-trigger { width: 32px; height: 36px; }
    .header-actions { gap: 0; }
    .reading-time { display: none; }
    .main-content { padding-inline: 17px; }
    .page-pagination { grid-template-columns: minmax(0, 1fr); }
    .pagination-link.next { grid-column: 1; }
    .article-footer { flex-wrap: wrap; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  }
  @media print {
    .topbar, .sidebar, .toc-sidebar, .page-pagination, .article-footer, .copy-button, .heading-anchor { display: none !important; }
    .docs-layout { display: block; }
    .main-content { padding: 0; border: none; min-height: 0; }
    :root { --surface: #fff; --text: #000; --muted: #555; --code-bg: #fafafa; --link: #333; --border: #ccc; }
    .code-block, blockquote { break-inside: avoid; }
  }
}
