*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fs-base)/1.6 var(--font-ui); overflow-wrap: anywhere; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-text); padding: var(--sp-2) var(--sp-3); z-index: 100; }
.skip:focus { left: var(--sp-3); top: var(--sp-3); }

.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-4); padding: var(--sp-3) var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--border); }
.logo { font-weight: 800; font-size: var(--fs-lg); color: var(--text); text-decoration: none; }
.logo span { color: var(--accent); margin-left: 2px; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.nav a { color: var(--text); text-decoration: none; font-size: var(--fs-sm); padding: var(--sp-1) var(--sp-2); }
.nav a:hover { text-decoration: underline; }
.btn-link.big { padding: var(--sp-2) var(--sp-4); text-decoration: none; white-space: nowrap; }
.mb { margin-bottom: var(--sp-4); }
.mt { margin-top: var(--sp-5); }
.btn-link { background: var(--accent); color: var(--accent-text) !important; border-radius: var(--radius-sm); font-weight: 600; }
button { font: inherit; cursor: pointer; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.ghost:hover { border-color: var(--accent); }
kbd { font: 0.75rem var(--font-code); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: var(--sp-5) var(--sp-4) var(--sp-6); outline: none; }
.hero { padding: var(--sp-5) 0 var(--sp-4); }
.hero h1 { font-size: var(--fs-hero); line-height: 1.15; margin: 0 0 var(--sp-3); }
.hero p { color: var(--muted); max-width: 60ch; margin: 0 0 var(--sp-4); }
.heroSearch { display: flex; gap: var(--sp-2); max-width: 520px; }
.heroSearch input { flex: 1; min-width: 0; }

h2 { font-size: var(--fs-lg); margin: var(--sp-6) 0 var(--sp-3); }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--sp-3); list-style: none; padding: 0; margin: 0; }
.chip { display: block; height: 100%; padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.chip:hover { border-color: var(--accent); }
.chip b { display: block; }
.chip small { color: var(--muted); }

.sheetLayout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.toc { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; font-size: var(--fs-sm); }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a { display: block; padding: var(--sp-1) var(--sp-3); color: var(--muted); text-decoration: none; border-left: 3px solid var(--border); }
.toc a.on, .toc a:hover { color: var(--text); border-left-color: var(--accent); }
.crumbs { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--sp-2); }
.sheetHead h1 { margin: 0 0 var(--sp-2); font-size: var(--fs-xl); }
.sheetHead p { color: var(--muted); margin: 0 0 var(--sp-3); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--sp-4); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card.hit { outline: 3px solid var(--accent); }
.cardHead { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.cardHead h3 { margin: 0; font-size: var(--fs-base); }
.badge { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 0 var(--sp-2); color: var(--muted); white-space: nowrap; }
pre { margin: 0; padding: var(--sp-3); background: var(--code-bg); color: var(--code-text); font: 0.85rem/1.55 var(--font-code); overflow-x: auto; white-space: pre; flex: 1; }
.note { margin: 0; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); color: var(--muted); border-top: 1px solid var(--border); }
.by { margin: 0; padding: var(--sp-1) var(--sp-3) var(--sp-2); font-size: 0.8rem; color: var(--muted); }
.copy { font-size: 0.8rem; padding: 2px var(--sp-2); background: transparent; color: var(--accent); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.copy:hover { border-color: var(--accent); }
.k { color: var(--tok-kw); } .s { color: var(--tok-str); } .n { color: var(--tok-num); } .c { color: var(--tok-com); font-style: italic; }

form.box, .box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-5); max-width: 720px; }
label { display: block; font-weight: 600; font-size: var(--fs-sm); margin: var(--sp-4) 0 var(--sp-1); }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--muted); border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3); }
textarea { font-family: var(--font-code); font-size: 0.85rem; min-height: 180px; }
.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-4); font-weight: 700; margin-top: var(--sp-4); }
.help { color: var(--muted); font-size: var(--fs-sm); margin: var(--sp-1) 0 0; }
.err { color: var(--danger); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.filters button { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); }
.empty { color: var(--muted); }

dialog { width: min(600px, calc(100vw - 24px)); margin-top: 12vh; padding: var(--sp-3); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
#results { list-style: none; margin: var(--sp-2) 0 0; padding: 0; max-height: 50vh; overflow: auto; }
#results li { padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); cursor: pointer; }
#results li[aria-selected="true"], #results li:hover { background: var(--code-bg); outline: 1px solid var(--accent); }
#results small { color: var(--muted); display: block; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }
.foot { max-width: 1100px; margin: 0 auto; padding: var(--sp-4) var(--sp-4) var(--sp-6); color: var(--muted); font-size: var(--fs-sm); border-top: 1px solid var(--border); }
.foot p { margin: var(--sp-1) 0; }

@media (max-width: 800px) {
  .sheetLayout { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; max-height: none; }
  .toc ul { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .toc a { border: 1px solid var(--border); border-radius: 999px; }
  kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } #toast { transition: none; } }
