/* crystal docs 输出的结构适配：把默认紫色主题映射到 site.css 的 token。
   必须在 site.css 之后加载。 */

/* ── 骨架：侧栏 + 内容 ─────────────────────────────── */

/* crystal docs 默认让 body 定高、两个子容器各自滚动；改成整页滚动 +
   侧栏 sticky，与 Kit 站同一套滚动习惯。 */
html, body {
  height: auto;
  min-height: 100%;
  overflow: visible;
}

body {
  display: flex;
  align-items: flex-start;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  width: 17rem;
  flex: 0 0 17rem;
  color: var(--fg-soft);
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  box-shadow: none;
  font-size: .9rem;
  line-height: 1.45;
  padding-bottom: 2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.main-content {
  padding: 2.5rem clamp(1.25rem, 4vw, 3.5rem) 6rem;
  max-width: 62rem;
  margin: 0 auto;
  overflow: visible;
}

/* ── 侧栏头部 ──────────────────────────────────────── */

.sidebar .search-box { padding: .9rem .8rem .5rem; }

.sidebar input {
  width: 100%;
  padding: .45rem .65rem;
  font-family: inherit;
  font-size: .88rem;
  line-height: 1.3;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: none;
  transition: border-color .12s, box-shadow .12s;
}
.sidebar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  outline: none;
}
.sidebar input::placeholder { color: var(--muted); font-size: .86rem; }

.project-summary { padding: .3rem .8rem 1.1rem; }
.project-name { font-size: 1.06rem; font-weight: 700; letter-spacing: -.01em; margin: 0; color: var(--fg); }
.project-name a { color: inherit; }
.project-name a:hover { color: var(--accent); text-decoration: none; }
.project-version {
  display: inline-block;
  margin-top: .2rem;
  padding: .05rem .4rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--fg) 5%, transparent);
  border-radius: 999px;
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
}

.sidebar-links {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .1rem .8rem 1rem;
}
.sidebar-links a {
  padding: .18rem .5rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--fg-soft);
  font-size: .76rem;
  text-decoration: none;
}
.sidebar-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── 类型树 ────────────────────────────────────────── */

.types-list a {
  display: block;
  padding: .3rem .8rem;
  color: var(--fg-soft);
  text-decoration: none;
  border-radius: var(--r-sm);
  transition: background .12s, color .12s;
}
.types-list li.parent > a { padding-left: .8rem; }
.types-list li.parent { padding-left: 0; }
.types-list li ul { padding-left: .9rem; }
.types-list li.parent::before {
  color: var(--muted);
  font-size: 9px;
  line-height: 30px;
  width: 18px;
  left: 2px;
}
.types-list li.parent::before { z-index: 1; }
.sidebar .current > a { color: var(--accent); font-weight: 600; }
.sidebar a:hover { color: var(--fg); background: color-mix(in srgb, var(--fg) 6%, transparent); }
.sidebar a:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.sidebar .current > a:hover { color: var(--accent); background: var(--accent-soft); }

/* ── 标题与页首 ────────────────────────────────────── */

h1.type-name {
  margin: 0 0 1.4rem;
  padding: 0;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 0;
  font-size: clamp(1.7rem, 3.2vw, 2.1rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -.02em;
}
h1.type-name .kind {
  font-weight: 500;
  font-size: .42em;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: .5em;
  vertical-align: middle;
}

.main-content h1 { font-size: clamp(1.7rem, 3vw, 2rem); }
.main-content h2 {
  margin-top: 2.4em;
  padding: 1em 0 .35em;
  font-size: 1.24rem;
  font-weight: 650;
  color: var(--fg);
  border-top: 1px solid var(--border);
  border-bottom: 0;
}
.main-content h3 { font-size: 1.05rem; font-weight: 650; margin-top: 1.7em; }
.main-content h4, .main-content h5, .main-content h6 { font-weight: 600; }

.main-content .anchor { margin-left: -1.35rem; padding-right: .3rem; }
.main-content .anchor .octicon-link { color: var(--muted); width: 14px; height: 14px; }
.main-content h1:hover .anchor .octicon-link,
.main-content h2:hover .anchor .octicon-link,
.main-content h3:hover .anchor .octicon-link { color: var(--accent); }

/* ── 继承链 / 类型 chip ────────────────────────────── */

.superclass-hierarchy { margin: -.6rem 0 1.4rem; font-size: .88rem; }
.superclass-hierarchy .superclass { margin: 0 .35rem 0 0; }
.superclass-hierarchy .superclass + .superclass::before {
  content: "›";
  margin-right: .4rem;
  color: var(--muted);
}

.superclass-hierarchy .superclass a,
.other-type a,
.entry-summary .signature {
  padding: .12rem .45rem;
  margin-bottom: .25rem;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: .82rem;
  text-decoration: none;
  transition: border-color .12s, color .12s, background .12s;
}
.superclass-hierarchy .superclass a:hover,
.other-type a:hover,
.entry-summary .signature:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.entry-summary .summary { padding-left: 1.1rem; }
.entry-summary .summary p { margin: .5rem 0 1rem; }
.entry-summary { padding: .55rem 0; }
.entry-summary + .entry-summary { border-top: 1px solid var(--border); }

/* ── 方法详情 ──────────────────────────────────────── */

.entry-detail { padding: 1.6rem 0 .4rem; }

.entry-detail .signature {
  padding: .55rem .8rem;
  margin-bottom: .6rem;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: .85rem;
  transition: background .15s, border-color .15s;
}
.entry-detail:target .signature {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.entry-detail .signature .method-permalink {
  left: -1.6rem;
  padding: .55rem .3rem;
  color: var(--muted);
  opacity: 0;
}
.entry-detail:hover .signature .method-permalink { opacity: .7; }
.entry-detail .signature .method-permalink:hover { opacity: 1; color: var(--accent); }

.entry-detail > p, .entry-detail .doc { color: var(--fg-soft); }
.entry-detail > p { max-width: 46rem; }

.methods-inherited { padding-right: 0; margin-bottom: 1.4rem; }
.methods-inherited a { color: var(--fg-soft); }
.methods-inherited a:hover { color: var(--accent); }
.methods-inherited .tooltip > span { background: var(--card); border: 1px solid var(--border); color: var(--fg); }
.methods-inherited .tooltip * { color: var(--fg); }

/* ── 代码与表格 ────────────────────────────────────── */

.main-content pre {
  padding: 1rem 1.15rem;
  margin: .9rem 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--fg-soft);
  font-size: .85rem;
  line-height: 1.6;
}
.main-content pre code { font-size: inherit; }

.main-content :not(pre) > code {
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--fg);
}

.main-content table {
  display: table;
  width: 100%;
  max-width: 100%;
  margin: 1.2rem 0;
  padding: 0;
  font-size: .9rem;
  text-align: left;
  white-space: normal;
  border: 1px solid var(--border);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--r);
  background: var(--card);
  overflow: hidden;
}
.main-content table th {
  padding: .55rem .75rem;
  letter-spacing: 0;
  font-size: .83rem;
  font-weight: 600;
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 5%, transparent);
  border-bottom: 1px solid var(--border);
}
.main-content table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
}
.main-content table tr:last-child > * { border-bottom: 0; }
.main-content table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--fg) 2.5%, transparent); }

/* crystal docs 的语法着色类 */
.c { color: var(--muted); font-style: italic; }
.n, .t { color: #1f4f9c; }
.s { color: #1a6b3c; }
.i { color: #92500f; }
.k, .o { color: #a62639; }
.m { color: #6b3fa0; }

/* ── 搜索面板 ──────────────────────────────────────── */

.search-results {
  padding: .3rem .5rem .6rem;
  font-size: .88rem;
  line-height: 1.35;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
}
.search-result {
  padding: .45rem .55rem;
  border-left: 3px solid transparent;
  border-radius: var(--r-sm);
  transform: none;
  color: var(--fg-soft);
}
.search-result.current {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  transform: none;
}
.search-result:not(.current):nth-child(2n) { background: color-mix(in srgb, var(--fg) 3%, transparent); }
.search-result:not(.current):hover { background: color-mix(in srgb, var(--fg) 7%, transparent); }
.search-result__title { font-size: 1rem; line-height: 1.3; word-break: break-word; }
.search-result__title > a > .args { color: var(--muted); font-weight: 400; }
.search-result__type { color: var(--muted); font-weight: 500; font-size: .78rem; }
.search-result__doc { color: var(--muted); font-size: .82rem; }
.search-result__doc p { line-height: 1.45; max-height: 2.9em; }
.search-result a, .search-result a:hover { color: inherit; }
.search-result:not(.current):hover .search-result__title > a { color: var(--accent); }
.search-result:not(.current):hover .args { color: var(--muted); }
.search-results mark { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-radius: 2px; }

/* ── 快捷键弹窗 ────────────────────────────────────── */

.modal-background { background: color-mix(in srgb, var(--bg) 65%, transparent); backdrop-filter: blur(2px); }
.usage-modal {
  max-width: min(90vw, 40rem);
  background: var(--card);
  color: var(--fg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.modal-title { color: var(--fg); border-bottom-color: var(--border); }
.usage-modal > .close-button { color: var(--muted); }
.usage-modal > .close-button:hover { color: var(--fg); text-shadow: none; }
.usage-modal kbd {
  background: var(--code-bg);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  color: var(--fg);
  font-family: var(--font-mono);
}

/* ── 窄屏 ──────────────────────────────────────────── */

@media only screen and (max-width: 635px) {
  html, body { overflow: visible; }
  body { display: block; }
  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  /* 折叠展开沿用 crystal docs 的 checkbox 逻辑，这里只按 token 重写外观。
     窄屏下用 display 切换，避免零宽容器仍按内容撑高页面。 */
  #sidebar-btn ~ .sidebar { display: none; }
  #sidebar-btn:checked ~ .sidebar {
    display: block;
    position: static;
    width: 100%;
    max-width: 100vw;
    height: auto;
    padding-bottom: 1.5rem;
  }
  .main-content { max-width: 100%; padding: 3rem 1.15rem 4rem; }
  .main-content table { display: block; overflow-x: auto; }
  #sidebar-btn-label { color: var(--fg); top: .35rem; }
  #sidebar-btn:checked ~ #sidebar-btn-label { color: var(--fg); }
}

/* ── 深色：覆盖 crystal docs 自带深色块 ────────────── */

@media (prefers-color-scheme: dark) {
  html, body { background: var(--bg); }
  body { color: var(--fg); }
  .main-content a:visited { color: color-mix(in srgb, var(--accent) 75%, var(--fg)); }
  h1.type-name { color: var(--fg); background: none; border: 0; }
  .superclass-hierarchy .superclass a,
  .other-type a,
  .entry-summary .signature {
    background: var(--card);
    color: var(--fg);
    border-color: var(--border);
  }
  .superclass-hierarchy .superclass a:hover,
  .other-type a:hover,
  .entry-summary .signature:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
  }
  .entry-detail .signature { background: var(--code-bg); color: var(--fg); border-color: var(--border); }
  .entry-detail:target .signature { background: var(--accent-soft); border-color: var(--accent); }
  .methods-inherited a, .methods-inherited a:visited { color: var(--fg-soft); }
  .methods-inherited a:hover { color: var(--accent); }
  .methods-inherited .tooltip > span { background: var(--card); }
  .methods-inherited .tooltip * { color: var(--fg); }
  .main-content pre { background: var(--code-bg); border-color: var(--border); color: var(--fg-soft); }
  :not(pre) > code { background: color-mix(in srgb, var(--fg) 8%, transparent); }
  .main-content table { background: var(--card); border-color: var(--border); }
  .main-content table th { border-bottom-color: var(--border); }
  .main-content table td { border-bottom-color: var(--border); }
  .project-versions-nav > option { background: var(--card); }
  .n, .t { color: #8fb4ff; }
  .k, .o { color: #ff8b9a; }
  .s { color: #7fd6a3; }
  .i { color: #ffb37a; }
  .m { color: #c7a4ff; }
  .c { color: var(--muted); }
}
