.code-where { border-bottom: 1px solid var(--code-border); background: color-mix(in srgb, var(--code-head) 60%, var(--code-bg)); }
.code-where > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--code-fg);
  overflow: hidden;
}
.code-where > summary::-webkit-details-marker { display: none; }
.code-where > summary::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.7;
  transition: transform 0.15s ease;
}
.code-where[open] > summary::before { transform: rotate(45deg); }
.code-where > summary:hover .where-label { color: var(--accent-ink); }
.where-label { flex: none; font-weight: 700; font-family: var(--font-body); }
.where-path {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-code);
  font-size: 0.76rem;
  opacity: 0.85;
}
.where-sep { margin: 0 3px; color: var(--code-gutter); }
.where-file { color: var(--t-fdecl); font-weight: 700; }
.where-body { padding: 4px 14px 12px; }
.where-body .tree { margin: 8px 0 6px; background: var(--code-bg); border-color: var(--code-border); color: var(--code-fg); }
.where-body .tree-name { color: var(--code-fg); }
.where-body .tree-desc { color: color-mix(in srgb, var(--code-fg) 62%, transparent); }
.where-body .tree-file.is-muted > .tree-row { opacity: 0.55; }
.where-body .tree-file.is-here > .tree-row { background: var(--accent-soft); border-radius: 4px; margin: 1px -6px; padding: 2px 6px; }
.where-body .tree-file.is-here .tree-name { color: var(--accent-ink); font-weight: 800; }
.here-badge {
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  white-space: nowrap;
}
html[data-theme="light"] .here-badge { color: #fff; }
.where-package, .where-note { margin: 8px 0 0; font-size: 0.86rem; line-height: 1.5; color: var(--code-fg); font-family: var(--font-body); }
.where-note { opacity: 0.75; font-size: 0.8rem; }
.where-package code { font-size: 0.82em; background: var(--code-head); border: 1px solid var(--code-border); color: var(--code-fg); }

.listen-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.listen-btn:hover { border-color: var(--accent); }
.listen-btn.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.listen-i {
  width: 15px;
  height: 15px;
  background: currentColor;
  -webkit-mask: var(--icon-speaker) center / contain no-repeat;
  mask: var(--icon-speaker) center / contain no-repeat;
}
.page-meta { align-items: center; }

.reading-now { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; background: var(--accent-soft); }
.code-notes li.reading-now { outline-offset: 1px; }

.reader-bar {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 140%);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 24px);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transition: transform 0.2s ease;
}
.reader-bar.show { transform: translate(-50%, 0); }
.rb-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.rb-btn:hover { background: var(--raised); }
.rb-main { background: var(--accent); color: var(--accent-contrast); }
.rb-main:hover { background: var(--accent-ink); }
html[data-theme="light"] .rb-main { color: #fff; }
.rb-i { display: block; width: 14px; height: 14px; background: currentColor; }
.rb-play { clip-path: polygon(15% 5%, 95% 50%, 15% 95%); }
.rb-pause { clip-path: polygon(10% 5%, 40% 5%, 40% 95%, 10% 95%, 10% 5%, 60% 5%, 90% 5%, 90% 95%, 60% 95%, 60% 5%); }
.rb-stop { width: 12px; height: 12px; border-radius: 2px; }
.rb-next { clip-path: polygon(5% 8%, 62% 50%, 5% 92%, 5% 8%, 72% 8%, 92% 8%, 92% 92%, 72% 92%); }
.rb-prev { clip-path: polygon(95% 8%, 38% 50%, 95% 92%, 95% 8%, 28% 8%, 8% 8%, 8% 92%, 28% 92%); }
.rb-status { padding: 0 8px; font-size: 0.82rem; color: var(--muted); white-space: nowrap; min-width: 9ch; }
.rb-field select {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  padding: 0 8px;
  max-width: 13rem;
}

.ask-fab {
  position: fixed;
  z-index: 60;
  right: 18px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 46px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 10px 28px rgba(80, 40, 160, 0.4);
  cursor: pointer;
}
html[data-theme="light"] .ask-fab { color: #fff; }
.ask-fab:hover { background: var(--accent-ink); }
.ask-fab-i {
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--icon-chat) center / contain no-repeat;
  mask: var(--icon-chat) center / contain no-repeat;
}
body.ask-open .ask-fab { opacity: 0; pointer-events: none; }
.reader-bar.show ~ .ask-fab, body:has(.reader-bar.show) .ask-fab { bottom: 78px; }

.code-btn-ask { color: var(--accent-ink); }
html[data-theme="light"] .code-btn-ask { color: var(--accent); }

.ask-panel {
  position: fixed;
  z-index: 75;
  top: calc(var(--topbar-h) + 10px);
  right: 12px;
  bottom: 12px;
  width: min(30rem, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.22s ease;
}
.ask-panel.open { transform: none; }
.ask-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.ask-title { font-weight: 800; font-size: 1.02rem; }
.ask-mode { font-size: 0.74rem; font-weight: 700; color: var(--faint); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.ask-mode.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.ask-icon {
  margin-left: auto;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.ask-icon + .ask-icon { margin-left: 0; }
.ask-icon:hover { color: var(--text); border-color: var(--faint); }
.ask-close { width: 30px; padding: 0; position: relative; }
.ask-close::before, .ask-close::after { content: ""; position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: currentColor; transform: rotate(45deg); }
.ask-close::after { transform: rotate(-45deg); }
.ask-context { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line-soft); }
.ask-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 2px 10px; border-radius: 999px; background: var(--raised); color: var(--muted); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-chip-on { background: var(--accent-soft); color: var(--accent-ink); }
.ask-chip button { border: 0; background: transparent; color: inherit; font-weight: 800; cursor: pointer; padding: 0 2px; }
.ask-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
.ask-empty p { margin: 0 0 10px; color: var(--muted); font-size: 0.92rem; }
.ask-note { padding: 8px 10px; border-radius: var(--radius-m); background: var(--warn-soft); color: var(--text) !important; }
.ask-suggests { display: grid; gap: 6px; }
.ask-suggest { text-align: left; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); color: var(--text); font: inherit; font-size: 0.88rem; padding: 8px 10px; cursor: pointer; }
.ask-suggest:hover { border-color: var(--accent); }
.ask-msg { display: flex; }
.ask-user { justify-content: flex-end; }
.ask-bubble { max-width: 92%; padding: 9px 12px; border-radius: 12px; font-size: 0.92rem; line-height: 1.55; overflow-wrap: anywhere; }
.ask-user .ask-bubble { background: var(--accent); color: var(--accent-contrast); border-bottom-right-radius: 4px; }
html[data-theme="light"] .ask-user .ask-bubble { color: #fff; }
.ask-bot .ask-bubble { background: var(--bg); border: 1px solid var(--line-soft); border-bottom-left-radius: 4px; }
.ask-error .ask-bubble { border-color: var(--bad); }
.ask-bubble p { margin: 0 0 8px; }
.ask-bubble p:last-child, .ask-bubble ul:last-child, .ask-bubble ol:last-child { margin-bottom: 0; }
.ask-bubble ul, .ask-bubble ol { margin: 0 0 8px; padding-left: 1.2em; }
.ask-bubble code { font-size: 0.85em; background: var(--raised); border-radius: 4px; padding: 0.05em 0.3em; }
.ask-code { margin: 8px 0; border: 1px solid var(--code-border); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.ask-code-head { display: flex; align-items: center; justify-content: space-between; padding: 3px 6px 3px 10px; background: var(--code-head); font-size: 0.75rem; color: var(--code-fg); }
.ask-code-head button { border: 0; background: transparent; color: var(--code-fg); font: inherit; font-weight: 700; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.ask-code-head button:hover { background: color-mix(in srgb, var(--code-fg) 12%, transparent); }
.ask-code pre { margin: 0; padding: 10px; overflow-x: auto; font-size: 0.8rem; line-height: 1.55; color: var(--code-fg); }
.ask-code pre code { background: transparent; padding: 0; font-size: 1em; }
.ask-typing { display: inline-flex; gap: 4px; }
.ask-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: ask-dot 1s infinite ease-in-out; }
.ask-typing span:nth-child(2) { animation-delay: 0.15s; }
.ask-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ask-dot { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.ask-form { padding: 10px 12px 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.ask-input { width: 100%; resize: none; min-height: 64px; max-height: 40vh; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); color: var(--text); font: inherit; font-size: 0.92rem; }
.ask-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ask-row { display: flex; align-items: center; gap: 8px; }
.ask-model { margin-right: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }

@media (max-width: 860px) {
  .ask-fab-text { display: none; }
  .ask-fab { padding: 0 13px; }
  .ask-panel { top: 8px; right: 8px; left: 8px; bottom: 8px; width: auto; }
  .rb-voice-field { display: none; }
  .rb-status { display: none; }
}

@media print {
  .ask-fab, .ask-panel, .reader-bar, .listen-btn { display: none !important; }
}

.rb-speed {
  height: 30px;
  min-width: 48px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}
.rb-speed:hover { border-color: var(--accent); }
.rb-status { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
.rb-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(26rem, calc(100vw - 32px));
  margin: 0;
  padding: 6px 12px;
  border-radius: var(--radius-m);
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--text);
  font-size: 0.8rem;
  text-align: center;
}
