/* ==========================================================================
   MAPLE REMAKE — 몬스터 도감 (monsters.html 전용)
   style.css 의 토큰(--sky/--grass/--accent/--line …)만 사용하는 플랫 테마 확장.
   이 파일은 도감 페이지에서만 로드된다.
   ========================================================================== */

.dex-page {
  --zone-normal-bg: #e9f5e4;
  --zone-normal-ink: #2c6421;
  --zone-hell-bg: #fdecec;
  --zone-hell-ink: #b3261e;
  --zone-boss-bg: #fff1d8;
  --zone-boss-ink: #7c4f24;
  --tone-sky-bg: #e6f4fd;
  --tone-sky-ink: #1a6389;
  --tone-mute-bg: #f2efe8;
  --list-w: 316px;
}

/* 도감은 표가 많아 기본(1120px)보다 넓은 폭을 쓴다 */
.dex-page .container {
  width: min(1400px, 100% - 48px);
}

.dex-page .page-body {
  padding: 40px 0 88px;
}

/* ---------- 요약 카드 ---------- */

.dex-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.dex-summary-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.dex-summary-card strong {
  display: block;
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1.2;
  color: var(--accent-deep);
  letter-spacing: -0.02em;
}

.dex-summary-card span {
  display: block;
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

/* ---------- 알림 / 안내 문구 ---------- */

.dex-alert {
  margin: 0 0 20px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid #f2c9c9;
  background: #fdecec;
  color: #a3271f;
  font-size: 0.94rem;
  font-weight: 700;
}

.dex-note {
  margin: 0;
  padding: 44px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.dex-note.is-error {
  color: var(--danger);
  font-weight: 700;
}

.dex-footnote {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

/* ---------- 탭 ---------- */

.dex-tabbar {
  position: sticky;
  top: var(--nav-h);
  z-index: 20;
  padding: 12px 0;
  margin-bottom: 6px;
  background: var(--sky-light);
}

.dex-tabbar .filter-tabs {
  margin-bottom: 0;
}

.dex-view[hidden] {
  display: none;
}

/* ---------- 필터 툴바 ---------- */

.dex-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 18px;
  margin-bottom: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
}

.dex-fields {
  flex: 1 1 640px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px 14px;
}

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

.dex-field-wide {
  grid-column: span 2;
}

.dex-field-narrow {
  max-width: 150px;
}

.dex-field label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: -0.01em;
}

.dex-field input,
.dex-field select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  transition: border-color 0.2s var(--ease);
}

.dex-field select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.dex-field input:hover,
.dex-field select:hover {
  border-color: var(--accent);
}

.dex-field input:focus,
.dex-field select:focus {
  border-color: var(--accent-deep);
  outline: none;
}

.dex-field input:focus-visible,
.dex-field select:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 2px;
}

.dex-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

/* ---------- 좌: 목록 / 우: 상세 ---------- */

.dex-split {
  display: grid;
  grid-template-columns: var(--list-w) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.dex-list-panel {
  position: sticky;
  top: calc(var(--nav-h) + 66px);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--nav-h) - 92px);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.dex-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
  font-size: 0.92rem;
}

.dex-list-head strong {
  font-weight: 900;
}

.dex-list-info {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.dex-list {
  position: relative; /* 행 offsetTop 기준점 — 선택 행 스크롤 계산에 쓰인다 */
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

/* 조각 렌더용 감시 지점 (IntersectionObserver) */
.dex-sentinel {
  height: 1px;
}

.dex-row {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  /* 목록이 길어도 화면 밖 행의 레이아웃/페인트를 건너뛴다 */
  content-visibility: auto;
  contain-intrinsic-size: auto 62px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.dex-row:last-child {
  border-bottom: 0;
}

.dex-row:hover {
  background: #fff8ef;
  border-left-color: var(--accent);
}

.dex-row.is-active {
  background: #fff2e0;
  border-left-color: var(--accent-deep);
}

.dex-row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dex-row-name {
  font-weight: 700;
  font-size: 0.97rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dex-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 700;
}

/* ---------- 상세 패널 ---------- */

.dex-detail {
  min-width: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.dex-detail-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
}

.dex-detail-hero.zone-normal { background: var(--zone-normal-bg); }
.dex-detail-hero.zone-hell { background: var(--zone-hell-bg); }
.dex-detail-hero.zone-boss { background: var(--zone-boss-bg); }

.dex-detail-hero h2 {
  margin: 8px 0 4px;
  font-size: clamp(1.25rem, 2.4vw, 1.6rem);
}

.dex-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dex-subline {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.dex-item-desc {
  margin: 10px 0 0;
  max-width: 68ch;
  color: var(--text);
  font-size: 0.92rem;
  white-space: pre-line;
}

.dex-orb {
  flex: none;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  background: var(--sky);
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.dex-orb small {
  display: block;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: rgba(61, 44, 23, 0.72);
}

.dex-orb strong {
  display: block;
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1.1;
}

/* 합쳐진 항목은 레벨이 "21~35" 범위라 글자를 줄인다 */
.dex-orb.is-range strong {
  font-size: 1rem;
  letter-spacing: -0.03em;
}

.dex-section {
  padding: 22px 24px;
  border-top: 1px solid var(--line);
}

.dex-section:first-of-type {
  border-top: 0;
}

.dex-section-head {
  margin-bottom: 14px;
}

.dex-section-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.dex-section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

/* 스펙 카드 그리드 */

.dex-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 8px;
}

.dex-stat {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
}

.dex-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.dex-stat strong {
  display: block;
  margin-top: 2px;
  font-size: 0.98rem;
  font-weight: 900;
  word-break: break-all;
}

/* 부가 설명 스트립 */

.dex-strip {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--sky);
  border-radius: var(--radius-sm);
  background: var(--tone-sky-bg);
  font-size: 0.88rem;
}

.dex-strip .dex-strip-icon {
  flex: none;
  font-size: 1.1rem;
  line-height: 1.3;
}

.dex-strip strong {
  font-weight: 900;
}

/* 표 */

/* 상세 표는 길어도 페이지를 늘리지 않고 이 컨테이너 안에서만 스크롤한다.
   (목록 패널과 같은 방식 · thead 는 sticky 로 남고, overscroll-behavior 로
    표 끝에서 페이지가 따라 스크롤되는 것도 막는다) */
.dex-table-wrap {
  overflow: auto;
  overscroll-behavior: contain;
  max-height: max(280px, calc(100vh - var(--nav-h) - 250px));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.dex-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.dex-table th,
.dex-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.dex-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--cream);
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 900;
  white-space: nowrap;
}

.dex-table tbody tr:last-child td {
  border-bottom: 0;
}

.dex-table tbody tr:hover {
  background: #fffaf3;
}

.dex-table .nowrap {
  white-space: nowrap;
}

.dex-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-deep);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.dex-link:hover {
  text-decoration: underline;
}

.dex-muted {
  color: var(--muted);
  font-size: 0.85rem;
}

/* 수량별 확률 — "1개 20%" 배지를 나란히 */
.dex-tiers {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.dex-tier b {
  font-weight: 900;
  opacity: 0.75;
}

/* ---------- 아이템 아이콘 (스프라이트 시트) ---------- */
/* --icon-sheet / --icon-cell / --icon-sheet-w 는 monsters.js 가 데이터의 meta.icons 로 채운다.
   칸 위치는 요소마다 --x(열) --y(행) 로 주고, --k 배율만 바꾸면 같은 시트로 크기를 달리 그린다. */

.dex-icon {
  --k: 1;
  flex: none;
  display: inline-block;
  width: calc(var(--icon-cell) * var(--k));
  height: calc(var(--icon-cell) * var(--k));
  background-image: var(--icon-sheet);
  background-repeat: no-repeat;
  background-size: calc(var(--icon-sheet-w) * var(--k)) auto;
  background-position:
    calc(var(--x) * var(--icon-cell) * var(--k) * -1)
    calc(var(--y) * var(--icon-cell) * var(--k) * -1);
  vertical-align: middle;
}

/* 상세 헤더용 2배 — 정수 배율이라 픽셀아트가 번지지 않게 그대로 키운다 */
.dex-icon.is-lg {
  --k: 2;
  image-rendering: pixelated;
}

/* 몬스터 이미지 — 같은 .dex-icon 규칙을 쓰되 시트만 바꿔 끼운다 */
.dex-mob {
  --icon-sheet: var(--mob-s-sheet);
  --icon-cell: var(--mob-s-cell);
  --icon-sheet-w: var(--mob-s-sheet-w);
}

.dex-mob.is-lg {
  --k: 1;
  --icon-sheet: var(--mob-l-sheet);
  --icon-cell: var(--mob-l-cell);
  --icon-sheet-w: var(--mob-l-sheet-w);
  image-rendering: auto;
}

.dex-icon-fallback {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  font-size: 1.15rem;
  line-height: 1;
}

.dex-icon-fallback.is-lg {
  width: 72px;
  height: 72px;
  font-size: 2.4rem;
}

.dex-item-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dex-row.has-icon {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dex-row-body {
  flex: 1;
  min-width: 0;
}

.dex-hero-main {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

/* ---------- 배지 ---------- */

.dex-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--tone-mute-bg);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
  line-height: 1.5;
}

.dex-badge.zone-normal { background: var(--zone-normal-bg); color: var(--zone-normal-ink); }
.dex-badge.zone-hell { background: var(--zone-hell-bg); color: var(--zone-hell-ink); }
.dex-badge.zone-boss { background: var(--zone-boss-bg); color: var(--zone-boss-ink); }
.dex-badge.category { background: var(--tone-sky-bg); color: var(--tone-sky-ink); }
.dex-badge.quest { background: #f3ecfb; color: #6a3fa0; }
.dex-badge.count { background: var(--zone-normal-bg); color: var(--zone-normal-ink); }
.dex-badge.chance-high { background: var(--zone-normal-bg); color: var(--zone-normal-ink); }
.dex-badge.chance-mid { background: var(--zone-boss-bg); color: var(--zone-boss-ink); }
.dex-badge.chance-low { background: var(--tone-mute-bg); color: var(--muted); }

/* ---------- 로딩 스켈레톤 ---------- */

.dex-page .sk {
  display: block;
  height: 13px;
  border-radius: 7px;
  background: linear-gradient(90deg, #f0ece2 25%, #faf8f2 50%, #f0ece2 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.dex-summary-card.is-skeleton .sk-num { height: 24px; width: 60%; margin: 0 auto; }
.dex-summary-card.is-skeleton .sk-label { width: 74%; margin: 8px auto 0; }
.dex-row.is-skeleton { cursor: default; }
.dex-row.is-skeleton .sk-title { width: 62%; }
.dex-row.is-skeleton .sk-meta { width: 84%; margin-top: 8px; height: 10px; }

/* ---------- 반응형 ---------- */

@media (max-width: 1180px) {
  .dex-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1040px) {
  .dex-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .dex-list-panel {
    position: static;
    max-height: 340px;
  }

  .dex-detail-hero {
    align-items: flex-start;
  }
}

@media (max-width: 960px) {
  .dex-page .container {
    width: min(1400px, 100% - 40px);
  }

  .dex-actions {
    flex: 1 1 100%;
  }

  .dex-actions .btn {
    flex: 1;
  }
}

@media (max-width: 600px) {
  .dex-page .container {
    width: min(1400px, 100% - 32px);
  }

  .dex-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .dex-summary-card {
    padding: 12px 8px;
  }

  .dex-summary-card strong {
    font-size: 1.25rem;
  }

  .dex-field-wide {
    grid-column: span 2;
  }

  .dex-toolbar {
    padding: 14px;
  }

  .dex-detail-hero,
  .dex-section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .dex-orb {
    width: 66px;
    height: 66px;
  }

  .dex-hero-main {
    gap: 12px;
  }

  .dex-icon.is-lg {
    --k: 1.5;
    image-rendering: auto;
  }

  .dex-mob.is-lg {
    --k: 0.6;
  }

  .dex-icon-fallback.is-lg {
    width: 54px;
    height: 54px;
    font-size: 1.8rem;
  }

  .dex-orb strong {
    font-size: 1.2rem;
  }
}

/* ---------- 인쇄 (현재 선택한 상세만) ---------- */

@media print {
  .site-nav,
  .site-footer,
  .page-hero,
  .dex-tabbar,
  .dex-toolbar,
  .dex-list-panel,
  .dex-summary,
  .dex-footnote {
    display: none !important;
  }

  .dex-page .page-body {
    padding: 0;
  }

  .dex-page .container {
    width: 100%;
  }

  .dex-split {
    display: block;
  }

  .dex-detail {
    border: 0;
    box-shadow: none;
  }

  .dex-table-wrap {
    overflow: visible;
    max-height: none; /* 인쇄에서는 표를 자르지 않는다 */
  }

  .dex-row,
  .dex-table tbody tr {
    break-inside: avoid;
  }
}
