/* ==========================================================================
   HK-RAG Universe Explorer — Crisp Fullscreen B&W Layout & Grainy Backdrop
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input {
  font: inherit;
  color: inherit;
}

/* --------------------------------------------------------------------------
   CSS-Tricks Grainy Gradient Backdrop (Zero Blur, Crisp Paper/Ink Grain)
   -------------------------------------------------------------------------- */

.grainy-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  isolation: isolate;
  background:
    radial-gradient(65% 60% at 45% 42%, var(--bg-grad-center) 0%, var(--bg-grad-mid) 55%, var(--bg-grad-edge) 100%);
}

.grainy-backdrop__noise {
  position: absolute;
  inset: -24px;
  width: calc(100% + 48px);
  height: calc(100% + 48px);
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  filter: contrast(var(--grain-contrast)) brightness(var(--grain-brightness)) blur(var(--grain-blur));
  will-change: filter;
}

.grainy-backdrop__plus {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--plus-color);
  pointer-events: none;
}

body.no-grain .grainy-backdrop__noise {
  opacity: 0 !important;
}

/* --------------------------------------------------------------------------
   Fullscreen Universe Viewport & Floating Crisp HUD
   -------------------------------------------------------------------------- */

.universe-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  z-index: 1;
}

.universe-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.universe-viewport:active {
  cursor: grabbing;
}

.universe-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.universe-canvas--tether { z-index: 1; }
.universe-canvas--stipple {
  z-index: 2;
  filter: blur(var(--grain-blur));
  will-change: filter;
}
.universe-canvas--label { z-index: 3; }

/* Top Floating Bar: Brand/Breadcrumb + Semantic Search + Theme Toggle */
.hud-top {
  position: fixed;
  top: 16px;
  left: 20px;
  right: 20px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr minmax(260px, 520px) 1fr;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

.hud-top > * {
  pointer-events: auto;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  min-width: 0;
  flex-wrap: wrap;
}

.brand-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 0;
  text-align: left;
  border: none;
  background: none;
  box-shadow: none;
  font-weight: 700;
  cursor: pointer;
}

.brand-pill__name {
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0.12em;
  color: var(--text-primary);
}

.brand-pill__sub {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* Semantic Search Box */
.search-wrap {
  position: relative;
  width: 100%;
  justify-self: center;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: border-color 140ms ease;
}

.search-box:focus-within {
  border-color: var(--border-focus);
}

.search-box__icon {
  width: 15px;
  height: 15px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.search-box__input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
}

.search-box__input::placeholder {
  color: var(--text-muted);
}

.search-box__kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.search-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: 8px;
  display: none;
  max-height: 410px;
  overflow-y: auto;
  z-index: 40;
}

.search-popover.is-open {
  display: block;
}

.search-popover__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 6px;
}

.search-item {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.search-item:hover,
.search-item.is-active {
  background: var(--surface-muted);
  border-color: var(--border-subtle);
}

.search-item__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-primary);
}

.search-item__title {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-item__meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
}

.search-item__snippet {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.search-item__score {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
}

/* Top Right Controls */
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.pill-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.pill-btn.is-active {
  background: var(--surface-strong);
  color: var(--text-on-strong);
  border-color: var(--surface-strong);
}

/* Icon-only pills: theme (sun/moon) and language */
.pill-btn--icon {
  padding: 7px 9px;
  color: var(--text-primary);
}

.pill-btn--icon svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.pill-btn--lang {
  padding-right: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Light (paper): show the moon; dark (ink): show the sun */
.theme-toggle__sun { display: none; }
[data-theme="ink"] .theme-toggle__sun { display: block; }
[data-theme="ink"] .theme-toggle__moon { display: none; }

/* --------------------------------------------------------------------------
   Right Collapsible Entity Inspector Drawer
   -------------------------------------------------------------------------- */

.inspector-drawer {
  position: fixed;
  top: 72px;
  right: 20px;
  bottom: 78px;
  width: 360px;
  z-index: 18;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 200ms ease, opacity 180ms ease;
}

.inspector-drawer.is-collapsed {
  transform: translateX(calc(100% + 36px));
  opacity: 0;
  pointer-events: none;
}

.inspector-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.inspector-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  display: inline-block;
  margin-bottom: 6px;
}

.inspector-title {
  margin: 0;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.2;
}

.inspector-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

.close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.close-btn:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 7px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mono-chip {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--surface-muted);
  font-size: 11.5px;
}

.mono-chip--btn {
  cursor: pointer;
}

.mono-chip--btn:hover {
  background: var(--surface-strong);
  color: var(--text-on-strong);
}

.excerpt-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.68;
  color: var(--text-secondary);
}

.wikilink-btn {
  border: none;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface-muted);
  padding: 0 4px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
}

.wikilink-btn:hover {
  background: var(--surface-strong);
  color: var(--text-on-strong);
}

.rel-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rel-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.rel-btn:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

.rel-btn__kind {
  font-size: 11.5px;
  color: var(--text-muted);
}

.rel-btn__target {
  font-size: 12.5px;
  font-weight: 600;
}

.source-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.source-a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  font-size: 12px;
  color: var(--text-secondary);
}

.source-a:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.id-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.id-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 3px 8px;
  padding: 6px 9px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
  background: transparent;
  text-decoration: none;
  color: var(--text-primary);
}

.id-row--link {
  color: var(--text-secondary);
}

.id-row--link:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.id-row__label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.id-row__val {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}

.id-row__code {
  font-size: 10.5px;
  user-select: all;
}

/* --------------------------------------------------------------------------
   Bottom Floating Pagination + Zoom + Grain/Bridge Tuner Dock
   -------------------------------------------------------------------------- */

.hud-bottom {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  pointer-events: none;
}

.hud-bottom > * {
  pointer-events: auto;
}

.dock-pill {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 7px 14px;
  border-radius: 22px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  font-size: 12px;
}

.dock-pill.is-hidden {
  display: none;
}

.dock-mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.action-btn {
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
  color: var(--text-on-strong);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.action-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.ghost-btn {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: transparent;
  font-size: 11.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

.ghost-btn:hover,
.ghost-btn.is-on {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--surface-muted);
}

.dock-slider {
  width: 60px;
  accent-color: var(--text-primary);
  cursor: pointer;
}

.status-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
  color: var(--text-on-strong);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.status-toast.is-visible {
  opacity: 1;
}

@media (max-width: 960px) {
  .hud-top {
    grid-template-columns: 1fr;
    gap: 8px;
    left: 12px;
    right: 12px;
    top: 12px;
  }

  .hud-left,
  .hud-right {
    justify-self: stretch;
    justify-content: space-between;
  }

  .inspector-drawer {
    left: 12px;
    right: 12px;
    width: auto;
    top: auto;
    bottom: 72px;
    max-height: 46vh;
  }

  .hud-bottom {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}

/* --------------------------------------------------------------------------
   API & MCP Setup Modal
   -------------------------------------------------------------------------- */

.pill-btn--api {
  padding: 0 12px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: 0.03em;
}

.pill-btn--link {
  text-decoration: none;
}

.api-modal[hidden] {
  display: none;
}

.api-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.api-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 16, 16, 0.45);
  backdrop-filter: blur(4px);
}

.api-modal__card {
  position: relative;
  width: min(720px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.api-modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.api-modal__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.api-modal__sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.api-modal__close {
  font-size: 20px;
  line-height: 1;
  padding: 4px 10px;
}

.api-modal__body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  display: grid;
  gap: 18px;
}

.api-section__title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
}

.api-section__desc,
.api-section__meta {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.api-section__meta {
  margin-top: 8px;
  margin-bottom: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
}

.api-code-wrap {
  position: relative;
  margin-bottom: 8px;
}

.api-code-wrap:last-child {
  margin-bottom: 0;
}

.api-code {
  margin: 0;
  padding: 11px 68px 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-base);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

.api-copy-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  font-size: 11px;
  padding: 3px 9px;
}
