body:has(.v2-codex-page) {
  overflow: hidden;
  height: 100dvh;
  background-image:
    linear-gradient(90deg, rgba(5, 8, 14, 0.46), rgba(5, 8, 14, 0.16) 46%, rgba(5, 8, 14, 0.5)),
    linear-gradient(180deg, rgba(5, 8, 14, 0.1), rgba(5, 8, 14, 0.5)),
    url("/static/images/backgrounds/build-antique-interior.webp");
  background-size: auto, auto, cover;
  background-position: center;
  background-attachment: fixed;
}

body:has(.v2-codex-page) .shell {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  margin: 0;
  padding: 0;
}

.v2-codex-page {
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  overflow: hidden;
  color: var(--text);
}

.v2-codex-page .v2-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 6;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 280px));
}

.v2-codex-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 20px;
}

.v2-codex-nav {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(232, 201, 136, 0.16);
  background: rgba(10, 12, 16, 0.7);
  backdrop-filter: blur(12px);
}

.v2-codex-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  color: inherit;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.v2-codex-nav button.selected {
  border-color: rgba(232, 201, 136, 0.7);
  background: rgba(232, 201, 136, 0.12);
}

.v2-codex-unpublished {
  display: inline-flex;
  flex: none;
  align-items: center;
  padding: 2px 6px;
  border: 1px solid rgba(255, 191, 87, 0.5);
  border-radius: 999px;
  color: #ffd28e;
  background: rgba(255, 191, 87, 0.1);
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
}

.v2-codex-nav .v2-codex-unpublished {
  margin-left: auto;
}

.v2-codex-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.v2-codex-title h2 {
  margin: 0;
}

.v2-codex-nav img,
.v2-codex-nav .v2-image-fallback {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}

.v2-codex-body {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(232, 201, 136, 0.16);
  background: rgba(10, 12, 16, 0.7);
  backdrop-filter: blur(12px);
}

.v2-codex-hero {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
}

.v2-codex-hero-art {
  height: 200px;
  overflow: hidden;
  border-radius: 14px;
  background: #0b121d;
}

.v2-codex-hero-art img,
.v2-codex-hero-art .v2-image-fallback {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.v2-codex-hero p {
  margin: 6px 0;
}

.v2-codex-hero .v2-character-meta {
  margin: 8px 0;
}

.v2-codex-cards {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.v2-codex-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(16, 20, 28, 0.88);
  display: grid;
  align-content: start;
  gap: 8px;
}

.v2-codex-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #d7cbb3;
}

.v2-codex-card.is-mechanism {
  border-color: rgba(232, 201, 136, 0.45);
}

.v2-codex-card .v2-frame-stats {
  margin-left: auto;
}

.v2-codex-card .v2-stat-badge {
  min-height: 26px;
  font-size: 14px;
}

.v2-codex-help {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(232, 201, 136, 0.5);
  border-radius: 50%;
  background: rgba(232, 201, 136, 0.08);
  color: #e8c988;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
}

.v2-codex-help:hover,
.v2-codex-help:focus-visible {
  background: rgba(232, 201, 136, 0.2);
  outline: 2px solid #e8c988;
  outline-offset: 3px;
}

.v2-glossary {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 1px solid rgba(232, 201, 136, 0.4);
  border-radius: 20px;
  background: #111720;
  color: #eee6d7;
  box-shadow: 0 24px 100px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.v2-glossary[open] {
  display: flex;
  flex-direction: column;
}

.v2-glossary::backdrop {
  background: rgba(3, 6, 12, 0.76);
  backdrop-filter: blur(5px);
}

.v2-glossary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 24px 12px;
}

.v2-glossary-header h2,
.v2-glossary-header p {
  margin: 0;
}

.v2-glossary-header button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 26px;
  cursor: pointer;
}

.v2-glossary-search {
  padding: 0 24px 16px;
}

.v2-glossary-search label {
  display: block;
  margin-bottom: 6px;
  color: #d7cbb3;
  font-size: 13px;
}

.v2-glossary-search input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid rgba(232, 201, 136, 0.3);
  border-radius: 10px;
  background: #080e16;
  color: inherit;
}

.v2-glossary-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 24px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.v2-glossary-content h3 {
  margin: 22px 0 10px;
  color: #e8c988;
  font-size: 15px;
}

.v2-glossary-content article {
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.v2-glossary-content h4 {
  margin: 0 0 6px;
  font-size: 16px;
}

.v2-glossary-content article p {
  margin: 0;
  color: #c6ccd5;
  font-size: 14px;
  line-height: 1.75;
}

@media (max-width: 1100px) {
  .v2-codex-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .v2-codex-stage,
  .v2-codex-hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .v2-codex-page .v2-home-nav {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .v2-codex-page .v2-home-account {
    display: block;
  }
}

@media (max-width: 980px), (pointer: coarse) and (max-height: 600px) {
  body:has(.v2-codex-page) { height: auto; overflow: auto; }
  body:has(.v2-codex-page) .shell,
  .v2-codex-page { height: auto; min-height: 100dvh; max-height: none; overflow: visible; }
  .v2-codex-page { grid-template-rows: auto auto; }
  .v2-codex-page .v2-home-nav { padding: 8px 12px; gap: 8px; }
  .v2-codex-page .v2-home-links { justify-content: flex-end; }
  .v2-codex-stage { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .v2-codex-nav { display: flex; overflow-x: auto; padding: 8px; }
  .v2-codex-nav button { width: auto; flex: 0 0 auto; min-height: 44px; }
  .v2-codex-body { grid-template-rows: auto auto; overflow: visible; padding: 12px; }
  .v2-codex-hero { grid-template-columns: 120px minmax(0, 1fr); gap: 12px; }
  .v2-codex-hero-art { height: 160px; }
  .v2-codex-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: visible; }
  .v2-codex-help,
  .v2-glossary-header button { width: 44px; height: 44px; flex: 0 0 auto; }
  .v2-glossary-search input { font-size: 16px; }
}
@media (max-width: 600px) {
  .v2-codex-page .v2-home-logo { width: 80px; }
  .v2-codex-page .v2-home-links { gap: 0; }
  .v2-codex-page .v2-home-links a { padding: 10px 6px; }
  .v2-codex-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .v2-codex-hero { grid-template-columns: 88px minmax(0, 1fr); }
  .v2-codex-hero-art { height: 120px; }
}
