/* ==========================================================================
   Wiki Drawer — Guide surface
   Code namespace : wikiDrawer
   UI name        : Guide / ScriptReader Guide
   Spec           : docs/wiki_drawer_spec.md v2.1
   ========================================================================== */

/* ── Z-index tokens ────────────────────────────────────────────────────── */
:root {
  --z-scene-modal:   199050;
  --z-wiki-backdrop: 209900;
  --z-wiki-drawer:   210000;

  /* Drawer geometry */
  --wiki-drawer-width: 520px;
  --wiki-drawer-anim:  220ms ease-out;

  /* Palette (matches existing app chrome) */
  --wiki-bg:          #ffffff;
  --wiki-border:      rgba(0, 0, 0, 0.10);
  --wiki-header-bg:   #083A54;
  --wiki-header-text: #ffffff;
  --wiki-text:        #1a2530;
  --wiki-muted:       #6b7a87;
  --wiki-link:        #0A6A64;
  --wiki-link-hover:  #0d857d;
  --wiki-badge-bg:    rgba(10, 106, 100, 0.12);
  --wiki-badge-text:  #0A6A64;
  --wiki-search-bg:   #f5f7f9;
  --wiki-search-border: #d0d8de;
  --wiki-item-hover:  #f0f4f6;
  --wiki-separator:   #e4eaee;
}

/* ── Scroll-lock (applied to <body>) ───────────────────────────────────── */
body.wiki-scroll-locked {
  overflow: hidden;
}

/* ── Backdrop ──────────────────────────────────────────────────────────── */
.wiki-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: var(--z-wiki-backdrop);
  opacity: 0;
  transition: opacity var(--wiki-drawer-anim);
}

.wiki-backdrop.is-visible {
  opacity: 1;
}

/* ── Drawer panel ──────────────────────────────────────────────────────── */
.wiki-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--wiki-drawer-width);
  max-width: 100vw;
  background: var(--wiki-bg);
  border-left: 1px solid var(--wiki-border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  z-index: var(--z-wiki-drawer);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--wiki-drawer-anim);
  will-change: transform;
}

.wiki-drawer.is-open {
  transform: translateX(0);
}

/* ── Mobile: full-screen + slide-up ───────────────────────────────────── */
@media (max-width: 879px) {
  .wiki-drawer {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 92vh;
    border-left: none;
    border-top: 1px solid var(--wiki-border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.14);
    transform: translateY(100%);
  }

  .wiki-drawer.is-open {
    transform: translateY(0);
  }
}

/* ── Drawer header ─────────────────────────────────────────────────────── */
.wiki-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 52px;
  flex-shrink: 0;
  background: var(--wiki-header-bg);
  color: var(--wiki-header-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.wiki-header-back {
  display: none; /* shown via JS when inside an article */
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--wiki-header-text);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 14px;
  transition: background 0.15s;
}

.wiki-header-back.is-visible {
  display: flex;
}

.wiki-header-back:hover {
  background: rgba(255, 255, 255, 0.22);
}

.wiki-header-breadcrumb {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.wiki-header-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--wiki-header-text);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 16px;
  transition: background 0.15s;
}

.wiki-header-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ── Search bar ────────────────────────────────────────────────────────── */
.wiki-search-wrap {
  padding: 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--wiki-separator);
  background: var(--wiki-bg);
}

.wiki-search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--wiki-search-border);
  border-radius: 7px;
  background: var(--wiki-search-bg);
  font-size: 13.5px;
  color: var(--wiki-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7a87' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.wiki-search-input:focus {
  border-color: var(--wiki-link);
  box-shadow: 0 0 0 3px rgba(10, 106, 100, 0.12);
}

.wiki-search-input::placeholder {
  color: var(--wiki-muted);
}

/* ── Body (scrollable content area) ───────────────────────────────────── */
.wiki-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 32px;
  overscroll-behavior: contain;
}

/* ── Index view ────────────────────────────────────────────────────────── */
.wiki-home-intro {
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--wiki-separator);
}

.wiki-home-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--wiki-text);
  margin: 0 0 8px;
}

.wiki-home-desc {
  font-size: 14px;
  color: var(--wiki-muted);
  line-height: 1.6;
  margin: 0 0 14px;
}

.wiki-home-prompt {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--wiki-text);
  margin: 0 0 8px;
}

/* ── Index categories ──────────────────────────────────────────────────── */
.wiki-category {
  margin-bottom: 6px;
  border: 1px solid var(--wiki-separator);
  border-radius: 8px;
  overflow: hidden;
}

.wiki-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 11px 14px;
  border: none;
  background: var(--wiki-bg);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--wiki-text);
  transition: background 0.12s;
}

.wiki-category-header:hover {
  background: var(--wiki-item-hover);
}

.wiki-category-header .wiki-chevron {
  font-size: 10px;
  color: var(--wiki-muted);
  transition: transform 0.18s;
}

.wiki-category-header.is-open .wiki-chevron {
  transform: rotate(180deg);
}

.wiki-category-list {
  display: none;
  border-top: 1px solid var(--wiki-separator);
}

.wiki-category-list.is-open {
  display: block;
}

.wiki-article-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--wiki-text);
  font-size: 13.5px;
  border-bottom: 1px solid var(--wiki-separator);
  transition: background 0.1s;
  cursor: pointer;
}

.wiki-article-link:last-child {
  border-bottom: none;
}

.wiki-article-link:hover {
  background: var(--wiki-item-hover);
  color: var(--wiki-link);
}

/* ── Category badge ────────────────────────────────────────────────────── */
.wiki-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--wiki-badge-bg);
  color: var(--wiki-badge-text);
  white-space: nowrap;
  flex-shrink: 0;
}

.wiki-badge.is-howto  { background: rgba(255, 160, 0, 0.12);  color: #9a6000; }
.wiki-badge.is-concept{ background: rgba(90, 50, 200, 0.10);  color: #5a32c8; }
.wiki-badge.is-band   { background: rgba(200, 50, 50, 0.10);  color: #c03232; }
.wiki-badge.is-axis   { background: rgba(10, 106, 100, 0.12); color: #0A6A64; }

/* ── Article view ──────────────────────────────────────────────────────── */
.wiki-article-meta {
  font-size: 12px;
  color: var(--wiki-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wiki-article-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--wiki-text);
  margin: 0 0 6px;
  line-height: 1.3;
}

.wiki-article-separator {
  border: none;
  border-top: 2px solid var(--wiki-separator);
  margin: 14px 0 18px;
}

/* Article body typography */
.wiki-article-body {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--wiki-text);
}

.wiki-article-body h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--wiki-text);
  margin: 24px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--wiki-separator);
}

.wiki-article-body h3 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--wiki-text);
  margin: 18px 0 6px;
}

.wiki-article-body p {
  margin: 0 0 12px;
}

.wiki-article-body ul,
.wiki-article-body ol {
  margin: 0 0 12px 18px;
  padding: 0;
}

.wiki-article-body li {
  margin-bottom: 5px;
}

.wiki-article-body strong {
  font-weight: 700;
}

.wiki-article-body em {
  font-style: italic;
}

.wiki-article-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
  background: #f0f4f6;
  padding: 1px 5px;
  border-radius: 4px;
}

.wiki-article-body pre {
  background: #f0f4f6;
  border: 1px solid var(--wiki-separator);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 14px;
}

.wiki-article-body blockquote {
  border-left: 3px solid var(--wiki-link);
  margin: 0 0 14px;
  padding: 8px 14px;
  background: rgba(10, 106, 100, 0.05);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--wiki-muted);
}

.wiki-article-body a {
  color: var(--wiki-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.wiki-article-body a:hover {
  color: var(--wiki-link-hover);
}

/* Cross-link (broken, dev only) */
.wiki-cross-link-broken {
  color: #cc2222;
  text-decoration: underline wavy;
  cursor: help;
}

/* ── See also ──────────────────────────────────────────────────────────── */
.wiki-see-also {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--wiki-separator);
}

.wiki-see-also-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--wiki-muted);
  margin: 0 0 10px;
}

.wiki-see-also-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wiki-see-also-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13.5px;
  color: var(--wiki-link);
  transition: background 0.1s;
  cursor: pointer;
}

.wiki-see-also-link:hover {
  background: var(--wiki-item-hover);
}

/* ── Search results ────────────────────────────────────────────────────── */
.wiki-search-results {
  padding-top: 4px;
}

.wiki-search-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--wiki-muted);
  font-size: 14px;
}

.wiki-search-clear {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--wiki-link);
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: underline;
}

/* ── Loading + error states ────────────────────────────────────────────── */
.wiki-loading {
  padding: 32px 0;
  text-align: center;
  color: var(--wiki-muted);
  font-size: 14px;
}

.wiki-loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--wiki-separator);
  border-top-color: var(--wiki-link);
  border-radius: 50%;
  animation: wiki-spin 0.7s linear infinite;
  margin-bottom: 10px;
}

@keyframes wiki-spin {
  to { transform: rotate(360deg); }
}

.wiki-error {
  padding: 20px 0;
  text-align: center;
  color: #c03232;
  font-size: 14px;
}

.wiki-retry-btn {
  margin-top: 10px;
  padding: 6px 14px;
  border: 1px solid #c03232;
  border-radius: 6px;
  background: none;
  color: #c03232;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}

.wiki-retry-btn:hover {
  background: rgba(192, 50, 50, 0.07);
}

/* ── Toast notification ────────────────────────────────────────────────── */
.wiki-toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1a2530;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1;
}

.wiki-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Guide button (page chrome) ────────────────────────────────────────── */
.wiki-guide-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.wiki-guide-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
  color: #111827;
}

.wiki-guide-btn:active {
  background: #e5e7eb;
}

/* ── Popover "Open guide" link ─────────────────────────────────────────── */
.sqv-info-popover-guide-link {
  display: block;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 12.5px;
  color: var(--wiki-link);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.sqv-info-popover-guide-link:hover {
  color: var(--wiki-link-hover);
  text-decoration: underline;
}
