/* Ponsedex handheld, gallery grid and the dex entry modal. */

.dexdev {
  --b: var(--px);
  background: var(--lilac); padding: 10px 6px 8px; margin: 0 calc(var(--gut) * -1);
  box-shadow: 0 calc(var(--b) * -1) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink), 0 calc(var(--b) * 3) 0 0 var(--lilac-dark), 0 calc(var(--b) * 4) 0 0 var(--ink);
}
@media (min-width: 720px) {
  .dexdev {
    margin: calc(var(--b) * 3); padding: 16px 20px 24px;
    box-shadow:
      0 calc(var(--b) * -1) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
      calc(var(--b) * -1) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink),
      inset calc(var(--b) * -2) calc(var(--b) * -2) 0 0 var(--lilac-dark),
      inset var(--b) var(--b) 0 0 rgb(255 255 255 / .45),
      calc(var(--b) * 2) calc(var(--b) * 3) 0 var(--b) rgb(29 23 51 / .25);
  }
}
.dexdev__top { display: flex; align-items: center; gap: 14px; padding: 2px 6px 12px; }
.dexdev__leds { display: flex; gap: 8px; }
.dexdev__leds i { width: 12px; height: 12px; background: var(--pink); box-shadow: 0 0 0 2px var(--ink), inset 3px 3px 0 0 rgb(255 255 255 / .6); }
.dexdev__leds i:nth-child(2) { background: var(--butter); }
.dexdev__leds i:nth-child(3) { background: var(--mint); animation: blink 1.4s steps(1) infinite; }
.dexdev__brand { font: var(--fs-s)/1 var(--font-px); text-transform: uppercase; color: var(--ink); letter-spacing: .06em; }
.dexdev__brand small { font-size: var(--fs-xs); color: var(--ink-2); }
.dexdev__grill { margin-left: auto; display: grid; grid-template-columns: repeat(3, 4px); gap: 4px; }
.dexdev__grill i { display: block; width: 4px; height: 4px; background: var(--ink-2); }

/* controls */
.dex-controls { display: grid; gap: 10px; padding: 0 4px 12px; }
@media (min-width: 720px) { .dex-controls { padding: 4px 0 16px; gap: 12px; } }
.dex-controls__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field {
  display: flex; align-items: center; gap: 8px; background: var(--paper); min-height: 48px; padding: 0 10px; margin: 3px;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 3px 3px 0 0 var(--paper-2);
}
.field:focus-within { outline: 3px dashed var(--ink); outline-offset: 5px; }
.field .px-icon { color: var(--ink-2); }
.field--search { flex: 1 1 100%; }
.field--search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 44px; padding: 0;
  font: var(--fs-s)/1 var(--font-px); color: var(--ink);
}
.field--search input::placeholder { color: #8f88a3; }
.field--search input::-webkit-search-cancel-button { filter: grayscale(1); }
/* selects: small label stacked over the value */
.field--select { flex: 1 1 0; min-width: 0; flex-direction: column; align-items: stretch; justify-content: center; gap: 3px; padding: 6px 0 0 9px; position: relative; }
.field__label { font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--ink-2); }
.field--select select {
  appearance: none; -webkit-appearance: none; border: 0; border-radius: 0; background: transparent; outline: none;
  width: 100%; min-width: 0; height: 30px; padding: 0 26px 0 0; margin: 0; cursor: pointer; text-overflow: ellipsis;
  font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--ink);
}
.field--select::after { content: ""; position: absolute; right: 9px; bottom: 12px; width: 14px; height: 8px; background: url(../assets/ui/arrow-down.svg) center / 100% 100% no-repeat; image-rendering: pixelated; pointer-events: none; }
@media (min-width: 720px) {
  .field--search { flex: 2 1 300px; }
  .field--select { flex: 1 1 140px; }
  .field--select select { font-size: var(--fs-s); }
}

.type-chips { display: flex; gap: 8px; }
@media (max-width: 719px) {
  /* one swipeable row on phones */
  .type-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 8px; margin: 0 -4px; scroll-snap-type: x proximity; }
  .type-chips::-webkit-scrollbar { display: none; }
  .type-chip { flex: none; scroll-snap-align: start; }
}
@media (min-width: 720px) { .type-chips { flex-wrap: wrap; } }
.type-chip {
  appearance: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 6px 9px 5px 7px; margin: 2px; background: var(--paper); color: var(--ink);
  font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), 0 4px 0 0 var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.type-chip img { height: 14px; width: auto; }
.type-chip[aria-pressed="true"] { background: var(--tc, var(--butter)); color: var(--tfg, var(--ink)); transform: translateY(2px); box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink); }
.type-chip[data-type=""][aria-pressed="true"] { background: var(--butter); }
.type-chip:hover { filter: brightness(1.04); }
@media (min-width: 720px) { .type-chip { padding: 8px 11px 7px 9px; } .type-chip img { height: 21px; } }

.dex-controls__row--foot { justify-content: space-between; row-gap: 8px; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle {
  appearance: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; margin: 2px;
  padding: 6px 10px 5px 8px; background: var(--paper); font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--ink);
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), 0 4px 0 0 var(--ink);
}
.toggle img { width: 14px; height: 14px; filter: grayscale(1) opacity(.5); }
.toggle[aria-pressed="true"] { background: var(--butter); transform: translateY(2px); box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink); }
.toggle[aria-pressed="true"] img { filter: none; }
.dex-count { font: var(--fs-xs)/1.5 var(--font-px); text-transform: uppercase; color: var(--ink); background: rgb(255 248 231 / .6); padding: 6px 8px 5px; }
.dex-count b { font-weight: 400; color: var(--pink-dark); }
.dex-controls__btns { display: flex; gap: 6px; margin-left: auto; }
.dex-controls__btns .px-btn { margin-top: 0; margin-bottom: calc(var(--b) * 2 + 2px); }
@media (max-width: 719px) {
  .dex-count { order: 3; width: 100%; text-align: center; }
  .dex-controls__btns .px-btn { min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
}

/* screen: scrolls inside the handheld so the page stays a sane length */
.dexdev__screen {
  --b: var(--px); background: var(--paper); margin: var(--b) 0 0; position: relative;
  box-shadow: 0 0 0 var(--b) var(--ink), 0 0 0 calc(var(--b) * 2) var(--ink-2);
}
.dex-scroll {
  max-height: 72vh; max-height: 72svh; overflow-y: auto; padding: 8px 6px 12px;
  scrollbar-width: thin; scrollbar-color: var(--lilac-dark) var(--paper-2);
}
.dex-scroll::-webkit-scrollbar { width: 12px; }
.dex-scroll::-webkit-scrollbar-track { background: var(--paper-2); }
.dex-scroll::-webkit-scrollbar-thumb { background: var(--lilac-dark); border: 3px solid var(--paper-2); }
@media (min-width: 720px) {
  .dexdev__screen { margin: calc(var(--b) * 3); }
  .dex-scroll { padding: 16px 14px 20px; max-height: min(78vh, 980px); }
}
.dexdev__screen::after { /* faint scanlines on the glass */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(transparent 0 3px, rgb(29 23 51 / .025) 3px 4px);
}
.dex-grid {
  --ds: 3;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(32px * var(--ds) + 10px), 1fr)); gap: 12px 6px; padding: 6px 4px;
}
@media (max-width: 359px) { .dex-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 720px) { .dex-grid { --ds: 4; gap: 16px 12px; padding: 8px; } }
.dex-grid > li { min-width: 0; }
.dex-card {
  appearance: none; border: 0; width: 100%; padding: 5px 0 0; margin: 0; cursor: pointer; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; position: relative; background: var(--paper);
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), 2px 4px 0 0 rgb(29 23 51 / .3);
  -webkit-tap-highlight-color: transparent; transition: transform .12s steps(2);
}
.dex-card__img { width: calc(32px * var(--ds)); height: calc(32px * var(--ds)); max-width: none; background: var(--paper-2); }
.dex-card__no { display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; font: var(--fs-xs)/1 var(--font-px); padding: 7px 0 7px; border-bottom: 5px solid var(--tc, var(--paper-2)); }
.dex-card:hover, .dex-card:focus-visible { background: var(--butter); transform: translateY(-3px); }
.dex-card:focus-visible { outline: 3px dashed var(--ink); outline-offset: 4px; }
.dex-card.is-legend { background: linear-gradient(var(--gold), var(--butter)); }
.dex-card__badge { position: absolute; top: -6px; right: -6px; width: 21px; height: 21px; image-rendering: pixelated; }
.dex-card.is-legend .dex-card__no::before { content: ""; width: 14px; height: 14px; background: url(../assets/ui/star-small.svg) center / 100% 100% no-repeat; image-rendering: pixelated; }
.dex-empty { display: grid; justify-items: center; gap: 12px; padding: 32px 12px; text-align: center; }
.dex-empty img, .dex-empty canvas { width: 96px; height: 96px; }
.dex-more { display: grid; justify-items: center; padding-top: 12px; }
.dex-sentinel { display: block; width: 1px; height: 1px; }
.dex-noscript { padding: 16px; font-weight: 600; }

/* ============ modal ============ */
.modal { position: fixed; inset: 0; z-index: 140; display: grid; place-items: center; padding: 24px; }
.modal__backdrop {
  position: absolute; inset: 0; background: rgb(29 23 51 / .62);
  background-image: radial-gradient(rgb(255 255 255 / .08) 1.5px, transparent 1.6px); background-size: 12px 12px;
}
.modal__sheet {
  --b: 4px; position: relative; width: min(940px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  background: var(--paper); overflow: hidden;
  box-shadow:
    0 calc(var(--b) * -1) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
    calc(var(--b) * -1) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink),
    0 0 0 calc(var(--b) * 2) var(--lilac),
    0 calc(var(--b) * -1) 0 calc(var(--b) * 2) var(--ink), 0 var(--b) 0 calc(var(--b) * 2) var(--ink),
    calc(var(--b) * -1) 0 0 calc(var(--b) * 2) var(--ink), var(--b) 0 0 calc(var(--b) * 2) var(--ink),
    calc(var(--b) * 3) calc(var(--b) * 4) 0 calc(var(--b) * 2) rgb(0 0 0 / .3);
  animation: sheet-in .2s steps(3) both;
}
@keyframes sheet-in { from { clip-path: inset(50% 0 50% 0); } to { clip-path: inset(-40px -40px -40px -40px); } }
.modal__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--ink); color: var(--paper); padding: 6px 8px 6px 16px; flex: none; }
.modal__brand { display: inline-flex; align-items: center; gap: 10px; font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--butter); }
.modal__bar .icon-btn { margin: 4px; }
.entry { display: grid; gap: 20px; padding: 20px 16px; overflow: auto; flex: 1 1 auto; overscroll-behavior: contain; }
@media (min-width: 760px) { .entry { grid-template-columns: auto minmax(0, 1fr); gap: 32px; padding: 28px 28px 24px; } }
.entry__art { position: relative; justify-self: center; align-self: start; }
.entry__img {
  --es: 8; width: calc(32px * var(--es)); height: calc(32px * var(--es));
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), 8px 10px 0 0 rgb(29 23 51 / .2);
  margin: 4px; background: var(--paper-2);
}
@media (min-width: 900px) { .entry__img { --es: 10; } }
.entry__legend {
  position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--gold); padding: 6px 9px 5px; font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink);
}
.entry__legend img { width: 14px; height: 14px; }
.entry__no { font: var(--fs-s)/1 var(--font-px); color: var(--ink-2); }
.entry__name { font: var(--fs-l)/1.35 var(--font-px); text-transform: uppercase; margin: 10px 0 12px; overflow-wrap: anywhere; }
@media (min-width: 1180px) { .entry__name { font-size: 24px; } }
.entry__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.entry__meta .type-badge { font-size: var(--fs-s); padding: 6px 9px 5px 6px; margin: 3px; }
.entry__meta .type-badge img { height: 21px; }
.entry__lv { font: var(--fs-s)/1 var(--font-px); }
.entry__facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 18px; }
.entry__facts > div { background: var(--paper-2); padding: 10px 12px; }
.entry__facts dt { font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--ink-2); margin-bottom: 8px; }
.entry__facts dd { font-size: 18px; font-weight: 600; line-height: 1.2; }
.entry__sub { font: var(--fs-xs)/1 var(--font-px); text-transform: uppercase; color: var(--ink-2); margin-bottom: 8px; padding-bottom: 8px; border-bottom: 2px dashed var(--shadow); }
.traits { display: grid; gap: 2px; }
.traits li { display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; grid-template-areas: "k v p" "k b b"; gap: 2px 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid rgb(29 23 51 / .08); }
.traits__k { grid-area: k; font: var(--fs-xs)/1.3 var(--font-px); text-transform: uppercase; color: var(--ink-2); align-self: start; padding-top: 5px; }
.traits__v { grid-area: v; font-size: 17px; font-weight: 600; line-height: 1.2; }
.traits__p { grid-area: p; font: var(--fs-xs)/1 var(--font-px); color: var(--ink-2); }
.traits__p.is-rare { color: var(--gold-dark); }
.traits__bar { grid-area: b; display: flex; gap: 2px; height: 8px; }
.traits__bar i { flex: 1; background: #e6dcc6; }
.traits__bar i.on { background: var(--mint-dark); }
.traits__bar.is-rare i.on { background: var(--gold-dark); }
.traits__bar.is-uncommon i.on { background: var(--lilac-dark); }
@media (min-width: 760px) { .traits li { grid-template-columns: 96px minmax(0, 1fr) auto; } }
.modal__foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 10px; flex: none;
  padding: 8px 12px 10px; background: var(--paper-2); border-top: 3px solid var(--ink);
}
.modal__foot .px-btn { margin-bottom: calc(var(--px) * 2 + 2px); }
.modal__foot img { width: 8px; height: 14px; }
@media (max-width: 759px) {
  .modal { padding: 0; place-items: stretch; }
  .modal__sheet { width: 100%; max-height: none; height: 100vh; height: 100dvh; box-shadow: none; animation-name: sheet-up; }
  .modal__foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .modal__foot #entry-market { order: -1; flex: 1 1 100%; }
  .modal__foot #entry-prev, .modal__foot #entry-next { flex: 1 1 40%; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

/* keep the controls inside the device: a nowrap chip row must not widen the grid track */
.dex-controls { grid-template-columns: minmax(0, 1fr); }
.dex-controls__row, .type-chips { min-width: 0; }
