/* Copyright (c) 2026 geniuskey. MIT. */
/* @euiyun/book standard book UI: top bar, chapter drawer, pager and footer. Pairs with runtime/ui.js.
   Uses the book's --bg, --bg-elev, --surface, --text, --text-dim, --text-faint, --border, --accent, --accent-2,
   --accent-soft, --shadow, --mono, --radius, --maxw and --nav-h (58px when unset). */
.bk-topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h, 58px);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.bk-nav-left, .bk-nav-right { display: flex; align-items: center; gap: 12px; flex: 1 1 0; min-width: 0; }
.bk-nav-left { overflow: hidden; }
.bk-nav-right { justify-content: flex-end; gap: 8px; min-width: max-content; }
.bk-logo { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 800; color: var(--text); letter-spacing: -0.02em; font-size: 18px; white-space: nowrap; }
.bk-logo:hover { text-decoration: none; }
.bk-logo .mark { width: 28px; height: 28px; flex: none; }
.bk-logo > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bk-logo small { font-weight: 500; color: var(--text-dim); font-size: 13px; }
.bk-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  height: 36px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer; text-decoration: none;
}
.bk-btn:hover { border-color: var(--accent); text-decoration: none; }
.bk-btn.icon { width: 36px; padding: 0; }
.bk-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }
.bk-progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.bk-search { position: relative; flex: 0 1 340px; min-width: 80px; color: var(--text-dim); }
.bk-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.bk-search input { display: block; width: 100%; height: 36px; padding: 0 12px 0 37px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); color: var(--text); font: inherit; font-size: 14px; outline: none; }
.bk-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bk-search input::placeholder { color: var(--text-faint); }
.bk-search-results { display: none; position: absolute; top: calc(100% + 10px); left: 0; width: max(100%, 300px); max-width: min(420px, calc(100vw - 32px)); max-height: min(60vh, 460px); overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); box-shadow: var(--shadow); padding: 6px; }
.bk-search.open .bk-search-results { display: block; }
.bk-search-results a { display: block; padding: 9px 11px; border-radius: 8px; color: var(--text); line-height: 1.4; }
.bk-search-results a:hover, .bk-search-results a:focus { background: var(--accent-soft); text-decoration: none; outline: none; }
.bk-search-results strong, .bk-search-results small { display: block; }
.bk-search-results strong { font-size: 14px; }
.bk-search-results small { margin-top: 3px; color: var(--text-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-search-results p { margin: 0; padding: 10px 11px; font-size: 14px; }
.bk-search-results mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.bk-sr-type { display: inline-block; margin-right: 6px; padding: 0 5px; border-radius: 4px; background: var(--surface, var(--bg)); color: var(--text-dim); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.bk-sr-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; color: var(--text-dim); font-size: 12.5px; }
.bk-sr-foot { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.bk-sr-foot a { font-size: 13px; color: var(--accent); }

/* Tablet: the logo keeps only its mark, buttons only their icons, and search takes the room. */
@media (max-width: 760px) {
  .bk-logo > span, .bk-btn .bk-label { display: none; }
  .bk-nav-left { flex: 0 0 auto; }
  .bk-search { flex: 1 1 auto; }
  .bk-shelf, .bk-btn.has-label { padding: 0; width: 36px; }
}
/* Phone: [menu] [search] [one kept action] [feedback] [theme]. The shelf moves to the drawer. */
@media (max-width: 600px) {
  .bk-topbar { gap: 8px; padding: 0 12px; }
  .bk-nav-left, .bk-nav-right { flex: 0 0 auto; gap: 6px; }
  .bk-logo, .bk-action:not(.bk-keep) { display: none; }
  .bk-search { flex: 1 1 auto; }
  .bk-search-results { left: 50%; transform: translateX(-50%); }
}
@media (max-width: 440px) {
  .bk-shelf { display: none; }
  .bk-search input::placeholder { color: transparent; }
}

/* Chapter drawer */
.bk-drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; }
.bk-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(340px, 88vw); z-index: 61;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform .25s ease;
  overflow-y: auto; padding: 20px 14px 40px;
}
body.drawer-open .bk-drawer { transform: none; }
body.drawer-open .bk-drawer-backdrop { opacity: 1; pointer-events: auto; }
.bk-drawer h4 { margin: 8px 10px 10px; font-size: 12px; letter-spacing: .12em; color: var(--text-faint); text-transform: uppercase; }
.bk-chlist { list-style: none; margin: 0; padding: 0; }
.bk-chlist a { display: flex; gap: 12px; align-items: baseline; padding: 9px 10px; border-radius: 10px; color: var(--text); line-height: 1.4; }
.bk-chlist a:hover { background: var(--surface); text-decoration: none; }
.bk-chlist a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.bk-chlist .num { font-family: var(--mono); font-size: 12px; color: var(--text-faint); width: 22px; flex: none; }
.bk-chlist a.active .num { color: var(--accent); }
.bk-chlist .bk-part { font-size: 11px; letter-spacing: .12em; color: var(--text-faint); font-weight: 700; padding: 14px 10px 4px; }
.bk-drawer-shelf { display: block; margin: 18px 10px 0; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; font-weight: 600; }

/* Previous / next */
.bk-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: var(--maxw); margin: 0 auto; padding: 0 0 20px; }
.bk-pager a { display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--text); }
.bk-pager a:hover { border-color: var(--accent); text-decoration: none; }
.bk-pager small { display: block; color: var(--text-faint); font-size: 12px; }
.bk-pager .next { text-align: right; grid-column: 2; }
@media (max-width: 640px) { .bk-pager { grid-template-columns: 1fr; } .bk-pager .next { grid-column: 1; } }

/* Footer */
.bk-foot { border-top: 1px solid var(--border); color: var(--text-faint); font-size: 13px; padding: 28px 16px 40px; text-align: center; }
