.codex-page {
  --cx-card: #ffffff;
  --cx-ink: #15392f;
  --cx-muted: #60756e;
  --cx-brand: #26a66b;
  --cx-brand-dark: #0d7550;
  --cx-danger: #b42318;
  --cx-warn: #b86b00;
  --cx-soft: #ecfff4;
  --cx-line: #dff2e7;
  --cx-shadow: 0 24px 70px rgba(21, 57, 47, .14);
  --cx-radius: 1.6rem;
  color: var(--cx-ink);
}

.codex-page button,
.codex-page input {
  font: inherit;
}

.codex-page button {
  cursor: pointer;
}

.codex-topbar {
  text-align: center;
  padding: 2.1rem 1.1rem 1.4rem;
  position: relative;
  border: 1px solid var(--cx-line);
  border-radius: var(--cx-radius);
  background: radial-gradient(circle at top left, #e2fff0, transparent 34%), linear-gradient(180deg, #f4fbf7, #fff);
}

.codex-method-btn {
  border: 0;
  background: var(--cx-ink);
  color: #fff;
  border-radius: 999px;
  padding: .75rem 1.35rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .16);
  font-weight: 900;
}

.codex-brandline {
  display: inline-flex;
  margin-top: 1.6rem;
  gap: .5rem;
  align-items: center;
  background: #fff;
  border: 1px solid #d9f4e4;
  padding: .6rem 1rem;
  border-radius: 999px;
  color: var(--cx-brand-dark);
  font-weight: 900;
}

.codex-topbar h1 {
  font-size: clamp(2.4rem, 6vw, 5rem);
  line-height: .95;
  margin: 1.1rem 0 .75rem;
  font-weight: 950;
}

.codex-topbar p {
  font-size: 1.12rem;
  color: var(--cx-muted);
  max-width: 860px;
  margin: 0 auto;
  line-height: 1.65;
}

.codex-actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: .75rem;
  margin: 1.5rem auto 0;
  max-width: 980px;
}

#codexGlobalSearch {
  border: 1px solid var(--cx-line);
  border-radius: 1rem;
  padding: .9rem 1rem;
  background: #fff;
  box-shadow: 0 10px 24px rgba(21, 57, 47, .08);
  outline: none;
}

.codex-primary,
.codex-ghost {
  border: 0;
  border-radius: 1rem;
  padding: .85rem 1.2rem;
  font-weight: 950;
  white-space: nowrap;
}

.codex-primary {
  background: linear-gradient(135deg, var(--cx-brand), var(--cx-brand-dark));
  color: #fff;
  box-shadow: 0 14px 28px rgba(38, 166, 107, .25);
}

.codex-ghost {
  background: #eef8f2;
  color: var(--cx-brand-dark);
}

.codex-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 1.35rem;
  align-items: start;
  margin-top: 1.35rem;
}

.codex-sidebar,
.codex-content-card {
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--cx-line);
  border-radius: var(--cx-radius);
  box-shadow: var(--cx-shadow);
  backdrop-filter: blur(12px);
}

.codex-sidebar {
  position: sticky;
  top: 5.5rem;
  max-height: calc(100vh - 7rem);
  overflow: auto;
}

.codex-sidebar-head {
  padding: 1.3rem 1.3rem .75rem;
}

.codex-sidebar-head strong {
  display: block;
  font-size: 1.15rem;
}

.codex-sidebar-head small {
  color: var(--cx-muted);
}

.codex-tree {
  padding: 0 .75rem 1.1rem;
}

.codex-tree-group {
  margin: .5rem 0;
}

.codex-tree-species,
.codex-tree-profile,
.codex-tree-section {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .6rem;
  border: 0;
  background: transparent;
  border-radius: .85rem;
  padding: .68rem .6rem;
  text-align: left;
  color: var(--cx-ink);
  transition: .18s ease;
}

.codex-tree-species:hover,
.codex-tree-profile:hover,
.codex-tree-section:hover,
.codex-tree .is-active {
  background: var(--cx-soft);
  color: var(--cx-brand-dark);
}

.codex-tree-species {
  font-weight: 950;
}

.codex-tree-profile {
  padding-left: 1.8rem;
  font-weight: 800;
}

.codex-tree-section {
  padding-left: 3.3rem;
  font-size: .92rem;
  color: var(--cx-muted);
}

.codex-chev {
  margin-left: auto;
  color: var(--cx-muted);
}

.codex-tree-children {
  display: none;
}

.codex-tree-group.is-open > .codex-tree-children {
  display: block;
}

.codex-content-card {
  min-height: 640px;
  padding: 1.85rem;
}

.codex-empty-state {
  text-align: center;
  padding: 5rem 1rem;
}

.codex-big-icon {
  font-size: 5rem;
}

.codex-empty-state h2 {
  font-size: 2rem;
  margin: 1.1rem 0 .5rem;
}

.codex-empty-state p {
  color: var(--cx-muted);
  font-size: 1.1rem;
  max-width: 660px;
  margin: auto;
  line-height: 1.7;
}

.codex-profile-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.2rem;
  align-items: start;
  border-bottom: 1px solid var(--cx-line);
  padding-bottom: 1.35rem;
  margin-bottom: 1.35rem;
}

.codex-profile-title {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.codex-profile-icon {
  font-size: 3.5rem;
  width: 78px;
  height: 78px;
  border-radius: 1.4rem;
  background: var(--cx-soft);
  display: grid;
  place-items: center;
}

.codex-profile-title h2 {
  font-size: clamp(2rem, 4vw, 3.3rem);
  margin: 0;
  font-weight: 950;
}

.codex-profile-title p {
  color: var(--cx-muted);
  line-height: 1.6;
  margin: .5rem 0 0;
}

.codex-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .85rem;
}

.codex-badge {
  padding: .5rem .75rem;
  background: #f3fbf6;
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  font-weight: 900;
  color: var(--cx-brand-dark);
  font-size: .9rem;
}

.codex-mini-card {
  background: linear-gradient(135deg, #e8fff2, #fff);
  border: 1px solid #d8f2e4;
  border-radius: 1.25rem;
  padding: 1rem;
  min-width: 240px;
}

.codex-mini-card b {
  display: block;
  margin-bottom: .5rem;
}

.codex-mini-card span,
.codex-section p,
.codex-list li,
.codex-note {
  color: var(--cx-muted);
  line-height: 1.65;
}

.codex-section {
  scroll-margin-top: 5.5rem;
  margin: 1.1rem 0;
  padding: 1.3rem;
  border: 1px solid #e4f1ea;
  border-radius: 1.25rem;
  background: #fff;
}

.codex-section h3 {
  display: flex;
  gap: .6rem;
  align-items: center;
  font-size: 1.45rem;
  margin: 0 0 .75rem;
  font-weight: 800;
}

.codex-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.codex-info-box,
.codex-source-card {
  background: #fafffc;
  border: 1px solid #e5f1ea;
  border-radius: 1rem;
  padding: .9rem;
  line-height: 1.65;
}

.codex-info-box b {
  display: block;
  color: var(--cx-ink);
  margin-bottom: .35rem;
}

.codex-list {
  display: grid;
  gap: .6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.codex-list li {
  position: relative;
  padding-left: 1.7rem;
}

.codex-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--cx-brand-dark);
  font-weight: 950;
}

.codex-warn-list li::before {
  content: "!";
  color: var(--cx-warn);
}

.codex-note {
  border-left: 5px solid var(--cx-brand);
  background: #f3fff8;
  border-radius: .85rem;
  padding: .85rem 1rem;
}

.codex-water-table,
.codex-cost-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border-radius: 1rem;
  border: 1px solid var(--cx-line);
}

.codex-water-table th,
.codex-water-table td,
.codex-cost-table th,
.codex-cost-table td {
  text-align: left;
  padding: .75rem .85rem;
  border-bottom: 1px solid var(--cx-line);
  vertical-align: top;
}

.codex-water-table tr:last-child td,
.codex-cost-table tr:last-child td {
  border-bottom: 0;
}

.codex-water-table th,
.codex-cost-table th {
  background: #f1fbf5;
  color: var(--cx-brand-dark);
}

.codex-source-grid {
  display: grid;
  gap: .65rem;
}

.codex-source-card small {
  display: block;
  color: var(--cx-muted);
  margin-top: .35rem;
  word-break: break-word;
}

.codex-search-hit {
  outline: 3px solid rgba(38, 166, 107, .25);
  background: #f7fff9;
}

.codex-modal {
  border: 0;
  border-radius: 1.6rem;
  width: min(900px, 92vw);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .25);
  padding: 0;
}

.codex-modal::backdrop {
  background: rgba(10, 30, 24, .55);
  backdrop-filter: blur(4px);
}

.codex-modal-body {
  padding: 1.9rem;
  position: relative;
}

.codex-modal-close {
  position: absolute;
  right: 1rem;
  top: .8rem;
  border: 0;
  background: #eef8f2;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.5rem;
}

.theme-dark .codex-page {
  --cx-ink: #e2e8f0;
  --cx-muted: #cbd5e1;
}

.theme-dark .codex-topbar,
.theme-dark .codex-sidebar,
.theme-dark .codex-content-card,
.theme-dark .codex-section {
  background: #111827;
  border-color: #334155;
}

.theme-dark .codex-brandline,
.theme-dark .codex-info-box,
.theme-dark .codex-source-card,
.theme-dark .codex-mini-card,
.theme-dark #codexGlobalSearch {
  background: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}

.theme-dark .codex-ghost,
.theme-dark .codex-profile-icon,
.theme-dark .codex-note,
.theme-dark .codex-badge {
  background: #164e63;
  color: #e2e8f0;
  border-color: #334155;
}

@media (max-width: 900px) {
  .codex-actions {
    grid-template-columns: 1fr;
  }

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

  .codex-sidebar {
    position: static;
    max-height: none;
  }

  .codex-content-card {
    padding: 1.25rem;
  }

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

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

@media print {
  .navbar,
  .site-footer,
  .codex-topbar,
  .codex-sidebar,
  .codex-method-btn,
  .codex-actions {
    display: none !important;
  }

  .codex-layout {
    display: block;
  }

  .codex-content-card {
    box-shadow: none;
    border: 0;
  }

  .codex-section {
    break-inside: avoid;
  }
}
