/* ============================================================================
 * Persistent Chimera Codex & Milestones Overlay (#codex-overlay)
 * ========================================================================== */
.overlay.codex-overlay {
  justify-content: center;
  align-items: center;
  padding: 18px;
  background: radial-gradient(ellipse at center, rgba(10, 12, 18, 0.80) 0%, rgba(8, 10, 15, 0.94) 100%);
  z-index: 29;
}

.codex-sheet {
  width: min(824px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--stone-base);
  border: 1px solid var(--stone-edge);
  border-top: 2px solid var(--brass);
  border-bottom: 2px solid var(--stone-ledge);
  border-radius: var(--radius-outer);
  box-shadow: 0 6px 0 var(--stone-ledge);
  overflow: hidden;
  transform: translateY(8px) scale(0.985);
  transition: transform 240ms var(--ease-ui);
}

.overlay.visible .codex-sheet {
  transform: translateY(0) scale(1);
}

.codex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #242936;
  flex-shrink: 0;
}

.codex-header-left {
  min-width: 0;
}

.codex-header-left h2 {
  font-size: 20px;
}

.codex-summary {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--brass);
  font-variant-numeric: tabular-nums;
}

.codex-close-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.codex-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 20px 0;
  background: var(--stone-deep);
  border-bottom: 1px solid var(--stone-edge);
  flex-shrink: 0;
}

.codex-tab {
  appearance: none;
  padding: 8px 14px;
  border-radius: var(--radius-inner) var(--radius-inner) 0 0;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 140ms var(--ease-ui), background-color 140ms var(--ease-ui), border-color 140ms var(--ease-ui);
}

.codex-tab.is-active {
  background: var(--stone-base);
  border-color: var(--stone-edge);
  border-top: 2px solid var(--brass);
  color: var(--ink-main);
}

@media (hover: hover) {
  .codex-tab:not(.is-active):hover {
    color: var(--ink-main);
    background: rgba(35, 40, 52, 0.55);
  }
}

.codex-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

/* Tab 1: Habitat-Filtered Silhouette Grid (Scales 16 -> 34 -> 50+) */
.codex-filter-bar {
  position: sticky;
  top: -16px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: -16px -20px 12px;
  padding: 10px 20px;
  background: var(--stone-base);
  border-bottom: 1px solid #242936;
}

.codex-filter-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: var(--stone-deep);
  color: var(--ink-muted);
  border: 1px solid var(--stone-edge);
  border-radius: var(--radius-inner);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 150ms var(--ease-ui), background-color 140ms var(--ease-ui), border-color 140ms var(--ease-ui), color 140ms var(--ease-ui);
}

.codex-filter-btn:not(:disabled):active {
  transform: scale(0.96);
}

.codex-filter-btn.is-active {
  background: #231e14;
  border-color: var(--brass-dim);
  border-top: 2px solid var(--brass);
  color: var(--ink-main);
}

.codex-filter-cnt {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.codex-filter-btn.is-active .codex-filter-cnt {
  color: var(--brass-bright);
}

@media (hover: hover) {
  .codex-filter-btn:not(.is-active):hover {
    background: var(--stone-raised);
    border-color: var(--brass-dim);
    color: var(--ink-main);
  }
}

.codex-arch-empty {
  margin: 12px 0;
  padding: 14px;
  text-align: center;
  background: var(--stone-deep);
  border: 1px solid #242936;
  border-radius: var(--radius-inner);
  font-size: 12px;
  color: var(--ink-muted);
}

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

.codex-arch-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 9px;
  border-radius: var(--radius-inner);
  background: var(--stone-deep);
  border: 1px solid #262b38;
  border-top: 2px solid var(--stone-edge);
  contain: layout style;
}

.codex-arch-habitat {
  padding: 2px 6px;
  background: #141822;
  border: 1px solid #222735;
  border-left: 2px solid var(--stone-edge);
  border-radius: 1px;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex-arch-habitat[data-habitat="stone"]     { border-left-color: #6ea87e; }
.codex-arch-habitat[data-habitat="forge"]     { border-left-color: #de8a42; }
.codex-arch-habitat[data-habitat="mire"]      { border-left-color: #54b898; }
.codex-arch-habitat[data-habitat="frost"]     { border-left-color: #56c8eb; }
.codex-arch-habitat[data-habitat="desert"]    { border-left-color: #d4a24e; }
.codex-arch-habitat[data-habitat="reef"]      { border-left-color: #3daec4; }
.codex-arch-habitat[data-habitat="sky"]       { border-left-color: #8ab6eb; }
.codex-arch-habitat[data-habitat="clockwork"] { border-left-color: #c97b42; }
.codex-arch-habitat[data-habitat="throne"],
.codex-arch-habitat[data-habitat="anomaly"],
.codex-arch-habitat[data-habitat="endless"],
.codex-arch-habitat[data-habitat="apex"]      { border-left-color: var(--brass); color: #d8c79e; }

.codex-arch-card.is-seen {
  border-top-color: var(--brass-dim);
}

.codex-arch-card.is-complete {
  border-color: #6b5322;
  border-top-color: var(--brass);
}

.codex-arch-card.is-rare:not(.is-complete) {
  border-top-color: var(--brass-dim);
}

.codex-arch-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.codex-rare-badge {
  flex-shrink: 0;
  padding: 0 5px;
  line-height: 1.45;
  border-radius: 1px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: #271f10;
  border: 1px solid var(--brass-dim);
  color: var(--brass-bright);
  white-space: nowrap;
}

.codex-rare-badge[data-rare="異変"] {
  background: #2b161b;
  border-color: #8c3c44;
  color: #f3b2b6;
}

.codex-rare-badge[data-rare="巨獣"] {
  background: #2b1d10;
  border-color: #9e6528;
  color: #f7c77a;
}

.codex-rare-badge[data-rare="宝庫"] {
  background: #292110;
  border-color: var(--brass);
  color: var(--brass-bright);
}

.codex-rare-badge[data-rare="無窮"] {
  background: #1e182c;
  border-color: #7b66b0;
  color: #d6c8ff;
}

.codex-rare-badge[data-rare="覇王"] {
  background: #2b1812;
  border-color: var(--brass-bright);
  color: #ffe196;
}

.codex-ms-progress {
  margin-left: auto;
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: 1px;
  background: var(--stone-base);
  border: 1px solid var(--stone-edge);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.codex-arch-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.codex-arch-thumb {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 1px;
  background: #0a0c12;
  border: 1px solid #262b38;
  image-rendering: pixelated;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-dim);
}

.codex-arch-meta {
  min-width: 0;
  flex: 1;
}

.codex-arch-name {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex-arch-card:not(.is-seen) .codex-arch-name {
  color: var(--ink-dim);
}

.codex-arch-role {
  display: block;
  font-size: 10px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex-slot-pips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.codex-slot-pip {
  text-align: center;
  padding: 2px 0;
  border-radius: 1px;
  font-size: 9.5px;
  font-weight: 700;
  background: #141720;
  border: 1px solid #232834;
  color: var(--ink-dim);
}

.codex-slot-pip.is-stolen {
  background: #271f10;
  border-color: var(--brass-dim);
  color: var(--brass-bright);
}

/* Tab 2: Giant Bosses, Variants & Lifetime Records */
.codex-section-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--brass);
  padding-bottom: 4px;
  border-bottom: 1px solid #242936;
}

.codex-section + .codex-section {
  margin-top: 16px;
}

.codex-boss-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.codex-record-box {
  padding: 8px 10px;
  border-radius: var(--radius-inner);
  background: var(--stone-deep);
  border: 1px solid #262b38;
  font-variant-numeric: tabular-nums;
}

.codex-record-box.is-cleared {
  border-top: 2px solid var(--brass);
}

.codex-record-box span {
  display: block;
  font-size: 10px;
  color: var(--ink-muted);
  line-height: 1.35;
}

.codex-record-box strong {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  color: var(--ink-main);
}

.codex-variant-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.codex-variant-grid .codex-record-box[data-variant="crimson"] { border-left: 2px solid #e05246; }
.codex-variant-grid .codex-record-box[data-variant="frost"]   { border-left: 2px solid #56d6f5; }
.codex-variant-grid .codex-record-box[data-variant="venom"]   { border-left: 2px solid #7ce052; }
.codex-variant-grid .codex-record-box[data-variant="gold"]    { border-left: 2px solid #f2c852; }

.codex-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.codex-cp-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.codex-cp-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  background: var(--stone-deep);
  border: 1px solid var(--brass-dim);
  border-left: 2px solid var(--brass);
  border-radius: var(--radius-inner);
  font-size: 11px;
  font-weight: 700;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
}

.codex-cp-empty {
  margin: 0;
  padding: 6px 10px;
  background: var(--stone-deep);
  border: 1px solid #242936;
  border-radius: var(--radius-inner);
  font-size: 11px;
  color: var(--ink-muted);
}

/* Tab 3: Milestones List */
.codex-milestones-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.codex-milestone-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 11px;
  border-radius: var(--radius-inner);
  background: var(--stone-deep);
  border: 1px solid #242936;
  border-left: 2px solid #2e3445;
}

.codex-milestone-row.is-unlocked {
  border-color: #6b5322;
  border-left: 2px solid var(--brass);
  background: #1a1813;
}

.codex-ms-mark {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-inner);
  background: #13161f;
  border: 1px solid #2a3040;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-dim);
}

.codex-milestone-row.is-unlocked .codex-ms-mark {
  background: var(--brass);
  border-color: var(--brass-bright);
  color: #161108;
}

.codex-ms-meta {
  min-width: 0;
  flex: 1;
}

.codex-ms-title {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-main);
}

.codex-milestone-row:not(.is-unlocked) .codex-ms-title {
  color: var(--ink-muted);
}

.codex-ms-desc {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink-muted);
}

/* Tab 4: Carved Stone Save & JSON Backup Panel */
.save-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.save-summary-head .codex-section-title {
  margin-bottom: 0;
}

.save-updated-badge {
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  padding: 2px 7px;
  border-radius: var(--radius-inner);
  background: var(--stone-deep);
  border: 1px solid var(--stone-edge);
}

.save-io-lead {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.save-io-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.save-action-btn {
  min-height: 38px;
  padding: 8px 12px;
  font-size: 12px;
}

.save-feedback {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: var(--radius-inner);
  background: var(--stone-deep);
  border: 1px solid var(--stone-edge);
  border-left: 2px solid var(--brass);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-main);
}

.save-feedback[data-tone="good"] {
  border-left-color: var(--soul-cyan);
  color: #cff6fc;
}

.save-feedback[data-tone="error"] {
  border-left-color: var(--crimson);
  color: #f4b6b2;
}

.save-import-preview {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-outer);
  background: var(--stone-deep);
  border: 1px solid var(--stone-edge);
  border-left: 3px solid var(--brass);
  box-shadow: 0 3px 0 var(--stone-ledge);
}

.save-import-preview.is-valid {
  border-left-color: var(--soul-cyan);
}

.save-import-preview.is-error {
  border-color: #5b282b;
  border-left-color: var(--crimson);
}

.save-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--ink-main);
}

.save-inline-btn {
  appearance: none;
  padding: 3px 8px;
  border-radius: var(--radius-inner);
  background: var(--stone-base);
  border: 1px solid var(--stone-edge);
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.save-inline-btn:not(:disabled):active {
  transform: scale(0.96);
}

.save-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.save-preview-grid > div {
  padding: 6px 8px;
  border-radius: var(--radius-inner);
  background: var(--stone-base);
  border: 1px solid #262c3a;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.save-preview-grid span {
  font-size: 10px;
  color: var(--ink-muted);
}

.save-preview-grid strong {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-main);
}

.save-preview-msg,
.save-preview-note,
.save-preview-warn {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-muted);
}

.save-preview-warn {
  color: #f0c674;
}

.save-import-preview.is-error .save-preview-msg {
  margin-bottom: 0;
  color: #f4b6b2;
}

.save-preview-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.save-danger-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-outer);
  background: #171216;
  border: 1px solid #482428;
  border-left: 2px solid var(--crimson);
}

.save-danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.save-danger-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.save-danger-copy strong {
  font-size: 12px;
  color: #f0c4c0;
}

.save-danger-copy span {
  font-size: 11px;
  color: var(--ink-muted);
}

.save-danger-btn {
  appearance: none;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: var(--radius-outer);
  background: #2b1518;
  border: 1px solid #7d3339;
  border-bottom: 2px solid #16090b;
  color: #f5c0bc;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 120ms var(--ease-ui), background-color 140ms var(--ease-ui), border-color 140ms var(--ease-ui);
}

.save-danger-btn.is-armed {
  background: #962b32;
  border-color: #d9534f;
  color: #fff3f2;
}

.save-danger-btn:not(:disabled):active {
  transform: scale(0.96);
}

@media (hover: hover) {
  .save-danger-btn:hover {
    background: #3d1c20;
    border-color: #b5454c;
  }
  .save-danger-btn.is-armed:hover {
    background: #b5343c;
  }
  .save-inline-btn:hover {
    color: var(--ink-main);
    border-color: var(--brass-dim);
  }
}

.save-reset-confirm p {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  color: #f5c0bc;
}
