/* SETOR: Itens e economia. Códex (itens/codex.js): janela #codex-dialog no visual dourado do Mercado,
   interruptor "Registrar automático" da mochila e o item que cai e vai para o Códex (fases.js → playLootDrop). */

/* ---------- Janela ---------- */
#codex-dialog {
  width: min(800px, calc(100% - 24px));
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(214, 173, 98, .6);
  background: radial-gradient(ellipse at 12% 0%, rgba(92, 74, 40, .4), transparent 60%), linear-gradient(170deg, #18221f, #0d1416 70%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 230, 170, .1);
  scrollbar-width: thin;
  scrollbar-color: rgba(214, 173, 98, .5) transparent;
}
#codex-dialog .codex-content { display: grid; gap: 12px; padding: clamp(12px, 2vw, 20px); }
#codex-dialog .codex-header { flex-wrap: wrap; gap: 10px 14px; padding-bottom: 0; }
#codex-dialog .codex-header h2 {
  display: flex; align-items: center; gap: 10px; margin-right: auto;
  font: 800 26px/1.05 'Cinzel Decorative', Cinzel, Georgia, serif; color: #f3d48e;
  text-shadow: 0 1px 0 #3a2508, 0 0 14px rgba(255, 196, 90, .25);
}
#codex-dialog .codex-header h2 > span:last-child { display: grid; gap: 3px; }
#codex-dialog .codex-header h2 small {
  font: 600 11px/1.3 var(--font-body, Nunito, sans-serif); color: #b6ad98; letter-spacing: .04em; text-shadow: none;
}
#codex-dialog .codex-emblem {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 12px;
  border: 1px solid rgba(243, 212, 142, .6); background: radial-gradient(circle at 50% 30%, #4a3a18, #140f06 80%);
  box-shadow: 0 0 14px rgba(240, 190, 90, .25), inset 0 1px 0 rgba(255, 240, 200, .25);
}
#codex-dialog .codex-emblem .hud-icon { --icon-size: 34px; }
#codex-dialog .codex-progress {
  display: grid; grid-template-columns: auto auto; align-items: center; gap: 4px 10px; min-width: 170px;
  padding: 7px 12px; border: 1px solid rgba(214, 173, 98, .35); border-radius: 12px; background: rgba(6, 10, 12, .6);
}
#codex-dialog .codex-progress-label { color: #b6ad98; font: 800 10.5px var(--font-body, Nunito, sans-serif); letter-spacing: .08em; text-transform: uppercase; }
#codex-dialog .codex-progress strong { justify-self: end; color: #fff0cc; font: 600 17px/1 'Fredoka', sans-serif; font-variant-numeric: tabular-nums; }
#codex-dialog .codex-progress-bar {
  grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, .08);
}
#codex-dialog .codex-progress-bar > span {
  display: block; height: 100%; min-width: 2px; border-radius: inherit;
  background: linear-gradient(90deg, #d7a94e, #f7dc96); box-shadow: 0 0 8px rgba(240, 190, 90, .6); transition: width .3s ease;
}
#codex-dialog .shop-close { align-self: flex-start; min-height: 34px; }

/* ---------- Bônus permanente ---------- */
#codex-dialog .codex-totals-box { display: grid; gap: 7px; }
#codex-dialog .codex-totals-box h3,
#codex-dialog .codex-table caption { font: 700 13px/1.2 Cinzel, Georgia, serif; color: #f3d48e; letter-spacing: .04em; }
#codex-dialog .codex-totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; list-style: none; }
#codex-dialog .codex-total {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 7px; min-width: 0;
  padding: 6px 10px 6px 7px; border: 1px solid rgba(255, 255, 255, .08); border-radius: 10px; background: rgba(6, 10, 12, .55);
}
#codex-dialog .codex-total.has-bonus { border-color: color-mix(in srgb, var(--stat-color) 45%, transparent); background: linear-gradient(100deg, color-mix(in srgb, var(--stat-color) 14%, transparent), rgba(6, 10, 12, .55) 70%); }
#codex-dialog .codex-total-icon { display: grid; place-items: center; width: 24px; height: 24px; }
#codex-dialog .codex-total-icon > span { display: block; }
#codex-dialog .codex-total-icon .hud-icon { --icon-size: 22px; }
#codex-dialog .codex-total-icon :is(.accuracy-sigil, .evasion-sigil, .spdef-sigil) { transform: scale(.82); }
#codex-dialog .codex-total-label { overflow: hidden; color: #c8bfa8; font: 700 12px/1.2 var(--font-body, Nunito, sans-serif); text-overflow: ellipsis; white-space: nowrap; }
#codex-dialog .codex-total b { color: #6f6a5c; font: 600 16px/1 'Fredoka', sans-serif; font-variant-numeric: tabular-nums; }
#codex-dialog .codex-total.has-bonus b { color: #fff0cc; }

/* ---------- Abas dos tipos e faixas de nível ---------- */
#codex-dialog .codex-types {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; padding: 5px;
  border: 1px solid rgba(214, 173, 98, .25); border-radius: 12px; background: rgba(6, 10, 12, .5);
}
#codex-dialog .codex-type {
  position: relative; display: grid; justify-items: center; align-content: start; gap: 2px; min-width: 0; padding: 6px 3px 5px;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: #c8bfa8; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
#codex-dialog .codex-type:hover { background: rgba(255, 255, 255, .05); color: #f2e4c2; }
#codex-dialog .codex-type[aria-pressed="true"] {
  color: #2a1a05; border-color: #f3d48e; background: linear-gradient(180deg, #f7dc96, #d7a94e); box-shadow: 0 2px 10px rgba(240, 190, 90, .25);
}
#codex-dialog .codex-type-icon .item-art { --item-size: 28px; display: block; }
#codex-dialog .codex-type-name { max-width: 100%; font: 700 11px/1.15 Cinzel, Georgia, serif; text-align: center; overflow-wrap: anywhere; }
#codex-dialog .codex-type-count { font: 700 10px/1 var(--font-body, Nunito, sans-serif); opacity: .8; font-variant-numeric: tabular-nums; }
#codex-dialog .codex-ready-badge {
  position: absolute; top: 2px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: #3fd47a; color: #06200f; font: 900 10px/17px 'Fredoka', sans-serif; text-align: center; box-shadow: 0 0 8px rgba(80, 230, 140, .6);
}
#codex-dialog .codex-bands { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
#codex-dialog .codex-band {
  position: relative; display: grid; justify-items: center; gap: 2px; min-height: 40px; padding: 5px 4px;
  border: 1px solid rgba(214, 173, 98, .3); border-radius: 9px; background: rgba(6, 10, 12, .55); color: #e8dcc0; cursor: pointer;
}
#codex-dialog .codex-band:hover { border-color: #f3d48e; }
#codex-dialog .codex-band[aria-pressed="true"] { border-color: #f3d48e; background: rgba(214, 173, 98, .26); color: #fff3cf; box-shadow: 0 0 10px rgba(240, 190, 90, .25); }
#codex-dialog .codex-band-name { font: 700 12.5px/1.1 var(--font-body, Nunito, sans-serif); white-space: nowrap; }
#codex-dialog .codex-band small { color: #a9a08b; font: 700 10px/1 var(--font-body, Nunito, sans-serif); font-variant-numeric: tabular-nums; }
#codex-dialog .codex-ready-dot { position: absolute; top: 5px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #3fd47a; box-shadow: 0 0 6px rgba(80, 230, 140, .8); }

/* ---------- Grade raridade × estrelas ---------- */
#codex-dialog .codex-board { padding: 8px 10px 10px; border: 1px solid rgba(214, 173, 98, .25); border-radius: 12px; background: rgba(6, 10, 12, .45); }
#codex-dialog .codex-table { width: 100%; border-collapse: separate; border-spacing: 5px; table-layout: fixed; }
#codex-dialog .codex-table caption { padding: 2px 5px 6px; text-align: left; }
#codex-dialog .codex-caption { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
#codex-dialog .codex-caption-stat {
  padding: 2px 9px; border: 1px solid color-mix(in srgb, var(--stat-color) 55%, transparent); border-radius: 999px;
  color: var(--stat-color); font: 800 11px var(--font-body, Nunito, sans-serif); letter-spacing: 0;
}
#codex-dialog .codex-caption-count { margin-left: auto; color: #fff0cc; font: 600 13px 'Fredoka', sans-serif; letter-spacing: 0; }
#codex-dialog .codex-table thead th { color: #f3d48e; font: 600 13px/1 'Fredoka', sans-serif; text-align: center; }
#codex-dialog .codex-table thead th:first-child { width: 112px; }
#codex-dialog .codex-table tbody th { padding-right: 4px; text-align: left; vertical-align: middle; }
#codex-dialog .codex-rarity { display: block; color: var(--tier, #d8dfe2); font: 800 12.5px/1.15 var(--font-body, Nunito, sans-serif); letter-spacing: .02em; }
#codex-dialog .codex-table tbody th small { color: #8f8877; font: 700 10.5px/1.2 var(--font-body, Nunito, sans-serif); white-space: nowrap; }
#codex-dialog .codex-table td { padding: 0; text-align: center; }
#codex-dialog .codex-cell {
  --tier-glow: color-mix(in srgb, var(--tier, #d8dfe2) 55%, transparent);
  position: relative; display: grid; place-items: center; width: 100%; max-width: 58px; aspect-ratio: 1; margin: 0 auto; padding: 0;
  border: 1px solid rgba(255, 255, 255, .08); border-radius: 10px; background: rgba(6, 10, 12, .65); cursor: default;
  transition: transform .15s ease, box-shadow .15s ease;
}
#codex-dialog .codex-cell .item-art { --item-size: 30px; display: block; }
#codex-dialog .codex-cell.is-missing .item-art { filter: grayscale(1) brightness(.7); opacity: .22; }
#codex-dialog .codex-cell.is-missing:hover, #codex-dialog .codex-cell.is-missing:focus-visible { border-color: rgba(255, 255, 255, .22); }
#codex-dialog .codex-cell.is-ready {
  border-color: var(--tier, #d8dfe2); cursor: pointer;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--tier, #d8dfe2) 32%, #1b2627), #0f1516 75%);
  box-shadow: 0 0 10px var(--tier-glow); animation: codex-ready 1.6s ease-in-out infinite;
}
#codex-dialog .codex-cell.is-ready:hover { transform: translateY(-2px) scale(1.05); }
#codex-dialog .codex-cell.is-done {
  border-color: #f3d48e;
  background: radial-gradient(circle at 50% 28%, #fff1b8 0, #e7bb5f 42%, #8a5f18 100%);
  box-shadow: inset 0 1px 0 rgba(255, 245, 210, .75), inset 0 -2px 0 rgba(90, 54, 8, .45), 0 0 8px rgba(240, 190, 90, .35);
}
#codex-dialog .codex-cell.is-done .item-art { filter: drop-shadow(0 1px 1px rgba(70, 40, 4, .9)); }
#codex-dialog .codex-cell.is-new { animation: codex-new 1s ease-out; }
#codex-dialog .codex-cell-check {
  position: absolute; right: -4px; bottom: -4px; display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%;
  background: #1f6b3a; color: #c8ffd8; font: 900 10px/1 var(--font-body, Nunito, sans-serif); box-shadow: 0 0 0 1px #7df0a4;
}
#codex-dialog .codex-cell-count {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--tier, #d8dfe2); color: #0d1416; font: 900 10px/17px 'Fredoka', sans-serif;
}
#codex-dialog .codex-cell:focus-visible, #codex-dialog .codex-type:focus-visible, #codex-dialog .codex-band:focus-visible,
#codex-dialog .codex-auto-btn:focus-visible { outline: 2px solid #f3d48e; outline-offset: 2px; }
@keyframes codex-ready { 50% { box-shadow: 0 0 18px var(--tier-glow), 0 0 0 2px color-mix(in srgb, var(--tier, #d8dfe2) 35%, transparent); } }
@keyframes codex-new { 0% { transform: scale(1.3); filter: brightness(1.8); } 100% { transform: scale(1); filter: none; } }
.codex-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Dica, retorno e botões ---------- */
#codex-dialog .codex-detail {
  min-height: 38px; padding: 8px 12px; border: 1px solid rgba(255, 255, 255, .1); border-radius: 10px; background: rgba(6, 10, 12, .5);
  color: #a9a08b; font: 600 12.5px/1.45 var(--font-body, Nunito, sans-serif);
}
#codex-dialog .codex-detail strong { color: #fff0cc; }
#codex-dialog .codex-detail-gain { margin-left: 4px; color: #ffd76a; font-weight: 800; }
#codex-dialog .codex-detail-status { margin-left: 4px; color: #a9a08b; font-weight: 800; }
#codex-dialog .codex-detail.is-done { border-color: rgba(243, 212, 142, .45); }
#codex-dialog .codex-detail.is-done .codex-detail-status { color: #f3d48e; }
#codex-dialog .codex-detail.is-ready { border-color: rgba(80, 230, 140, .45); }
#codex-dialog .codex-detail.is-ready .codex-detail-status { color: #9ff0b5; }
#codex-dialog .codex-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
#codex-dialog .codex-feedback { flex: 1 1 240px; margin: 0; }
#codex-dialog .codex-feedback:not(:empty) {
  padding: 8px 12px; border: 1px solid rgba(214, 173, 98, .4); border-radius: 10px; background: rgba(214, 173, 98, .1);
  color: #f2e4c2; font: 700 13px/1.4 var(--font-body, Nunito, sans-serif);
}
#codex-dialog .codex-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
#codex-dialog .codex-register-all {
  min-height: 38px; padding: 7px 16px; border: 1px solid #f3d48e; border-radius: 10px;
  background: linear-gradient(180deg, #f7dc96, #c9963c); color: #2a1a05; font: 800 13px/1 Cinzel, Georgia, serif;
}
#codex-dialog .codex-register-all:hover:enabled { filter: brightness(1.08); box-shadow: 0 0 12px rgba(240, 190, 90, .35); transform: none; }
#codex-dialog .codex-register-all:disabled { border-color: rgba(214, 173, 98, .3); background: rgba(6, 10, 12, .55); color: #8f8877; cursor: default; }

/* Ganho na confirmação de "Registrar tudo" (interface/confirm.js) */
.action-confirm .codex-gains { display: grid; gap: 4px; margin: 10px 0 2px; padding: 0; list-style: none; text-align: left; }
.action-confirm .codex-gains li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: baseline; gap: 8px; padding: 5px 10px;
  border: 1px solid color-mix(in srgb, var(--stat-color, #f3d48e) 40%, transparent); border-radius: 8px; background: rgba(0, 0, 0, .3);
}
.action-confirm .codex-gains span { color: var(--stat-color, #f3d48e); font-weight: 800; }
.action-confirm .codex-gains b { color: #fff; font-family: 'Fredoka', sans-serif; font-weight: 600; }
.action-confirm .buy-confirm-text .codex-gains small { margin: 0; color: #b9ae92; }

/* ---------- Interruptor "Registrar automático" (mochila e rodapé do Códex) ---------- */
.codex-auto-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 5px 12px 5px 7px; border-radius: 999px;
  border: 1px solid rgba(243, 212, 142, .6); background: linear-gradient(180deg, #4a3a18, #1c1508); color: #f7e3b0;
  font: 900 12px var(--font-body, Nunito, sans-serif); letter-spacing: .02em; white-space: nowrap; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 240, 200, .25), 0 0 10px rgba(240, 190, 90, .15);
}
.codex-auto-btn:hover { border-color: #f3d48e; box-shadow: inset 0 1px 0 rgba(255, 240, 200, .25), 0 0 14px rgba(240, 190, 90, .35); }
.codex-auto-emblem {
  width: 20px; height: 20px; flex: none; border-radius: 6px;
  background: url('../sprites/hud-icons.png') 0 0 / 400% 400% no-repeat;
  filter: drop-shadow(0 0 3px rgba(255, 210, 120, .55));
}
.codex-auto-state {
  padding: 2px 7px; border-radius: 999px; background: rgba(0, 0, 0, .45); color: #c8bfa8;
  font-size: 10px; letter-spacing: .05em; text-transform: uppercase;
}
.codex-auto-btn.is-on .codex-auto-state { background: #1f6b3a; color: #c8ffd8; box-shadow: 0 0 0 1px #7df0a4, 0 0 8px rgba(110, 230, 140, .6); }
#inventory-dialog .inventory-sections .pack-codex-auto-btn[hidden] { display: none; }

/* ---------- Item que cai e vai direto para o Códex (some com um brilho dourado) ---------- */
.loot-drop.is-codex .loot-drop-item { box-shadow: 0 0 14px rgba(255, 215, 106, .85), 0 3px 6px #000a; }
.loot-drop.is-codex .loot-drop-name { border-color: #f3d48ecc; background: linear-gradient(180deg, #3a2a0ce8, #0b0f10e8); color: #ffe7a8; }
.loot-drop.is-codex .loot-drop-beam {
  display: block; position: absolute; left: 0; bottom: 0; width: 26px; height: 110px; transform-origin: 50% 100%;
  background: linear-gradient(0deg, rgba(255, 215, 106, .75), transparent); filter: blur(4px);
  animation: loot-beam 1.3s ease-out .5s both;
}

/* ---------- Celular ---------- */
@media (max-width: 680px) {
  #codex-dialog .codex-types { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 510px) {
  #codex-dialog { width: calc(100% - 12px); max-height: calc(100dvh - 12px); }
  #codex-dialog .codex-content { gap: 9px; padding: 10px; }
  #codex-dialog .codex-header h2 { gap: 8px; font-size: 21px; }
  #codex-dialog .codex-header h2 small { display: none; }
  #codex-dialog .codex-emblem { width: 36px; height: 36px; border-radius: 10px; }
  #codex-dialog .codex-emblem .hud-icon { --icon-size: 28px; }
  #codex-dialog .codex-progress { order: 3; flex: 1 1 100%; min-width: 0; padding: 6px 10px; }
  #codex-dialog .codex-progress strong { font-size: 15px; }
  #codex-dialog .codex-totals { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
  #codex-dialog .codex-total { grid-template-columns: 20px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 5px; row-gap: 0; padding: 4px 7px 4px 5px; }
  #codex-dialog .codex-total-icon { grid-row: 1 / span 2; width: 20px; height: 20px; }
  #codex-dialog .codex-total-icon > span { transform: scale(.8); }
  /* "Ataque especial" e "Defesa especial" quebram em duas linhas em vez de cortar com "…". */
  #codex-dialog .codex-total-label { font-size: 10px; line-height: 1.1; white-space: normal; text-overflow: clip; }
  #codex-dialog .codex-total b { font-size: 14px; }
  #codex-dialog .codex-types { gap: 3px; padding: 3px; }
  #codex-dialog .codex-type { padding: 4px 2px; }
  #codex-dialog .codex-type-icon .item-art { --item-size: 24px; }
  #codex-dialog .codex-type-name { font-size: 9.5px; }
  #codex-dialog .codex-bands { gap: 3px; }
  #codex-dialog .codex-band { min-height: 36px; padding: 4px 2px; }
  #codex-dialog .codex-band-prefix { display: none; }
  #codex-dialog .codex-band-name { font-size: 11.5px; }
  #codex-dialog .codex-board { padding: 4px 3px 6px; }
  #codex-dialog .codex-table { border-spacing: 3px; }
  #codex-dialog .codex-table thead th:first-child { width: 62px; }
  #codex-dialog .codex-table thead th { font-size: 11.5px; }
  #codex-dialog .codex-rarity { font-size: 10.5px; }
  #codex-dialog .codex-table tbody th small { font-size: 9px; }
  #codex-dialog .codex-cell { border-radius: 8px; }
  #codex-dialog .codex-cell .item-art { --item-size: 24px; }
  #codex-dialog .codex-cell-check { right: -3px; bottom: -3px; width: 14px; height: 14px; font-size: 8.5px; }
  #codex-dialog .codex-cell-count { top: -4px; right: -4px; min-width: 15px; height: 15px; font-size: 9px; line-height: 15px; }
  #codex-dialog .codex-detail { font-size: 11.5px; }
  #codex-dialog .codex-actions { width: 100%; margin-left: 0; }
  #codex-dialog .codex-actions > * { flex: 1 1 auto; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  #codex-dialog .codex-cell.is-ready, #codex-dialog .codex-cell.is-new { animation: none; }
}
