/* —— Codex — premium in-game encyclopedia —— */

.codex-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    color 0.25s ease,
    background 0.25s ease,
    box-shadow 0.3s ease,
    transform 0.2s ease;
}

.codex-btn-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.codex-btn:hover,
.codex-btn:focus-visible {
  color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 42%, transparent);
  outline: none;
}

.codex-btn.is-active {
  color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 14px color-mix(in srgb, var(--primary) 35%, transparent);
}

body.codex-page-open .app-main,
body.codex-page-open .app-footer {
  display: none;
}

body.codex-page-open .ptr-viewport .app {
  z-index: 200;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
  transform: none !important;
  will-change: auto;
}

body.codex-page-open .app-header {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
  pointer-events: auto;
}

body.codex-page-open .settings-menu {
  position: relative;
  z-index: 2;
}

body.codex-page-open .settings-dropdown {
  z-index: 500;
}

body.codex-page-open .ptr-viewport.is-ptr-active {
  overflow: visible;
  touch-action: auto;
}

/* —— Page shell —— */

.codex-page {
  --codex-header-offset: 5.75rem;
  --codex-nav-width: 248px;
  --codex-article-width: 380px;
  --codex-accent-0: #c9a227;
  --codex-accent-1: #5b8def;
  --codex-accent-2: #9b6dd7;
  --codex-accent-3: #3db88a;
  --codex-accent-4: #e07a5f;
  --codex-accent-5: #6b9bd1;
  position: fixed;
  top: var(--codex-header-offset);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  height: calc(100dvh - var(--codex-header-offset));
  height: calc(100vh - var(--codex-header-offset));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.codex-page.is-open {
  pointer-events: auto;
  opacity: 1;
}

.codex-page-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 5% -5%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 58%),
    radial-gradient(ellipse 60% 45% at 95% 105%, color-mix(in srgb, var(--primary) 9%, transparent), transparent 52%),
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 30%, transparent) 0%, transparent 35%);
}

.codex-page-scroll {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.codex-page-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1.1rem 1.35rem 1.35rem;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
}

/* —— Page header —— */

.codex-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.codex-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.codex-eyebrow {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: color-mix(in srgb, var(--primary) 75%, var(--text-muted));
}

.codex-title {
  margin: 0;
  font-size: clamp(1.65rem, 3.2vw, 2.15rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.codex-project-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: min(100%, 260px);
  margin-top: 0.35rem;
}

.codex-project-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.codex-project-select,
.codex-search-input {
  width: 100%;
  font: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, var(--bg));
  color: var(--text);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.codex-search-wrap {
  flex: 1;
  min-width: min(100%, 240px);
  max-width: 340px;
}

.codex-search-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.7rem center;
  padding-left: 2.1rem;
}

.codex-project-select:focus-visible,
.codex-search-input:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.codex-main-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.55;
  padding: 3rem 2rem;
  max-width: 28rem;
}

/* —— Three-column layout —— */

.codex-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--codex-nav-width) minmax(0, 1fr) var(--codex-article-width);
  gap: 0.9rem;
}

.codex-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: calc(var(--radius-lg) + 2px);
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  box-shadow:
    0 1px 0 color-mix(in srgb, #fff 4%, transparent) inset,
    var(--shadow);
  overflow: hidden;
}

.codex-panel-chrome {
  flex-shrink: 0;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  background: color-mix(in srgb, var(--bg) 35%, var(--surface));
}

.codex-panel-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.codex-panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

/* —— Navigation (left) —— */

.codex-nav .codex-panel-body {
  padding: 0.65rem 0.55rem 0.85rem;
}

.codex-nav-head {
  padding: 0 0.45rem 0.65rem;
}

.codex-nav-add-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
  width: 100%;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.62rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--border) 90%, transparent);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

.codex-nav-add-btn-icon {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  opacity: 0.88;
}

.codex-nav-add-btn-icon svg {
  width: 0.9rem;
  height: 0.9rem;
}

.codex-nav-add-btn-text {
  line-height: 1.2;
}

.codex-nav-add-btn:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--primary-light);
}

.codex-nav-add-btn:hover .codex-nav-add-btn-icon {
  color: var(--primary);
}

.codex-nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.codex-nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.codex-nav-children {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.1rem 0 0.25rem 0.55rem;
  margin: 0 0.45rem 0.15rem 1.1rem;
  border-left: 2px solid color-mix(in srgb, var(--primary) 18%, var(--border));
}

.codex-nav-item--sub {
  font-size: 0.8125rem;
  padding: 0.52rem 0.65rem 0.52rem 0.7rem;
}

.codex-nav-item--sub .codex-nav-item-icon svg {
  width: 0.95rem;
  height: 0.95rem;
}

.codex-nav-add-sub-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  width: 100%;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.48rem 0.65rem;
  border-radius: var(--radius);
  border: 1px dashed color-mix(in srgb, var(--border) 90%, transparent);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

.codex-nav-add-sub-btn:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--primary-light);
}

.codex-nav-add-sub-btn:hover .codex-nav-add-btn-icon {
  color: var(--primary);
}

.codex-nav-sub-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.15rem 0 0.25rem;
}

.codex-nav-sub-form .codex-field-input {
  width: 100%;
}

.codex-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.62rem 0.7rem 0.62rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    transform 0.18s ease,
    box-shadow 0.22s ease;
}

.codex-nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.45rem;
  bottom: 0.45rem;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--codex-item-accent, var(--primary));
  opacity: 0;
  transform: scaleY(0.6);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.codex-nav-item:hover {
  background: color-mix(in srgb, var(--primary-light) 45%, transparent);
  transform: translateX(2px);
}

.codex-nav-item.is-active {
  background: color-mix(in srgb, var(--primary-light) 70%, transparent);
  border-color: color-mix(in srgb, var(--primary) 22%, transparent);
  color: color-mix(in srgb, var(--primary) 85%, var(--text));
  box-shadow: 0 2px 12px color-mix(in srgb, var(--primary) 10%, transparent);
}

.codex-nav-item.is-active::before {
  opacity: 1;
  transform: scaleY(1);
}

.codex-nav-item-icon {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--codex-item-accent, var(--primary));
  opacity: 0.88;
}

.codex-nav-item-icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.codex-nav-item-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.codex-nav-item-count {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  color: var(--text-muted);
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.codex-nav-item.is-active .codex-nav-item-count {
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  border-color: color-mix(in srgb, var(--primary) 25%, transparent);
  color: var(--primary);
}

/* —— Explorer (center) —— */

.codex-explorer .codex-panel-body {
  padding: 0;
}

.codex-explorer-inner {
  padding: 1.15rem 1.25rem 1.5rem;
}

.codex-explorer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.codex-explorer-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
  max-width: min(100%, 36rem);
}

.codex-explorer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.codex-explorer-toolbar .codex-icon-picker--toolbar {
  margin-right: 0.15rem;
  padding-right: 0.55rem;
  border-right: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.codex-explorer-head-text {
  min-width: 0;
  flex: 1;
}

.codex-explorer-eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.codex-explorer-title {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 1.55rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.codex-explorer-stats {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.codex-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.codex-ghost-btn {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.codex-ghost-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg) 50%, var(--surface));
  border-color: var(--border);
}

.codex-ghost-btn--accent:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
  background: var(--primary-light);
}

.codex-ghost-btn--danger:hover {
  color: #e85d6f;
  border-color: color-mix(in srgb, #e85d6f 35%, var(--border));
  background: color-mix(in srgb, #e85d6f 12%, transparent);
}

.codex-explorer-tree {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.codex-explorer-articles {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Nested sections — depth classes for future unlimited nesting */

.codex-nest {
  --codex-nest-indent: 0;
  padding-left: var(--codex-nest-indent);
}

.codex-nest--depth-0 {
  --codex-nest-indent: 0;
}

.codex-nest--depth-1 {
  --codex-nest-indent: 0.85rem;
  padding-left: 0.85rem;
  border-left: 2px solid color-mix(in srgb, var(--primary) 18%, var(--border));
}

.codex-nest--depth-2 {
  --codex-nest-indent: 1.7rem;
  padding-left: 1.7rem;
  border-left: 2px solid color-mix(in srgb, var(--border) 90%, transparent);
}

.codex-nest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.codex-nest-head-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.codex-nest-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: color-mix(in srgb, var(--primary) 70%, var(--text-muted));
}

.codex-nest-icon svg {
  width: 100%;
  height: 100%;
}

.codex-nest-title-btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: color 0.18s ease;
}

.codex-nest-title-btn:hover {
  color: var(--primary);
}

.codex-nest.is-active .codex-nest-title-btn {
  color: var(--primary);
}

.codex-nest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  opacity: 0.65;
  transition: opacity 0.2s ease;
}

.codex-nest:hover .codex-nest-actions,
.codex-nest.is-active .codex-nest-actions {
  opacity: 1;
}

.codex-nest-label {
  margin: 0 0 0.65rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.codex-entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.65rem;
}

.codex-entry-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 7.5rem;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  background: color-mix(in srgb, var(--bg) 25%, var(--surface));
  color: var(--text);
  overflow: visible;
  transition:
    border-color 0.22s ease,
    background 0.22s ease,
    box-shadow 0.25s ease,
    transform 0.2s ease;
}

.codex-entry-card:hover {
  border-color: color-mix(in srgb, var(--primary) 32%, var(--border));
  background: color-mix(in srgb, var(--primary-light) 35%, var(--surface));
  box-shadow: 0 6px 20px color-mix(in srgb, var(--primary) 8%, transparent);
  transform: translateY(-2px);
}

.codex-entry-card.is-active {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--border));
  background: color-mix(in srgb, var(--primary-light) 55%, var(--surface));
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--primary) 22%, transparent),
    0 8px 24px color-mix(in srgb, var(--primary) 12%, transparent);
}

.codex-entry-card-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  flex: 1;
  text-align: left;
  font: inherit;
  padding: 0.85rem 0.95rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.codex-entry-card--has-image .codex-entry-card-body {
  padding: 0.7rem 0.95rem 0.85rem;
}

.codex-entry-card-icon {
  color: color-mix(in srgb, var(--primary) 75%, var(--text-muted));
  opacity: 0.9;
}

.codex-entry-card-icon svg {
  width: 1rem;
  height: 1rem;
}

.codex-entry-card-title {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.codex-entry-card-location {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--primary) 70%, var(--text-muted));
}

.codex-entry-card-excerpt {
  flex: 1;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.codex-entry-card-meta {
  font-size: 0.68rem;
  font-weight: 500;
  color: color-mix(in srgb, var(--text-muted) 90%, transparent);
  font-variant-numeric: tabular-nums;
}

/* —— Article viewer (right) —— */

.codex-article-panel .codex-panel-body {
  padding: 0;
}

.codex-article-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 16rem;
  padding: 2.5rem 1.75rem;
  text-align: center;
  color: var(--text-muted);
}

.codex-article-empty-icon {
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 1rem;
  color: color-mix(in srgb, var(--primary) 50%, var(--text-muted));
  opacity: 0.7;
}

.codex-article-empty-icon svg {
  width: 100%;
  height: 100%;
}

.codex-article-empty p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  max-width: 16rem;
}

.codex-article-doc {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.codex-article-header {
  padding: 1.35rem 1.5rem 1.1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  background: color-mix(in srgb, var(--bg) 20%, var(--surface));
}

.codex-article-icon-slot {
  margin-bottom: 0.85rem;
}

.codex-article-hero-wrap {
  margin: 0 0 1rem;
}

/* Shared article / explorer image preview (hover zoom + click fullscreen) */

.codex-image-preview {
  position: relative;
  display: block;
  max-width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  cursor: zoom-in;
  z-index: 1;
}

.codex-image-preview-img {
  display: block;
  object-fit: cover;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: 0 4px 16px color-mix(in srgb, #000 18%, transparent);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease;
}

.codex-image-preview--hero .codex-image-preview-img {
  max-width: min(100%, 280px);
  max-height: 150px;
  width: auto;
  height: auto;
}

.codex-image-preview--card {
  width: 4.25rem;
  height: 4.25rem;
  margin: 0.85rem 0.95rem 0;
  border-radius: calc(var(--radius) + 2px);
  overflow: visible;
}

.codex-image-preview--card .codex-image-preview-img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: 0 4px 14px color-mix(in srgb, #000 14%, transparent);
}

.codex-image-preview-hint {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: color-mix(in srgb, #000 62%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.codex-image-preview:hover .codex-image-preview-img {
  transform: scale(1.03);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--primary) 12%, transparent);
}

.codex-image-preview--card:hover .codex-image-preview-img {
  transform: scale(1.02);
}

.codex-image-preview:hover .codex-image-preview-hint {
  opacity: 1;
}

body.codex-page-open .thumb-hover-preview {
  z-index: 150;
  aspect-ratio: auto;
  width: min(400px, calc(100vw - 2rem));
  max-height: min(360px, 55vh);
  height: auto;
  border-radius: calc(var(--radius-lg) + 2px);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
  box-shadow:
    0 12px 40px color-mix(in srgb, #000 35%, transparent),
    0 0 0 1px color-mix(in srgb, var(--primary) 12%, transparent);
}

body.codex-page-open .thumb-hover-preview img {
  width: 100%;
  height: auto;
  max-height: min(360px, 55vh);
  object-fit: contain;
}

/* Codex fullscreen image lightbox */

#image-viewer-dialog.codex-image-fullscreen {
  max-width: none;
  width: 100%;
  height: 100%;
  max-height: none;
}

#image-viewer-dialog.codex-image-fullscreen .image-viewer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  padding: 3rem 1.5rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 94%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--primary) 8%, transparent),
    0 24px 64px color-mix(in srgb, #000 45%, transparent);
}

#image-viewer-dialog.codex-image-fullscreen .image-viewer-close {
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  background: color-mix(in srgb, var(--bg) 35%, var(--surface));
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  box-shadow: 0 4px 18px color-mix(in srgb, #000 24%, transparent);
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

#image-viewer-dialog.codex-image-fullscreen .image-viewer-close:hover,
#image-viewer-dialog.codex-image-fullscreen .image-viewer-close:focus-visible {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--primary-light);
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 35%, transparent);
  transform: scale(1.04);
  outline: none;
}

#image-viewer-dialog.codex-image-fullscreen .image-viewer-img {
  max-width: min(96vw, 1600px);
  max-height: calc(100vh - 6rem);
  aspect-ratio: auto;
}

.codex-article-image-field {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.codex-article-image-preview {
  min-height: 5.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem;
  border-radius: calc(var(--radius) + 2px);
  border: 1px dashed color-mix(in srgb, var(--border) 85%, transparent);
  background: color-mix(in srgb, var(--bg) 35%, var(--surface));
}

.codex-article-image-preview img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: var(--radius);
}

.codex-article-image-empty {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.45;
  padding: 0.5rem;
}

.codex-article-image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.codex-article-hero-slot {
  display: none;
}

.codex-article-header-body {
  max-width: 36rem;
}

.codex-article-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.8vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.codex-article-subtitle-slot {
  display: none;
  margin: 0.45rem 0 0;
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.codex-article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0.85rem 0 0;
  padding: 0;
}

.codex-article-meta dt {
  display: none;
}

.codex-article-meta dd {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.codex-article-meta dd::before {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 0.35rem;
  color: color-mix(in srgb, var(--text-muted) 75%, transparent);
}

.codex-article-meta dd[data-meta="created"]::before {
  content: 'Created';
}

.codex-article-meta dd[data-meta="updated"]::before {
  content: 'Updated';
}

.codex-article-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.codex-article-edit-btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  background: color-mix(in srgb, var(--primary-light) 50%, transparent);
  color: var(--primary);
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.codex-article-edit-btn:hover {
  background: var(--primary-light);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
}

.codex-article-body {
  flex: 1;
  padding: 1.35rem 1.5rem 2rem;
  max-width: 36rem;
}

.codex-article-paragraph {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  line-height: 1.72;
  color: color-mix(in srgb, var(--text) 95%, var(--text-muted));
}

.codex-article-paragraph:last-child {
  margin-bottom: 0;
}

.codex-article-lead {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.codex-article-lead--empty {
  font-style: italic;
  opacity: 0.85;
}

/* Future feature slots */

.codex-article-aside,
.codex-article-footer-slots {
  display: none;
}

.codex-article-edit {
  padding: 1.25rem 1.5rem 1.5rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  background: color-mix(in srgb, var(--bg) 30%, var(--surface));
}

.codex-article-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.codex-article-edit-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.codex-article-cancel-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.18s ease;
}

.codex-article-cancel-btn:hover {
  color: var(--text);
}

/* —— Shared form + empty states —— */

.codex-empty-state {
  text-align: center;
  padding: 1.75rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.codex-empty-state p {
  margin: 0;
}

.codex-inline-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.75rem;
  padding: 0 0.45rem;
}

.codex-inline-form .codex-field-input {
  width: 100%;
}

.codex-inline-form-actions {
  display: flex;
  gap: 0.45rem;
  width: 100%;
}

.codex-inline-form-actions .btn {
  flex: 1;
  width: 100%;
  justify-content: center;
}

.codex-inline-form.hidden {
  display: none;
}

.codex-inline-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.25rem 0;
}

.codex-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.codex-field-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.codex-field-input,
.codex-field-textarea {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.codex-field-input:focus-visible,
.codex-field-textarea:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

/* —— Codex icons —— */

.codex-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: color-mix(in srgb, var(--primary) 75%, var(--text-muted));
}

.codex-icon svg {
  width: 100%;
  height: 100%;
}

.codex-icon--sm {
  width: 1.1rem;
  height: 1.1rem;
}

.codex-icon--md {
  width: 1.35rem;
  height: 1.35rem;
}

.codex-icon--lg {
  width: 2rem;
  height: 2rem;
}

.codex-icon--custom {
  width: 2rem;
  height: 2rem;
  object-fit: cover;
  border-radius: calc(var(--radius) - 1px);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background: color-mix(in srgb, var(--bg) 40%, var(--surface));
}

.codex-entry-card-icon .codex-icon--custom,
.codex-nav-item-icon .codex-icon--custom {
  width: 1.1rem;
  height: 1.1rem;
}

.codex-icon-picker {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.codex-icon-picker--toolbar {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  border: none;
  background: transparent;
}

.codex-icon-picker--toolbar .codex-icon-picker-field {
  margin: 0;
  min-width: 6.75rem;
}

.codex-icon-picker--toolbar .codex-icon-upload-btn {
  flex-shrink: 0;
  padding: 0.35rem 0.55rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

.codex-icon-picker-field {
  margin: 0;
}

.codex-icon-select {
  position: relative;
  width: 100%;
}

.codex-icon-select-trigger {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  min-height: 2.35rem;
  padding: 0.45rem 2rem 0.45rem 0.55rem;
  text-align: left;
  cursor: pointer;
}

.codex-icon-select-trigger-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.codex-icon-select-trigger-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 500;
}

.codex-icon-select-chevron {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
  transition: transform 0.18s ease;
}

.codex-icon-select.is-open .codex-icon-select-chevron {
  transform: translateY(-35%) rotate(225deg);
}

.codex-icon-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 60;
  width: min(18rem, calc(100vw - 2rem));
  max-height: min(22rem, 50vh);
  overflow: auto;
  padding: 0.35rem;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  background: color-mix(in srgb, var(--surface) 98%, var(--bg));
  box-shadow:
    0 16px 40px color-mix(in srgb, #000 32%, transparent),
    0 0 0 1px color-mix(in srgb, var(--primary) 8%, transparent);
}

.codex-icon-select.is-open .codex-icon-select-menu {
  display: block;
}

.codex-icon-select-group + .codex-icon-select-group {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.codex-icon-select-group-label {
  margin: 0 0 0.25rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.codex-icon-select-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.42rem 0.45rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.16s ease,
    color 0.16s ease;
}

.codex-icon-select-option:hover,
.codex-icon-select-option:focus-visible {
  background: color-mix(in srgb, var(--primary-light) 55%, var(--surface));
  color: var(--text);
  outline: none;
}

.codex-icon-select-option.is-selected {
  background: color-mix(in srgb, var(--primary-light) 70%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 22%, transparent);
}

.codex-icon-select-option-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
}

.codex-icon-select-option-label {
  font-size: 0.8rem;
  font-weight: 500;
}

.codex-icon-picker--toolbar .codex-icon-select-trigger {
  min-height: 1.85rem;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  font-size: 0.72rem;
}

.codex-icon-picker--toolbar .codex-icon-select-menu {
  right: 0;
  left: auto;
}

.codex-icon-upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  border: 1px dashed color-mix(in srgb, var(--border) 90%, transparent);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

.codex-icon-upload-btn:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--primary-light);
}

.codex-entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.codex-entry-placement {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  padding-bottom: 0.15rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.codex-field-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2rem;
}

.codex-field-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.codex-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* —— Responsive —— */

@media (max-width: 1100px) {
  .codex-layout {
    --codex-nav-width: 220px;
    --codex-article-width: 340px;
  }
}

@media (max-width: 1024px) {
  .codex-layout {
    grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .codex-article-panel {
    grid-column: 1 / -1;
    max-height: 46vh;
  }
}

@media (max-width: 720px) {
  .codex-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .codex-nav {
    max-height: 30vh;
  }

  .codex-article-panel {
    max-height: 42vh;
  }

  .codex-entry-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .codex-page-inner {
    padding: 0.85rem 0.85rem 1rem;
  }

  .codex-page-head {
    flex-direction: column;
    align-items: stretch;
  }

  .codex-search-wrap {
    max-width: none;
  }

  .codex-explorer-inner {
    padding: 1rem;
  }

  .codex-explorer-head {
    flex-direction: column;
    align-items: stretch;
  }

  .codex-explorer-head-actions {
    max-width: none;
    justify-content: flex-start;
  }

  .codex-explorer-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .codex-explorer-toolbar .codex-icon-picker--toolbar {
    width: 100%;
    margin-right: 0;
    padding-right: 0;
    padding-bottom: 0.35rem;
    border-right: none;
    border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  }

  .codex-article-header,
  .codex-article-body,
  .codex-article-edit {
    padding-left: 1.1rem;
    padding-right: 1.1rem;
  }

  .codex-entry-placement {
    grid-template-columns: 1fr;
  }
}
