:root {
  --encyclopedia-lime: #ccff00;
  --encyclopedia-panel: #24272d;
  --encyclopedia-card: #30343b;
  --encyclopedia-black: #050608;
}

.main-menu-library-actions {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(2, 112px);
  gap: 14px;
}
.main-menu-library-button {
  width: 112px !important;
  min-width: 112px !important;
  height: 92px !important;
  min-height: 92px !important;
  padding: 10px 8px !important;
  border-radius: 17px !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 0 !important;
  font-size: 15px !important;
}
.main-menu-library-button svg {
  width: 31px;
  height: 31px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The archive is a real screen: nothing below it is visible or interactive. */
.encyclopedia-overlay {
  position: fixed;
  z-index: 15020;
  inset: 0;
  display: none;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
  background: #15171c;
}
.encyclopedia-overlay.visible { display: block; }
.encyclopedia-panel {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: linear-gradient(145deg, #24272d, #111318 74%);
  color: #fff;
  box-shadow: none;
}
.encyclopedia-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: max(13px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 12px max(25px, env(safe-area-inset-left));
  border-bottom: 4px solid var(--encyclopedia-black);
  background: #292c32;
}
.encyclopedia-kicker {
  color: var(--encyclopedia-lime);
  font: 900 10px/1 monospace;
  letter-spacing: .18em;
}
.encyclopedia-header h2 {
  margin: 5px 0 0;
  font: 950 clamp(30px, 3.4vw, 48px)/1 "Microsoft YaHei", sans-serif;
  letter-spacing: .08em;
  text-shadow: 0 4px 0 #000;
}
.encyclopedia-close { width: 160px !important; min-height: 54px !important; margin: 0 !important; }
.encyclopedia-section-tabs,
.encyclopedia-filter-tabs {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 10px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--encyclopedia-lime) #17191d;
  touch-action: pan-x;
}
.encyclopedia-section-tabs { background: #1c1e23; }
.encyclopedia-filter-tabs { padding-top: 8px; padding-bottom: 8px; border-bottom: 2px solid #0a0b0d; }
.encyclopedia-tab,
.encyclopedia-filter {
  flex: 0 0 auto;
  min-width: 150px;
  height: 44px;
  padding: 0 20px;
  border: 4px solid var(--encyclopedia-black);
  border-radius: 999px;
  background: #393d44;
  color: #fff;
  font: 950 15px/1 "Microsoft YaHei", sans-serif;
  text-shadow: 0 2px 0 #000;
}
.encyclopedia-filter { min-width: 112px; height: 36px; border-width: 3px; font-size: 12px; }
.encyclopedia-tab:hover,
.encyclopedia-filter:hover,
.encyclopedia-tab:focus-visible,
.encyclopedia-filter:focus-visible,
.encyclopedia-tab.selected,
.encyclopedia-filter.selected {
  outline: none;
  background: var(--encyclopedia-lime);
  color: #171a00;
  text-shadow: none;
  box-shadow: 0 0 18px rgba(204, 255, 0, .24);
}
.encyclopedia-summary {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
  padding: 8px 23px;
  background: rgba(10, 11, 14, .66);
}
.encyclopedia-summary strong { flex: 0 0 auto; color: var(--encyclopedia-lime); font: 950 17px/1.2 "Microsoft YaHei", sans-serif; }
.encyclopedia-summary span { min-width: 0; color: #adb5be; font: 750 12px/1.35 "Microsoft YaHei", sans-serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.encyclopedia-content {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(520px, 1.35fr) minmax(390px, .65fr);
  overflow: hidden;
  background: #17191d;
}
.encyclopedia-grid,
.encyclopedia-detail {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-color: var(--encyclopedia-lime) #121418;
  scrollbar-width: auto;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
}
.encyclopedia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  grid-auto-rows: 102px;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border-right: 4px solid #08090b;
  background: linear-gradient(135deg, rgba(37, 40, 47, .96), rgba(18, 20, 24, .98));
}
.encyclopedia-grid:focus { outline: none; }
.encyclopedia-grid.is-empty { display: grid; place-items: center; }
.encyclopedia-detail {
  position: relative;
  padding: 18px;
  background: radial-gradient(circle at 50% 0, rgba(87, 99, 114, .22), transparent 44%), #15171b;
}
.encyclopedia-detail-back { display: none !important; }
.encyclopedia-detail-body { width: 100%; min-height: 100%; }

/* Compact list entries never contain the long description, so grid rows cannot overlap. */
.encyclopedia-entry {
  box-sizing: border-box;
  width: 100%;
  height: 102px;
  min-width: 0;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  overflow: hidden;
  padding: 9px;
  border: 4px solid var(--encyclopedia-black);
  border-radius: 17px;
  background: linear-gradient(145deg, #373b43, #292c32);
  color: #fff;
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 7px 16px rgba(0, 0, 0, .3);
  cursor: pointer;
}
.encyclopedia-entry:hover,
.encyclopedia-entry:focus-visible,
.encyclopedia-entry.selected {
  outline: none;
  border-color: #0b0c0e;
  background: linear-gradient(145deg, #454b54, #30343b);
  box-shadow: inset 5px 0 0 var(--encyclopedia-lime), 0 0 0 2px rgba(204, 255, 0, .52), 0 0 20px rgba(204, 255, 0, .16);
}
.encyclopedia-artwork {
  box-sizing: border-box;
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid #090a0d;
  border-radius: 12px;
  background: radial-gradient(circle, #454a53, #17191d);
}
.encyclopedia-artwork img { display: block; width: 100%; height: 100%; object-fit: contain; }
.encyclopedia-artwork-fallback { font: 950 28px/1 "Microsoft YaHei", sans-serif; }
.encyclopedia-entry-copy { min-width: 0; display: block; }
.encyclopedia-entry-copy > strong { display: block; overflow: hidden; color: #fff; font: 950 17px/1.15 "Microsoft YaHei", sans-serif; text-overflow: ellipsis; text-shadow: 0 2px 0 #000; white-space: nowrap; }
.encyclopedia-entry-copy > small { display: block; margin-top: 5px; overflow: hidden; color: #c4cad2; font: 750 9px/1.25 "Microsoft YaHei", sans-serif; text-overflow: ellipsis; white-space: nowrap; }
.encyclopedia-entry-identity { min-width: 0; }
.encyclopedia-entry-identity h3 { margin: 0; color: #fff; font: 950 24px/1.15 "Microsoft YaHei", sans-serif; text-shadow: 0 3px 0 #000; overflow-wrap: anywhere; }
.encyclopedia-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.encyclopedia-badge { padding: 3px 6px; border: 2px solid #08090b; border-radius: 999px; background: #555a62; color: #fff; font: 850 8px/1 "Microsoft YaHei", sans-serif; }
.encyclopedia-badge.danger { background: #a5283b; }
.encyclopedia-badge.special { background: #4b347c; }
.encyclopedia-badge.summon { background: #245e74; }
.encyclopedia-badge.growth { background: #6a571e; }
.encyclopedia-badge.mechanism { background: #5a2a83; }
.encyclopedia-badge.attribute { background: #087998; }
.encyclopedia-badge.requirement { background: #443f32; color: #ffe57b; }

.encyclopedia-detail-sheet {
  box-sizing: border-box;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  border: 4px solid var(--encyclopedia-black);
  border-radius: 20px;
  background: linear-gradient(145deg, #363a42, #24272d);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 12px 30px rgba(0, 0, 0, .38);
}
.encyclopedia-detail-top {
  min-height: 126px;
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 15px;
  border-bottom: 4px solid #111318;
  background: linear-gradient(90deg, rgba(255, 255, 255, .07), rgba(0, 0, 0, .09));
}
.encyclopedia-detail-top .encyclopedia-artwork { width: 104px; height: 96px; }
.encyclopedia-detail-top .encyclopedia-badge { font-size: 10px; }
.encyclopedia-stat-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  margin: 0;
  padding: 11px 17px;
}
.encyclopedia-stat-grid dt,
.encyclopedia-stat-grid dd { margin: 0; padding: 9px 4px; border-bottom: 1px solid rgba(255, 255, 255, .09); font: 800 13px/1.25 "Microsoft YaHei", sans-serif; }
.encyclopedia-stat-grid dt { color: #aeb6bf; }
.encyclopedia-stat-grid dd { color: #fff; text-align: right; }
.encyclopedia-rules { padding: 13px 18px 18px; }
.encyclopedia-rules h4 { margin: 0 0 10px; color: var(--encyclopedia-lime); font: 950 15px/1 "Microsoft YaHei", sans-serif; }
.encyclopedia-rules ul { display: grid; gap: 9px; margin: 0; padding-left: 20px; }
.encyclopedia-rules li { color: #e0e4e9; font: 700 12px/1.62 "Microsoft YaHei", sans-serif; }
.encyclopedia-compact-levels { margin: 16px; padding: 16px; border: 3px solid #111318; border-radius: 15px; background: rgba(12, 14, 18, .5); }
.encyclopedia-level-caption { margin-bottom: 11px; color: var(--encyclopedia-lime); font: 950 13px/1.3 monospace; letter-spacing: .04em; overflow-wrap: anywhere; }
.encyclopedia-compact-levels p { margin: 0; color: #f0f2f5; font: 800 14px/1.7 "Microsoft YaHei", sans-serif; overflow-wrap: anywhere; }
.encyclopedia-level-chain { display: grid; gap: 0; margin: 0; padding: 12px 16px 15px; list-style: none; }
.encyclopedia-level-chain li { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 11px; align-items: start; padding: 11px 2px; border-bottom: 1px solid rgba(255, 255, 255, .09); }
.encyclopedia-level-chain li:last-child { border-bottom: 0; }
.encyclopedia-level-label { display: inline-grid; place-items: center; min-height: 29px; padding: 0 7px; border: 2px solid #08090b; border-radius: 8px; background: #5c6169; color: #fff; font: 950 11px/1 "Microsoft YaHei", sans-serif; }
.encyclopedia-level-label.premium { background: #b48312; color: #fff7bd; }
.encyclopedia-level-chain p,
.encyclopedia-evolution p { margin: 0; color: #e8ebee; font: 750 13px/1.62 "Microsoft YaHei", sans-serif; overflow-wrap: anywhere; }
.encyclopedia-evolution { margin: 0 16px 16px; padding: 14px 15px; border: 3px solid #100919; border-radius: 14px; background: linear-gradient(135deg, #53277b, #2d1746); }
.encyclopedia-evolution strong { display: block; margin-bottom: 7px; color: #e6bcff; font: 950 14px/1 "Microsoft YaHei", sans-serif; }
.encyclopedia-empty { box-sizing: border-box; width: min(520px, 100%); display: grid; gap: 10px; padding: 34px 24px; border: 4px dashed #60656d; border-radius: 20px; color: #aeb6bf; text-align: center; }
.encyclopedia-empty strong { color: #fff; font: 950 20px/1.3 "Microsoft YaHei", sans-serif; }
.encyclopedia-empty span { font: 750 13px/1.55 "Microsoft YaHei", sans-serif; }

@media (max-width: 1100px) {
  .encyclopedia-content { grid-template-columns: minmax(450px, 1.15fr) minmax(350px, .85fr); }
  .encyclopedia-grid { grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); }
}

/* Phones and short landscape windows use two full panes instead of crushing both columns. */
@media (max-width: 860px), (max-height: 650px) {
  .main-menu-library-actions { left: var(--qsd-mobile-left-center, 28%); bottom: max(7px, env(safe-area-inset-bottom)); grid-template-columns: repeat(2, 78px); gap: 8px; }
  .main-menu-library-button { width: 78px !important; min-width: 78px !important; height: 60px !important; min-height: 60px !important; padding: 5px !important; border-radius: 12px !important; gap: 3px; font-size: 10px !important; }
  .main-menu-library-button svg { width: 21px; height: 21px; }
  .encyclopedia-panel { grid-template-rows: auto auto auto auto minmax(0, 1fr); }
  .encyclopedia-header { min-height: 50px; padding: max(6px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-right)) 6px max(11px, env(safe-area-inset-left)); }
  .encyclopedia-kicker { font-size: 6px; }
  .encyclopedia-header h2 { margin-top: 1px; font-size: 21px; }
  .encyclopedia-close { width: 98px !important; min-height: 34px !important; font-size: 12px !important; }
  .encyclopedia-section-tabs { padding: 5px 8px; }
  .encyclopedia-filter-tabs { padding: 4px 8px; }
  .encyclopedia-tab { min-width: 105px; height: 32px; border-width: 3px; font-size: 11px; }
  .encyclopedia-filter { min-width: 80px; height: 28px; font-size: 9px; }
  .encyclopedia-summary { gap: 7px; padding: 4px 10px; }
  .encyclopedia-summary strong { font-size: 12px; }
  .encyclopedia-summary span { font-size: 8px; }
  .encyclopedia-content { position: relative; display: block; }
  .encyclopedia-grid,
  .encyclopedia-detail { position: absolute; inset: 0; }
  .encyclopedia-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); grid-auto-rows: 82px; gap: 7px; padding: 8px; border-right: 0; }
  .encyclopedia-entry { height: 82px; grid-template-columns: 58px minmax(0, 1fr); gap: 7px; padding: 6px; border-width: 3px; border-radius: 12px; }
  .encyclopedia-artwork { width: 56px; height: 56px; border-radius: 8px; }
  .encyclopedia-entry-copy > strong { font-size: 14px; }
  .encyclopedia-entry-copy > small { font-size: 7.5px; }
  .encyclopedia-badges { gap: 2px; margin-top: 4px; }
  .encyclopedia-badge { padding: 2px 4px; font-size: 6.5px; }
  .encyclopedia-detail {
    z-index: 2;
    padding: 7px;
    transform: translateX(102%);
    visibility: hidden;
    transition: transform .2s ease-out, visibility 0s linear .2s;
  }
  .encyclopedia-content.detail-open .encyclopedia-detail { transform: translateX(0); visibility: visible; transition: transform .2s ease-out; }
  .encyclopedia-detail-back { position: sticky; z-index: 4; top: 0; display: block !important; width: 112px !important; min-height: 34px !important; margin: 0 0 6px auto !important; font-size: 11px !important; }
  .encyclopedia-detail-body { min-height: calc(100% - 40px); }
  .encyclopedia-detail-sheet { min-height: 100%; border-width: 3px; border-radius: 14px; }
  .encyclopedia-detail-top { min-height: 82px; grid-template-columns: 72px minmax(0, 1fr); gap: 9px; padding: 8px; border-bottom-width: 3px; }
  .encyclopedia-detail-top .encyclopedia-artwork { width: 68px; height: 64px; }
  .encyclopedia-entry-identity h3 { font-size: 20px; }
  .encyclopedia-detail-top .encyclopedia-badge { font-size: 8px; }
  .encyclopedia-stat-grid { padding: 5px 10px; }
  .encyclopedia-stat-grid dt,
  .encyclopedia-stat-grid dd { padding: 5px 2px; font-size: 9px; }
  .encyclopedia-rules { padding: 8px 11px 11px; }
  .encyclopedia-rules h4 { font-size: 11px; }
  .encyclopedia-rules li { font-size: 9px; line-height: 1.48; }
  .encyclopedia-compact-levels { margin: 9px; padding: 10px; }
  .encyclopedia-level-caption { margin-bottom: 7px; font-size: 10px; }
  .encyclopedia-compact-levels p,
  .encyclopedia-level-chain p,
  .encyclopedia-evolution p { font-size: 10.5px; line-height: 1.55; }
  .encyclopedia-level-chain { padding: 6px 9px 8px; }
  .encyclopedia-level-chain li { grid-template-columns: 43px minmax(0, 1fr); gap: 7px; padding: 7px 1px; }
  .encyclopedia-level-label { min-height: 22px; font-size: 8px; }
  .encyclopedia-evolution { margin: 0 9px 9px; padding: 9px 10px; }
  .encyclopedia-evolution strong { font-size: 10px; }
}

@media (orientation: portrait) and (pointer: coarse) {
  .main-menu-library-actions { left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); }
  .encyclopedia-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

html.encyclopedia-open,
html.encyclopedia-open body { overflow: hidden !important; overscroll-behavior: none; }
