#codex-view {
  min-height: 100vh;
  padding: 26px clamp(18px, 3vw, 48px) 58px;
  background:
    radial-gradient(circle at 86% 0, #ffffffa8, transparent 30%),
    linear-gradient(145deg, #f7f1df, #e6dcc4);
}

.codex-shell { width: min(1680px, 100%); margin: 0 auto; }

.codex-heading-panel {
  display: grid;
  grid-template-columns: 1fr minmax(270px, 360px);
  gap: 28px;
  align-items: end;
  margin-bottom: 18px;
}

.codex-heading-copy h2 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 3vw, 3rem);
}

.codex-heading-copy > p:last-child {
  max-width: 760px;
  margin: 0;
  color: #68746c;
}

.codex-progress-card {
  padding: 16px 18px;
  border: 1px solid #a99d8066;
  border-radius: 17px;
  background: #fffaf0c7;
  box-shadow: 0 8px 25px #39433112;
}

.codex-progress-card > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.codex-progress-card strong {
  color: #285b40;
  font-family: Georgia, serif;
  font-size: 1.65rem;
}

.codex-progress-card span,
.codex-progress-card small { color: #746d60; font-size: .72rem; font-weight: 800; }

.codex-progress-track {
  height: 9px;
  margin: 10px 0 6px;
  overflow: hidden;
  border-radius: 10px;
  background: #dcd4c2;
}

.codex-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #285b40, #7a5ca8);
  transition: width .35s ease;
}

.codex-element-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(125px, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}

.codex-element-chip {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 9px;
  align-items: center;
  min-width: 0;
  border: 1px solid #c7bda5;
  border-radius: 13px;
  background: #fffdf6b8;
  padding: 9px 11px;
  color: #34483b;
  text-align: left;
  cursor: pointer;
}

.codex-element-chip:hover,
.codex-element-chip.active {
  border-color: #58735e;
  background: #eef2e6;
}

.codex-element-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: #e9e1cf;
  font-size: 1.05rem;
}

.codex-element-chip span:nth-child(2) { overflow: hidden; font-size: .73rem; font-weight: 900; text-overflow: ellipsis; }
.codex-element-chip strong { color: #6d6251; font-size: .72rem; }

.codex-toolbar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: grid;
  grid-template-columns: minmax(210px, 1.4fr) repeat(4, minmax(135px, .8fr)) auto;
  gap: 10px;
  margin: 0 -8px 16px;
  padding: 13px;
  border: 1px solid #a99d8070;
  border-radius: 18px;
  background: #f8f3e8ed;
  box-shadow: 0 12px 35px #28361e22;
  backdrop-filter: blur(10px);
}

.codex-toolbar label { display: flex; min-width: 0; flex-direction: column; gap: 5px; }
.codex-toolbar label > span { padding-left: 3px; color: #746d60; font-size: .66rem; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }

.codex-toolbar input,
.codex-toolbar select {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid #b9ae91;
  border-radius: 11px;
  outline: 0;
  background: #fffdf6;
  color: #24382c;
  padding: 0 11px;
  font: inherit;
  font-size: .84rem;
  font-weight: 700;
}

.codex-toolbar input:focus,
.codex-toolbar select:focus { border-color: #326849; box-shadow: 0 0 0 3px #32684922; }

.codex-reset {
  align-self: end;
  height: 42px;
  border: 1px solid #a99d80;
  border-radius: 11px;
  background: #e8e1cf;
  color: #506057;
  padding: 0 13px;
  font-weight: 900;
  cursor: pointer;
}

.codex-reset:hover { background: #dcd2ba; }

.codex-results-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0 2px 12px;
  color: #706b60;
  font-size: .8rem;
}

.codex-results-line strong { color: #2c4f3a; }

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

.codex-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 330px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #d1c6ad;
  border-radius: 18px;
  background: #fffdf6;
  box-shadow: 0 7px 20px #253f2a0d;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

button.codex-card { width: 100%; padding: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
button.codex-card:hover { transform: translateY(-3px); border-color: #9e8d64; box-shadow: 0 14px 28px #253f2a1c; }

.codex-card-art {
  position: relative;
  display: grid;
  flex: 0 0 178px;
  height: 178px;
  min-height: 178px;
  overflow: hidden;
  place-items: center;
  padding: 30px 20px 9px;
  background: radial-gradient(circle at 50% 72%, #ebe1ca, transparent 61%);
}

.codex-card-art img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 140px;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 12px 9px #1934232c);
}

.codex-number,
.codex-status-badge {
  position: absolute;
  z-index: 2;
  top: 11px;
  border: 1px solid #ffffff9e;
  border-radius: 20px;
  background: #17271fe8;
  color: #fff7df;
  padding: 4px 9px;
  box-shadow: 0 4px 12px #0003;
  font-size: .62rem;
  font-weight: 1000;
}

.codex-number { left: 11px; }
.codex-status-badge { right: 11px; background: #316448e8; }

.codex-card-body { display: flex; flex: 1; flex-direction: column; padding: 13px 16px 16px; }
.codex-card-body h3 { overflow: hidden; margin: 0; font-family: Georgia, serif; font-size: 1.35rem; text-overflow: ellipsis; white-space: nowrap; }
.codex-card-meta { margin: 4px 0 11px; color: #6b756e; font-size: .76rem; font-weight: 750; }
.codex-location { margin: 0 0 12px; color: #726c61; font-size: .73rem; }

.codex-card-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: auto; }
.codex-card-fact { padding: 8px 4px; border-radius: 9px; background: #f0eadb; text-align: center; }
.codex-card-fact span,
.codex-card-fact strong { display: block; }
.codex-card-fact span { color: #817a6d; font-size: .55rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.codex-card-fact strong { overflow: hidden; margin-top: 2px; color: #283d30; font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }

.codex-card.unknown { cursor: default; border-style: dashed; background: #e8e2d4; box-shadow: none; }
.codex-card.unknown .codex-card-art { background: radial-gradient(circle, #d8d0bd, transparent 62%); }
.codex-card.unknown .codex-card-art img { opacity: .16; filter: brightness(0); }
.codex-lock { position: absolute; z-index: 2; color: #716b60; font-family: Georgia, serif; font-size: 3.4rem; font-weight: 900; }
.codex-card.unknown .codex-card-body { align-items: center; justify-content: center; text-align: center; }
.codex-card.unknown h3 { color: #676257; }
.codex-card.unknown p { margin: 6px 0 0; color: #888174; font-size: .76rem; }

.codex-empty {
  grid-column: 1 / -1;
  display: grid;
  min-height: 280px;
  place-items: center;
  border: 2px dashed #bfb49b;
  border-radius: 20px;
  color: #776f62;
  padding: 35px;
  text-align: center;
}

.codex-empty strong { display: block; margin-bottom: 6px; color: #344d3e; font-family: Georgia, serif; font-size: 1.35rem; }

.codex-pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 22px; }
.codex-pagination:empty { display: none; }
.codex-pagination button { min-width: 40px; height: 40px; border: 1px solid #a99d80; border-radius: 10px; background: #fffaf0; color: #405248; font-weight: 900; cursor: pointer; }
.codex-pagination button.active { border-color: #285b40; background: #285b40; color: white; }
.codex-pagination button:disabled { opacity: .4; cursor: default; }
.codex-page-label { margin: 0 5px; color: #70695e; font-size: .78rem; font-weight: 850; }

.codex-details-overlay {
  position: fixed;
  z-index: 95;
  inset: 0;
  display: none;
  place-items: center;
  overflow: auto;
  background: #06120deb;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.codex-details-overlay.show { display: grid; }
.codex-details-panel { position: relative; width: min(1120px, 100%); max-height: 94vh; overflow: auto; border: 1px solid #c8b88c; border-radius: 25px; background: #f8f3e4; box-shadow: 0 28px 90px #000a; }
.codex-details-close { position: absolute; z-index: 5; top: 14px; right: 14px; width: 40px; height: 40px; border: 1px solid #ffffff55; border-radius: 50%; background: #10231de8; color: white; font-size: 1.55rem; line-height: 1; cursor: pointer; }

.codex-details-hero {
  display: grid;
  grid-template-columns: minmax(300px, .8fr) 1.2fr;
  min-height: 340px;
  background: radial-gradient(circle at 24% 62%, #e4d8bd, transparent 31%), linear-gradient(130deg, #efe6d2, #fffaf0);
}

.codex-details-art { display: grid; min-height: 320px; place-items: center; padding: 35px; }
.codex-details-art img { width: 100%; height: 285px; object-fit: contain; filter: drop-shadow(0 18px 14px #24113235); }
.codex-details-summary { align-self: center; padding: 46px 65px 38px 15px; }
.codex-details-summary h2 { margin: 3px 0 8px; font-family: Georgia, serif; font-size: clamp(2.2rem, 4vw, 3.4rem); }
.codex-details-summary > p { color: #68746c; }
.codex-details-pills { display: flex; flex-wrap: wrap; gap: 7px; margin: 18px 0; }
.codex-details-pill { padding: 7px 10px; border: 1px solid #d4c8ad; border-radius: 20px; background: #fffdf6b8; color: #46564d; font-size: .74rem; font-weight: 900; }

.codex-affinities { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codex-affinity { padding: 10px 12px; border-radius: 11px; background: #e8efdf; color: #385342; font-size: .75rem; }
.codex-affinity.weak { background: #f1e2dc; color: #7d493e; }
.codex-affinity span,
.codex-affinity strong { display: block; }
.codex-affinity span { font-size: .58rem; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }

.codex-details-body { display: grid; gap: 16px; padding: 18px; }
.codex-detail-section { min-width: 0; border: 1px solid #d8d0b9; border-radius: 18px; background: #fffdf6; padding: 18px; }
.codex-detail-section h3 { margin: 0 0 4px; font-family: Georgia, serif; font-size: 1.3rem; }
.codex-detail-section > p { margin: 0 0 15px; color: #7a7468; font-size: .78rem; }

.codex-base-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 15px; }
.codex-base-stat { padding: 12px; border-radius: 12px; background: #eee8d8; text-align: center; }
.codex-base-stat span,
.codex-base-stat strong { display: block; }
.codex-base-stat span { color: #80796c; font-size: .62rem; font-weight: 900; text-transform: uppercase; }
.codex-base-stat strong { margin-top: 3px; color: #2c4334; font-size: 1.15rem; }

.codex-evolution-line { display: flex; align-items: center; gap: 9px; overflow-x: auto; padding: 8px 2px 13px; }
.codex-evolution-form { flex: 1 0 190px; min-width: 190px; padding: 12px; border: 1px solid #ded3bc; border-radius: 14px; background: #faf6eb; text-align: center; }
.codex-evolution-form img { width: 100%; height: 145px; object-fit: contain; }
.codex-evolution-form strong,
.codex-evolution-form span { display: block; }
.codex-evolution-form strong { margin-top: 4px; font-family: Georgia, serif; font-size: 1.03rem; }
.codex-evolution-form span { color: #7a7468; font-size: .7rem; font-weight: 800; }
.codex-evolution-arrow { flex: 0 0 auto; color: #9b895b; font-size: 1.4rem; }

.codex-evolution-form.locked {
  border-style: dashed;
  border-color: #9d9686;
  background: linear-gradient(145deg, #ddd7ca, #c9c2b4);
  color: #686257;
}
.codex-form-mystery {
  display: grid;
  height: 145px;
  place-items: center;
  color: #716b60;
  text-shadow: 0 2px 0 #fff6;
  font-family: Georgia, serif;
  font-size: 4.2rem;
  font-weight: 900;
}

.codex-moves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.codex-move { display: grid; grid-template-columns: 44px 1fr; gap: 11px; align-items: start; padding: 12px; border-radius: 13px; background: #eee8d8; }
.codex-move-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 11px; background: #dfd5bf; font-size: 1.1rem; }
.codex-move strong,
.codex-move small { display: block; }
.codex-move strong { color: #2e4336; font-size: .84rem; }
.codex-move small { margin-top: 4px; color: #6f6a60; font-size: .72rem; line-height: 1.35; }
.codex-move em {
  display: inline-block;
  margin-top: 7px;
  border-radius: 20px;
  background: #3c7552;
  color: white;
  padding: 3px 7px;
  font-size: .52rem;
  font-style: normal;
  font-weight: 1000;
  letter-spacing: .06em;
}
.codex-move.observed { border: 1px solid #b99749; background: #f0e5c8; }
.codex-move.observed .codex-move-icon { background: #dcc890; color: #66531e; }
.codex-move.observed em { background: #97772d; }
.codex-move.unknown { border: 1px dashed #aca493; background: #dfdbd0; }
.codex-move.unknown .codex-move-icon { background: #c9c3b7; color: #6e685d; font-family: Georgia, serif; font-size: 1.5rem; font-weight: 900; }
.codex-move.unknown strong,
.codex-move.unknown small { color: #777167; }
.codex-move.unknown em { background: #858075; }

@media (max-width: 1100px) {
  .codex-element-summary { grid-template-columns: repeat(3, 1fr); }
  .codex-toolbar { grid-template-columns: repeat(3, minmax(145px, 1fr)); }
  .codex-search { grid-column: span 2; }
}

@media (max-width: 720px) {
  #codex-view { padding: 18px 12px 38px; }
  .codex-heading-panel { grid-template-columns: 1fr; gap: 17px; }
  .codex-element-summary { display: flex; overflow-x: auto; padding-bottom: 3px; }
  .codex-element-chip { flex: 0 0 155px; }
  .codex-toolbar { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 0 14px; padding: 10px; }
  .codex-search { grid-column: span 2; }
  .codex-reset { grid-column: span 2; }
  .codex-results-line { align-items: flex-start; flex-direction: column; gap: 3px; }
  .codex-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .codex-card { min-height: 290px; border-radius: 14px; }
  .codex-card-art { flex-basis: 135px; height: 135px; min-height: 135px; padding: 25px 9px 6px; }
  .codex-card-art img { max-height: 104px; }
  .codex-card-body { padding: 10px; }
  .codex-card-body h3 { font-size: 1.03rem; }
  .codex-card-facts { grid-template-columns: 1fr; }
  .codex-card-fact { display: flex; justify-content: space-between; padding: 6px 8px; }
  .codex-details-overlay { padding: 8px; }
  .codex-details-panel { max-height: 97vh; border-radius: 18px; }
  .codex-details-hero { grid-template-columns: 1fr; }
  .codex-details-art { min-height: 220px; padding: 24px 45px 0; }
  .codex-details-art img { height: 200px; }
  .codex-details-summary { padding: 12px 20px 24px; }
  .codex-base-stats { grid-template-columns: repeat(2, 1fr); }
  .codex-moves { grid-template-columns: 1fr; }
  .codex-evolution-form { flex-basis: 155px; min-width: 155px; }
  .codex-evolution-form img { height: 115px; }
  .codex-form-mystery { height: 115px; }
}

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