/* Documentation pages (/app/docs/), on top of app.css: flat, dense, logical properties for right-to-left. */

:root {
  --d-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --d-cmd: #1e40af;
  --d-math: #9a3412;
  --d-brace: #6e6e73;
  --d-note: #1e3a8a;
  --d-tip: #007a55;
  --d-limits: #8a5a00;
  --d-warn: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root { --d-cmd: #7cc4fa; --d-math: #fdba74; --d-brace: #a1a1a6; --d-note: #5fd4e8; --d-tip: #00d492; --d-limits: #f5c451; --d-warn: #ff8a80; }
}

.d-shell { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 40px; width: min(1320px, 100% - 40px); margin-inline: auto; align-items: start; }
@media (min-width: 860px) { .d-shell { grid-template-columns: 232px minmax(0, 1fr); } }
@media (min-width: 1180px) { .d-shell { grid-template-columns: 232px minmax(0, 1fr) 188px; } }

/* Sidebar */
.d-menu { display: none; }
.d-side { position: sticky; top: 48px; max-height: calc(100vh - 48px); overflow: auto; padding: 20px 0 40px; font-size: 14px; scrollbar-width: thin; }
.d-nav-home { display: block; padding: 5px 8px; margin: 10px 0 6px; border-radius: 6px; color: var(--text); font-weight: 600; }
.d-nav-g { margin: 2px 0; }
.d-nav-g summary { cursor: pointer; padding: 5px 8px; border-radius: 6px; font-weight: 600; color: var(--text); list-style: none; display: flex; align-items: center; justify-content: space-between; }
.d-nav-g summary::-webkit-details-marker { display: none; }
.d-nav-g summary::after { content: ''; width: 6px; height: 6px; border-inline-end: 1.5px solid var(--text-3); border-block-end: 1.5px solid var(--text-3); transform: rotate(-45deg); transition: transform 0.15s; }
[dir='rtl'] .d-nav-g summary::after { transform: rotate(135deg); }
.d-nav-g[open] summary::after { transform: rotate(45deg); }
.d-nav-g ul { list-style: none; margin: 0 0 8px; padding: 0; }
.d-nav a { display: block; padding: 4px 8px 4px 16px; border-radius: 6px; color: var(--text-2); line-height: 1.35; }
[dir='rtl'] .d-nav a { padding: 4px 16px 4px 8px; }
.d-nav a:hover { background: var(--fill); color: var(--text); text-decoration: none; }
.d-nav summary:hover { background: var(--fill); }
.d-nav a[aria-current='page'] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.d-nav-home { padding-inline-start: 8px !important; }

@media (max-width: 859px) {
  .d-menu { display: inline-flex; align-items: center; gap: 6px; margin: 10px 0 0; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; }
  .d-menu::before { content: ''; width: 12px; height: 8px; border-block: 1.5px solid currentColor; box-shadow: inset 0 -3.25px 0 -1.75px currentColor; }
  .d-side { position: static; max-height: none; overflow: visible; padding: 14px 0 12px; border-block-end: 1px solid var(--hair); }
  .d-nav { display: none; padding-top: 4px; }
  .d-nav[data-open] { display: block; }
}
.d-main .d-lang { margin: 0 0 14px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; color: var(--text-2); }

/* Skip link: hidden until focused */
.d-skip { position: absolute; inset-inline-start: 8px; top: -60px; z-index: 100; padding: 8px 14px; border-radius: 8px; background: var(--surface); color: var(--text); border: 2px solid var(--accent); font-weight: 600; }
.d-skip:focus { top: 8px; text-decoration: none; }
.d-main:focus { outline: none; }

/* Search */
.d-search { position: relative; }
.d-search input { width: 100%; height: 34px; padding: 0 30px 0 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 14px; }
.d-search input::-webkit-search-cancel-button { display: none; }
.d-search input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.d-search-i { position: absolute; inset-inline-start: 9px; top: 10px; color: var(--text-3); pointer-events: none; }
.d-search kbd { position: absolute; inset-inline-end: 8px; top: 8px; font: 11px/16px var(--d-mono); color: var(--text-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.d-search input:focus + kbd, .d-search input:not(:placeholder-shown) + kbd { display: none; }
.d-results ul { list-style: none; margin: 0; padding: 0; }
.d-results { position: absolute; z-index: 30; inset-inline: 0; top: 38px; width: min(420px, calc(100vw - 40px)); margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-height: 70vh; overflow: auto; }
.d-results a { display: block; padding: 7px 9px; border-radius: 7px; color: var(--text); }
.d-results a:hover, .d-results [aria-selected='true'] a { background: var(--accent-soft); text-decoration: none; }
.d-results strong { display: block; font-size: 14px; font-weight: 600; }
.d-results small { display: block; font-size: 11px; color: var(--text-2); margin: 1px 0 2px; }
.d-results span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; color: var(--text-2); line-height: 1.4; }
.d-res-none { margin: 0; padding: 10px; font-size: 13px; color: var(--text-2); }

/* Article */
.d-main { min-width: 0; padding: 22px 0 72px; font-size: 16px; line-height: 1.6; letter-spacing: -0.011em; }
.d-main article > * { max-width: 820px; }
.d-crumbs { font-size: 12px; color: var(--text-2); margin-bottom: 14px; }
.d-crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.d-main .d-crumbs ol { margin: 0; padding: 0; }
.d-main .d-crumbs li { margin: 0; }
.d-crumbs a { color: var(--text-2); }
.d-crumbs li + li::before { content: '›'; margin-inline-end: 6px; }
[dir='rtl'] .d-crumbs li + li::before { content: '‹'; }
.d-main h1 { font-family: var(--display); font-size: clamp(28px, 4vw, 36px); line-height: 1.15; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 10px; }
.d-answer { font-size: 18px; line-height: 1.5; color: var(--text); margin: 0 0 26px; padding-block-end: 20px; border-block-end: 1px solid var(--hair); }
.d-main h2 { font-size: 21px; line-height: 1.3; font-weight: 650; letter-spacing: -0.012em; margin: 40px 0 10px; scroll-margin-top: 64px; }
.d-main h3 { font-size: 17px; line-height: 1.35; font-weight: 650; margin: 28px 0 8px; scroll-margin-top: 64px; }
.d-main h2 .anchor, .d-main h3 .anchor { margin-inline-start: 0.3em; color: var(--text-3); opacity: 0; font-weight: 400; }
.d-main .anchor::before { content: '#'; }
.d-main h2:hover .anchor, .d-main h3:hover .anchor { opacity: 1; text-decoration: none; }
.d-main p { margin: 0 0 12px; color: var(--text); }
.d-main ul, .d-main ol { margin: 0 0 14px; padding-inline-start: 22px; }
.d-main li { margin: 3px 0; }
.d-main li > ul, .d-main li > ol { margin: 4px 0; }
.d-main :not(pre) > code { font: 0.86em var(--d-mono); background: var(--fill); padding: 0.1em 0.35em; border-radius: 4px; white-space: break-spaces; overflow-wrap: anywhere; }
.d-main strong { font-weight: 600; }
.d-checked { margin-top: 36px !important; font-size: 13px; color: var(--text-2) !important; }

/* Tables */
.d-table { overflow-x: auto; margin: 0 0 18px; border: 1px solid var(--line); border-radius: 8px; }
.d-table table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.45; }
.d-table th, .d-table td { padding: 7px 12px; text-align: start; vertical-align: top; border-block-end: 1px solid var(--hair); }
.d-table th { font-weight: 600; background: var(--bg-alt); }
.d-table tr:last-child td { border-block-end: 0; }

/* Code */
.d-code, .d-ex { margin: 0 0 18px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.d-code-bar { display: flex; align-items: center; gap: 6px; min-height: 34px; padding: 3px 6px 3px 12px; border-block-end: 1px solid var(--hair); background: var(--bg-alt); font-size: 12px; color: var(--text-2); }
[dir='rtl'] .d-code-bar { padding: 3px 12px 3px 6px; }
.d-code-bar > span:first-child { font-weight: 600; letter-spacing: 0.02em; margin-inline-end: auto; }
.d-ex-pre { order: -1; margin-inline-end: auto; font-size: 12px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-ex-pre + .d-btn { margin-inline-start: 0; }
.d-code-bar:has(.d-ex-pre) > span:first-child { display: none; }
.d-ex-pre code { white-space: nowrap !important; font: 11.5px var(--d-mono) !important; background: none !important; padding: 0 !important; color: var(--text-2); }
.d-btn { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--text-2); font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.d-btn:hover { background: var(--fill); color: var(--text); text-decoration: none; }
.d-btn[data-done] { color: var(--ok); }
.d-main pre { margin: 0; padding: 12px 14px; overflow: auto; font: 13px/1.55 var(--d-mono); tab-size: 2; direction: ltr; text-align: left; }
.d-main pre code { font: inherit; }
.tk { color: var(--d-cmd); }
.tc { color: var(--text-3); font-style: italic; }
.tm { color: var(--d-math); }
.tb { color: var(--d-brace); }

/* Examples: source and the rendered result, side by side when there is room */
.d-ex { container-type: inline-size; }
.d-ex-title { margin: 0 !important; padding: 8px 12px; font-size: 13px; font-weight: 600; border-block-end: 1px solid var(--hair); }
.d-ex-grid { display: grid; grid-template-columns: minmax(0, 1fr); }
@container (min-width: 700px) {
  .d-ex:not(.d-ex-one):not(.d-ex-wide) .d-ex-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .d-ex:not(.d-ex-one):not(.d-ex-wide) .d-ex-src { border-inline-end: 1px solid var(--hair); }
}
.d-ex-src { min-width: 0; }
.d-ex-src .d-code-bar { border-block-end: 1px solid var(--hair); }
.d-ex-out:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.d-ex-out { margin: 0; padding: 14px; background: var(--bg-alt); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-width: 0; border-block-start: 1px solid var(--hair); }
@container (min-width: 700px) { .d-ex:not(.d-ex-one):not(.d-ex-wide) .d-ex-out { border-block-start: 0; } }
.d-ex-one .d-ex-out { border-block-start: 0; }
.d-paper { width: 100%; max-width: calc(var(--w, 612) * 1.5px); background: #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08); direction: ltr; }
@media (prefers-color-scheme: dark) { .d-paper { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14); } }
.d-paper svg, .d-paper img { display: block; width: 100%; height: auto; }
.d-paper-img { max-width: 560px; }
.d-ex-note { margin: 0 !important; font-size: 13px; color: var(--text-2) !important; align-self: stretch; }
.d-fail { align-self: stretch; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--d-warn); font-size: 14px; }
.d-fail p { margin: 0 !important; }

/* Callouts */
.d-call { margin: 0 0 18px; padding: 10px 14px; border: 1px solid var(--line); border-inline-start: 3px solid var(--d-note); border-radius: 6px; background: var(--surface); font-size: 15px; }
.d-call > :last-child { margin-bottom: 0 !important; }
.d-call-t { font-weight: 600; margin: 0 0 4px !important; font-size: 13px; letter-spacing: 0.01em; color: var(--d-note) !important; }
.d-tip, .d-works { border-inline-start-color: var(--d-tip); }
.d-tip .d-call-t, .d-works .d-call-t { color: var(--d-tip) !important; }
.d-limits { border-inline-start-color: var(--d-limits); }
.d-limits .d-call-t { color: var(--d-limits) !important; }
.d-warning { border-inline-start-color: var(--d-warn); }
.d-warning .d-call-t { color: var(--d-warn) !important; }

/* FAQ */
.d-faq details { border-block-end: 1px solid var(--hair); }
.d-faq summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.d-faq details > :not(summary) { margin-inline-start: 0; }

/* Cards (section lists, docs home) */
.d-cards { list-style: none; padding: 0 !important; margin: 0 0 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.d-cards li { margin: 0; }
.d-cards a { display: block; height: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); }
.d-cards a:hover { border-color: var(--accent); text-decoration: none; }
.d-cards strong { display: block; font-size: 15px; margin-bottom: 3px; }
.d-cards span { display: block; font-size: 13.5px; line-height: 1.45; color: var(--text-2); }

/* Symbols */
.d-sym { list-style: none; padding: 0 !important; margin: 0 0 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.d-sym li { position: relative; display: flex; align-items: center; gap: 10px; margin: 0; padding: 6px 30px 6px 8px; border: 1px solid var(--hair); border-radius: 8px; background: var(--surface); min-height: 44px; }
[dir='rtl'] .d-sym li { padding: 6px 8px 6px 30px; }
.d-sym img { flex: none; max-width: 64px; height: auto; max-height: 40px; object-fit: contain; background: #fff; border-radius: 3px; padding: 2px; }
.d-sym code { font: 12px var(--d-mono) !important; background: none !important; padding: 0 !important; overflow-wrap: anywhere; direction: ltr; }
.d-sym-odd { border-style: dashed; border-color: var(--line); }
.d-sym li small { display: block; font-size: 10.5px; line-height: 1.2; color: var(--text-2); }
.d-sym li code + small { margin-inline-start: auto; }
.d-sym-copy { position: absolute; inset-inline-end: 3px; top: 50%; transform: translateY(-50%); width: 24px; padding: 0; justify-content: center; opacity: 0.55; }
.d-sym li:hover .d-sym-copy, .d-sym-copy:focus-visible { opacity: 1; }

/* Templates */
.d-tpl { margin: 0 0 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.d-tpl .d-paper { max-width: 420px; }

/* Right rail: on this page */
.d-rail { position: sticky; top: 48px; padding: 28px 0; max-height: calc(100vh - 48px); overflow: auto; font-size: 13px; display: none; }
@media (min-width: 1180px) { .d-rail { display: block; } }
.d-toc p { margin: 0 0 6px; font-weight: 600; color: var(--text); }
.d-toc ul { list-style: none; margin: 0; padding: 0; border-inline-start: 1px solid var(--hair); }
.d-toc a { display: block; padding: 3px 10px; color: var(--text-2); line-height: 1.35; }
.d-toc a:hover { color: var(--text); text-decoration: none; }
.d-toc a[aria-current] { color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
[dir='rtl'] .d-toc a[aria-current] { box-shadow: inset -2px 0 0 var(--accent); }

/* Previous and next */
.d-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
.d-pager a { display: block; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.d-pager a:hover { border-color: var(--accent); text-decoration: none; }
.d-pager small { display: block; font-size: 12px; color: var(--text-2); }
.d-pager span { font-weight: 600; font-size: 14.5px; }
.d-next { text-align: end; grid-column: 2; }

@media print { .d-side, .d-rail, .d-menu, .d-pager, .d-btn, .d-skip { display: none !important; } .d-shell { display: block; } }
/* Phones: a result keeps at least close to its print size (1.25 px per pt) and scrolls sideways, instead of shrinking to unreadable text. */
@media (max-width: 600px) {
  .d-ex-out { overflow-x: auto; align-items: safe center; }
  .d-paper:not(.d-paper-img) { min-width: min(calc(var(--w, 300) * 1.25px), 560px); }
}

/* A translated page: links to pages that are only in English carry a small EN. */
html:not([lang='en']) .d-nav a[hreflang='en']::after, html:not([lang='en']) .d-cards a[hreflang='en'] strong::after, html:not([lang='en']) .d-results a[hreflang='en'] strong::after { content: 'EN'; display: inline-block; margin-inline-start: 6px; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px; font-size: 10px; font-weight: 500; line-height: 14px; color: var(--text-3); vertical-align: 1px; }

/* Right-to-left languages (ar, fa, ur, ckb, he): the page mirrors, LaTeX stays left to right. Code, the
   example grid (source left, result right) and inline code keep their direction inside the text. */
[dir='rtl'] .d-main, [dir='rtl'] .d-main h1, [dir='rtl'] .d-main h2, [dir='rtl'] .d-main h3, [dir='rtl'] .d-side { letter-spacing: 0; }
[dir='rtl'] .d-main { line-height: 1.75; }
[dir='rtl'] .d-main h1 { line-height: 1.35; }
[dir='rtl'] .d-main :not(pre) > code, [dir='rtl'] .d-sym code, [dir='rtl'] .d-search kbd { direction: ltr; unicode-bidi: isolate; }
[dir='rtl'] .d-ex-grid, [dir='rtl'] .d-code { direction: ltr; }
[dir='rtl'] .d-ex-note, [dir='rtl'] .d-fail, [dir='rtl'] .d-code-bar .d-btn span { direction: rtl; }
[dir='rtl'] .d-ex .d-code-bar, [dir='rtl'] .d-code .d-code-bar { padding: 3px 6px 3px 12px; }
/* Scripts without capitals or with tall marks: no tightened letter spacing. */
:lang(ja) .d-main, :lang(ko) .d-main, :lang(zh-Hans) .d-main, :lang(zh-Hant) .d-main, :lang(th) .d-main, :lang(hi) .d-main, :lang(mr) .d-main, :lang(bn) .d-main { letter-spacing: 0; }
:lang(ja) .d-main h1, :lang(ko) .d-main h1, :lang(zh-Hans) .d-main h1, :lang(zh-Hant) .d-main h1, :lang(th) .d-main h1, :lang(hi) .d-main h1, :lang(mr) .d-main h1, :lang(bn) .d-main h1 { letter-spacing: 0; line-height: 1.3; }
