/* open-audiovisual — the API reference (/docs/reference/, /zh/docs/reference/).
   Built on the handbook's frame (assets/docs/docs.css loads first: layout, contents drawer, tables, callouts, code blocks);
   this file adds the entry card, the search bar, the example tools and the live frame. Tokens come from assets/home/home.css. */

/* ───────────── search ───────────── */
/* the box stays under the top bar while you read (about 70 px), so a jump to an entry has to stop below it */
html.refpage { --ref-search-h: 74px; scroll-padding-top: calc(var(--bar-h) + var(--docs-bar-h) + var(--ref-search-h) + 14px); }
.ref-search { position: sticky; top: calc(var(--bar-h) + var(--docs-bar-h)); z-index: 12; margin: 22px 0 6px; padding: 12px 0 10px;
  background: var(--ink); box-shadow: 0 10px 12px -10px var(--ink); }
.ref-search-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ref-search-box { position: relative; display: flex; align-items: center; }
.ref-search input { width: 100%; box-sizing: border-box; font: 500 16px/1.3 var(--mono); color: var(--fg); background: var(--ink-2);
  border: 1px solid var(--line-2); border-radius: 0; padding: 13px 90px 13px 16px; appearance: none; -webkit-appearance: none; }
.ref-search input::placeholder { color: var(--fg-3); }
.ref-search input:focus { outline: 0; border-color: var(--sig); box-shadow: 0 0 0 3px rgba(255, 90, 31, .18); }
.ref-search input::-webkit-search-cancel-button { display: none; }
.ref-search-key { position: absolute; right: 14px; pointer-events: none; }
.ref-search input:not(:placeholder-shown) ~ .ref-search-key { display: none; }
.ref-search-clear { position: absolute; right: 8px; font: 500 12px var(--mono); color: var(--fg-2); background: var(--ink-3); border: 1px solid var(--line-2); padding: 6px 10px; cursor: pointer; }
.ref-search-clear:hover { color: var(--fg); }
.ref-search-status { position: absolute; right: 86px; bottom: 21px; margin: 0; font: 400 12.5px/1.5 var(--mono); color: var(--fg-3); pointer-events: none; }
@media (max-width: 1000px) { html.refpage { --ref-search-h: 0px; } .ref-search { position: static; margin-top: 12px; box-shadow: none; } .ref-search-status { right: 80px; } }
@media (max-width: 520px) { .ref-search-status { display: none; } }

/* the loader line */
.ref-loader { margin: 18px 0 8px; padding: 14px 18px 12px; background: var(--ink-2); border: 1px solid var(--line); border-left: 3px solid var(--sig); max-width: 860px; }
.ref-loader-title { font: 500 11.5px/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--sig); margin: 0 0 8px; }
.ref-loader .term { margin: 0 0 10px; }
.ref-loader .term pre { font-size: 12.5px; white-space: pre-wrap; word-break: break-all; }
.ref-loader-body { margin: 0; color: var(--fg-2); font-size: 14.5px; }
.ref-p5v { display: inline-block; margin-top: 10px; font: 400 12.5px var(--mono); color: var(--fg-3); }
.ref-p5v select { font: inherit; color: var(--fg); background: var(--ink-3); border: 1px solid var(--line-2); padding: 3px 6px; }

/* ───────────── categories and entries ───────────── */
.ref-cat { margin-top: clamp(56px, 7vw, 96px); }
.ref-cat-hint { margin: 0 0 18px !important; color: var(--fg-2); }
.ref-cat-n { font: 400 12px var(--mono); color: var(--fg-3); margin-left: .4em; }
.ref-pkg-head { margin: 34px 0 6px !important; font: 500 12px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--fg-3); }

.ref { position: relative; margin: 0 0 6px; padding: 26px 0 30px; border-top: 1px solid var(--line); }
.ref:target, .ref.is-hit { box-shadow: inset 3px 0 0 var(--sig); padding-left: 16px; margin-left: -16px; background: linear-gradient(90deg, rgba(255, 90, 31, .07), transparent 40%); }
.ref-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 14px; margin-bottom: 10px; }
.chapter .ref-head h3 { margin: 0; font: 700 clamp(19px, 1.8vw, 24px)/1.25 var(--sans); letter-spacing: -.005em; overflow-wrap: anywhere; }
.chapter .ref-head h3 code { font: inherit; background: none; padding: 0; color: var(--fg); }
.ref-alias-anchor { position: absolute; top: 0; }
.ref-badges { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.badge { font: 500 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; padding: 5px 8px; border: 1px solid var(--line-2); color: var(--fg-2); white-space: nowrap; }
.badge-kind { color: var(--ink); border-color: transparent; background: var(--fg-2); }
.badge-kind[data-kind="variable"] { background: var(--l1); }
.badge-kind[data-kind="function"] { background: var(--l2); }
.badge-kind[data-kind="event"] { background: var(--sig); }
.badge-kind[data-kind="class"] { background: var(--l3); }
.badge-kind[data-kind="option"] { background: #e6c86a; }
.badge-kind[data-kind="constant"], .badge-kind[data-kind="object"], .badge-kind[data-kind="tool"] { background: var(--fg-2); }
.ref-tag { display: inline-block; font: 500 11px/1.2 var(--mono); color: var(--fg-3); border: 1px solid var(--line); padding: 2px 6px; margin-right: 2px; vertical-align: .08em; white-space: nowrap; }
.ref-tag code { background: none !important; padding: 0 !important; font-size: inherit; color: var(--fg-2); }

.ref-sig { margin: 0 0 14px; padding: 10px 14px; background: var(--void); border: 1px solid var(--line); overflow-x: auto; font-size: 13.5px; line-height: 1.6; color: var(--fg); }
.ref-sig code { background: none !important; padding: 0 !important; white-space: pre; }
.chapter .ref-summary { font-size: 17px; line-height: 1.5; color: var(--fg) !important; margin: 0 0 12px; max-width: 70ch; }
.chapter .ref-also { margin: -6px 0 12px; font-size: 13.5px; color: var(--fg-3); }
.ref-body p { max-width: 70ch; }
.ref-sec { margin-top: 22px; }
.ref-sec h4, .chapter .ref-sec h4 { margin: 0 0 8px; font: 500 12px/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--fg-3); }
.ref .table-wrap { margin: 6px 0 4px; }
.ref .table-wrap td:first-child { white-space: nowrap; }
.ref-value { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, max-content)); gap: 8px 28px; margin: 14px 0 6px; padding: 10px 14px; border: 1px solid var(--line); background: var(--ink-2); }
.ref-value div { display: flex; flex-direction: column; gap: 3px; }
.ref-value dt { font: 500 11px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--fg-3); }
.ref-value dd { margin: 0; color: var(--fg); }
.ref .callout { margin: 18px 0 6px; }
.ref-nodoc { color: var(--fg-3) !important; font-size: 14.5px; }
.ref-srcdoc { color: var(--fg-2) !important; font-size: 14.5px; }
.ref-stub { padding-top: 18px; padding-bottom: 20px; }
.ref-stub .ref-sig { margin-bottom: 8px; }
.ref-rel ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; max-width: none; }
.ref-rel li { margin: 0; padding: 10px 12px; border: 1px solid var(--line); background: var(--ink-2); font-size: 14px; }
.ref-rel li a { text-decoration: none; }
.ref-rel li span { display: block; margin-top: 4px; color: var(--fg-3); font-size: 13px; line-height: 1.4; }
.ref-source { margin: 22px 0 0 !important; font: 400 12.5px/1.8 var(--mono); color: var(--fg-3) !important; }
.ref-source a { color: var(--fg-2) !important; }
.ref-import { color: var(--fg-2); background: none !important; padding: 0 !important; margin-right: 10px; }

/* ───────────── examples ───────────── */
.ref-ex { margin: 0 0 22px; }
.ref-ex .term { margin: 0; }
.ref-ex .term pre { font-size: 13px; }
.ref-ex figcaption { margin: 8px 0 0; font-size: 14.5px; line-height: 1.55; color: var(--fg-2); max-width: 70ch; }
.ref-ex-tools { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; }
.ref-ex .term-bar { flex-wrap: wrap; gap: 6px; }
.ref-ex-tools button, .ref-ex-tools a { white-space: nowrap; }
.ref-ex-tools button, .ref-ex-tools a, .ref-loader-copy { font: 500 12px var(--mono); color: var(--fg); background: var(--ink-3); border: 1px solid var(--line-2); padding: 5px 10px; cursor: pointer; text-decoration: none; line-height: 1.2; }
.ref-ex-tools button:hover, .ref-ex-tools a:hover, .ref-loader-copy:hover { border-color: var(--fg-2); }
.ref-ex-tools .ref-run { color: var(--ink); background: var(--fg); border-color: var(--fg); }
.ref-ex-tools .ref-op { color: var(--fg-2); }
.ref-ex-tools .ref-stop, .ref-ex-tools .ref-reset { color: var(--fg-2); }
/* the live box: the canvas's own shape (4:3 until the frame reports its size), at most its own width */
.ref-live { position: relative; margin-top: 10px; width: 100%; max-width: 400px; aspect-ratio: 4 / 3; border: 1px solid var(--line-2); background: #111; }
.ref-live iframe { display: block; width: 100%; height: 100%; border: 0; background: #111; }
.ref-poster { position: absolute; inset: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font: 500 13px var(--mono); color: var(--fg-2); background: #111; border: 0; cursor: pointer; }
.ref-poster:hover, .ref-poster:focus-visible { color: var(--fg); }
.ref-ex[data-run="sketch"] pre code[contenteditable] { display: block; outline: none; caret-color: var(--fg); }
.ref-ex[data-run="sketch"] .term:focus-within { border-color: var(--fg-3); }
.ref-ex.is-edited .term-bar > span:first-child::after { content: ' ·'; color: var(--fg-2); }
.ref-auto { display: inline-flex; gap: 6px; align-items: center; margin: 10px 0 0 14px; font: 400 12.5px var(--mono); color: var(--fg-3); cursor: pointer; }
.ref-auto input { accent-color: var(--fg); margin: 0; }
/* wide enough: the canvas beside its code, the way p5.js's reference lays an example out */
.ref-sec:has(> .ref-ex[data-run="sketch"]) { container-type: inline-size; }
@container (min-width: 760px) {
  .ref-ex[data-run="sketch"] { display: grid; grid-template-columns: minmax(260px, 400px) minmax(0, 1fr); grid-template-areas: "live code" "live cap"; column-gap: 16px; align-items: start; }
  .ref-ex[data-run="sketch"] > .term { grid-area: code; min-width: 0; }
  .ref-ex[data-run="sketch"] > figcaption { grid-area: cap; }
  .ref-ex[data-run="sketch"] > .ref-live { grid-area: live; margin-top: 0; }
}
@media (max-width: 640px) { .ref-search input { font-size: 16px; } }

/* ───────────── search mode ───────────── */
.ref-list { display: flex; flex-direction: column; }
.ref-list .ref-cat { display: block; }
.ref-page[data-searching] .ref-cat { margin-top: 0; }
.ref-page[data-searching] .ref-cat > h2, .ref-page[data-searching] .ref-cat-hint, .ref-page[data-searching] .ref-pkg-head,
.ref-page[data-searching] .chapter::before { display: none; }
.ref-page[data-searching] .ref-cat { display: contents; }
.ref-page[data-searching] .ref-loader { display: none; }
.ref[hidden], .ref-cat[hidden], .toc-ch[hidden] { display: none !important; }
.ref-none { margin: 40px 0; font: 400 14px var(--mono); color: var(--fg-2); }

/* while searching the categories are not where you are: no "current" mark (docs.js's scroll-spy measures hidden headings) */
.ref-page[data-searching] .toc-ch.is-current > a, .ref-page[data-searching] .toc a[aria-current] { color: var(--fg-2); }
.ref-page[data-searching] .toc-ch.is-current > a .n { color: var(--fg-3); }
.ref-page[data-searching] .docs-bar-where { visibility: hidden; }

/* a long address or identifier in a sentence must wrap, not widen the page (SAMPLES_URL's summary did, on a 360 px phone) */
.ref p, .ref li, .ref td, .ref dd, .ref figcaption { overflow-wrap: anywhere; }
