/* ---------- Exhibition Theme bar: horizontal, bottom-centre ---------- */
.category-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 21;
  max-width: calc(100vw - 36px);
  padding: 8px 10px;
}

.category-stack {
  display: flex;
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-gold) transparent;
  padding-bottom: 2px;
}
.category-stack::-webkit-scrollbar { height: 6px; }
.category-stack::-webkit-scrollbar-thumb { background: var(--accent-gold); border-radius: 999px; }

.category-theme-card {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 260px;
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.category-theme-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-gold);
  background: rgba(201, 168, 106, 0.08);
}
.category-theme-card { --theme-color: var(--accent-teal); border-left: 4px solid var(--theme-color); }
.category-theme-card .category-theme-icon { box-shadow: inset 0 0 0 2px var(--theme-color); }
.category-theme-card.active {
  border-color: var(--theme-color);
  background: color-mix(in srgb, var(--theme-color) 22%, transparent);
}

.category-theme-icon {
  flex-shrink: 0;
  font-size: calc((17px) * var(--fs, 1));
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
}

.category-theme-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.category-theme-name {
  font-size: calc((13px) * var(--fs, 1));
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.category-theme-count {
  font-size: calc((10.5px) * var(--fs, 1));
  color: var(--text-muted);
}

.category-stack-empty {
  font-size: calc((12px) * var(--fs, 1));
  color: var(--text-muted);
  padding: 8px 12px;
  white-space: nowrap;
}

/* The audiobook player owns the bottom-left corner while it is open. */
body.ab-open .category-nav { left: 396px; transform: none; max-width: calc(100vw - 414px); }

/* ---------- Search ---------- */
.search-wrap { position: relative; flex: 0 0 auto; }
.search-input {
  width: 210px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font: inherit;
  font-size: calc((13px) * var(--fs, 1));
  outline: none;
}
.search-input:focus { border-color: var(--accent-gold); }
.search-input::placeholder { color: var(--text-muted); }
.search-results {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: 340px;
  max-width: calc(100vw - 36px);
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  z-index: 40;
}
.search-results[hidden] { display: none; }
.search-group {
  padding: 8px 10px 4px;
  font-size: calc((11px) * var(--fs, 1));
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-color);
  font-weight: 700;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-left: 3px solid var(--theme-color);
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: calc((13px) * var(--fs, 1));
  text-align: left;
  cursor: pointer;
}
.search-result:hover, .search-result:focus-visible { background: rgba(255, 255, 255, 0.08); outline: none; }
.search-result-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { padding: 12px; font-size: calc((13px) * var(--fs, 1)); color: var(--text-muted); }

/* ---------- Mobile hamburger + drawer (hidden on desktop) ---------- */
.menu-btn { display: none; }
.mobile-drawer, .drawer-backdrop { display: none; }

/* ---------- Virtual joystick ---------- */
.joystick-zone {
  position: fixed;
  left: 14px;
  bottom: calc(16px + var(--sheet-h, 0px) + env(safe-area-inset-bottom, 0px));
  z-index: 19;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: bottom 0.25s ease, opacity 0.2s ease;
}
.joystick-zone[hidden] { display: none; }
.joy-toggle {
  position: fixed; left: 14px; z-index: 19;
  bottom: calc(16px + var(--sheet-h, 0px) + env(safe-area-inset-bottom, 0px));
  width: 42px; height: 42px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; opacity: .85;
  transition: bottom .25s ease;
}
.joy-toggle[hidden] { display: none; }
body.intro-open .joy-toggle, body.touring .joy-toggle { display: none; }
.joy-hide { font-size: 13px; }
.joystick-zone.suspended { opacity: 0; pointer-events: none; }
.joystick {
  position: relative;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(255, 255, 255, 0.06);
  touch-action: none;
}
.joystick-ring {
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.55), color-mix(in srgb, var(--accent-gold) 55%, transparent));
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transition: transform 0.12s ease-out;
}
.joystick.engaged .joystick-knob { transition: none; }
.joystick-side { display: flex; flex-direction: column; gap: 8px; }
.joy-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc((15px) * var(--fs, 1));
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  touch-action: none;
}
.joy-btn.held { border-color: var(--accent-gold); color: var(--accent-gold); }
.joystick-zone[data-mode="look"] .joystick { border-color: var(--accent-teal); }

@media (max-width: 760px) {
  /* The horizontal theme bar is replaced by the ☰ drawer. */
  .category-nav { display: none; }
  .menu-btn { display: inline-flex; }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 48;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }
  .drawer-backdrop.open { opacity: 1; pointer-events: auto; }

  .mobile-drawer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 49;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 16px;
    border-radius: 0 18px 18px 0;
    transform: translateX(-102%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
  }
  .mobile-drawer[hidden] { display: none; }
  .mobile-drawer.open { transform: translateX(0); }
  .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .drawer-title { font-family: var(--font-display); font-size: calc((17px) * var(--fs, 1)); }
  .drawer-search .search-input { width: 100%; box-sizing: border-box; font-size: calc((16px) * var(--fs, 1)); /* no iOS zoom */ }
  .drawer-search .search-results {
    position: static;
    width: auto;
    max-width: none;
    max-height: 38vh;
    margin-top: 8px;
    box-shadow: none;
  }
  .drawer-themes { display: flex; flex-direction: column; gap: 8px; }
  .drawer-theme-card { max-width: none; width: 100%; border-radius: 14px; }
  .drawer-theme-card .category-theme-name { white-space: normal; font-size: calc((14px) * var(--fs, 1)); }

  /* Top bar: slim — just ☰ on the left and a vertical stack of round buttons on the right. */
  .topbar {
    background: transparent;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 12px;
    right: 12px;
    pointer-events: none;
    align-items: flex-start;
  }
  .topbar > * { pointer-events: auto; }
  .brand { display: none; }
  .topbar-actions { margin-left: auto; flex-direction: column; align-items: flex-end; gap: 8px; }
  .menu-btn,
  .topbar-actions .icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    font-size: calc((18px) * var(--fs, 1));
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .icon-audio-on { display: inline-block; font-size: calc((0) * var(--fs, 1)); }
  .icon-audio-on::first-letter { font-size: calc((18px) * var(--fs, 1)); }
  .bgm-volume { display: none; }

  .video-dock { left: 12px; right: 66px; width: auto; transform: none; }
  .ab-player { margin-right: 66px; }
}

.drawer-lobby { width: 100%; margin: 6px 0 10px; }

.category-more-btn { flex: 0 0 auto; align-self: center; white-space: nowrap; font-size: calc((12.5px) * var(--fs, 1)); }
.search-result-page { margin-left: auto; font-size: calc((11px) * var(--fs, 1)); opacity: .7; white-space: nowrap; padding-left: 8px; }

/* Tương phản cao */
body.hc .category-theme-card, body.hc .search-input, body.hc .search-results, body.hc .search-result {
  background: #000 !important; color: #fff !important; border: 2px solid #fff !important; box-shadow: none !important;
}
body.hc .category-theme-card.active, body.hc .category-theme-card[aria-pressed="true"] { background: #ffd54a !important; color: #000 !important; }

/* Tìm kiếm nâng cao: bộ lọc + dòng phụ */
.search-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 8px; border-bottom: 1px solid var(--panel-border); margin-bottom: 4px; position: sticky; top: -6px; background: var(--panel-bg); z-index: 1; }
.search-chip, .search-select { font: inherit; font-size: calc((11.5px) * var(--fs, 1)); padding: 4px 9px; border-radius: 999px; border: 1px solid var(--panel-border); background: rgba(255, 255, 255, .05); color: var(--text-primary); cursor: pointer; max-width: 160px; }
.search-chip[aria-pressed="true"] { background: var(--accent-gold); color: var(--on-accent); border-color: transparent; }
.search-clear { color: var(--text-muted); }
.search-select option { color: #111; }
.search-result-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.search-result-sub { font-size: calc((11px) * var(--fs, 1)); opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-snippet { font-size: calc((11px) * var(--fs, 1)); opacity: .75; font-style: italic; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Tìm trong nội dung sách */
.search-ft { margin-top: 4px; }
.search-ft-book { padding: 2px 0 6px; }
.search-ft-book > .search-result-title { padding: 4px 10px; font-weight: 600; }
.search-ft-hit { width: 100%; text-align: left; }
.search-ft-hit mark { background: color-mix(in srgb, var(--accent-gold, #c9a86a) 45%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

/* Hỏi thủ thư AI */
.search-lib { padding: 8px 10px; border-top: 1px solid rgba(255,255,255,.1); }
.search-lib-btn { width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px; border: 1px dashed rgba(230,201,122,.6); background: rgba(230,201,122,.08); color: inherit; cursor: pointer; font: inherit; }
.search-lib-btn:disabled { opacity: .6; cursor: progress; }
.search-lib-reply { margin: 8px 2px; font-size: 13px; line-height: 1.5; opacity: .9; }
