/* ============================================================
   DEEP ARK CODEX — The Black Book of Potions
   ============================================================ */

.codex {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--void);
  overflow-x: hidden;
}

.codex__header {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(10, 10, 12, 0.92);
  border-bottom: 1px solid rgba(201, 168, 76, 0.2);
  backdrop-filter: blur(8px);
}

.codex__brand {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  text-decoration: none;
  font-family: var(--font-heading);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 1.1rem;
}

.codex__brand-ark {
  color: var(--parchment);
}

.codex__brand-codex {
  color: var(--gold);
}

.codex__nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
  justify-content: flex-end;
}

.codex__nav-link {
  color: var(--parchment-dim);
  text-decoration: none;
  font-family: var(--font-heading);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  position: relative;
  padding-bottom: 0.3rem;
  transition: color 0.25s ease;
  background: none;
  border: none;
  cursor: pointer;
}

.codex__nav-link::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: 1px;
  background: var(--gold);
  transition: width 0.3s var(--ease-out-expo), left 0.3s var(--ease-out-expo);
}

.codex__nav-link:hover,
.codex__nav-link[aria-current="page"] {
  color: var(--gold);
}

.codex__nav-link:hover::after,
.codex__nav-link[aria-current="page"]::after {
  left: 0;
  width: 100%;
}

.codex__nav-divider {
  width: 1px;
  height: 1.4rem;
  background: linear-gradient(180deg, transparent, rgba(201, 168, 76, 0.52), transparent);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.12);
}

.codex__mobile-bar,
.codex__mobile-menu {
  display: none;
}

.codex__mobile-bar {
  width: 100%;
  position: relative;
  align-items: center;
  grid-template-columns: minmax(4.5rem, auto) minmax(0, 1fr) 2.35rem;
  gap: 0.65rem;
}

.codex__mobile-mark {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-decoration: none;
  text-transform: uppercase;
}

.codex__mobile-title {
  min-width: 0;
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex__mobile-toggle {
  display: grid;
  place-items: center;
  gap: 0.22rem;
  width: 2.35rem;
  height: 2.15rem;
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 999px;
  background: rgba(201, 168, 76, 0.06);
  color: var(--parchment);
  cursor: pointer;
}

.codex__mobile-toggle span {
  display: block;
  width: 0.95rem;
  height: 1px;
  background: currentColor;
  transition: transform 0.24s ease, opacity 0.18s ease;
}

.codex__mobile-toggle.is-open span:nth-child(1) {
  transform: translateY(5px) rotate(42deg);
}

.codex__mobile-toggle.is-open span:nth-child(2) {
  opacity: 0;
}

.codex__mobile-toggle.is-open span:nth-child(3) {
  transform: translateY(-5px) rotate(-42deg);
}

.codex__mobile-menu[hidden] {
  display: none;
}

.codex__mobile-panel {
  display: grid;
  gap: 1rem;
  max-height: calc(100vh - 4.5rem);
  overflow: auto;
  padding: 0.9rem;
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: 20px;
  background:
    radial-gradient(circle at 15% 0, rgba(201, 168, 76, 0.12), transparent 36%),
    rgba(14, 14, 18, 0.96);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(16px);
  animation: codexMenuIn 0.24s ease both;
}

@keyframes codexMenuIn {
  from {
    opacity: 0;
    transform: translateY(-0.4rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.codex__mobile-group {
  display: grid;
  gap: 0.42rem;
}

.codex__mobile-group p {
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.codex__mobile-menu-link,
.codex__mobile-section-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.4rem;
  padding: 0.58rem 0.72rem;
  border: 1px solid rgba(201, 168, 76, 0.12);
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--parchment-dim);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.codex__mobile-section-link {
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.codex__mobile-session {
  width: 100%;
  cursor: pointer;
}

.codex__mobile-menu-link[aria-current="page"] {
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.32);
  background: rgba(201, 168, 76, 0.08);
}

.codex__mobile-page-links {
  display: grid;
  gap: 0.42rem;
}

.codex__identity {
  display: inline-flex;
  align-items: center;
  max-width: min(26vw, 290px);
  min-height: 2rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 999px;
  background: rgba(201, 168, 76, 0.06);
  color: var(--parchment-dim);
  font-size: 0.78rem;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.codex__identity:hover {
  color: var(--gold-bright);
  border-color: rgba(201, 168, 76, 0.32);
  background: rgba(201, 168, 76, 0.1);
}

.codex__identity[hidden] {
  display: none;
}

.codex__session-control {
  display: inline-grid;
  place-items: center;
  min-width: 2.15rem;
  height: 2.15rem;
  padding: 0 0.72rem;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 999px;
  background: rgba(201, 168, 76, 0.06);
  color: var(--parchment-dim);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.codex__session-control:hover {
  color: var(--gold-bright);
  border-color: rgba(201, 168, 76, 0.34);
  background: rgba(201, 168, 76, 0.11);
  transform: translateY(-1px);
}

.codex__session-control svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.codex__main {
  flex: 1;
  padding: 2rem 1.5rem 4rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.codex__footer {
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--stone);
  font-size: 0.9rem;
  border-top: 1px solid rgba(201, 168, 76, 0.1);
}

.codex__loading,
.codex__error {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--parchment-dim);
}

.codex__error {
  color: var(--blood-bright);
}

/* Landing view */
.codex__landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.codex__landing-title {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 6vw, 4rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.codex__landing-subtitle {
  font-family: var(--font-body);
  font-size: 1.25rem;
  color: var(--parchment-dim);
  margin-bottom: 2rem;
  font-style: italic;
}

.codex__landing-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 360px;
}

.codex__landing-form label {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.codex__login-stack {
  width: 100%;
  max-width: 390px;
}

.codex__login-stack .codex__landing-form {
  max-width: none;
}

.codex__landing-form--code {
  padding: 1rem;
  border: 1px solid rgba(201, 168, 76, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.14);
}

.codex__login-divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.1rem 0;
  color: var(--stone);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.codex__login-divider::before,
.codex__login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201, 168, 76, 0.24), transparent);
}

.codex__access-note {
  width: min(100%, 520px);
  margin: 0 0 1.2rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(201, 168, 76, 0.13), rgba(139, 46, 46, 0.08)),
    rgba(0, 0, 0, 0.22);
  color: var(--parchment-dim);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

.codex__access-note strong,
.codex__access-note span {
  display: block;
}

.codex__access-note strong {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.86rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.codex__input {
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 4px;
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 1rem;
}

.codex__input::placeholder {
  color: var(--stone);
}

.codex__input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.15);
}

.codex__btn {
  padding: 0.85rem 1.5rem;
  background: var(--gold);
  color: var(--void);
  border: none;
  border-radius: 4px;
  font-family: var(--font-heading);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.codex__btn:hover {
  background: var(--gold-bright);
}

.codex__btn:active {
  transform: translateY(1px);
}

.codex__btn--secondary {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--gold);
}

.codex__btn--secondary:hover {
  background: rgba(201, 168, 76, 0.1);
}

.codex__help {
  margin-top: 1.5rem;
  color: var(--stone);
  font-size: 0.9rem;
}

/* Browse view */
.codex__browse-header {
  margin-bottom: 1.5rem;
}

.codex__browse-title {
  font-family: var(--font-heading);
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.codex__browse-meta {
  color: var(--stone);
  font-size: 0.95rem;
}

.codex__search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.codex__search {
  flex: 1 1 260px;
}

.codex__filter {
  flex: 0 1 200px;
}

.codex__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.codex__card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid rgba(201, 168, 76, 0.15);
  border-radius: 6px;
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.codex__card-image {
  width: calc(100% + 2.5rem);
  margin: -1.25rem -1.25rem 1rem;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-bottom: 1px solid rgba(201, 168, 76, 0.15);
}

.codex__card-image--ingredient {
  width: min(68%, 150px);
  margin: -0.25rem auto 0.85rem;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border: 0;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 35%, rgba(201, 168, 76, 0.12), transparent 55%),
    var(--depth);
}

.codex__card:hover {
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.codex__card-number {
  font-family: var(--font-heading);
  color: var(--gold-dim);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

.codex__card-name {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  text-transform: uppercase;
  color: var(--parchment);
  margin-bottom: 0.5rem;
}

.codex__card-family {
  font-size: 0.85rem;
  color: var(--family-color, var(--parchment-dim));
  margin-bottom: 0.5rem;
}

.codex__card-rarity,
.codex__rarity-pill {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.5rem;
  border: 1px solid color-mix(in srgb, var(--rarity-color, var(--gold)) 72%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--rarity-color, var(--gold)) 20%, transparent);
  color: color-mix(in srgb, var(--rarity-color, var(--gold)) 72%, var(--parchment));
}

.codex__card-rarity {
  margin-top: auto;
  align-self: flex-start;
}

.codex__card--ingredient {
  min-height: 0;
  text-align: center;
}

.codex__card-summary {
  color: var(--parchment-dim);
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 1rem;
}

/* Commerce views */
.codex__commerce-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

.codex__package-card {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(201, 168, 76, 0.15);
  border-radius: 6px;
}

.codex__owned-section {
  margin-top: 2.5rem;
}

.codex__owned-list {
  display: grid;
  gap: 1rem;
}

.codex__package-card--profile {
  grid-template-columns: 118px minmax(0, 1fr);
  grid-template-rows: 1fr;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.055), transparent 44%),
    rgba(23, 23, 29, 0.88);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
}

.codex__package-card--profile .codex__package-cover {
  width: 118px;
  height: 100%;
  min-height: 170px;
  aspect-ratio: auto;
  object-fit: contain;
  padding: 0.75rem;
  border: 0;
  border-right: 1px solid rgba(201, 168, 76, 0.13);
  background:
    radial-gradient(circle at 50% 24%, rgba(201, 168, 76, 0.12), transparent 48%),
    rgba(0, 0, 0, 0.2);
}

.codex__package-card--profile .codex__package-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  align-content: center;
  padding: 1.35rem 1.5rem;
}

.codex__package-card--profile .codex__package-kicker,
.codex__package-card--profile .codex__package-title,
.codex__package-card--profile .codex__package-desc,
.codex__package-card--profile .codex__package-meta,
.codex__package-card--profile .codex__package-includes {
  grid-column: 1;
}

.codex__package-card--profile .codex__package-includes {
  display: none;
}

.codex__package-card--profile .codex__package-actions {
  grid-column: 2;
  grid-row: 1 / span 5;
  align-self: center;
  min-width: min(100%, 300px);
}

.codex__package-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-bottom: 1px solid rgba(201, 168, 76, 0.15);
  background: var(--depth);
}

.codex__package-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem;
}

.codex__package-kicker {
  font-family: var(--font-heading);
  color: var(--gold-dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.codex__package-title {
  font-family: var(--font-heading);
  color: var(--parchment);
  font-size: 1.3rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.codex__package-desc {
  color: var(--parchment-dim);
  line-height: 1.45;
}

.codex__package-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.codex__package-price {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.codex__status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.45rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  background: rgba(201, 168, 76, 0.12);
  color: var(--gold);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.codex__status-chip.is-owned {
  background: rgba(95, 146, 96, 0.18);
  color: #9ed29d;
}

.codex__status-chip.is-planned {
  background: rgba(154, 139, 110, 0.16);
  color: var(--parchment-dim);
}

.codex__package-includes {
  display: grid;
  gap: 0.45rem;
  list-style: none;
  padding: 0;
  margin: 0 0 0.25rem;
}

.codex__package-includes li {
  position: relative;
  padding-left: 1rem;
  color: var(--parchment-dim);
  font-size: 0.93rem;
}

.codex__package-includes li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--gold-dim);
}

.codex__package-actions {
  margin-top: auto;
}

.codex__package-actions--stacked {
  display: grid;
  gap: 0.8rem;
}

.codex__action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.codex__btn--inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: auto;
}

.codex__btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.codex__pod-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem;
  border: 1px solid rgba(201, 168, 76, 0.14);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.18);
}

.codex__pod-panel strong,
.codex__pod-panel span {
  display: block;
}

.codex__pod-panel strong {
  color: var(--gold);
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.codex__pod-panel span {
  color: var(--parchment-dim);
  font-size: 0.95rem;
}

.codex__tier-note {
  display: grid;
  gap: 0.2rem;
  max-width: 310px;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(201, 168, 76, 0.12);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
}

.codex__tier-note strong {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.codex__tier-note span {
  color: var(--stone);
  font-size: 0.88rem;
  line-height: 1.35;
}

.codex__commerce-empty,
.codex__commerce-notice {
  margin-bottom: 1.5rem;
}

.codex__profile-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 1.25rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: clamp(1.3rem, 4vw, 2rem);
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 24px;
  background:
    radial-gradient(circle at 12% 18%, rgba(201, 168, 76, 0.17), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 48%),
    rgba(16, 16, 21, 0.82);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.27), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.codex__profile-seal {
  display: grid;
  place-items: center;
  width: clamp(64px, 8vw, 88px);
  aspect-ratio: 1;
  border: 1px solid rgba(232, 213, 163, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.18), transparent 28%),
    linear-gradient(145deg, rgba(201, 168, 76, 0.26), rgba(139, 46, 46, 0.2));
  color: var(--gold-bright);
  font-family: var(--font-heading);
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.24), 0 14px 36px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.codex__profile-seal img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.codex__profile-kicker {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.codex__profile-title {
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: clamp(1.55rem, 4vw, 2.5rem);
  line-height: 1.05;
  text-transform: uppercase;
}

.codex__profile-email {
  color: var(--parchment-dim);
  margin-top: 0.35rem;
}

.codex__profile-stats {
  display: flex;
  gap: 0.65rem;
}

.codex__profile-stats span {
  min-width: 92px;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(201, 168, 76, 0.13);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--stone);
  font-size: 0.78rem;
  text-align: center;
}

.codex__profile-stats strong {
  display: block;
  color: var(--gold-bright);
  font-family: var(--font-heading);
  font-size: 1.2rem;
}

.codex__profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: stretch;
}

.codex__profile-panel {
  padding: 1.25rem;
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 46%),
    rgba(0, 0, 0, 0.22);
}

.codex__profile-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.codex__profile-panel h2 {
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: 1.15rem;
  text-transform: uppercase;
}

.codex__profile-form {
  display: grid;
  gap: 0.7rem;
}

.codex__profile-form + .codex__profile-form {
  margin-top: 1.35rem;
  padding-top: 1.35rem;
  border-top: 1px solid rgba(201, 168, 76, 0.1);
}

.codex__profile-form label {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.codex__profile-field-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.codex__username-prefix {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 2.6rem;
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-right: 0;
  border-radius: 4px 0 0 4px;
  background: rgba(201, 168, 76, 0.08);
  color: var(--gold);
}

.codex__profile-field-row .codex__input {
  border-radius: 0 4px 4px 0;
}

.codex__profile-guidance {
  color: var(--stone);
  font-size: 0.88rem;
  line-height: 1.4;
}

.codex__bio-form textarea {
  min-height: 120px;
  resize: vertical;
}

.codex__profile-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.codex__profile-form-footer span {
  color: var(--stone);
  font-size: 0.82rem;
}

.codex__avatar-section {
  display: grid;
  gap: 0.8rem;
  margin-top: 1.35rem;
  padding-top: 1.35rem;
  border-top: 1px solid rgba(201, 168, 76, 0.1);
}

.codex__avatar-section label {
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.codex__avatar-choice {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 50%;
  background: var(--depth);
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s var(--ease-out-expo), border-color 0.25s ease, box-shadow 0.25s ease;
}

.codex__avatar-choice:hover {
  transform: translateY(-3px);
  border-color: rgba(201, 168, 76, 0.55);
}

.codex__avatar-choice.is-selected {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.13), 0 12px 30px rgba(0, 0, 0, 0.34);
}

.codex__avatar-choice img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.codex__account-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.codex__account-copy {
  color: var(--parchment-dim);
}

.codex__account-email {
  display: block;
  color: var(--parchment);
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.codex__account-copy span {
  display: block;
  color: var(--stone);
  font-size: 0.92rem;
}

.codex__redeem-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  margin-top: 1.25rem;
  align-items: start;
}

.codex__redeem-status {
  grid-column: 1 / -1;
  min-height: 1.1rem;
  color: var(--stone);
  font-size: 0.86rem;
}

.codex__flash {
  margin-bottom: 1rem;
  color: var(--parchment);
}

/* Detail view */
.codex__detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  padding: 0.24rem 0.68rem;
  border: 1px solid rgba(201, 168, 76, 0.13);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  color: var(--parchment-dim);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.codex__detail-back:hover {
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.32);
  background: rgba(201, 168, 76, 0.08);
}

.codex__detail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.codex__detail-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 390px);
  grid-template-areas:
    "heading art";
  gap: 1rem 1.35rem;
  padding: clamp(1.15rem, 2.4vw, 1.8rem);
  margin-bottom: 1.25rem;
  overflow: hidden;
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: 24px;
  background:
    radial-gradient(circle at 10% 5%, rgba(201, 168, 76, 0.14), transparent 30%),
    radial-gradient(circle at 95% 0%, rgba(139, 46, 46, 0.16), transparent 34%),
    linear-gradient(135deg, rgba(36, 29, 22, 0.96), rgba(16, 16, 21, 0.94) 58%, rgba(27, 24, 21, 0.96));
  box-shadow:
    0 20px 70px rgba(0, 0, 0, 0.36),
  inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.codex__detail-hero--potion {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.42fr);
  grid-template-areas:
    "art art"
    "heading heading";
  border-color: color-mix(in srgb, var(--entry-family-color, var(--gold)) 18%, rgba(201, 168, 76, 0.16));
  box-shadow:
    0 22px 72px rgba(0, 0, 0, 0.38),
    0 0 42px color-mix(in srgb, var(--entry-family-color, var(--gold)) 9%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.codex__detail-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(90deg, rgba(201, 168, 76, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(201, 168, 76, 0.05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 35% 28%, black, transparent 72%);
}

.codex__detail-hero--potion::after {
  content: '';
  position: absolute;
  inset: auto 8% -24% 8%;
  height: 36%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--entry-family-color, var(--gold)) 12%, transparent), transparent 68%);
  filter: blur(8px);
  opacity: 0.78;
}

.codex__detail-hero > * {
  position: relative;
}

.codex__detail-heading {
  grid-area: heading;
  align-self: end;
}

.codex__folio-kicker {
  margin-bottom: 0.4rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.codex__detail-artwork {
  grid-area: art;
  align-self: stretch;
  margin: 0;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(201, 168, 76, 0.2);
  background:
    radial-gradient(circle at 50% 34%, rgba(201, 168, 76, 0.12), transparent 58%),
    var(--depth);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
}

.codex__detail-artwork img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 430px;
  object-fit: contain;
}

.codex__detail-hero--potion .codex__detail-artwork {
  min-height: clamp(280px, 42vw, 540px);
  border-radius: 20px;
}

.codex__detail-hero--potion .codex__detail-artwork img {
  aspect-ratio: 16 / 7;
  max-height: 560px;
  object-fit: cover;
}

.codex__potion-art-banner {
  position: relative;
  width: 100%;
  aspect-ratio: 2914 / 1260;
  min-height: clamp(320px, 34vw, 520px);
  max-height: 560px;
  margin: -0.35rem 0 0;
  overflow: hidden;
  border: 1px solid rgba(201, 168, 76, 0.13);
  border-bottom-color: rgba(0, 0, 0, 0);
  border-radius: 24px;
  background: #000;
  box-shadow:
    0 18px 58px rgba(0, 0, 0, 0.46),
    0 0 52px color-mix(in srgb, var(--entry-family-color, var(--gold)) 13%, transparent);
}

.codex__potion-art-banner::before,
.codex__potion-art-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.codex__potion-art-banner::before {
  background:
    radial-gradient(circle at 50% 10%, color-mix(in srgb, var(--entry-family-color, var(--gold)) 16%, transparent), transparent 48%),
    linear-gradient(180deg, rgba(10, 10, 12, 0.04), rgba(10, 10, 12, 0.04) 48%, rgba(0, 0, 0, 0.58));
  mix-blend-mode: screen;
}

.codex__potion-art-banner::after {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.3), transparent 14%, transparent 86%, rgba(0, 0, 0, 0.3)),
    linear-gradient(180deg, transparent 62%, rgba(0, 0, 0, 0.96));
}

.codex__potion-art-banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.codex__detail-artwork--ingredient {
  align-self: center;
  border: 0;
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 45%, rgba(201, 168, 76, 0.12), transparent 60%),
    rgba(0, 0, 0, 0.1);
  box-shadow: none;
}

.codex__detail-artwork--ingredient img {
  height: auto;
  max-height: min(58vh, 520px);
  object-fit: contain;
}

.codex__detail-title {
  font-family: var(--font-heading);
  font-size: clamp(1.75rem, 3.25vw, 2.8rem);
  line-height: 0.96;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.5rem;
  text-shadow: 0 0 24px rgba(201, 168, 76, 0.12);
}

.codex__detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  color: var(--parchment-dim);
  font-size: 0.82rem;
}

.codex__detail-meta span,
.codex__detail-meta a {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0.28rem 0.62rem;
  border: 1px solid rgba(201, 168, 76, 0.14);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.16);
  color: var(--parchment);
  text-decoration: none;
}

.codex__detail-meta .codex__meta-pill {
  border-color: color-mix(in srgb, var(--rarity-color, var(--family-color, var(--gold))) 62%, transparent);
  background: color-mix(in srgb, var(--rarity-color, var(--family-color, var(--gold))) 18%, rgba(0, 0, 0, 0.22));
  color: color-mix(in srgb, var(--rarity-color, var(--family-color, var(--gold))) 64%, var(--parchment));
}

.codex__family-pill {
  color: color-mix(in srgb, var(--family-color, var(--gold)) 70%, var(--parchment));
}

.codex__family-pill:hover {
  color: var(--family-color, var(--gold));
}

.codex__detail-meta a:hover {
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.32);
}

.codex__detail-lede {
  max-width: 66ch;
  margin-top: 0.9rem;
  color: rgba(241, 226, 190, 0.9);
  font-family: var(--font-body);
  font-size: clamp(1.02rem, 1.7vw, 1.2rem);
  font-style: italic;
  line-height: 1.45;
}

.codex__entry-ledger {
  grid-area: ledger;
  align-self: start;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(201, 168, 76, 0.08), rgba(0, 0, 0, 0.14)),
    rgba(0, 0, 0, 0.2);
}

.codex__entry-ledger h2 {
  margin-bottom: 0.75rem;
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex__entry-ledger dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 0.65rem 0.85rem;
}

.codex__entry-ledger dt,
.codex__fact-grid dt {
  margin-bottom: 0.18rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex__entry-ledger dd,
.codex__fact-grid dd {
  margin: 0;
  color: var(--parchment);
  font-size: 0.92rem;
  line-height: 1.25;
}

.codex__entry-ledger a {
  color: color-mix(in srgb, var(--family-color, var(--gold)) 70%, var(--parchment));
  text-decoration: underline;
  text-decoration-color: var(--gold-dim);
}

.codex__inline-link {
  color: var(--parchment);
  text-decoration: underline;
  text-decoration-color: var(--gold-dim);
  text-underline-offset: 0.18em;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.codex__inline-link:hover {
  color: var(--gold);
  text-decoration-color: var(--gold);
}

.codex__detail-body {
  display: grid;
  gap: 1rem;
}

.codex__detail-body--folio {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}

.codex__detail-body--book {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: clamp(0.9rem, 2vw, 1.25rem);
}

.codex__potion-art-banner + .codex__detail-body--book {
  position: relative;
  z-index: 2;
  margin-top: clamp(-3.8rem, -5vw, -1.6rem);
}

.codex__detail-column {
  display: grid;
  gap: 1rem;
  align-content: start;
  min-width: 0;
}

.codex__detail-body--book .codex__section {
  grid-column: auto;
}

.codex__section {
  grid-column: span 6;
  min-width: 0;
  background:
    radial-gradient(circle at 0 0, rgba(201, 168, 76, 0.08), transparent 34%),
    linear-gradient(135deg, rgba(31, 28, 26, 0.94), rgba(18, 18, 24, 0.92));
  border: 1px solid rgba(201, 168, 76, 0.13);
  border-radius: 18px;
  padding: 1.05rem 1.1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.codex__section--wide {
  grid-column: span 12;
}

.codex__section--major {
  grid-column: span 7;
}

.codex__section--side {
  grid-column: span 5;
}

.codex__section--effect,
.codex__section--formula {
  border-color: rgba(201, 168, 76, 0.2);
  background:
    radial-gradient(circle at 0 0, rgba(201, 168, 76, 0.12), transparent 34%),
    linear-gradient(135deg, rgba(39, 31, 24, 0.96), rgba(18, 18, 24, 0.94));
}

.codex__section--family-card {
  border-color: color-mix(in srgb, var(--entry-family-color, var(--gold)) 22%, rgba(201, 168, 76, 0.12));
  border-top-color: color-mix(in srgb, var(--entry-rarity-color, var(--gold)) 28%, rgba(201, 168, 76, 0.18));
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--entry-family-color, var(--gold)) 8%, transparent), transparent 42%),
    radial-gradient(circle at 0 0, rgba(201, 168, 76, 0.08), transparent 34%),
    linear-gradient(135deg, rgba(31, 28, 26, 0.94), rgba(18, 18, 24, 0.92));
  box-shadow:
    0 0 34px color-mix(in srgb, var(--entry-family-color, var(--gold)) 7%, transparent),
    inset 0 2px 0 color-mix(in srgb, var(--entry-rarity-color, var(--gold)) 20%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.codex__section--reference {
  position: relative;
  overflow: hidden;
  padding: 1.05rem 1.15rem 1.15rem;
}

.codex__reference-heading {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-right: clamp(3.7rem, 8vw, 6.4rem);
}

.codex__reference-heading > div {
  min-width: 0;
}

.codex__potion-sigil {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 0;
  width: clamp(4.2rem, 9vw, 7.8rem);
  height: auto;
  opacity: 0.24;
  filter:
    invert(1)
    sepia(0.18)
    saturate(1.3)
    brightness(1.25)
    drop-shadow(0 0 18px color-mix(in srgb, var(--entry-family-color, var(--gold)) 32%, transparent));
  mix-blend-mode: screen;
}

.codex__section--reference > *:not(.codex__potion-sigil) {
  position: relative;
  z-index: 1;
}

.codex__page-mark {
  position: absolute;
  top: 0;
  right: 0;
  color: var(--stone);
  font-family: var(--font-heading);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex__detail-lede--reference {
  max-width: none;
  margin: 0.95rem 0 1rem;
  padding-bottom: 0.95rem;
  border-bottom: 1px solid rgba(201, 168, 76, 0.12);
}

.codex__reference-block {
  padding-top: 0.9rem;
  margin-top: 0.9rem;
  border-top: 1px solid rgba(201, 168, 76, 0.12);
}

.codex__reference-block:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.codex__reference-block h3,
.codex__formula-ingredients h3 {
  margin-bottom: 0.62rem;
  color: color-mix(in srgb, var(--entry-family-color, #4d0000) 16%, var(--gold) 84%);
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.codex__ingredient-notes {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 1rem;
  align-items: start;
}

.codex__section--ingredient-note {
  height: 100%;
  background:
    radial-gradient(circle at 0 0, rgba(201, 168, 76, 0.09), transparent 34%),
    linear-gradient(135deg, rgba(28, 25, 23, 0.9), rgba(14, 14, 19, 0.86));
}

.codex__section--ingredient-uses {
  grid-column: span 1;
}

.codex__ingredient-use-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.7rem;
}

.codex__ingredient-use-card {
  min-width: 0;
  padding: 0.78rem 0.82rem;
  border: 1px solid rgba(201, 168, 76, 0.12);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(201, 168, 76, 0.06), transparent),
    rgba(0, 0, 0, 0.18);
}

.codex__ingredient-use-card h3 {
  margin-bottom: 0.45rem;
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: 0.86rem;
  line-height: 1.2;
  text-transform: uppercase;
}

.codex__ingredient-use-card p {
  margin: 0;
  color: var(--stone);
  font-size: 0.88rem;
  line-height: 1.35;
}

.codex__ingredient-use-card strong {
  color: var(--gold-dim);
  font-weight: 400;
}

.codex__section-title {
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
  margin-bottom: 0.75rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(201, 168, 76, 0.15);
}

.codex__section p,
.codex__section li {
  color: var(--parchment-dim);
  margin-bottom: 0.55rem;
  line-height: 1.42;
}

.codex__section ul {
  list-style: none;
  padding-left: 0;
}

.codex__section ol {
  counter-reset: codex-step;
  list-style: none;
  padding-left: 0;
}

.codex__section li {
  position: relative;
  padding-left: 1.25rem;
}

.codex__section ul > li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--gold-dim);
}

.codex__section ol > li {
  counter-increment: codex-step;
  padding-left: 2rem;
}

.codex__section ol > li::before {
  content: counter(codex-step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.08rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.codex__effect-label {
  color: color-mix(in srgb, var(--gold) 86%, var(--parchment));
  font-weight: 400;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.codex__fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin: 0 0 0.9rem;
}

.codex__fact-grid > div {
  padding: 0.65rem 0.72rem;
  border: 1px solid rgba(201, 168, 76, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.codex__line-list {
  display: grid;
  gap: 0.38rem;
  margin: 0;
}

.codex__line-list > div {
  display: grid;
  grid-template-columns: minmax(6.8rem, auto) minmax(0, 1fr);
  gap: 0.65rem;
  align-items: baseline;
}

.codex__line-list dt,
.codex__formula-stats dt {
  color: color-mix(in srgb, var(--gold) 84%, var(--parchment));
  font-family: var(--font-heading);
  font-size: 0.76rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.codex__line-list dd,
.codex__formula-stats dd {
  color: var(--parchment-dim);
  margin: 0;
  line-height: 1.35;
}

.codex__compact-list {
  display: grid;
  gap: 0.42rem;
}

.codex__formula-head {
  display: grid;
  grid-template-columns: minmax(140px, 0.72fr) minmax(0, 1.28fr);
  gap: clamp(0.85rem, 2vw, 1.15rem);
  align-items: start;
  margin-bottom: 0.95rem;
}

.codex__formula-stats {
  display: grid;
  gap: 0.42rem;
  margin: 0;
}

.codex__formula-stats > div {
  display: grid;
  grid-template-columns: 3.45rem minmax(0, 1fr);
  gap: 0.55rem;
  align-items: baseline;
}

.codex__formula-ingredients {
  min-width: 0;
  padding-left: 1rem;
  border-left: 1px solid rgba(201, 168, 76, 0.12);
}

.codex__formula-ingredient-list {
  display: grid;
  gap: 0.38rem;
}

.codex__formula-ingredient-list li {
  margin-bottom: 0;
}

.codex__formula-procedure {
  padding-top: 0.9rem;
  border-top: 1px solid rgba(201, 168, 76, 0.12);
}

.codex__mix-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.codex__mix {
  position: relative;
  overflow: hidden;
  padding: 0.95rem 1rem 1rem;
  background:
    radial-gradient(circle at 0 0, color-mix(in srgb, var(--mix-family-color, var(--gold)) 8%, transparent), transparent 46%),
    rgba(0, 0, 0, 0.22);
  border: 1px solid color-mix(in srgb, var(--mix-family-color, var(--gold)) 20%, transparent);
  border-left: 2px solid color-mix(in srgb, var(--mix-family-color, var(--gold)) 74%, transparent);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.codex__mix::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: color-mix(in srgb, var(--mix-family-color, var(--gold)) 82%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--mix-family-color, var(--gold)) 22%, transparent);
}

.codex__mix-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.codex__mix-name {
  font-family: var(--font-heading);
  color: var(--parchment);
  text-transform: uppercase;
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.06em;
}

.codex__mix-heading span {
  color: var(--stone);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.codex__mix-target {
  font-size: 0.9125rem;
  color: var(--parchment-dim);
  margin-bottom: 0.75rem;
}

.codex__mix-target a {
  color: color-mix(in srgb, var(--family-color, var(--gold)) 70%, var(--parchment));
  text-decoration: none;
}

.codex__mix-target a:hover {
  color: var(--family-color, var(--gold));
  text-decoration: underline;
}

.codex__mix-block {
  padding-top: 0.72rem;
  margin-top: 0.72rem;
  border-top: 1px solid rgba(201, 168, 76, 0.1);
}

.codex__mix-block h5 {
  margin-bottom: 0.35rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex__mix-block p {
  margin-bottom: 0;
}

.codex__entry-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
}

.codex__entry-nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.24rem 0.68rem;
  border: 1px solid rgba(201, 168, 76, 0.13);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  color: var(--parchment-dim);
  font-size: 0.95rem;
  text-decoration: none;
  transition: border-color 0.22s ease, background 0.22s ease, transform 0.22s ease;
}

.codex__entry-nav-link:hover {
  border-color: rgba(201, 168, 76, 0.34);
  background: rgba(201, 168, 76, 0.08);
  color: var(--gold);
  transform: translateY(-1px);
}

.codex__entry-nav-link--next {
  text-align: right;
}

.codex__entry-nav-link--next:hover {
  background: rgba(201, 168, 76, 0.08);
}

.codex__entry-nav-link span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex__entry-nav-link strong {
  display: block;
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: 1rem;
  line-height: 1.2;
  text-transform: uppercase;
}

/* Annotations view */
.codex__annotations-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--stone);
}

.codex__annotation-form {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.codex__annotation-form textarea {
  min-height: 120px;
  resize: vertical;
}

.codex__entry-annotations {
  margin-top: 2rem;
  padding: clamp(1.2rem, 3vw, 1.7rem);
  border: 1px solid rgba(201, 168, 76, 0.14);
  border-radius: 18px;
  background:
    radial-gradient(circle at 8% 0%, rgba(201, 168, 76, 0.1), transparent 32%),
    rgba(18, 18, 24, 0.78);
}

.codex__annotation-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.codex__annotation-intro h2 {
  color: var(--parchment);
  font-family: var(--font-heading);
  font-size: 1.15rem;
  text-transform: uppercase;
}

.codex__annotation-intro > p {
  max-width: 440px;
  color: var(--stone);
  font-size: 0.92rem;
  text-align: right;
}

.codex__target-annotation-form {
  display: grid;
  gap: 0.75rem;
}

.codex__target-annotation-form textarea {
  min-height: 105px;
  resize: vertical;
}

.codex__annotation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.codex__private-annotations,
.codex__public-annotations {
  margin-top: 1rem;
  border-top: 1px solid rgba(201, 168, 76, 0.1);
}

.codex__private-annotations {
  border-top-color: rgba(201, 168, 76, 0.16);
}

.codex__private-annotations summary,
.codex__public-annotations summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0 0;
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.codex__private-annotations summary::marker,
.codex__public-annotations summary::marker {
  color: var(--gold-dim);
}

.codex__private-annotations summary span:last-child,
.codex__public-annotations summary span:last-child {
  display: inline-grid;
  place-items: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: rgba(201, 168, 76, 0.1);
  color: var(--parchment-dim);
  font-size: 0.7rem;
}

.codex__private-annotation-list,
.codex__public-annotation-list {
  display: grid;
  gap: 0.75rem;
  padding-top: 1rem;
}

.codex__public-note {
  padding: 0.95rem 1rem;
  border: 1px solid rgba(201, 168, 76, 0.09);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
}

.codex__public-note--owned {
  border-color: rgba(201, 168, 76, 0.18);
  background:
    radial-gradient(circle at 0 0, rgba(201, 168, 76, 0.08), transparent 36%),
    rgba(0, 0, 0, 0.22);
}

.codex__public-note-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.45rem;
}

.codex__public-note-meta strong {
  color: var(--gold);
}

.codex__public-note-author {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.codex__public-note-author img {
  width: 1.9rem;
  height: 1.9rem;
  object-fit: cover;
  border: 1px solid rgba(201, 168, 76, 0.22);
  border-radius: 50%;
}

.codex__public-note-tools {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.42rem;
}

.codex__public-note-meta span,
.codex__public-note time,
.codex__annotation-card time {
  color: var(--stone);
  font-size: 0.8rem;
}

.codex__annotation-votes {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
  padding: 0.22rem;
  border: 1px solid rgba(201, 168, 76, 0.1);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
}

.codex__annotation-votes button {
  display: grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--stone);
  font-size: 0.68rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.codex__annotation-votes button:hover,
.codex__annotation-votes button.is-active {
  border-color: rgba(201, 168, 76, 0.28);
  background: rgba(201, 168, 76, 0.08);
  color: var(--gold);
}

.codex__annotation-votes span {
  min-width: 2rem;
  color: var(--parchment-dim);
  font-family: var(--font-heading);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-align: center;
}

.codex__annotation-archive {
  display: grid;
  gap: 0.85rem;
}

.codex__annotation-card {
  padding: 1rem 1.1rem;
  border: 1px solid rgba(201, 168, 76, 0.12);
  border-radius: 14px;
  background: rgba(24, 24, 30, 0.78);
}

.codex__annotation-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.codex__annotation-card-heading > div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.codex__annotation-card-actions {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.42rem;
}

.codex__annotation-card-heading a,
.codex__annotation-card-heading span {
  color: var(--parchment-dim);
}

.codex__annotation-view p {
  margin-bottom: 0.55rem;
}

.codex__annotation-edit-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.8rem;
  padding: 0.22rem 0.68rem;
  border: 1px solid rgba(201, 168, 76, 0.18);
  border-radius: 999px;
  background: rgba(201, 168, 76, 0.06);
  color: var(--parchment-dim);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.codex__annotation-edit-toggle:hover {
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.36);
  background: rgba(201, 168, 76, 0.1);
}

.codex__annotation-delete {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid rgba(166, 58, 58, 0.26);
  border-radius: 999px;
  background: rgba(139, 46, 46, 0.08);
  color: var(--parchment-dim);
  font-size: 1rem;
  cursor: pointer;
}

.codex__annotation-delete:hover {
  color: #e9b1b1;
  border-color: rgba(166, 58, 58, 0.5);
}

.codex__annotation-edit-form {
  display: none;
  gap: 0.75rem;
  padding-top: 0.2rem;
}

.codex__annotation-card.is-editing .codex__annotation-view,
.codex__public-note.is-editing .codex__annotation-view {
  display: none;
}

.codex__annotation-card.is-editing .codex__annotation-edit-form,
.codex__public-note.is-editing .codex__annotation-edit-form {
  display: grid;
}

.codex__annotation-card.is-editing .codex__annotation-edit-toggle,
.codex__public-note.is-editing .codex__annotation-edit-toggle {
  color: var(--gold);
  border-color: rgba(201, 168, 76, 0.36);
}

.codex__annotation-edit-form textarea {
  min-height: 7rem;
  resize: vertical;
}

.codex__annotation-edit-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.85rem;
}

.codex__annotation-edit-controls label {
  display: grid;
  flex: 1 1 14rem;
  gap: 0.35rem;
  color: var(--gold-dim);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.codex__annotation-edit-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Utility */
.codex__badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  background: rgba(139, 46, 46, 0.2);
  color: var(--blood-bright);
}

.codex__notice {
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: 4px;
  padding: 1rem;
  color: var(--parchment-dim);
  font-size: 0.95rem;
}

@media (max-width: 900px) {
  .codex__detail-hero {
    grid-template-columns: 1fr;
    grid-template-areas:
      "heading"
      "art";
  }

  .codex__detail-hero--potion {
    grid-template-areas:
      "art"
      "heading";
  }

  .codex__detail-artwork {
    max-width: 560px;
    width: 100%;
  }

  .codex__detail-artwork img {
    max-height: 420px;
  }

  .codex__entry-ledger dl {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .codex__detail-body--folio {
    grid-template-columns: 1fr;
  }

  .codex__detail-body--book,
  .codex__ingredient-notes {
    grid-template-columns: 1fr;
  }

  .codex__section--ingredient-uses {
    grid-column: 1;
  }

  .codex__section,
  .codex__section--wide,
  .codex__section--major,
  .codex__section--side {
    grid-column: 1;
  }
}

@media (max-width: 760px) {
  .codex__header {
    min-height: 3.15rem;
    padding: 0.48rem 0.75rem;
  }

  .codex__brand,
  .codex__nav {
    display: none;
  }

  .codex__mobile-bar {
    display: block;
    min-height: 2.15rem;
  }

  .codex__mobile-mark,
  .codex__mobile-toggle,
  .codex__mobile-title {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  .codex__mobile-mark {
    left: 0;
  }

  .codex__mobile-toggle {
    right: 0;
  }

  .codex__mobile-title {
    left: 50%;
    width: min(54vw, calc(100% - 8rem));
    transform: translate(-50%, -50%);
  }

  .codex__mobile-menu {
    position: fixed;
    top: 3.55rem;
    left: 0.75rem;
    right: 0.75rem;
    z-index: 1001;
    display: block;
  }

  .codex__main {
    padding-top: 1.1rem;
  }

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

  .codex__formula-ingredients {
    padding-top: 0.8rem;
    padding-left: 0;
    border-top: 1px solid rgba(201, 168, 76, 0.12);
    border-left: 0;
  }
}

@media (max-width: 640px) {
  .codex__header {
    padding: 0.48rem 0.75rem;
  }

  .codex__nav {
    gap: 1rem;
    justify-content: center;
  }

  .codex__nav-divider {
    flex-basis: 100%;
    width: min(240px, 72vw);
    height: 1px;
    margin: -0.25rem auto;
    background: linear-gradient(90deg, transparent, rgba(201, 168, 76, 0.42), transparent);
  }

  .codex__identity {
    max-width: 100%;
    max-width: min(82vw, 310px);
    justify-content: center;
  }

  .codex__main {
    padding: 1.5rem 1rem 3rem;
  }

  .codex__search-row {
    gap: 0.58rem;
  }

  #potions-filters .codex__search {
    flex: 0 0 100%;
  }

  #potions-filters .codex__filter {
    flex: 1 1 calc(50% - 0.32rem);
    min-width: 0;
  }

  .codex__potion-art-banner {
    width: 100vw;
    min-height: clamp(190px, 52vw, 260px);
    max-height: 290px;
    margin: -0.25rem calc(50% - 50vw) 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .codex__potion-art-banner img {
    object-fit: cover;
  }

  .codex__potion-art-banner + .codex__detail-body--book {
    margin-top: -1.25rem;
  }

  #codex-grid.codex__grid--potions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .codex__card--potion {
    position: relative;
    min-height: 0;
    padding: 0.72rem 0.58rem 0.78rem;
    border-radius: 13px;
    text-align: center;
    background:
      linear-gradient(180deg, color-mix(in srgb, var(--family-color, var(--gold)) 11%, transparent), transparent 62%),
      var(--surface);
  }

  .codex__card--potion::before {
    content: '';
    position: absolute;
    top: 0.42rem;
    left: 50%;
    width: 2.4rem;
    height: 1px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--family-color, var(--gold)) 58%, transparent);
    transform: translateX(-50%);
  }

  .codex__card--potion .codex__card-image,
  .codex__card--potion .codex__card-family,
  .codex__card--potion .codex__card-rarity {
    display: none;
  }

  .codex__card--potion .codex__card-name {
    margin: 0;
    padding-top: 0.24rem;
    font-size: 0.78rem;
    line-height: 1.12;
    letter-spacing: 0.04em;
  }

  #codex-ingredient-grid.codex__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .codex__card--ingredient {
    min-height: 0;
    padding: 0.62rem 0.52rem 0.7rem;
    border-radius: 13px;
  }

  .codex__card--ingredient .codex__card-image--ingredient {
    width: min(72px, 62%);
    margin: 0 auto 0.52rem;
    border-radius: 16px;
  }

  .codex__card--ingredient .codex__card-number,
  .codex__card--ingredient .codex__card-summary,
  .codex__card--ingredient .codex__card-family,
  .codex__card--ingredient .codex__card-rarity {
    display: none;
  }

  .codex__card--ingredient .codex__card-name {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.12;
    letter-spacing: 0.04em;
  }

  .codex__detail-hero {
    border-radius: 18px;
    padding: 1rem;
  }

  .codex__detail-topbar {
    align-items: center;
    flex-direction: row;
    gap: 0.4rem;
    justify-content: space-between;
  }

  .codex__detail-back,
  .codex__entry-nav-link {
    min-height: 1.8rem;
    padding: 0.2rem 0.46rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .codex__entry-nav {
    flex: 0 0 auto;
    justify-content: flex-end;
    width: auto;
    gap: 0.28rem;
  }

  .codex__detail-meta span,
  .codex__detail-meta a {
    min-height: 1.65rem;
    padding: 0.22rem 0.5rem;
  }

  .codex__detail-lede {
    font-size: 1rem;
  }

  .codex__reference-heading {
    padding-right: 3.45rem;
  }

  .codex__potion-sigil {
    top: 1.65rem;
    width: 3.8rem;
    opacity: 0.2;
  }

  .codex__page-mark {
    top: 0;
    right: 0;
  }

  .codex__entry-ledger,
  .codex__section {
    border-radius: 14px;
  }

  .codex__entry-ledger dl,
  .codex__fact-grid,
  .codex__tasting-grid,
  .codex__mix-list,
  .codex__entry-nav {
    grid-template-columns: 1fr;
  }

  .codex__line-list > div,
  .codex__formula-stats > div {
    grid-template-columns: minmax(5.7rem, auto) minmax(0, 1fr);
  }

  .codex__entry-nav-link--next {
    text-align: left;
  }

  .codex__profile-hero {
    grid-template-columns: auto minmax(0, 1fr);
    border-radius: 20px;
  }

  .codex__profile-stats {
    grid-column: 1 / -1;
    width: 100%;
  }

  .codex__profile-stats span {
    flex: 1;
  }

  .codex__profile-grid {
    grid-template-columns: 1fr;
  }

  .codex__annotation-intro {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
  }

  .codex__annotation-intro > p {
    text-align: left;
  }

  .codex__annotation-card-heading {
    gap: 0.75rem;
  }

  .codex__annotation-edit-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .codex__annotation-edit-actions {
    justify-content: flex-start;
  }

  .codex__package-card--profile {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .codex__package-card--profile .codex__package-cover {
    width: 86px;
    min-height: 130px;
    padding: 0.5rem;
  }

  .codex__package-card--profile .codex__package-body {
    display: flex;
    padding: 1rem;
  }

  .codex__package-card--profile .codex__package-actions {
    min-width: 0;
    width: 100%;
  }

  .codex__redeem-form {
    grid-template-columns: 1fr;
  }

  .codex__redeem-form .codex__btn {
    width: 100%;
  }
}
