/* Pal Gallery -- project-specific layout on top of css-base's primitives
   (index.css, reset.css, themes.css, utility.css, elements.css, buttons.css,
   layout.css, components.css). Mobile-first: the filters panel is a
   slide-down overlay by default and becomes a persistent sidebar at the
   DESKTOP_BREAKPOINT below. */

:root {
  --tile: 90px;
  --topbar-height: 56px;
}

@media (min-width: 640px) {
  :root {
    --tile: 120px;
  }
}

body {
  margin: 0;
  background: var(--background-color);
  color: var(--text-color);
}

.topbar {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 1rem;
  background: var(--secondary-background-color);
  box-shadow: var(--box-shadow);
}

.topbar-title {
  font-size: 1.1rem;
  margin: 0;
}

.filters-toggle {
  padding: 0.4rem 0.8rem;
}

.layout {
  display: flex;
  align-items: flex-start;
}

/* Mobile: filters is a full-width slide-down panel, hidden until toggled. */
.filters-panel {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  z-index: 15;
  background: var(--secondary-background-color);
  box-shadow: var(--box-shadow);
  padding: 1rem;
  max-height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  transform: translateY(-110%);
  transition: transform 0.2s ease;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.filters-panel.open {
  transform: translateY(0);
}

/* Mobile: while the slide-down panel is open, the page behind it must not
   scroll/pan — without this, a touch-drag on the panel bleeds through and
   drags the background (the panel is `position: fixed`, not a real child
   of the scrolling flow, so the body scrolls underneath it). */
body.filters-open {
  overflow: hidden;
  touch-action: none;
}

.filters-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.filters-heading {
  margin: 0;
  font-size: 1rem;
}

.filter-reset {
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--secondary-text-color);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.filter-reset:hover {
  color: var(--text-color);
}

.filter-section {
  margin-bottom: 1.25rem;
}

.filter-section:last-child {
  margin-bottom: 0;
}

.filters-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--secondary-color);
}

.theme-toggle {
  width: 100%;
}

.filter-section-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--secondary-text-color);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--secondary-color);
  background: transparent;
  color: var(--text-color);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.pill:hover {
  border-color: var(--text-color);
}

.pill:active {
  transform: scale(0.97);
}

.pill[aria-pressed="true"] {
  background: var(--primary-bg-subtle);
  color: var(--primary-text-subtle);
  border-color: transparent;
}

/* Location and mount pills share one fixed color each when active, echoing
   .badge-map / .badge-ridable in the detail modal. Type pills get a
   per-element color, echoing .badge-type there. Unselected pills get the
   same color as a faint border/background tint, so the sidebar reads
   color-coded even before anything is picked; selecting swaps to the
   solid badge color. */
.pill-map {
  border-color: #234e52;
  background: #234e5226;
}
.pill-map[aria-pressed="true"] {
  background: #234e52;
  color: #e6fffa;
}

.pill-ridable {
  border-color: #975a16;
  background: #975a1626;
}
.pill-ridable[aria-pressed="true"] {
  background: #975a16;
  color: #fffaf0;
}

.pill-flying {
  border-color: #2b6cb0;
  background: #2b6cb026;
}
.pill-flying[aria-pressed="true"] {
  background: #2b6cb0;
  color: #ebf8ff;
}

.pill-swimming {
  border-color: #2c7a7b;
  background: #2c7a7b26;
}
.pill-swimming[aria-pressed="true"] {
  background: #2c7a7b;
  color: #e6fffa;
}

.pill-type[data-type="Normal"] {
  border-color: #8b8b73;
  background: #8b8b7326;
}
.pill-type[data-type="Normal"][aria-pressed="true"] {
  background: #8b8b73;
  color: #ffffff;
}
.pill-type[data-type="Fire"] {
  border-color: #c53c1f;
  background: #c53c1f26;
}
.pill-type[data-type="Fire"][aria-pressed="true"] {
  background: #c53c1f;
  color: #ffffff;
}
.pill-type[data-type="Water"] {
  border-color: #2b6cb0;
  background: #2b6cb026;
}
.pill-type[data-type="Water"][aria-pressed="true"] {
  background: #2b6cb0;
  color: #ffffff;
}
.pill-type[data-type="Leaf"] {
  border-color: #2f7a3d;
  background: #2f7a3d26;
}
.pill-type[data-type="Leaf"][aria-pressed="true"] {
  background: #2f7a3d;
  color: #ffffff;
}
.pill-type[data-type="Electricity"] {
  border-color: #b7860b;
  background: #b7860b26;
}
.pill-type[data-type="Electricity"][aria-pressed="true"] {
  background: #b7860b;
  color: #ffffff;
}
.pill-type[data-type="Ice"] {
  border-color: #2c7a7b;
  background: #2c7a7b26;
}
.pill-type[data-type="Ice"][aria-pressed="true"] {
  background: #2c7a7b;
  color: #ffffff;
}
.pill-type[data-type="Earth"] {
  border-color: #8a5a2b;
  background: #8a5a2b26;
}
.pill-type[data-type="Earth"][aria-pressed="true"] {
  background: #8a5a2b;
  color: #ffffff;
}
.pill-type[data-type="Dark"] {
  border-color: #44337a;
  background: #44337a26;
}
.pill-type[data-type="Dark"][aria-pressed="true"] {
  background: #44337a;
  color: #ffffff;
}
.pill-type[data-type="Dragon"] {
  border-color: #6b3fa0;
  background: #6b3fa026;
}
.pill-type[data-type="Dragon"][aria-pressed="true"] {
  background: #6b3fa0;
  color: #ffffff;
}

.grid-container {
  flex: 1;
  min-width: 0;
  padding: 1rem;
}

/* Desktop: filters becomes a persistent sidebar, no toggle needed. */
@media (min-width: 900px) {
  .filters-toggle {
    display: none;
  }

  .filters-panel {
    position: sticky;
    top: 0;
    transform: none;
    box-shadow: none;
    border-right: 1px solid var(--secondary-color);
    width: 220px;
    flex-shrink: 0;
    height: 100vh;
  }
}

.masonry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  grid-auto-rows: var(--tile);
  grid-auto-flow: dense;
  gap: 6px;
}

.pal-card {
  display: block;
  padding: 0;
  border: none;
  background: var(--secondary-background-color);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.pal-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.empty-state {
  text-align: center;
  color: var(--secondary-text-color);
  padding: 2rem 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--backdrop-color);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 1rem;
  animation: modal-backdrop-in 0.15s ease;
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes modal-backdrop-in {
  from {
    opacity: 0;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

.modal {
  position: relative;
  background: var(--secondary-background-color);
  border-radius: 16px;
  max-width: 760px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.25),
    0 8px 10px -6px rgba(0, 0, 0, 0.25);
  animation: modal-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Per-type gradient wash behind the Pal image, echoing the badge colors
   below so the whole card feels tied to the Pal's element(s). */
.modal-stage {
  position: relative;
  padding: 2rem 1.5rem 1.5rem;
  background: radial-gradient(
    ellipse at center,
    var(--stage-accent, var(--secondary-color)) 0%,
    transparent 72%
  );
  background-color: var(--background-color);
}

.modal[data-type="Normal"] { --stage-accent: rgba(139, 139, 115, 0.35); }
.modal[data-type="Fire"] { --stage-accent: rgba(197, 60, 31, 0.35); }
.modal[data-type="Water"] { --stage-accent: rgba(43, 108, 176, 0.35); }
.modal[data-type="Leaf"] { --stage-accent: rgba(47, 122, 61, 0.35); }
.modal[data-type="Electricity"] { --stage-accent: rgba(183, 134, 11, 0.35); }
.modal[data-type="Ice"] { --stage-accent: rgba(44, 122, 123, 0.35); }
.modal[data-type="Earth"] { --stage-accent: rgba(138, 90, 43, 0.35); }
.modal[data-type="Dark"] { --stage-accent: rgba(68, 51, 122, 0.35); }
.modal[data-type="Dragon"] { --stage-accent: rgba(107, 63, 160, 0.35); }

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1;
  box-sizing: border-box;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--secondary-background-color);
  opacity: 0.85;
  border: none;
  border-radius: 50%;
  line-height: 1;
  cursor: pointer;
  color: var(--text-color);
  box-shadow: var(--box-shadow);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.modal-close svg {
  display: block;
}

.modal-close:hover {
  opacity: 1;
  transform: scale(1.08);
}

.modal-body {
  padding: 0 1.5rem 1.5rem;
}

/* Scaled up from the gallery's --tile unit (this is the detail view, it
   should read bigger than a grid cell) while still growing per shape --
   a 2x2/3x3 Pal gets a visibly bigger stage than a 1x1 one, capped so a
   3x3 doesn't blow out the whole modal. */
.modal-stage {
  --stage-cell: 340px;
}

.modal-image {
  display: block;
  width: clamp(var(--stage-cell), calc(var(--stage-cell) * var(--cols, 1)), min(900px, 82vw));
  height: auto;
  aspect-ratio: var(--cols, 1) / var(--rows, 1);
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.25));
}

.modal-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0 0.5rem;
}

.modal-name {
  margin: 0;
  font-size: 1.5rem;
}

.modal-rarity {
  flex-shrink: 0;
  color: var(--warning-color);
  letter-spacing: 0.05em;
  font-size: 0.9rem;
}

.modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

/* Desktop: stage becomes a left rail sized to the image (see --stage-cell),
   body sits to its right with a hard min-width. Flex-wrap (not grid) is what
   makes that min-width real: once the rail eats too much space for a 2x2/3x3
   Pal to leave the body that much room, the body wraps below the stage
   instead of getting squeezed into an unreadably narrow column. */
@media (min-width: 700px) {
  .modal {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    /* Centers the stage on its own line once the body has wrapped below it,
       instead of leaving it stranded against the left edge with dead space
       to its right. */
    justify-content: center;
    max-width: 1400px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-stage {
    --stage-cell: 460px;
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
  }

  .modal-image {
    max-height: none;
  }

  .modal-body {
    flex: 1 1 380px;
    min-width: 380px;
    padding: 1.5rem 1.75rem 1.75rem;
  }

  .modal-heading {
    margin-top: 0;
  }
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  /* Fallback color if a badge's kind/type doesn't match a rule below. */
  background: var(--primary-bg-subtle);
  color: var(--primary-text-subtle);
}

/* Element-type badges, one color per Pal element (data-type set in
   js/app.js). Map (spawn location) badges all share one color regardless
   of which of the three spawnCategory values they show; ridable is a
   single fixed color too. */
.badge-map {
  background: #234e52;
  color: #e6fffa;
}

.badge-ridable {
  background: #975a16;
  color: #fffaf0;
}

.badge-flying {
  background: #2b6cb0;
  color: #ebf8ff;
}

.badge-swimming {
  background: #2c7a7b;
  color: #e6fffa;
}

.badge-type[data-type="Normal"] {
  background: #8b8b73;
  color: #ffffff;
}
.badge-type[data-type="Fire"] {
  background: #c53c1f;
  color: #ffffff;
}
.badge-type[data-type="Water"] {
  background: #2b6cb0;
  color: #ffffff;
}
.badge-type[data-type="Leaf"] {
  background: #2f7a3d;
  color: #ffffff;
}
.badge-type[data-type="Electricity"] {
  background: #b7860b;
  color: #ffffff;
}
.badge-type[data-type="Ice"] {
  background: #2c7a7b;
  color: #ffffff;
}
.badge-type[data-type="Earth"] {
  background: #8a5a2b;
  color: #ffffff;
}
.badge-type[data-type="Dark"] {
  background: #44337a;
  color: #ffffff;
}
.badge-type[data-type="Dragon"] {
  background: #6b3fa0;
  color: #ffffff;
}

.modal-summary p {
  margin: 0 0 0.75rem;
  color: var(--secondary-text-color);
  line-height: 1.5;
}

.modal-summary p:last-child {
  margin-bottom: 0;
}

.modal-skills ul {
  margin: 0;
  padding-left: 1.2rem;
}

.partner-skill {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: var(--background-color);
  border: 1px solid var(--secondary-color);
  border-left: 3px solid var(--primary-color);
  border-radius: 8px;
}

.partner-skill h3 {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 1rem;
  margin: 0 0 0.35rem;
}

.partner-skill-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-color);
}

.partner-skill-desc p {
  margin: 0 0 0.75rem;
  line-height: 1.5;
  color: var(--secondary-text-color);
}

.partner-skill-desc p:last-child {
  margin-bottom: 0;
}
