.is-codex-screen .floating-inventory { display: none !important; }
#game-screen.is-codex-screen { padding-bottom: 0; }

.codex-screen {
  width: min(1500px, 100%);
  min-height: calc(100dvh - 112px);
  padding: 18px clamp(14px, 3vw, 44px) 44px;
  color: #e8e2cf;
  font-family: "Trebuchet MS", sans-serif;
}

.codex-shell {
  position: relative;
  min-height: calc(100dvh - 150px);
  padding: clamp(18px, 3vw, 38px);
  overflow: hidden;
  border: 1px solid rgba(212, 180, 103, .5);
  border-radius: 20px;
  background:
    linear-gradient(135deg, transparent 14px, rgba(218, 185, 104, .4) 15px, transparent 16px) 0 0 / 34px 34px no-repeat,
    linear-gradient(225deg, transparent 14px, rgba(218, 185, 104, .4) 15px, transparent 16px) 100% 0 / 34px 34px no-repeat,
    radial-gradient(circle at 50% -10%, rgba(35, 126, 95, .22), transparent 42%),
    linear-gradient(155deg, rgba(18, 39, 29, .98), rgba(6, 17, 12, .99) 60%, rgba(11, 28, 20, .99));
  box-shadow: inset 0 0 0 4px rgba(5, 14, 10, .7), inset 0 0 0 5px rgba(206, 170, 88, .13), 0 18px 44px rgba(0, 0, 0, .48);
}

.codex-shell::before,
.codex-shell::after {
  content: "";
  position: absolute;
  z-index: 0;
  pointer-events: none;
}

.codex-shell::before {
  inset: 9px;
  border: 1px solid rgba(204, 170, 90, .12);
  border-radius: 14px;
}

.codex-shell::after {
  top: 0;
  left: 50%;
  width: min(440px, 55%);
  height: 2px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, #d0ac5b 35%, #85d9ba 50%, #d0ac5b 65%, transparent);
  box-shadow: 0 0 16px rgba(84, 211, 165, .5);
}

.codex-shell > * { position: relative; z-index: 1; }

.codex-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  padding: 4px 4px 24px;
  border-bottom: 1px solid rgba(210, 178, 100, .24);
}

.codex-kicker,
.codex-card-category,
.codex-detail-category {
  color: #66c9a6;
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.codex-heading h1 {
  margin: 2px 0 4px;
  color: #eedb9a;
  font: 700 clamp(2.2rem, 5vw, 4.25rem)/.95 var(--font-heading, Georgia, serif);
  letter-spacing: .11em;
  text-transform: uppercase;
  text-shadow: 0 2px 14px rgba(0, 0, 0, .6), 0 0 28px rgba(78, 183, 144, .14);
}

.codex-heading p { max-width: 680px; margin: 8px 0 0; color: rgba(224, 232, 221, .62); font-size: .84rem; line-height: 1.55; }

.codex-close,
.codex-view-toggle,
.codex-detail-back {
  border: 1px solid rgba(212, 179, 98, .48);
  border-radius: 999px;
  background: linear-gradient(rgba(53, 78, 57, .72), rgba(22, 43, 31, .92));
  color: #e9d697;
  font: 800 .62rem/1 "Trebuchet MS", sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}

.codex-close { flex: none; min-height: 38px; padding: 0 18px; }
.codex-close:hover,
.codex-view-toggle:hover,
.codex-detail-back:hover { border-color: #e3c46f; background: rgba(54, 111, 79, .6); transform: translateY(-1px); }

.codex-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 580px) auto;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 24px;
}

.codex-search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(103, 199, 164, .34);
  border-radius: 10px;
  background: rgba(2, 12, 8, .55);
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, .38);
}

.codex-search:focus-within { border-color: #66c9a6; box-shadow: 0 0 0 2px rgba(83, 202, 159, .11), inset 0 1px 8px rgba(0, 0, 0, .38); }
.codex-search > span { color: #77d2b2; font: 1.5rem/1 Georgia, serif; }
.codex-search input { width: 100%; border: 0; outline: 0; background: transparent; color: #f1eddf; font: .82rem "Trebuchet MS", sans-serif; }
.codex-search input::placeholder { color: rgba(221, 231, 222, .4); }

.codex-discovered-count { color: #d8c47e; font: 700 .68rem var(--font-heading, Georgia, serif); letter-spacing: .05em; text-align: right; }

.codex-filters {
  display: flex;
  gap: 7px;
  margin: 17px -4px 0;
  padding: 4px 4px 10px;
  overflow-x: auto;
  scrollbar-color: rgba(104, 190, 157, .5) transparent;
  scrollbar-width: thin;
}

.codex-filter {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(210, 178, 100, .24);
  border-radius: 8px;
  background: rgba(18, 42, 30, .62);
  color: rgba(232, 226, 207, .68);
  font: 700 .61rem "Trebuchet MS", sans-serif;
  white-space: nowrap;
  cursor: pointer;
}

.codex-filter span { color: rgba(116, 205, 173, .72); font-size: .53rem; }
.codex-filter:hover { border-color: rgba(109, 202, 168, .7); color: #f1ead5; }
.codex-filter.is-active { border-color: rgba(225, 191, 105, .72); background: linear-gradient(rgba(76, 118, 82, .55), rgba(24, 55, 38, .8)); color: #f0d98e; box-shadow: inset 0 0 12px rgba(84, 196, 156, .11), 0 0 10px rgba(0, 0, 0, .3); }

.codex-results-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 10px 2px 14px; color: rgba(222, 229, 218, .46); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; }
.codex-view-toggle { min-height: 30px; padding: 0 12px; font-size: .53rem; }

.codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.codex-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 280px;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(207, 172, 89, .3);
  border-radius: 13px;
  background: linear-gradient(155deg, rgba(31, 61, 43, .8), rgba(8, 23, 16, .95) 58%, rgba(15, 34, 24, .96));
  color: #ece8da;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .018), 0 8px 20px rgba(0, 0, 0, .3);
  transition: transform .18s, border-color .18s, box-shadow .18s;
}

.codex-card::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(226, 196, 118, .07); border-radius: 9px; pointer-events: none; }
.codex-card:hover,
.codex-card:focus-visible { outline: 0; transform: translateY(-3px); border-color: rgba(226, 193, 105, .72); box-shadow: inset 0 0 18px rgba(74, 174, 137, .08), 0 13px 28px rgba(0, 0, 0, .46); }

.codex-image-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  min-height: 112px;
  overflow: hidden;
  background: radial-gradient(circle, rgba(76, 173, 137, .14), transparent 62%), linear-gradient(rgba(4, 14, 9, .25), rgba(4, 12, 8, .63));
}

.codex-card > .codex-image-frame { height: 132px; border-bottom: 1px solid rgba(210, 174, 89, .18); }
.codex-entry-image { position: relative; z-index: 1; width: min(108px, 72%); height: 108px; object-fit: contain; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .56)); }
.codex-entry-image[src*="viridian-hollow-map/locations"] { width: 100%; height: 100%; object-fit: cover; opacity: .8; }
.codex-entry-image.is-obscured { opacity: .22; filter: grayscale(1) brightness(.38) contrast(1.25) drop-shadow(0 7px 8px rgba(0, 0, 0, .7)); }
.codex-image-fallback { position: absolute; color: rgba(101, 196, 161, .16); font: 700 3.5rem/1 var(--font-heading, Georgia, serif); }
.codex-image-frame:not(.is-missing) > img:not([hidden]) + .codex-image-fallback { opacity: 0; }
.codex-image-frame.is-missing .codex-image-fallback { opacity: 1; }

.codex-card-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; padding: 14px 15px 15px; }
.codex-card-copy strong { width: 100%; margin: 4px 0 7px; overflow: hidden; color: #f1e3b6; font: 700 1.1rem/1.12 var(--font-heading, Georgia, serif); text-overflow: ellipsis; white-space: nowrap; }
.codex-card-description { display: -webkit-box; overflow: hidden; color: rgba(221, 228, 216, .56); font-size: .66rem; line-height: 1.42; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.codex-card-status { display: inline-flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 12px; color: rgba(224, 214, 180, .57); font-size: .54rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.codex-card-status i { width: 6px; height: 6px; border-radius: 50%; background: #63c9a5; box-shadow: 0 0 7px rgba(99, 201, 165, .7); }
.is-undiscovered .codex-card-status i { background: #59645e; box-shadow: none; }
.is-partial .codex-card-status i { background: #d2ad60; box-shadow: 0 0 7px rgba(210, 173, 96, .55); }
.codex-card.is-undiscovered { border-color: rgba(146, 151, 138, .16); background: linear-gradient(155deg, rgba(31, 43, 36, .62), rgba(6, 14, 10, .95)); }

.codex-list { display: flex; flex-direction: column; gap: 7px; }
.codex-list-row { display: grid; grid-template-columns: 48px minmax(160px, 1fr) minmax(110px, .45fr) minmax(120px, .35fr); align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 5px 13px 5px 5px; border: 1px solid rgba(207, 172, 89, .24); border-radius: 9px; background: rgba(12, 31, 21, .78); color: rgba(231, 229, 217, .62); text-align: left; cursor: pointer; }
.codex-list-row:hover { border-color: rgba(222, 188, 101, .68); background: rgba(25, 57, 39, .75); }
.codex-list-row .codex-image-frame { min-height: 46px; height: 46px; border-radius: 6px; }
.codex-list-image { position: relative; z-index: 1; width: 40px; height: 40px; object-fit: contain; }
.codex-list-row strong { color: #eadcae; font: 700 .86rem var(--font-heading, Georgia, serif); }
.codex-list-status { color: rgba(106, 203, 168, .7); font-size: .57rem; text-align: right; text-transform: uppercase; }

.codex-empty { grid-column: 1 / -1; display: grid; place-items: center; min-height: 230px; border: 1px dashed rgba(210, 178, 100, .24); border-radius: 13px; color: rgba(231, 225, 206, .5); text-align: center; }
.codex-empty strong { align-self: end; color: #d9c27a; font: 700 1.2rem var(--font-heading, Georgia, serif); }
.codex-empty span { align-self: start; margin-top: 6px; font-size: .67rem; }

.codex-detail-back { margin: 24px 0 14px; min-height: 36px; padding: 0 15px; }
.codex-detail-card { overflow: hidden; border: 1px solid rgba(211, 178, 97, .43); border-radius: 16px; background: linear-gradient(145deg, rgba(23, 54, 38, .8), rgba(5, 17, 11, .92)); box-shadow: 0 14px 34px rgba(0, 0, 0, .38); }
.codex-detail-hero { display: grid; grid-template-columns: minmax(210px, 34%) 1fr; align-items: center; min-height: 290px; border-bottom: 1px solid rgba(211, 178, 97, .22); background: radial-gradient(circle at 16% 50%, rgba(75, 185, 144, .17), transparent 36%); }
.codex-detail-hero > .codex-image-frame { min-height: 290px; border-right: 1px solid rgba(211, 178, 97, .16); }
.codex-detail-image { position: relative; z-index: 1; width: min(260px, 80%); height: 240px; object-fit: contain; filter: drop-shadow(0 14px 16px rgba(0, 0, 0, .58)); }
.codex-detail-image[src*="viridian-hollow-map/locations"] { width: 100%; height: 100%; object-fit: cover; opacity: .78; }
.codex-detail-image.is-obscured { opacity: .18; filter: grayscale(1) brightness(.35); }
.codex-detail-hero > div { padding: clamp(22px, 4vw, 48px); }
.codex-detail-hero h2 { margin: 5px 0 4px; color: #f0dfa8; font: 700 clamp(1.9rem, 4vw, 3.4rem)/1 var(--font-heading, Georgia, serif); }
.codex-detail-hero p { max-width: 700px; margin: 18px 0 0; color: rgba(224, 230, 218, .67); font-size: .78rem; line-height: 1.65; }
.codex-detail-body { padding: clamp(18px, 3vw, 36px); }
.codex-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 9px; margin: 0 0 25px; }
.codex-facts > div { min-height: 76px; padding: 13px; border: 1px solid rgba(106, 197, 164, .2); border-radius: 9px; background: rgba(4, 17, 11, .46); }
.codex-facts dt { color: rgba(220, 225, 213, .44); font-size: .53rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.codex-facts dd { margin: 6px 0 0; color: #e5ce84; font: 700 .84rem var(--font-heading, Georgia, serif); }
.codex-facts dd small { display: block; margin-top: 6px; overflow-wrap: anywhere; color: rgba(100, 205, 167, .54); font: .48rem/1.35 "Trebuchet MS", sans-serif; }

.codex-detail-section { margin-top: 25px; }
.codex-detail-section h3 { display: flex; align-items: center; gap: 9px; margin: 0 0 11px; color: #d8bd6f; font: 700 1rem var(--font-heading, Georgia, serif); letter-spacing: .04em; }
.codex-detail-section h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(211, 178, 97, .3), transparent); }
.codex-detail-section h3 span { order: 2; color: rgba(102, 201, 166, .62); font: .53rem "Trebuchet MS", sans-serif; }
.codex-relations,
.codex-requirements { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 9px; }
.codex-relation,
.codex-requirements button { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 10px; min-height: 62px; padding: 4px 11px 4px 4px; border: 1px solid rgba(211, 178, 97, .2); border-radius: 8px; background: rgba(12, 35, 23, .72); color: #e9dfbd; text-align: left; cursor: pointer; }
.codex-relation:hover,
.codex-requirements button:hover { border-color: rgba(109, 207, 171, .6); background: rgba(26, 66, 44, .66); }
.codex-relation .codex-image-frame,
.codex-requirements .codex-image-frame { min-height: 52px; height: 52px; border-radius: 6px; }
.codex-relation-image,
.codex-requirement-image { position: relative; z-index: 1; width: 45px; height: 45px; object-fit: contain; }
.codex-relation strong,
.codex-requirements strong { display: block; font: 700 .75rem var(--font-heading, Georgia, serif); }
.codex-relation small,
.codex-requirements small { display: block; margin-top: 3px; color: rgba(102, 201, 166, .62); font-size: .48rem; letter-spacing: .06em; text-transform: uppercase; }
.codex-system-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.codex-system-list li { padding: 8px 11px; border: 1px solid rgba(104, 198, 164, .23); border-radius: 999px; background: rgba(17, 49, 32, .7); color: rgba(228, 226, 211, .7); font-size: .61rem; }
.codex-concealed p { margin: 0; color: rgba(226, 225, 211, .46); font-size: .68rem; font-style: italic; }
.codex-locked-detail { display: grid; place-items: center; min-height: 250px; padding: 30px; text-align: center; }
.codex-locked-detail > span { color: rgba(94, 194, 157, .34); font-size: 3rem; }
.codex-locked-detail strong { color: #d8c07a; font: 700 1.2rem var(--font-heading, Georgia, serif); }
.codex-locked-detail p { color: rgba(222, 226, 214, .48); font-size: .67rem; }

.codex-technical { padding: 16px; border: 1px solid rgba(83, 196, 155, .24); border-radius: 10px; background: rgba(2, 16, 10, .52); }
.codex-technical dl { display: grid; gap: 7px; margin: 0; }
.codex-technical dl > div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; align-items: start; }
.codex-technical dt { color: rgba(222, 225, 213, .48); font-size: .54rem; text-transform: uppercase; }
.codex-technical dd { display: flex; min-width: 0; align-items: center; gap: 8px; margin: 0; }
.codex-technical code { overflow-wrap: anywhere; color: #72d0af; font-size: .61rem; }
.codex-technical button { min-height: 24px; padding: 0 8px; border: 1px solid rgba(211, 178, 97, .4); border-radius: 5px; background: rgba(60, 84, 52, .7); color: #e5ce84; font-size: .49rem; cursor: pointer; }
.codex-technical p { min-height: 1em; margin: 8px 0 0 130px; color: rgba(229, 206, 132, .68); font-size: .52rem; }

@media (max-width: 900px) {
  #game-screen.is-codex-screen { padding-top: 268px; }
  .codex-screen { min-height: calc(100dvh - 268px); padding-top: 10px; }
  .codex-shell { min-height: calc(100dvh - 290px); }
  .codex-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}

@media (max-width: 680px) {
  .codex-screen { padding-inline: 8px; }
  .codex-shell { padding: 16px 12px 24px; border-radius: 14px; }
  .codex-heading { display: block; }
  .codex-close { margin-top: 16px; }
  .codex-toolbar { grid-template-columns: 1fr; }
  .codex-discovered-count { text-align: left; }
  .codex-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .codex-card { min-height: 238px; }
  .codex-card > .codex-image-frame { height: 106px; min-height: 106px; }
  .codex-entry-image { width: 82px; height: 82px; }
  .codex-card-copy { padding: 11px; }
  .codex-card-copy strong { font-size: .9rem; }
  .codex-card-description { font-size: .58rem; -webkit-line-clamp: 2; }
  .codex-list-row { grid-template-columns: 42px minmax(0, 1fr) auto; gap: 8px; }
  .codex-list-row > span:not(.codex-image-frame):not(.codex-list-status) { display: none; }
  .codex-list-status { font-size: .48rem; }
  .codex-detail-hero { grid-template-columns: 1fr; }
  .codex-detail-hero > .codex-image-frame { min-height: 210px; border-right: 0; border-bottom: 1px solid rgba(211, 178, 97, .16); }
  .codex-detail-image { height: 185px; }
  .codex-detail-hero > div { padding: 20px; }
  .codex-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .codex-relations,
  .codex-requirements { grid-template-columns: 1fr; }
  .codex-technical dl > div { grid-template-columns: 1fr; gap: 4px; }
  .codex-technical p { margin-left: 0; }
}

@media (max-width: 420px) {
  .codex-grid { grid-template-columns: 1fr; }
  .codex-card { min-height: 255px; }
  .codex-card > .codex-image-frame { height: 120px; }
}

html[data-ui-mode="mobile-landscape"] #game-screen.is-codex-screen { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
html[data-ui-mode="mobile-landscape"] .codex-screen { width: 100%; min-height: calc(100dvh - 70px); padding: 0 4px 8px; }
html[data-ui-mode="mobile-landscape"] .codex-shell { min-height: calc(100dvh - 70px); padding: 12px; }
html[data-ui-mode="mobile-landscape"] .codex-heading { align-items: center; padding-bottom: 12px; }
html[data-ui-mode="mobile-landscape"] .codex-heading h1 { font-size: 2rem; }
html[data-ui-mode="mobile-landscape"] .codex-heading p { display: none; }
html[data-ui-mode="mobile-landscape"] .codex-toolbar { margin-top: 12px; }
html[data-ui-mode="mobile-landscape"] .codex-filters { margin-top: 8px; }
html[data-ui-mode="mobile-landscape"] .codex-card { min-height: 220px; }
.mobile-portrait-codex { margin-top: 10px; }

html[data-ui-mode="mobile-portrait"] #game-screen.is-codex-screen { padding: 0; }
html[data-ui-mode="mobile-portrait"] #game-screen.is-codex-screen > .mobile-portrait-screen { display: none; }
html[data-ui-mode="mobile-portrait"] #game-screen.is-codex-screen > .codex-screen {
  visibility: visible;
  pointer-events: auto;
  width: 100%;
  min-height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom));
}
html[data-ui-mode="mobile-portrait"] #game-screen.is-codex-screen .codex-shell { min-height: calc(100dvh - 16px); }
