/* WikiLAN app shell: tokens, top bar, palette, drawer, home, search page. */

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", Arial, sans-serif;
  --font-serif: "Noto Serif", "Noto Serif Hebrew", Charter, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --reader-size: 18px;
  --reader-width: 46rem;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --surface: #f5f6f8;
  --surface-2: #eceef2;
  --line: #e1e4ea;
  --text: #1a1c21;
  --text-2: #4b505b;
  --muted: #7a808c;
  --accent: #2c5bd8;
  --accent-soft: #e8eefc;
  --accent-text: #ffffff;
  --link: #2a56c6;
  --link-visited: #6a4bc4;
  --mark: #ffe58a;
  --mark-text: #1a1c21;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .10);
  --backdrop: rgba(20, 22, 28, .32);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121316;
  --bg-elev: #1a1b20;
  --surface: #1c1d22;
  --surface-2: #25272d;
  --line: #2e3037;
  --text: #e6e7ea;
  --text-2: #b7bac2;
  --muted: #8b8f99;
  --accent: #7ea2ff;
  --accent-soft: #1f2a46;
  --accent-text: #0d1220;
  --link: #8fb0ff;
  --link-visited: #b9a2ff;
  --mark: #6b5a17;
  --mark-text: #fff6d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  --backdrop: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

:root[data-theme="sepia"] {
  --bg: #f6efe2;
  --bg-elev: #fbf6ec;
  --surface: #efe5d3;
  --surface-2: #e7dbc5;
  --line: #ddcfb6;
  --text: #3b3024;
  --text-2: #5c4c3a;
  --muted: #8a7760;
  --accent: #9a5b1e;
  --accent-soft: #efdcc2;
  --accent-text: #fffaf2;
  --link: #8a4f14;
  --link-visited: #7a4a6e;
  --mark: #f2d48a;
  --mark-text: #3b3024;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 8px 24px rgba(60, 40, 20, .14);
  --backdrop: rgba(50, 35, 20, .3);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; scroll-padding-top: calc(var(--topbar-h) + 12px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s var(--ease), color .25s var(--ease);
}
a { color: var(--link); }
button { font: inherit; color: inherit; }
kbd {
  font: 600 11px/1 var(--font-ui);
  padding: 3px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--text-2);
}
.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.progress {
  position: fixed; inset-inline-start: 0; top: 0; height: 3px; width: 0;
  background: var(--accent); z-index: 60; transition: width .1s linear;
}
.progress.loading { width: 35%; transition: width 2.5s var(--ease); }
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 18px; }
.brand img { border-radius: 8px; }
.searchbox {
  flex: 1; min-width: 0; max-width: 560px; margin-inline: auto;
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  cursor: text; text-align: start;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.searchbox:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.searchbox-label { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background-color .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

@media (max-width: 640px) {
  .brand span, .kbd-hint { display: none; }
  .topbar { gap: 6px; padding: 0 10px; }
  .actions { gap: 2px; }
  .actions .icon-btn { width: 34px; }
}
@media (max-width: 520px) {
  .topbar .searchbox { flex: 0 0 40px; padding: 0; justify-content: center; }
  .topbar .searchbox-label { display: none; }
}

/* svh: the height with the phone's address bar shown, so a short page never scrolls (100vh is taller there). */
.view { min-height: calc(100vh - var(--topbar-h)); min-height: calc(100svh - var(--topbar-h)); outline: none; }
.view.enter { animation: view-in .28s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ---------- buttons, chips ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text);
  cursor: pointer; text-decoration: none; font-weight: 500;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text-2);
  cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; height: 32px; padding: 0 12px; border-radius: 7px;
  cursor: pointer; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; font-size: 14px;
}
.seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- search palette ---------- */
.palette { position: fixed; inset: 0; z-index: 80; display: grid; justify-items: center; align-items: start; }
.palette-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fade .15s ease; }
.palette-panel {
  position: relative; margin-top: min(12vh, 110px);
  width: min(680px, calc(100vw - 24px)); max-height: min(72vh, 640px);
  display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
  animation: pop .18s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
.palette-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.palette-head .ico { color: var(--muted); }
.palette-head input {
  flex: 1; min-width: 0; height: 40px; border: 0; outline: none; background: transparent;
  color: var(--text); font: 500 18px var(--font-ui);
}
.palette-head input::-webkit-search-cancel-button { display: none; }
.palette-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.palette-filters .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.palette-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.palette-group { padding: 10px 10px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.palette-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 10px; cursor: pointer;
}
.palette-item .p-icon {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; background: var(--surface); color: var(--text-2);
}
.palette-item .p-body { flex: 1; min-width: 0; }
.palette-item .p-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .p-title mark { background: none; color: var(--accent); }
.palette-item .p-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .p-tag { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; text-transform: uppercase; }
.palette-item[aria-selected="true"] { background: var(--accent-soft); }
.palette-item[aria-selected="true"] .p-icon { background: var(--accent); color: var(--accent-text); }
.palette-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.palette-foot {
  display: flex; flex-wrap: wrap; gap: 14px; padding: 8px 16px;
  border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.palette-foot kbd { margin-inline-end: 2px; }
@media (max-width: 640px) {
  .palette-panel { margin-top: 0; width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; }
  .palette-foot { display: none; }
}

/* ---------- drawer (settings) ---------- */
.drawer { position: fixed; inset: 0; z-index: 70; }
.drawer-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fade .15s ease; }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; inset-inline-end: 0;
  width: min(380px, 100vw); background: var(--bg-elev); border-inline-start: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slide-in .22s var(--ease);
}
[dir="rtl"] .drawer-panel { animation-name: slide-in-rtl; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes slide-in-rtl { from { transform: translateX(-24px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { padding: 8px 16px 24px; overflow-y: auto; }
.setting { padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-label { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.setting-label small { font-weight: 400; color: var(--muted); }
.range { width: 100%; accent-color: var(--accent); }
.setting-note { margin: 0 0 10px; font-size: 14px; color: var(--text-2); overflow-wrap: anywhere; }
.remote-form { margin-bottom: 10px; }
.remote-form input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font: inherit; }
.remote-actions { flex-wrap: wrap; }

/* Password screen for remote devices */
.login-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: min(100%, 360px); display: grid; gap: 14px; justify-items: center; text-align: center; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card .field { width: 100%; text-align: start; }
.login-card .btn { width: 100%; justify-content: center; }
.login-note { margin: 0; color: var(--text-2); }
.login-error { margin: 0; color: #c62828; font-size: 14px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; color: var(--text-2); }
.shortcuts kbd { justify-self: start; }

/* ---------- popover, toast, lightbox ---------- */
.popover {
  position: absolute; z-index: 65; width: min(360px, calc(100vw - 24px));
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; font-size: 14px; line-height: 1.5;
  animation: pop .14s var(--ease);
}
.popover .pv-img { width: 100%; max-height: 180px; object-fit: cover; display: block; background: var(--surface); }
.popover .pv-body { padding: 12px 14px; }
.popover .pv-title { font-weight: 700; margin-bottom: 4px; }
.popover .pv-text { color: var(--text-2); }
.popover.ref .pv-body { max-height: 260px; overflow: auto; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; animation: pop .18s var(--ease);
}
.lightbox {
  position: fixed; inset: 0; z-index: 85; background: rgba(0, 0, 0, .9);
  display: grid; place-items: center; padding: 24px; animation: fade .15s ease;
}
.lightbox figure { margin: 0; display: grid; gap: 12px; justify-items: center; max-width: 100%; max-height: 100%; }
.lightbox img { max-width: 92vw; max-height: 82vh; object-fit: contain; background: #fff; border-radius: 6px; }
.lightbox figcaption { color: #ddd; max-width: 70ch; text-align: center; font-size: 14px; }
.lightbox-close { position: absolute; top: 12px; inset-inline-end: 12px; color: #fff; }
.lightbox-close:hover { background: rgba(255, 255, 255, .12); color: #fff; }

/* ---------- home ---------- */
.home { max-width: 1080px; margin: 0 auto; padding: 48px 16px 64px; }
.hero { text-align: center; padding: 24px 0 36px; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); margin: 0 0 8px; letter-spacing: -.02em; }
.hero p { margin: 0 0 24px; color: var(--text-2); }
.hero .searchbox { height: 56px; max-width: 640px; font-size: 18px; padding: 0 20px; box-shadow: var(--shadow); background: var(--bg-elev); }
/* Phones and small tablets, portrait and landscape: the search field takes ~88% of the width. */
@media (max-width: 960px) {
  .home { padding-top: 32px; padding-bottom: 32px; }
  .hero .searchbox { width: 88vw; max-width: none; margin-inline: auto; }
}
/* Touch screens have no keyboard shortcuts. */
@media (pointer: coarse) { .kbd-hint { display: none; } }
/* Landscape phones: little height, so a compact hero that fits without scrolling. */
@media (max-height: 520px) and (orientation: landscape) {
  .home { padding-top: 12px; padding-bottom: 16px; }
  .hero { padding: 8px 0 12px; }
  .hero h1 { font-size: 26px; margin-bottom: 4px; }
  .hero p { margin-bottom: 14px; font-size: 15px; }
  .hero .searchbox { height: 50px; }
}
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 36px 0 14px; }
.section-title h2 { font-size: 20px; margin: 0; }
.section-title .link-btn { background: none; border: 0; color: var(--link); cursor: pointer; font-size: 14px; }
.card-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface); display: grid; place-items: center; overflow: hidden; flex: none; }
.card-icon img { width: 100%; height: 100%; object-fit: contain; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); text-transform: uppercase; }
.recent-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.recent {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: var(--radius);
  text-decoration: none; color: var(--text); border: 1px solid var(--line); background: var(--bg-elev);
  transition: background-color .15s;
}
.recent:hover { background: var(--surface); }
.recent-thumb { width: 52px; height: 52px; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; flex: none; display: grid; place-items: center; color: var(--muted); }
.recent-body { min-width: 0; }
.recent-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 13px; color: var(--muted); }
.recent-bar { height: 3px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.recent-bar span { display: block; height: 100%; background: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- full-text results page ---------- */
.results { max-width: 820px; margin: 0 auto; padding: 24px 16px 64px; }
.results-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 8px; }
.results-head h1 { font-size: 22px; margin: 0; }
.corrected { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); margin-bottom: 12px; font-size: 14px; }
.results-count { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.hit { padding: 16px 0; border-bottom: 1px solid var(--line); }
.hit-title { font-size: 18px; font-weight: 600; text-decoration: none; }
.hit-title:hover { text-decoration: underline; }
.hit-meta { font-size: 13px; color: var(--muted); margin: 2px 0 6px; display: flex; gap: 8px; align-items: center; }
.hit-snippet { color: var(--text-2); }
.hit-snippet mark { background: var(--mark); color: var(--mark-text); border-radius: 3px; padding: 0 2px; }
.more { display: flex; justify-content: center; padding: 24px 0; }

/* skeleton loading */
.skel { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Phase 4: profiles, menus, dialogs, highlights, library pages ---------- */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 0;
}
.avatar.sm { width: 24px; height: 24px; font-size: 12px; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.sm .ico { width: 17px; height: 17px; }
.ico.big { width: 40px; height: 40px; stroke-width: 1.4; color: var(--muted); }
a.icon-btn { text-decoration: none; }
.bm-btn[aria-pressed="true"] { color: #e0a400; background: transparent; }

.menu {
  position: fixed; z-index: 75; min-width: 230px; padding: 6px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); animation: pop .14s var(--ease);
}
.menu-head { padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; text-align: start; color: var(--text);
}
.menu-item:hover { background: var(--surface); }
.menu-item .ico { color: var(--text-2); width: 18px; height: 18px; }
.menu-label { flex: 1; }
.menu-check { color: var(--accent); font-weight: 700; }
.menu-item.danger, .menu-item.danger .ico { color: #d23c3c; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

.toast { display: flex; align-items: center; gap: 14px; }
.toast-action { border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; }
:root[data-theme="light"] .toast-action, :root[data-theme="sepia"] .toast-action { color: #9cc0ff; }

.btn.danger-text { color: #d23c3c; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.dialog { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: 16px; }
.dialog-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fade .15s ease; }
.dialog-panel {
  position: relative; width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 16px 18px 18px; display: grid; gap: 14px; animation: pop .18s var(--ease);
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.dialog-head h2 .ico { color: #e0a400; }
.dialog-article { font-weight: 600; color: var(--text-2); padding: 8px 12px; background: var(--surface); border-radius: 10px; }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea, .lib-search, .hl-note {
  font: 400 15px var(--font-ui); color: var(--text); background: var(--bg); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.field textarea, .hl-note { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus, .lib-search:focus, .hl-note:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: flex; gap: 8px; }
.field-row select { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; }

/* highlights */
.article mark.wl-hl { color: inherit; border-radius: 3px; padding: 0 1px; cursor: pointer; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl-yellow { --hl: #ffe27a; } .hl-green { --hl: #b7ec9c; } .hl-blue { --hl: #a9d4ff; } .hl-pink { --hl: #ffbfd9; }
:root[data-theme="dark"] .hl-yellow { --hl: #6b5a17; } :root[data-theme="dark"] .hl-green { --hl: #2f5b23; }
:root[data-theme="dark"] .hl-blue { --hl: #1f4a73; } :root[data-theme="dark"] .hl-pink { --hl: #6e2a48; }
.article mark.wl-hl { background: var(--hl); }
.article mark.wl-hl.has-note { border-bottom: 2px dotted var(--text-2); }
.hl-toolbar {
  position: absolute; z-index: 66; display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--text); border-radius: 12px; box-shadow: var(--shadow); animation: pop .12s var(--ease);
}
.hl-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: var(--hl); cursor: pointer; padding: 0; }
.hl-swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.hl-note-btn { border: 0; background: none; color: var(--bg); font-weight: 600; cursor: pointer; padding: 0 6px; }
.popover.hl-pop .pv-body { display: grid; gap: 10px; }
.hl-colors { display: flex; gap: 8px; }
.hl-colors .hl-swatch { border-color: var(--line); }
.hl-actions { display: flex; justify-content: space-between; }

/* library pages */
.lib { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }
.lib-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.lib-tab {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; text-decoration: none; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500;
}
.lib-tab .ico { width: 18px; height: 18px; }
.lib-tab:hover { color: var(--text); }
.lib-tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.lib-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; align-items: start; }
.lib-side { position: sticky; top: calc(var(--topbar-h) + 16px); display: grid; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; border: 0; background: none;
  color: var(--text-2); text-decoration: none; cursor: pointer; font-size: 14.5px; text-align: start; width: 100%;
}
.side-item .ico { width: 18px; height: 18px; }
.side-item:hover { background: var(--surface); color: var(--text); }
.side-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-item.drop-over { outline: 2px dashed var(--accent); background: var(--accent-soft); }
.side-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { font-size: 12px; color: var(--muted); }
.side-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 10px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.side-empty { padding: 4px 10px; font-size: 13px; color: var(--muted); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 10px; }
.tag { font-size: 13px; color: var(--accent); text-decoration: none; background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }
.tag small { color: var(--muted); }
.tag[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
.lib-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.lib-head h1 { margin: 0; font-size: 24px; }
.lib-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lib-search { margin-bottom: 14px; }
.lib-main.wide { max-width: 820px; }
.bm-list, .hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bm-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg-elev); transition: box-shadow .15s, opacity .15s;
}
.bm-row:hover { box-shadow: var(--shadow); }
.bm-row.dragging { opacity: .45; }
.drag-handle { cursor: grab; color: var(--muted); letter-spacing: -3px; user-select: none; padding: 0 2px; }
[data-sortable="false"] .drag-handle { visibility: hidden; }
.bm-thumb { width: 56px; height: 56px; border-radius: 9px; flex: none; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); }
.bm-body { flex: 1; min-width: 0; }
.bm-title { font-weight: 650; color: var(--text); text-decoration: none; }
.bm-title:hover { color: var(--accent); }
.bm-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.bm-note { margin-top: 6px; font-size: 14px; color: var(--text-2); white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bm-progress { width: 60px; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; display: inline-block; }
.bm-progress span { display: block; height: 100%; background: var(--accent); }
.bm-actions { display: flex; gap: 2px; opacity: .6; transition: opacity .15s; }
.bm-row:hover .bm-actions, .bm-row:focus-within .bm-actions { opacity: 1; }
.day-head { margin: 16px 0 4px; font-weight: 650; color: var(--text-2); font-size: 14px; }
.hist-row { display: flex; align-items: center; gap: 14px; padding: 8px 10px; border-radius: 10px; }
.hist-row:hover { background: var(--surface); }
.hist-time { width: 52px; flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist-body { flex: 1; min-width: 0; }
.hl-group { margin-bottom: 24px; }
.hl-group-title { display: block; font-family: var(--font-serif); font-size: 20px; color: var(--text); text-decoration: none; margin-bottom: 8px; }
.hl-group-title:hover { color: var(--accent); }
.hl-item { border-inline-start: 4px solid var(--hl); background: var(--bg-elev); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); border-inline-end: 1px solid var(--line); }
.hl-item blockquote { margin: 0; font-family: var(--font-serif); font-size: 16px; line-height: 1.6; }
.hl-item-note { margin-top: 6px; font-size: 14px; color: var(--text-2); white-space: pre-wrap; }
.hl-item-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
@media (max-width: 820px) {
  .lib-grid { grid-template-columns: 1fr; }
  .lib-side { position: static; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .side-head, .tag-cloud { grid-column: 1 / -1; }
  .drag-handle { display: none; }
  .bm-actions { opacity: 1; }
}

/* ---------- Phase 6: library management ---------- */
.badge-host { position: relative; }
.nav-badge {
  position: absolute; top: 4px; inset-inline-end: 3px; min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px; background: #e5484d; color: #fff; font: 700 10.5px/17px var(--font-ui); text-align: center;
}
.nav-badge.dot { min-width: 9px; width: 9px; height: 9px; padding: 0; top: 7px; background: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.library-page { max-width: 980px; }
.lib-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; margin-bottom: 18px; }
.lib-card h2 { display: flex; align-items: center; gap: 10px; font-size: 17px; margin: 0 0 14px; }
.lib-card h2 .ico { color: var(--accent); }
.muted { color: var(--muted); font-size: 14px; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 14px; }
.disk-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--surface-2); }
.disk-bar span { display: block; height: 100%; }
.seg-wl { background: var(--accent); } .seg-other { background: color-mix(in srgb, var(--muted) 70%, transparent); } .seg-free { background: var(--surface-2); border: 1px solid var(--line); }
.disk-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 14px; color: var(--text-2); }
.disk-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.dl-row { padding: 12px 0; border-top: 1px solid var(--line); }
.dl-row:first-of-type { border-top: 0; padding-top: 0; }
.dl-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dl-title { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dl-actions { display: flex; gap: 2px; }
.dl-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.dl-bar span { display: block; height: 100%; background: var(--accent); transition: width .6s var(--ease); }
.dl-bar.paused span, .dl-bar.scheduled span { background: var(--muted); }
.dl-bar.error span { background: #e5484d; }
.dl-bar.verifying span { background: #2c9d5b; }
.dl-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-status { font-weight: 600; color: var(--text-2); }
.inst-row, .cat-row { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.lib-card h2 + .inst-row, .lib-card h2 + .cat-row, [data-part="catalog"] > .cat-row:first-child { border-top: 0; }
.inst-body, .cat-body { flex: 1; min-width: 0; }
.inst-title { font-weight: 650; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cat-desc { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.inst-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.inst-actions { display: flex; gap: 6px; flex: none; align-items: center; }
.chip-ok, .chip-busy, .chip-wait { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip-ok { background: color-mix(in srgb, #2c9d5b 16%, transparent); color: #2c9d5b; }
.chip-busy { background: var(--accent-soft); color: var(--accent); }
.chip-wait { background: var(--surface-2); color: var(--text-2); }
.upd { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.upd.pending { background: var(--surface); color: var(--text-2); }
.upd .ico { width: 18px; height: 18px; color: var(--accent); }
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.set-grid .field-row { align-items: center; flex-wrap: wrap; }
.set-grid input[type="time"] { width: auto; }
.cat-filters { margin-bottom: 10px; }
@media (max-width: 640px) {
  .inst-row, .cat-row { flex-wrap: wrap; }
  .inst-actions { width: 100%; justify-content: flex-end; }
}

/* ---------- Phase 7: backup ---------- */
.drive { padding: 14px 0; border-top: 1px solid var(--line); }
.drive:first-child { border-top: 0; padding-top: 4px; }
.drive-head { display: flex; gap: 14px; align-items: flex-start; }
.bk-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.bk-status.success { border-color: color-mix(in srgb, #2c9d5b 45%, var(--line)); }
.bk-status.error { border-color: color-mix(in srgb, #e5484d 50%, var(--line)); }
.bk-error { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, #e5484d 12%, transparent); color: var(--text); font-size: 14px; }
.bk-install { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.bk-install pre { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bg); overflow-x: auto; font: 13px var(--font-mono); }
.lib-card h2 .btn .ico { color: inherit; }

/* ---------- Phase 8: app updates ---------- */
.app-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.app-steps li::before { content: "○ "; }
.app-steps li.done { color: #2c9d5b; } .app-steps li.done::before { content: "✓ "; }
.app-steps li.now { color: var(--accent); font-weight: 600; } .app-steps li.now::before { content: "◉ "; }
.lib-card code { font: 13px var(--font-mono); background: var(--surface); padding: 1px 6px; border-radius: 5px; }

/* ---------- bidi: keyboard keys, code and numbers always read left-to-right ---------- */
kbd, code, pre, .hist-time, input[type="time"] { unicode-bidi: isolate; direction: ltr; }
.lib-search, .field input, .field textarea, .hl-note, .palette-head input { text-align: start; }
[dir="rtl"] .palette-foot { direction: rtl; }

/* ---------- busy buttons and change highlight ---------- */
.spinner {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn.busy { cursor: progress; opacity: .85; }
.btn:disabled { cursor: not-allowed; opacity: .6; }
.btn.busy:disabled { opacity: .85; cursor: progress; }
.flash { animation: flash 1.6s var(--ease); border-radius: 6px; }
@keyframes flash { 0%, 30% { background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-soft); } 100% { background: transparent; box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
.advanced { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.advanced > summary { cursor: pointer; color: var(--text-2); font-size: 14px; font-weight: 600; }
.advanced[open] > summary { margin-bottom: 4px; }

/* ---------- restore books dialog ---------- */
.rb-panel { width: min(620px, 100%); }
.rb-list { display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; }
.rb-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.rb-row:hover { background: var(--surface); }
.rb-row.off { opacity: .6; cursor: default; }
.rb-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.rb-body { display: grid; gap: 2px; min-width: 0; }
.rb-title { font-weight: 650; }
.rb-status { font-size: 13px; color: var(--text-2); }
.rb-status.st-missing, .rb-status.st-older-installed { color: var(--accent); font-weight: 600; }
.rb-total { font-size: 14px; color: var(--text-2); }
.rb-nospace { color: #e5484d; font-weight: 600; }

/* translator */
.tr-page { max-width: 1120px; }
.tr-bar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-bottom: 10px; }
.tr-lang {
  font: 500 15px var(--font-ui); color: var(--text); background: var(--bg-elev); width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer;
}
.tr-lang:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tr-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tr-pane { display: flex; flex-direction: column; background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tr-pane-out { background: var(--surface); }
.tr-in, .tr-out { flex: 1; min-height: 240px; padding: 14px 16px; font: 400 18px/1.5 var(--font-ui); color: var(--text); text-align: start; white-space: pre-wrap; overflow-wrap: anywhere; }
.tr-in { border: 0; background: transparent; resize: vertical; outline: none; }
.tr-in:disabled, .tr-lang:disabled { opacity: .55; cursor: not-allowed; }
.tr-out.busy { opacity: .5; transition: opacity .2s .3s; }
.tr-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 8px 16px; min-height: 44px; }
.tr-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.tr-actions .kbd-hint { font-size: 11px; opacity: .8; }
.tr-error { color: #e5484d; font-weight: 600; }
@media (max-width: 720px) {
  .tr-panes { grid-template-columns: 1fr; }
  .tr-in, .tr-out { min-height: 150px; }
}
.tr-status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; padding: 8px 12px;
  border-radius: 12px; background: var(--accent-soft); font-size: 14px; color: var(--text);
}
.tr-status > .ico { color: var(--accent); width: 18px; height: 18px; flex: none; }
.tr-status-text { font-weight: 600; }
.tr-status-bar { flex: 1; min-width: 80px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.tr-status-bar span { display: block; height: 100%; background: var(--accent); transition: width .4s var(--ease); }
.tr-status-actions { display: flex; gap: 6px; margin-inline-start: auto; }
.tr-menu { width: 260px; }
.tr-menu-search { margin: 4px 0 6px; }
.tr-menu-list { max-height: min(320px, 50vh); overflow-y: auto; overscroll-behavior: contain; }
.hl-tr-btn { display: inline-grid; place-items: center; }
.hl-tr-btn .ico { width: 18px; height: 18px; }

/* AI assistant */
.ai-page {
  display: grid; grid-template-columns: 270px minmax(0, 1fr);
  height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); overflow: hidden;
}
.ai-side {
  display: flex; flex-direction: column; gap: 10px; min-height: 0;
  padding: 14px 10px; border-inline-end: 1px solid var(--line); background: var(--surface);
}
.ai-new { justify-content: center; }
.ai-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.ai-group { margin: 14px 8px 4px; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ai-group:first-child { margin-top: 2px; }
.ai-empty-list { padding: 8px; font-size: 14px; }
.ai-item { display: flex; align-items: center; border-radius: 10px; }
.ai-item a {
  flex: 1; min-width: 0; padding: 8px 10px; color: var(--text); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: start;
}
.ai-item .icon-btn { display: none; flex: none; }
.ai-item:hover, .ai-item.current { background: var(--surface-2); }
.ai-item:hover .icon-btn, .ai-item.current .icon-btn, .ai-item:focus-within .icon-btn { display: inline-grid; }
.ai-item.current a { font-weight: 600; }
.ai-scrim { display: none; }

.ai-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ai-head { display: flex; align-items: center; gap: 8px; padding: 8px 16px; min-height: 52px; border-bottom: 1px solid var(--line); }
.ai-title { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: start; }
.ai-menu { display: none; }
.ai-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 16px 8px; scrollbar-gutter: stable; }
.ai-scroll > [data-part="install"] { max-width: 760px; margin: 0 auto; }
.ai-msgs { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.ai-msg.user { display: flex; justify-content: flex-end; }
.ai-bubble {
  max-width: min(85%, 600px); padding: 10px 14px; border-radius: 18px; border-end-end-radius: 6px;
  background: var(--accent-soft); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; text-align: start;
}
.ai-msg.assistant { display: flex; gap: 12px; align-items: flex-start; }
.ai-avatar {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin-top: 2px;
  border-radius: 50%; background: var(--surface-2); color: var(--accent);
}
.ai-avatar .ico { width: 17px; height: 17px; }
.ai-body { flex: 1; min-width: 0; }
.ai-md { line-height: 1.6; overflow-wrap: anywhere; text-align: start; }
.ai-md > :first-child { margin-top: 0; }
.ai-md > :last-child { margin-bottom: 0; }
.ai-md p { margin: 0 0 .75em; }
.ai-md h3, .ai-md h4, .ai-md h5, .ai-md h6 { margin: 1.1em 0 .4em; font-size: 1.05em; line-height: 1.35; }
.ai-md h3 { font-size: 1.15em; }
.ai-md ul, .ai-md ol { margin: 0 0 .75em; padding-inline-start: 1.5em; }
.ai-md li { margin: .2em 0; }
.ai-md li > ul, .ai-md li > ol { margin: .2em 0 .4em; }
.ai-md li > ul { list-style-type: circle; }
.ai-md code { font: .9em var(--font-mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ai-md pre { margin: 0 0 .75em; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); overflow-x: auto; text-align: left; }
.ai-md pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.ai-md blockquote { margin: 0 0 .75em; padding: 2px 12px; border-inline-start: 3px solid var(--line); color: var(--text-2); }
.ai-md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.ai-table { overflow-x: auto; margin: 0 0 .75em; }
.ai-md table { border-collapse: collapse; font-size: 14px; }
.ai-md th, .ai-md td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; vertical-align: top; }
.ai-md th { background: var(--surface); font-weight: 600; }
.ai-md.streaming > :last-child::after, .ai-md.streaming:empty::after {
  content: ""; display: inline-block; width: .5em; height: 1.05em; margin-inline-start: 2px; vertical-align: -.15em;
  background: var(--accent); border-radius: 2px; animation: ai-blink 1s steps(2) infinite;
}
.ai-md.streaming > pre:last-child::after, .ai-md.streaming > ul:last-child::after, .ai-md.streaming > ol:last-child::after,
.ai-md.streaming > div:last-child::after { display: none; }
@keyframes ai-blink { 50% { opacity: 0; } }
.ai-status { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 14px; }
.ai-dots { width: 22px; height: 6px; background: radial-gradient(circle, var(--muted) 2.5px, transparent 3px) 0 50% / 8px 6px repeat-x; animation: ai-pulse 1.2s ease-in-out infinite; }
@keyframes ai-pulse { 50% { opacity: .35; } }
.ai-thoughts { margin: 0 0 10px; font-size: 14px; color: var(--text-2); }
.ai-thoughts summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.ai-thoughts > div { margin-top: 6px; padding: 8px 12px; border-inline-start: 2px solid var(--line); white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.ai-tools { display: flex; align-items: center; gap: 2px; margin-top: 6px; margin-inline-start: -6px; min-height: 30px; }
.ai-note, .ai-speed { font-size: 12px; padding: 0 6px; }
.ai-speed { margin-inline-start: auto; opacity: 0; transition: opacity .2s; }
.ai-msg:hover .ai-speed { opacity: 1; }

.ai-hello { text-align: center; padding: 6vh 0 12px; }
.ai-hello-icon { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); }
.ai-hello-icon .ico { width: 30px; height: 30px; }
.ai-hello h1 { margin: 14px 0 6px; font-size: 26px; }
.ai-hello > p { max-width: 520px; margin: 0 auto 22px; font-size: 14px; }
.ai-samples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 620px; margin: 0 auto; }
.ai-sample {
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-elev);
  color: var(--text-2); font: inherit; font-size: 14px; text-align: start; cursor: pointer; transition: background-color .15s, border-color .15s;
}
.ai-sample:hover { background: var(--surface); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); color: var(--text); }

.ai-compose {
  width: min(760px, calc(100% - 32px)); margin: 4px auto 14px; padding: 10px 10px 8px 14px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--bg-elev); box-shadow: var(--shadow);
}
.ai-compose:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.ai-input {
  display: block; width: 100%; max-height: 220px; resize: none; border: 0; outline: none; background: transparent;
  color: var(--text); font: 400 16px/1.5 var(--font-ui); padding: 4px 2px; text-align: start;
}
.ai-input:disabled { opacity: .55; cursor: not-allowed; }
.ai-compose-bar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.ai-think { height: 30px; border-radius: 999px; font-size: 13px; color: var(--text-2); }
.ai-think .ico { width: 16px; height: 16px; }
.ai-think[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); color: var(--accent); }
.ai-credit { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: end; }
.ai-send {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); cursor: pointer; transition: opacity .15s, transform .1s;
}
.ai-send:disabled { opacity: .35; cursor: default; }
.ai-send:not(:disabled):active { transform: scale(.94); }
.ai-send.stop { background: var(--text); color: var(--bg); }
.ai-send.stop .ico { fill: currentColor; }

@media (max-width: 800px) {
  .ai-page { grid-template-columns: minmax(0, 1fr); }
  .ai-side {
    position: fixed; top: var(--topbar-h); bottom: 0; inset-inline-start: 0; z-index: 30; width: min(300px, 85vw);
    transform: translateX(-105%); transition: transform .22s var(--ease); box-shadow: var(--shadow);
  }
  [dir="rtl"] .ai-side { transform: translateX(105%); }
  .ai-page.side-open .ai-side { transform: none; }
  .ai-page.side-open .ai-scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0; z-index: 29; background: var(--backdrop); }
  .ai-menu { display: inline-grid; }
  .ai-head { padding: 6px 8px; }
  .ai-item .icon-btn { display: inline-grid; }
}
@media (max-width: 560px) {
  .ai-scroll { padding: 14px 12px 6px; }
  .ai-compose { width: calc(100% - 16px); margin-bottom: 8px; }
  .ai-credit { display: none; }
  .ai-samples { grid-template-columns: minmax(0, 1fr); }
  .ai-hello { padding-top: 3vh; }
  .ai-bubble { max-width: 90%; }
}
@media (max-width: 400px) {
  .actions { gap: 0; }
  .actions .icon-btn { width: 31px; }
}

/* cross-language search results */
.cross { margin-top: 28px; }
.cross-title { display: flex; align-items: center; gap: 8px; font-size: 17px; margin: 0 0 4px; color: var(--text-2); }
.cross-title .ico { color: var(--accent); }
.cross-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text-2); font-size: 14px; }
.cross-hint .ico { color: var(--accent); }
.cross-hit .hit-title + .spinner { display: inline-block; margin-inline-start: 8px; vertical-align: middle; }
.hit-orig { color: var(--muted); font-size: 13px; }
