/* Card details share the Pokédex collection surfaces. */
.dex-detail {
  --dex-ink: var(--collection-ink, #e6eef4);
  --dex-muted: var(--collection-muted, #a4bac9);
  --dex-rule: var(--collection-line, #31505f);
  position: fixed;
  inset: 0;
  z-index: 950;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--collection-background, #0e1720);
  color: var(--dex-ink);
  font: 500 14px/1.5 var(--font-ptcg-zh);
}

.dex-detail-width {
  width: min(1720px, calc(100% - 44px));
  margin-inline: auto;
}

.dex-detail-bar {
  background: #162631;
  border-bottom: 1px solid var(--dex-rule);
}

.dex-detail-bar > div {
  min-height: 46px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #e2e9e9;
  font-size: 13px;
  font-weight: 700;
}

.dex-detail-bar--back-left > div {
  justify-content: flex-start;
  gap: 14px;
}

.dex-detail-bar > div > span > span { color: #9cafb5; padding-inline: 8px; }

.dex-detail .dex-detail-back { width: auto; padding: 5px 14px; font-size: 13px; }

.dex-shiny-toggle {
  appearance: none;
  border: 1px solid var(--dex-rule);
  border-radius: 6px;
  background: #0f1b24;
  color: #f3f6f4;
  padding: 5px 11px;
  min-height: 32px;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.dex-shiny-toggle:hover { background: #204252; }

.dex-detail :is(button, summary, [role="button"]):focus-visible {
  outline: 2px solid var(--collection-yellow, #facc15);
  outline-offset: 3px;
}

.dex-detail-scroll {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dex-detail-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-block: 8px 12px;
}

.dex-wiki-head {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--dex-rule);
}

.dex-wiki-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}

.dex-wiki-badges,
.dex-wiki-name-row,
.dex-wiki-head-types {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.dex-wiki-badges { color: #c4d1d3; font-size: 12px; font-weight: 700; }
.dex-num-pill {
  border-left: 3px solid var(--dex-accent);
  background: #101c24;
  color: #f3f5f3;
  padding: 2px 9px;
  font: 800 18px/1.1 var(--font-ptcg-num);
  letter-spacing: .05em;
}

.dex-wiki-name-row { align-items: baseline; margin-top: 0; }
#app .dex-wiki-name-row h2 {
  margin: 0;
  color: #f5f6f2;
  font-size: clamp(24px, 2.5vw, 34px);
  font-weight: 900;
  line-height: 1.12;
}
#dex-detail-title:focus { outline: none; }
.dex-wiki-name-en { color: #c4d1d3; font-size: clamp(13px, 1.25vw, 17px); font-weight: 700; }

.dex-detail-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.dex-wiki-head-types { gap: 6px; }
.dex-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  white-space: nowrap;
}
.dex-type-pill img { width: 18px; height: 18px; object-fit: contain; }
.dex-wiki-head-types .dex-type-pill {
  padding: 4px 9px;
  background: #17262e;
  border: 1px solid #647981;
  border-radius: 5px;
}

.dex-evo-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-block: 6px 8px;
  padding: 1px 2px 3px;
  overflow-x: auto;
  scrollbar-width: none;
}
.dex-evo-strip::-webkit-scrollbar { display: none; }
.dex-evo-strip-label { flex-shrink: 0; color: #c4d1d3; font-size: 12px; font-weight: 700; }
.dex-evo-chain { display: flex; align-items: center; gap: 6px; }
.dex-evo-arrow { color: #a4b4b8; font-size: 14px; flex-shrink: 0; }
.dex-evo-node {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-height: 38px;
  padding: 3px 10px;
  border: 1px solid var(--dex-rule);
  border-radius: 6px;
  background: #0f1b24;
  color: #eef3f1;
  font: inherit;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.dex-evo-node:hover { background: #204252; }
.dex-evo-node[aria-pressed="true"] {
  border-color: var(--collection-yellow, #facc15);
  background: #facc1524;
  color: var(--collection-highlight, #fef08a);
}
.dex-evo-thumb { width: 28px; height: 28px; object-fit: contain; }
.dex-evo-meta { display: grid; gap: 0; line-height: 1.24; }
.dex-evo-meta small { color: #d2dede; font-size: 11px; }
.dex-wiki-draft-note { flex: 0 0 auto; color: #f0cf99; margin: 0 0 8px; font-size: 12px; }

/* Main widescreen body: fills remaining viewport height with zero page scrollbar */
.dex-wiki-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(290px, 0.85fr) minmax(0, 1.45fr);
  gap: clamp(12px, 1.4vw, 20px);
  align-items: stretch;
}

.dex-wiki-body.has-altarts {
  grid-template-columns: minmax(280px, 0.88fr) minmax(320px, 1.08fr) minmax(300px, 1.04fr);
}

.dex-shiny-toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.dex-shiny-toggle img { width: 15px; height: 15px; image-rendering: pixelated; }
.dex-shiny-toggle.is-shiny { color: #fef08a; border-color: #facc15; background: #facc1524; }

.dex-foil-select {
  appearance: auto;
  border: 1px solid var(--dex-rule);
  border-radius: 6px;
  background: #0f1b24;
  color: #f3f6f4;
  padding: 4px 10px;
  min-height: 32px;
  max-width: 190px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.dex-foil-select:hover { background: #204252; }

.dex-showcase-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: clamp(12px, 1.6vw, 22px);
  border: 1px solid var(--dex-rule);
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 38%, #24404c, #111e28 76%);
  overflow: hidden;
}
#app .dex-detail .dex-showcase-card {
  width: min(100%, calc((100dvh - 195px) * 0.67), 348px) !important;
  margin: 0 !important;
  transform: none !important;
  cursor: zoom-in;
}
#app .dex-detail .dex-showcase-wrap.has-art-scale .dex-showcase-card {
  width: min(100%, calc((100dvh - 268px) * 0.67), 348px) !important;
}
.dex-art-scale-control {
  width: min(100%, 312px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 9px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 29, 38, 0.72);
  color: #e2e8f0;
  flex: 0 0 auto;
}
.dex-art-scale-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.dex-art-scale-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.dex-art-scale-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.dex-art-scale-val {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}
.dex-art-scale-reset {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.dex-art-scale-reset:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
}
.dex-art-scale-reset:disabled {
  opacity: 0.42;
  cursor: default;
}
.dex-art-scale-slider {
  width: 100%;
  margin: 0;
  accent-color: #38bdf8;
  cursor: pointer;
}
.dex-art-scale-status {
  font-size: 11px;
  line-height: 1.2;
  opacity: 0.72;
  text-align: right;
}

/* Middle column: Profile + Keywords + optional Tuning */
.dex-detail-record {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.dex-detail-record > div:empty { display: none; }

/* When there are NO alt-arts but there ARE keywords, split record into 2 balanced side-by-side columns */
.dex-wiki-body:not(.has-altarts) .dex-detail-record:has(#dex-wiki-keywords-host:not(:empty)) {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(12px, 1.4vw, 18px);
  align-items: stretch;
}
.dex-wiki-body:not(.has-altarts) .dex-detail-record:has(#dex-wiki-keywords-host:not(:empty)) .dex-tuning-disclosure {
  grid-column: 1 / -1;
}

.dex-wiki-profile,
.dex-detail .dex-wiki-keywords,
.dex-detail .dex-wiki-altarts,
.dex-tuning-disclosure {
  min-width: 0;
  border: 1px solid var(--dex-rule);
  border-radius: 10px;
  background: var(--collection-panel, #152530);
  color: var(--dex-ink);
}

.dex-wiki-profile {
  flex: 0 0 auto;
  padding: clamp(12px, 1.5vw, 18px);
  display: flex;
  flex-direction: column;
}

.dex-detail .dex-wiki-section-title {
  margin: 0 0 8px;
  color: var(--dex-ink);
  font-size: 13px;
  font-weight: 900;
}
.dex-wiki-facts { margin: 0; }
.dex-wiki-facts > div {
  display: grid;
  grid-template-columns: 6em minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding-block: 5px;
  border-bottom: 1px solid var(--dex-rule);
  font-size: 13px;
}
.dex-wiki-facts dt { color: var(--dex-muted); }
.dex-wiki-facts dd { margin: 0; font-weight: 700; }
.dex-bst-row { display: flex; align-items: center; gap: 8px; }
.dex-bst-row strong { font: 800 21px/.9 var(--font-ptcg-num); }
.dex-bst-bar { flex: 1; height: 4px; background: #0e1720; border-radius: 2px; overflow: hidden; }
.dex-bst-bar i { display: block; height: 100%; background: #55b3cb; }

.dex-wiki-matchup { display: grid; gap: 6px; margin-top: 12px; }
.dex-detail .dex-wiki-matchup h3 { margin-bottom: 2px; }
.dex-matchup-row { display: grid; grid-template-columns: 3em minmax(0, 1fr); gap: 8px; align-items: start; }
.dex-matchup-label { padding-top: 3px; font-size: 12px; font-weight: 800; }
.dex-matchup-label.weak { color: #ffad9c; }
.dex-matchup-label.resist { color: #99e4c3; }
.dex-matchup-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.dex-matchup-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 2px 4px;
  border: 1px solid var(--dex-rule);
  border-radius: 5px;
  background: #0f1b24;
}
.dex-matchup-chip .dex-type-pill { font-size: 11px; }
.dex-matchup-chip .dex-type-pill img { width: 15px; height: 15px; }
.dex-matchup-chip em { font: 800 13px var(--font-ptcg-num); color: #ffad9c; }
.dex-matchup-none { color: var(--dex-muted); font-size: 12px; }

#dex-wiki-keywords-host {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.dex-detail .dex-wiki-keywords {
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(12px, 1.4vw, 16px);
  display: flex;
  flex-direction: column;
  margin-top: 0;
}
.dex-detail .dex-wiki-kw-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  align-content: start;
}
.dex-detail .dex-wiki-kw-list::-webkit-scrollbar { display: none; }
.dex-detail .dex-wiki-kw-item { color: var(--dex-ink); border-bottom-color: var(--dex-rule); }

/* Right column: Full-Art Alt-Art Gallery Panel */
.dex-detail .dex-wiki-altarts {
  margin-top: 0;
  padding: clamp(12px, 1.4vw, 16px);
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.dex-detail .dex-wiki-altarts .dex-altart-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
  align-content: start;
  overflow: hidden;
  padding: 2px;
}
/* Switch to 3 columns when 5+ cards exist, 4 columns when 10+ cards exist so all fit in one screen */
.dex-detail .dex-wiki-altarts .dex-altart-grid:has(.dex-altart-item:nth-child(5)) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.dex-detail .dex-wiki-altarts .dex-altart-grid:has(.dex-altart-item:nth-child(10)) {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}
.dex-detail .dex-wiki-altarts .dex-altart-item {
  padding: 4px;
  gap: 3px;
  border-radius: 8px;
  background: #0f1b24;
  border-color: var(--dex-rule);
}
.dex-detail .dex-wiki-altarts .dex-altart-item img {
  height: auto;
  max-height: calc((100dvh - 330px) / 2);
  width: auto;
  max-width: 100%;
  aspect-ratio: 63 / 88;
  object-fit: cover;
}
.dex-detail .dex-wiki-altarts .dex-altart-grid:has(.dex-altart-item:nth-child(7)) .dex-altart-item img {
  max-height: calc((100dvh - 375px) / 3);
}
.dex-detail .dex-wiki-altarts .dex-altart-grid:has(.dex-altart-item:nth-child(13)) .dex-altart-item img {
  max-height: calc((100dvh - 410px) / 4);
}

.dex-tuning-disclosure { flex: 0 0 auto; }
.dex-tuning-disclosure summary { padding: 9px 14px; font-weight: 900; font-size: 13px; cursor: pointer; }
.dex-tuning-disclosure[open] summary { border-bottom: 1px solid var(--dex-rule); }
.dex-tuning-disclosure .dex-tuning-editor {
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--dex-ink);
  padding: 10px 14px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: none;
}
.dex-tuning-disclosure .dex-tuning-editor::-webkit-scrollbar { display: none; }
.dex-detail :is(.dex-tuning-tip, .dex-tuning-help, .dex-tuning-field small) { color: var(--dex-muted); }
.dex-detail .dex-tuning-field input { background: #0f1b24; border-color: var(--dex-rule); }
.dex-detail .dex-tuning-field input:invalid { border-color: #ffad9c; }
.dex-detail .dex-tuning-status.is-error { color: #ffad9c; }

/* Narrow screens: wrap alt-arts below only when viewport is too narrow for 3 columns */
@media (max-width: 760px) {
  .dex-detail-scroll { overflow-y: auto; scrollbar-width: none; }
  .dex-detail-scroll::-webkit-scrollbar { display: none; }
  .dex-detail-content { flex: 0 0 auto; }
  .dex-wiki-body,
  .dex-wiki-body.has-altarts {
    grid-template-columns: minmax(240px, 0.85fr) minmax(0, 1.15fr);
    align-items: start;
  }
  .dex-wiki-body.has-altarts .dex-wiki-altarts {
    grid-column: 1 / -1;
    height: auto;
  }
  .dex-wiki-body.has-altarts .dex-altart-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .dex-wiki-body:not(.has-altarts) .dex-detail-record:has(#dex-wiki-keywords-host:not(:empty)) {
    display: flex;
    flex-direction: column;
  }
  .dex-showcase-wrap { height: auto; }
}

@media (max-width: 690px) {
  .dex-detail-width { width: calc(100% - 24px); }
  .dex-detail-bar > div { min-height: 42px; }
  .dex-wiki-body,
  .dex-wiki-body.has-altarts { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 390px) {
  .dex-wiki-facts > div { grid-template-columns: 1fr; gap: 2px; }
}

@media (max-height: 600px) and (orientation: landscape) {
  .dex-detail-bar > div { min-height: 38px; }
  .dex-detail-content { padding-block: 8px 10px; }
  .dex-wiki-head { padding-bottom: 6px; }
  #app .dex-wiki-name-row h2 { font-size: clamp(20px, 2.8vw, 26px); }
  .dex-evo-strip { margin-block: 5px 8px; padding-block: 1px 2px; }
  .dex-evo-node { min-height: 34px; }
  .dex-evo-thumb { width: 24px; height: 24px; }
  #app .dex-detail .dex-showcase-card { width: min(100%, calc((100dvh - 165px) * 0.67), 240px) !important; }
}

/* Keep the detail entry reachable in the game's short landscape viewport. */
@media (max-height: 650px) and (orientation: landscape) {
  #card-zoom3d-overlay {
    flex-direction: row;
    padding: 10px 18px;
    overflow: auto;
  }
  #card-zoom3d-overlay .zoom3d-stage { padding: 8px 16px !important; }
  #card-zoom3d-overlay #zoom3d-card.ptcg-v2 {
    width: min(352px, 42vw, calc((100dvh - var(--run-hud-size, 0px) - 44px) * .718)) !important;
  }
  #card-zoom3d-overlay .zoom3d-toolbar { max-width: min(230px, 36vw); flex: 0 1 auto; }
  #card-zoom3d-overlay .zoom3d-foil-wrap { max-width: min(320px, 42vw); max-height: 112px; overflow: auto; }
  #card-zoom3d-overlay .zoom3d-foil-bar { max-width: 100%; }
  #card-zoom3d-overlay .zoom3d-hint { display: none; }
}
