@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/cormorant-garamond-latin-v1.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Cormorant Garamond";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/cormorant-garamond-latin-italic-v1.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;

  --ink-0: #080b12;
  --ink-1: #0b1018;
  --ink-2: #101620;
  --ink-3: #171e2a;
  --ink-4: #1e2735;

  --gold: #c9a96a;
  --gold-bright: #e6cf98;
  --gold-dim: #a88b55;
  --gold-line: rgba(201, 169, 106, 0.28);
  --gold-line-strong: rgba(201, 169, 106, 0.55);
  --gold-wash: rgba(201, 169, 106, 0.09);

  --ivory: #efe6d4;
  --ivory-2: #d8cdb8;
  --muted: #a49a84;
  --muted-2: #8f8675;
  --focus: #f3dca6;
  --danger: #e08b7d;

  --el-fire: #e0714f;
  --el-water: #5f9fd6;
  --el-earth: #8fae6a;
  --el-air: #b9a0e0;
  --el-life: #d9e3a3;
  --el-death: #b06d8f;

  --element: var(--gold);
  --element-glow: rgba(201, 169, 106, 0.16);

  --font-cjk: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC",
    "SimSun", "Yu Mincho", "Batang", serif;
  --font-cjk-sans: "Noto Sans CJK SC", "Source Han Sans SC", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans", sans-serif;
  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype",
    var(--font-cjk);
  --font-body: "Avenir Next", "Segoe UI", "Helvetica Neue", "Noto Sans",
    var(--font-cjk-sans), sans-serif;

  --gutter: clamp(16px, 3vw, 28px);
  --max-width: 1440px;
  --hairline: 1px solid var(--gold-line);
  --hairline-strong: 1px solid var(--gold-line-strong);

  --duration-fast: 140ms;
  --duration-ui: 220ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html:lang(zh-Hant) {
  --font-cjk: "Noto Serif CJK TC", "Source Han Serif TC", "Songti TC",
    "PMingLiU", serif;
  --font-cjk-sans: "Noto Sans CJK TC", "PingFang TC", "Microsoft JhengHei",
    sans-serif;
}

html:lang(ja) {
  --font-cjk: "Noto Serif JP", "Source Han Serif JP", "Yu Mincho",
    "Hiragino Mincho ProN", serif;
  --font-cjk-sans: "Noto Sans CJK JP", "Hiragino Sans", "Yu Gothic",
    "Meiryo", sans-serif;
}

html:lang(ko) {
  --font-cjk: "Noto Serif KR", "Source Han Serif KR", "Batang", serif;
  --font-cjk-sans: "Noto Sans CJK KR", "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--ink-0);
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 90% 50% at 50% -18%, rgba(201, 169, 106, 0.08), transparent 62%),
    radial-gradient(ellipse 60% 40% at 86% 6%, rgba(95, 159, 214, 0.045), transparent 60%),
    linear-gradient(180deg, #090d14 0%, var(--ink-0) 46%, #06090f 100%);
  color: var(--ivory);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.codex-detail-open {
  overflow: hidden;
}

::selection {
  background: rgba(201, 169, 106, 0.28);
  color: var(--ivory);
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  appearance: none;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

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

.codex-skip {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 9px 14px;
  border: var(--hairline-strong);
  background: var(--ink-0);
  color: var(--gold-bright);
  font-size: 0.82rem;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--duration-fast) ease;
}

.codex-skip:focus {
  transform: translateY(0);
}

/* ---------------------------------------------------------------- atmosphere */

.codex-atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  animation: codex-atmosphere-in 1.2s ease-out 0.08s forwards;
}

.codex-atmosphere::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(239, 230, 212, 0.55) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(201, 169, 106, 0.4) 0 1px, transparent 1.6px),
    radial-gradient(circle, rgba(239, 230, 212, 0.22) 0 1px, transparent 1.4px);
  background-size: 260px 260px, 380px 380px, 540px 540px;
  background-position: 30px 40px, 140px 230px, 80px 120px;
  opacity: 0.5;
  mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.5) 42%, transparent 82%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.5) 42%, transparent 82%);
}

.codex-atmosphere::after {
  content: "";
  position: absolute;
  top: min(-14vw, -160px);
  right: min(-10vw, -120px);
  width: min(70vw, 860px);
  aspect-ratio: 1;
  border: 1px solid rgba(201, 169, 106, 0.12);
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg, rgba(201, 169, 106, 0.07) 0deg 0.4deg, transparent 0.4deg 11.25deg),
    radial-gradient(circle, transparent 58%, rgba(201, 169, 106, 0.08) 58.5%, transparent 59.5%),
    radial-gradient(circle, transparent 38%, rgba(201, 169, 106, 0.08) 38.5%, transparent 39.5%);
  mask-image: radial-gradient(circle, transparent 28%, #000 30%, #000 72%, transparent 74%);
  -webkit-mask-image: radial-gradient(circle, transparent 28%, #000 30%, #000 72%, transparent 74%);
  opacity: 0.75;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 28%, transparent 48%, rgba(3, 5, 8, 0.5) 100%);
}

@keyframes codex-atmosphere-in {
  to { opacity: 1; }
}

/* ----------------------------------------------------------------- masthead */

.codex-masthead,
.codex-tabs,
.codex-toolbar,
.codex-countbar,
.codex-grid,
.codex-status {
  position: relative;
  z-index: 1;
}

.codex-masthead {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(46px, 7vw, 88px) var(--gutter) 30px;
  border-top: 1px solid rgba(201, 169, 106, 0.18);
}

.codex-masthead-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}

.codex-heading {
  min-width: 0;
  max-width: 860px;
}

.codex-heading h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 7.2vw, 5.6rem);
  font-weight: 600;
  line-height: 0.94;
  letter-spacing: 0.008em;
  color: var(--ivory);
  text-wrap: balance;
  animation: codex-rise 720ms var(--ease-out) both;
}

.codex-heading h1::after {
  content: "";
  display: block;
  width: 74px;
  height: 1px;
  margin-top: 20px;
  background: linear-gradient(90deg, var(--gold), transparent);
}

.codex-subtitle {
  max-width: 54ch;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
  letter-spacing: 0.02em;
  animation: codex-rise 720ms var(--ease-out) 60ms both;
}

.codex-census {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0;
  margin: 28px 0 0;
  padding: 0;
  border-top: var(--hairline);
  animation: codex-rise 720ms var(--ease-out) 120ms both;
}

.codex-census-item {
  min-width: 148px;
  padding: 13px 26px 0 0;
  margin-right: 26px;
  border-right: var(--hairline);
}

.codex-census-item:last-child {
  margin-right: 0;
  padding-right: 0;
  border-right: 0;
}

.codex-census-number {
  display: block;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  line-height: 1;
  color: var(--gold-bright);
  font-variant-numeric: lining-nums tabular-nums;
}

.codex-census-label {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  line-height: 1.35;
}

.codex-lang {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 176px;
  margin-left: auto;
  animation: codex-rise 720ms var(--ease-out) 100ms both;
}

.codex-lang-label {
  color: var(--gold-dim);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.codex-lang select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ivory);
  background: var(--ink-1);
  border: var(--hairline);
  border-radius: 2px;
  cursor: pointer;
}

.codex-lang select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@keyframes codex-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------- tabs */

.codex-tabs {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  overflow-x: auto;
  border-top: var(--hairline);
  border-bottom: var(--hairline);
  scrollbar-width: none;
  animation: codex-rise 720ms var(--ease-out) 150ms both;
}

.codex-tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  position: relative;
  padding: 15px clamp(18px, 2.4vw, 30px);
  border: 0;
  border-right: var(--hairline);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 1.06rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.2;
  cursor: pointer;
  transition: color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.tab:first-child {
  border-left: var(--hairline);
}

.tab::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-bright), transparent);
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
}

.tab:hover {
  color: var(--ivory);
  background: var(--gold-wash);
}

.tab.is-active {
  color: var(--ivory);
}

.tab.is-active::after {
  opacity: 1;
}

.tab:focus-visible {
  outline-offset: -4px;
}

/* ------------------------------------------------------------------ toolbar */

.codex-toolbar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px var(--gutter) 0;
  display: grid;
  grid-template-columns:
    minmax(240px, 1.7fr)
    repeat(3, minmax(116px, 0.7fr))
    auto
    auto;
  gap: 16px 18px;
  align-items: end;
  animation: codex-rise 720ms var(--ease-out) 190ms both;
}

.codex-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.codex-field-label {
  color: var(--gold-dim);
  font-size: 0.69rem;
  letter-spacing: 0.09em;
  line-height: 1.2;
}

.codex-search-wrap {
  position: relative;
  display: block;
}

.codex-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 11px;
  height: 11px;
  border: 1px solid var(--gold-dim);
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}

.codex-search-icon::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -3px;
  width: 6px;
  height: 1px;
  background: var(--gold-dim);
  transform: rotate(45deg);
  transform-origin: left center;
}

.codex-field-search input[type="search"] {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 38px;
  color: var(--ivory);
  background: var(--ink-1);
  border: var(--hairline);
  border-radius: 2px;
  outline: none;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.codex-field-search input[type="search"]::placeholder {
  color: var(--muted-2);
}

.codex-field-search input[type="search"]:focus {
  border-color: var(--gold-line-strong);
  background: var(--ink-2);
}

.codex-select-wrap {
  position: relative;
  display: block;
}

.codex-select-wrap select {
  width: 100%;
  height: 42px;
  padding: 0 34px 0 12px;
  color: var(--ivory);
  background: var(--ink-1);
  border: var(--hairline);
  border-radius: 2px;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.codex-select-wrap select:focus {
  border-color: var(--gold-line-strong);
  background: var(--ink-2);
}

.codex-select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1px solid var(--gold);
  border-bottom: 1px solid var(--gold);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.codex-check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.codex-check input {
  position: absolute;
  width: 18px;
  height: 18px;
  opacity: 0;
  pointer-events: none;
}

.codex-check-box {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  background: var(--ink-1);
  border: 1px solid var(--gold-line-strong);
  border-radius: 1px;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.codex-check input:checked + .codex-check-box {
  background: var(--gold);
  border-color: var(--gold);
}

.codex-check input:checked + .codex-check-box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border-right: 2px solid var(--ink-0);
  border-bottom: 2px solid var(--ink-0);
  transform: rotate(45deg);
}

.codex-check input:focus-visible + .codex-check-box {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.codex-reset {
  align-self: end;
  height: 42px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--gold-dim);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.codex-reset:hover {
  color: var(--gold-bright);
  border-bottom-color: var(--gold-line-strong);
}

.codex-countbar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px var(--gutter) 0;
  display: flex;
  justify-content: flex-end;
  animation: codex-rise 720ms var(--ease-out) 220ms both;
}

.codex-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.73rem;
  letter-spacing: 0.05em;
  font-variant-numeric: lining-nums tabular-nums;
}

.codex-count::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border: 1px solid var(--gold);
  transform: rotate(45deg);
  vertical-align: 1px;
}

/* -------------------------------------------------------------------- cards */

.codex-grid {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 22px var(--gutter) 84px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  column-gap: clamp(14px, 1.5vw, 22px);
  row-gap: clamp(28px, 3vw, 40px);
}

.codex-grid.is-revealed {
  animation: codex-grid-in 560ms var(--ease-out) both;
}

@keyframes codex-grid-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.codex-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.codex-card-aperture {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid var(--gold-line);
  border-radius: 50% 50% 6px 6px / 30% 30% 6px 6px;
  background:
    radial-gradient(ellipse at 50% 22%, var(--element-glow), transparent 58%),
    linear-gradient(180deg, var(--ink-2), var(--ink-1));
  transition:
    transform var(--duration-ui) var(--ease-out),
    border-color var(--duration-ui) ease,
    box-shadow var(--duration-ui) ease;
}

.codex-card-aperture::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(to top, rgba(8, 11, 18, 0.6), transparent 38%);
}

.codex-card-aperture::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 4px var(--ink-0),
    inset 0 0 0 5px var(--gold-line);
}

.codex-card-aperture img {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 22%;
}

.codex-card[data-section="weapons"] .codex-card-aperture {
  aspect-ratio: 1 / 1;
  border-radius: 0;
  clip-path: polygon(
    50% 0%, 87% 11%, 100% 50%, 87% 89%,
    50% 100%, 13% 89%, 0% 50%, 13% 11%
  );
}

.codex-card[data-section="weapons"] .codex-card-aperture::after {
  border-radius: 0;
}

.codex-card[data-section="weapons"] .codex-card-aperture img {
  object-fit: contain;
  object-position: 50% 50%;
  padding: 13%;
}

.codex-card[data-section="accessories"] .codex-card-aperture {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, var(--element-glow), transparent 58%),
    linear-gradient(180deg, var(--ink-2), var(--ink-1));
}

.codex-card[data-section="accessories"] .codex-card-aperture::after {
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 5px var(--ink-0),
    inset 0 0 0 6px var(--gold-line);
}

.codex-card[data-section="accessories"] .codex-card-aperture img {
  object-fit: contain;
  object-position: 50% 50%;
  padding: 15%;
}

.codex-card-gem {
  position: absolute;
  top: -12px;
  left: 50%;
  z-index: 4;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-0);
  border: 1px solid var(--element);
  box-shadow:
    0 0 0 3px var(--ink-0),
    0 0 18px var(--element-glow);
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
}

.codex-card-gem.is-relic {
  border-style: dashed;
}

.codex-card-gem-glyph {
  display: block;
  color: var(--element);
  font-family: var(--font-body);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
  transform: rotate(-45deg);
}

.codex-card-plate {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 4px 0;
  text-align: center;
}

.codex-card-plate::before {
  content: "";
  width: 26px;
  height: 1px;
  margin: 0 auto 5px;
  background: var(--gold-line-strong);
}

.codex-card-name {
  display: -webkit-box;
  min-height: 2.55em;
  overflow: hidden;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.27;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  transition: color var(--duration-fast) ease;
}

.codex-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 1.35em;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.codex-card-stars {
  color: var(--gold-dim);
  font-variant-numeric: lining-nums tabular-nums;
}

.codex-card-sep {
  width: 1px;
  height: 9px;
  background: var(--gold-line);
}

.codex-card-detail {
  color: var(--muted);
}

@media (hover: hover) and (pointer: fine) {
  .codex-card:hover .codex-card-aperture {
    transform: translateY(-3px);
    border-color: var(--gold-line-strong);
    box-shadow:
      0 20px 38px -22px rgba(0, 0, 0, 0.95),
      0 0 24px -8px var(--element);
  }

  .codex-card:hover .codex-card-name {
    color: var(--gold-bright);
  }

  .codex-card:hover .codex-card-plate::before {
    background: var(--gold);
  }
}

.codex-card:active .codex-card-aperture {
  transform: translateY(-1px);
}

.codex-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 6px;
  border-radius: 4px;
}

.codex-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-dim);
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
}

.codex-status {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 52px var(--gutter) 96px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-style: italic;
  text-align: center;
}

/* ------------------------------------------------------- element token maps */

.codex-card[data-element="Fire"],
.codex-detail-panel[data-element="Fire"] {
  --element: var(--el-fire);
  --element-glow: rgba(224, 113, 79, 0.17);
}

.codex-card[data-element="Water"],
.codex-detail-panel[data-element="Water"] {
  --element: var(--el-water);
  --element-glow: rgba(95, 159, 214, 0.17);
}

.codex-card[data-element="Earth"],
.codex-detail-panel[data-element="Earth"] {
  --element: var(--el-earth);
  --element-glow: rgba(143, 174, 106, 0.17);
}

.codex-card[data-element="Air"],
.codex-detail-panel[data-element="Air"] {
  --element: var(--el-air);
  --element-glow: rgba(185, 160, 224, 0.17);
}

.codex-card[data-element="Life"],
.codex-detail-panel[data-element="Life"] {
  --element: var(--el-life);
  --element-glow: rgba(217, 227, 163, 0.17);
}

.codex-card[data-element="Death"],
.codex-detail-panel[data-element="Death"] {
  --element: var(--el-death);
  --element-glow: rgba(176, 109, 143, 0.17);
}

/* ------------------------------------------------------------------- detail */

.codex-detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background: rgba(4, 6, 10, 0.88);
  backdrop-filter: blur(3px);
}

.codex-detail[hidden] {
  display: none;
}

.codex-detail-panel {
  position: relative;
  width: min(1040px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  border: var(--hairline-strong);
  border-radius: 2px;
  background:
    radial-gradient(ellipse at 12% -4%, var(--element-glow), transparent 44%),
    linear-gradient(180deg, #0e141d 0%, #090d14 62%);
  box-shadow:
    0 50px 140px -30px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(0, 0, 0, 0.6);
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.codex-detail-panel.is-opening {
  animation: codex-panel-in 320ms var(--ease-out) both;
}

@keyframes codex-panel-in {
  from { opacity: 0; transform: translateY(18px) scale(0.994); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.codex-detail-top {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0;
  padding: 12px 26px;
  background: rgba(9, 13, 20, 0.96);
  border-bottom: var(--hairline);
}

.codex-pagebar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.codex-page-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: var(--hairline);
  border-radius: 50%;
  background: transparent;
  color: var(--ivory-2);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}

.codex-page-btn:hover:not(:disabled),
.codex-page-btn:focus-visible {
  border-color: var(--gold-line-strong);
  color: var(--gold-bright);
}

.codex-page-btn:disabled {
  opacity: 0.32;
  cursor: default;
}

.codex-page-counter {
  min-width: 76px;
  color: var(--gold-dim);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-variant-numeric: lining-nums tabular-nums;
  text-align: center;
}

.codex-close {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: var(--hairline);
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.codex-close-glyph {
  font-size: 1.1rem;
  line-height: 1;
  color: var(--gold-dim);
}

.codex-close:hover {
  color: var(--ivory);
  border-color: var(--gold-line-strong);
}

.codex-detail-head {
  padding: 30px 26px 22px;
  border-bottom: var(--hairline);
}

.codex-kind {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  line-height: 1.2;
}

.codex-kind::before {
  content: "";
  width: 6px;
  height: 6px;
  border: 1px solid var(--gold);
  transform: rotate(45deg);
}

.codex-detail-title {
  margin: 12px 0 0;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.2vw, 3.5rem);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: 0.005em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.codex-detail-alias {
  margin: 8px 0 0;
  color: var(--gold-dim);
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-style: italic;
  line-height: 1.4;
}

/* ---------------------------------------------------------------- form nav */

.codex-form-nav {
  margin: 22px 26px 4px;
}

.codex-form-nav-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.codex-form-arrow {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: var(--hairline);
  border-radius: 50%;
  background: transparent;
  color: var(--ivory-2);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}

.codex-form-arrow:hover:not(:disabled),
.codex-form-arrow:focus-visible:not(:disabled) {
  border-color: var(--gold-line-strong);
  color: var(--gold-bright);
}

.codex-form-arrow:disabled {
  opacity: 0.32;
  cursor: default;
}

.codex-form-tabs {
  flex: 1 1 auto;
  display: flex;
  gap: 2px;
  padding: 2px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.codex-form-tab {
  flex: 0 0 auto;
  padding: 9px 14px;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.codex-form-tab:hover {
  color: var(--ivory);
}

.codex-form-tab.is-active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold);
}

/* ------------------------------------------------------------------ gallery */

.codex-gallery {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin: 22px 26px 6px;
}

.codex-gallery-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
}

.codex-figure {
  flex: 0 0 auto;
  margin: 0;
  min-width: 0;
}

.codex-figure-avatar {
  width: 120px;
}

.codex-figure-card {
  width: 340px;
}

.codex-figure-model {
  width: 220px;
}

.codex-figure-tachie {
  width: 300px;
}

.codex-figure-weapon,
.codex-figure-accessory {
  width: 200px;
}

.codex-figure-image {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: var(--hairline);
  border-radius: 2px;
  background:
    radial-gradient(ellipse at 50% 32%, var(--element-glow), transparent 66%),
    linear-gradient(180deg, var(--ink-2), var(--ink-1));
}

.codex-figure-image::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(201, 169, 106, 0.16);
  border-radius: 1px;
  pointer-events: none;
}

.codex-figure-avatar .codex-figure-image {
  height: 120px;
  border-radius: 50%;
}

.codex-figure-avatar .codex-figure-image::after {
  border-radius: 50%;
}

.codex-figure-card .codex-figure-image {
  height: 430px;
}

.codex-figure-model .codex-figure-image {
  height: 430px;
}

.codex-figure-tachie .codex-figure-image {
  height: 340px;
}

.codex-figure-weapon .codex-figure-image,
.codex-figure-accessory .codex-figure-image {
  height: 200px;
}

.codex-figure-image img,
.codex-figure-image video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.codex-figure-avatar .codex-figure-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.codex-figure figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  line-height: 1.4;
  text-align: center;
}

.codex-figure-empty .codex-figure-image {
  width: 200px;
  height: 200px;
}

/* ------------------------------------------------------------------ stats */

.codex-block {
  margin: 30px 26px 0;
  padding-top: 22px;
  border-top: var(--hairline);
}

.codex-block-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.codex-block-title::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border: 1px solid var(--gold);
  transform: rotate(45deg);
}

.codex-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border: var(--hairline);
  background: var(--gold-line);
}

.codex-stat {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 12px 15px;
  background: var(--ink-1);
}

.codex-stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  line-height: 1.3;
}

.codex-stat-value {
  margin: 0;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
  font-variant-numeric: lining-nums tabular-nums;
}

.codex-stat.is-primary .codex-stat-value {
  color: var(--gold-bright);
  font-size: 1.7rem;
}

.codex-stat.is-text .codex-stat-value {
  color: var(--ivory-2);
  font-family: var(--font-body);
  font-size: 0.87rem;
  font-weight: 500;
  line-height: 1.45;
}

/* ------------------------------------------------------------------ spells */

.codex-spell-list {
  display: flex;
  flex-direction: column;
}

.codex-skill {
  position: relative;
  padding: 16px 0 18px 28px;
  border-top: 1px solid rgba(201, 169, 106, 0.14);
  background: none;
  border-radius: 0;
}

.codex-skill:first-child {
  border-top: 0;
}

.codex-skill:last-child {
  border-bottom: 1px solid rgba(201, 169, 106, 0.14);
}

.codex-skill::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20px;
  bottom: 20px;
  width: 1px;
  background: linear-gradient(180deg, var(--gold), transparent);
}

.codex-skill-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.codex-spell-index {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--gold-line-strong);
  border-radius: 50%;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  transform: translateY(-1px);
}

.codex-spell-index.is-diamond {
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  color: var(--gold-dim);
  font-size: 0.8rem;
}

.codex-skill-name {
  margin: 0;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 1.16rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.codex-skill-desc {
  max-width: 72ch;
  margin: 8px 0 0;
  color: var(--ivory-2);
  font-size: 0.88rem;
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.codex-skill-selected {
  margin: 8px 0 0;
  color: var(--gold);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.codex-skill-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 11px;
}

.codex-skill-meta .codex-row {
  display: flex;
  gap: 6px;
  padding: 0;
  border: 0;
  font-size: 0.75rem;
}

.codex-skill-meta .codex-row-label {
  color: var(--muted-2);
}

.codex-skill-meta .codex-row-value {
  color: var(--ivory-2);
  text-align: left;
}

.codex-block.is-passives .codex-skill-name {
  font-size: 1.02rem;
}

.codex-block.is-leader {
  padding: 20px 22px;
  border: var(--hairline);
  border-left: 1px solid var(--gold);
  background: linear-gradient(90deg, var(--gold-wash), transparent 70%);
}

.codex-block.is-leader .codex-skill-name {
  color: var(--gold-bright);
}

.codex-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(201, 169, 106, 0.12);
  font-size: 0.85rem;
}

.codex-row-label {
  flex: 0 0 auto;
  color: var(--muted);
}

.codex-row-value {
  text-align: right;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------- links */

.codex-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 4px;
}

.codex-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  border: 0;
  border-bottom: 1px solid var(--gold-line);
  border-radius: 0;
  background: none;
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 1.02rem;
  line-height: 1.4;
  text-decoration: none;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.codex-link::before {
  content: "";
  width: 4px;
  height: 4px;
  flex: 0 0 auto;
  background: var(--gold-dim);
  transform: rotate(45deg);
}

.codex-link:hover {
  color: var(--ivory);
  border-bottom-color: var(--gold-bright);
}

/* --------------------------------------------------------------- form cards */

.codex-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.codex-form-card {
  width: 100%;
  padding: 10px;
  border: var(--hairline);
  border-radius: 2px;
  background: var(--ink-1);
  color: inherit;
  text-align: left;
}

.codex-form-card.is-link {
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.codex-form-card.is-link:hover,
.codex-form-card.is-link:focus-visible {
  border-color: var(--gold-line-strong);
  background: var(--ink-2);
  outline: none;
}

button.codex-form-card {
  font: inherit;
  cursor: pointer;
}

.codex-form-card.is-active {
  border-color: var(--gold-line-strong);
  box-shadow: inset 0 2px 0 var(--gold);
}

.codex-form-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.codex-form-images figure {
  margin: 0;
  text-align: center;
}

.codex-form-images img {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: contain;
}

.codex-form-images figcaption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.codex-form-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  color: var(--ivory);
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.3;
}

.codex-form-cosmo {
  padding: 1px 6px;
  border: 1px solid var(--gold-line-strong);
  border-radius: 1px;
  background: var(--gold-wash);
  color: var(--gold);
  font-family: var(--font-body);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------------- toast */

.codex-live-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border: var(--hairline-strong);
  border-radius: 2px;
  background: var(--ink-1);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  color: var(--ivory);
  font-size: 0.82rem;
}

.codex-live-toast-button {
  border: 1px solid var(--gold-line-strong);
  border-radius: 1px;
  background: var(--gold-wash);
  color: var(--gold-bright);
  padding: 7px 12px;
  font-size: 0.78rem;
  cursor: pointer;
}

.codex-live-toast-button:hover {
  background: rgba(201, 169, 106, 0.18);
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .codex-toolbar {
    grid-template-columns:
      minmax(220px, 1.5fr)
      repeat(3, minmax(108px, 0.7fr))
      auto;
  }

  .codex-reset {
    grid-column: 1 / -1;
    justify-self: end;
    height: auto;
  }
}

@media (max-width: 900px) and (min-width: 721px) {
  .codex-figure-card {
    width: 300px;
  }

  .codex-figure-model {
    width: 190px;
  }

  .codex-figure-card .codex-figure-image,
  .codex-figure-model .codex-figure-image {
    height: 380px;
  }

  .codex-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .codex-field-search {
    grid-column: 1 / -1;
  }

  .codex-check,
  .codex-reset {
    grid-column: auto;
  }

  .codex-reset {
    grid-column: 1 / -1;
    justify-self: end;
  }
}

@media (max-width: 720px) {
  .codex-masthead {
    padding: 26px var(--gutter) 18px;
  }

  .codex-heading h1 {
    font-size: clamp(2.2rem, 10vw, 2.9rem);
  }

  .codex-heading h1::after {
    margin-top: 12px;
  }

  .codex-subtitle {
    margin-top: 8px;
    font-size: 0.88rem;
  }

  .codex-census {
    margin-top: 18px;
  }

  .codex-census-item {
    min-width: 0;
    flex: 1 1 0;
    padding-right: 10px;
    margin-right: 10px;
  }

  .codex-census-number {
    font-size: 1.2rem;
  }

  .codex-census-label {
    font-size: 0.62rem;
  }

  .codex-lang {
    width: 100%;
    min-width: 0;
    margin-left: 0;
  }

  .tab {
    padding: 12px 11px;
    font-size: 0.88rem;
  }

  .codex-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 10px;
    padding-top: 16px;
  }

  .codex-field {
    gap: 5px;
  }

  .codex-field-label {
    font-size: 0.66rem;
  }

  .codex-field-search {
    grid-column: 1 / -1;
  }

  .codex-check {
    grid-column: auto;
    min-height: 42px;
  }

  .codex-reset {
    grid-column: 1 / -1;
    justify-self: end;
    height: 28px;
  }

  .codex-countbar {
    padding-top: 8px;
  }

  .codex-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
    row-gap: 26px;
    padding: 14px var(--gutter) 54px;
  }

  .codex-card-name {
    min-height: 2.5em;
    font-size: 0.98rem;
  }

  .codex-card-meta {
    font-size: 0.66rem;
  }

  .codex-card-gem {
    width: 23px;
    height: 23px;
    top: -10px;
  }

  .codex-card-gem-glyph {
    font-size: 0.6rem;
  }

  .codex-detail {
    padding: 0;
    backdrop-filter: none;
  }

  .codex-detail-panel {
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }

  .codex-detail-top {
    margin: 0;
    padding: 10px 16px;
  }

  .codex-page-btn {
    width: 44px;
    height: 44px;
  }

  .codex-close {
    padding: 9px 12px;
  }

  .codex-detail-head {
    padding: 24px 16px 18px;
  }

  .codex-form-nav {
    margin: 18px 16px 4px;
  }

  .codex-form-arrow {
    width: 44px;
    height: 44px;
  }

  .codex-gallery {
    margin: 18px 16px 6px;
    gap: 16px;
  }

  .codex-gallery-row {
    flex-direction: column;
    gap: 14px;
  }

  .codex-figure-avatar {
    width: 96px;
  }

  .codex-figure-card {
    width: min(100%, 360px);
  }

  .codex-figure-model {
    width: 200px;
  }

  .codex-figure-tachie {
    width: min(100%, 320px);
  }

  .codex-figure-weapon,
  .codex-figure-accessory {
    width: 160px;
  }

  .codex-figure-avatar .codex-figure-image {
    height: 96px;
  }

  .codex-figure-card .codex-figure-image,
  .codex-figure-model .codex-figure-image {
    height: min(430px, 62vh);
  }

  .codex-figure-tachie .codex-figure-image {
    height: 280px;
  }

  .codex-figure-weapon .codex-figure-image,
  .codex-figure-accessory .codex-figure-image {
    height: 160px;
  }

  .codex-block {
    margin: 26px 16px 0;
    padding-top: 18px;
  }

  .codex-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .codex-stat.is-primary .codex-stat-value {
    font-size: 1.45rem;
  }

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

  .codex-form-images img {
    height: 220px;
  }

  .codex-skill {
    padding-left: 20px;
  }

  .codex-skill::before {
    top: 18px;
    bottom: 18px;
  }

  .codex-skill-desc {
    font-size: 0.86rem;
  }

  .codex-live-toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    justify-content: space-between;
  }
}

@media (max-width: 420px) {
  .codex-census-item {
    flex: 1 1 0;
    min-width: 0;
    padding-right: 8px;
    margin-right: 8px;
  }

  .codex-census-number {
    font-size: 1.05rem;
  }

  .codex-census-label {
    font-size: 0.58rem;
    letter-spacing: 0.04em;
    min-height: 3.9em;
  }

  .codex-card-name {
    font-size: 0.94rem;
  }

  .codex-select-wrap select,
  .codex-lang select {
    padding-right: 24px;
    padding-left: 10px;
    font-size: 0.85rem;
  }

  .codex-select-wrap::after {
    right: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .codex-atmosphere {
    opacity: 1;
    animation: none;
  }

  .codex-card:hover .codex-card-aperture {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --gold-line: rgba(201, 169, 106, 0.55);
    --gold-line-strong: rgba(230, 207, 152, 0.9);
    --muted: #c6bba7;
    --muted-2: #b3a891;
  }

  .codex-card-aperture,
  .codex-figure-image,
  .codex-stat-grid,
  .codex-form-card {
    border-width: 2px;
  }
}

@media (forced-colors: active) {
  .codex-card-aperture,
  .codex-figure-image,
  .codex-card-gem,
  .codex-stat-grid,
  .codex-form-card {
    border: 1px solid CanvasText;
  }

  .codex-check input {
    opacity: 1;
  }

  .codex-check-box {
    display: none;
  }
}
