.pokedex-section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    border-radius: 25px;
    padding: 36px 32px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    margin-bottom: 32px;
}

.pokedex-section-title {
    text-align: center;
    font-size: 1.6em;
    color: #2c3e50;
    margin: 0 0 22px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

/* ── Filter row ────────────────────────────────────────────────── */
.pokedex-filter-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

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

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

.pokedex-field-label {
    font-size: 0.78em;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pokedex-search,
.pokedex-select,
.pokedex-number {
    width: 100%;
    box-sizing: border-box;
    border: 2px solid rgba(44, 62, 80, 0.12);
    background: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 1em;
    color: #2c3e50;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.pokedex-search:focus,
.pokedex-select:focus,
.pokedex-number:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.18);
}

.pokedex-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%232c3e50' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
    padding-right: 38px;
    cursor: pointer;
    font-weight: 600;
}

.pokedex-filter-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.pokedex-count-row {
    color: #34495e;
    font-size: 0.95em;
}

.pokedex-count {
    font-weight: bold;
    color: #2c3e50;
    font-size: 1.15em;
    font-variant-numeric: tabular-nums;
}

.pokedex-reset {
    appearance: none;
    background: transparent;
    border: 2px solid rgba(44, 62, 80, 0.18);
    color: #2c3e50;
    padding: 8px 18px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    font-family: inherit;
}

.pokedex-reset:hover {
    background: rgba(78, 205, 196, 0.1);
    border-color: #4ecdc4;
    transform: translateY(-1px);
}

/* ── Grid ──────────────────────────────────────────────────────── */
.pokedex-results-section {
    padding: 28px 24px;
}

.pokedex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.pokedex-card {
    appearance: none;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 12px 8px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    color: #2c3e50;
    font-family: inherit;
    text-align: center;
}

.pokedex-card:hover,
.pokedex-card:focus-visible {
    transform: translateY(-3px);
    border-color: #4ecdc4;
    box-shadow: 0 10px 22px rgba(78, 205, 196, 0.2);
    outline: none;
}

.pokedex-card-dex {
    align-self: flex-start;
    font-size: 0.78em;
    color: #95a5a6;
    font-weight: 700;
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
}

.pokedex-card-sprite {
    width: 96px;
    height: 96px;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
    visibility: hidden;
}

.pokedex-card-sprite.loaded {
    visibility: visible;
}

.pokedex-card-name {
    font-size: 0.95em;
    font-weight: 700;
    text-transform: capitalize;
    word-break: break-word;
    line-height: 1.15;
}

.pokedex-card-types {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin-top: 2px;
}

.pokedex-loading,
.pokedex-empty,
.pokedex-error {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 0;
    color: #7f8c8d;
    font-style: italic;
}

.pokedex-error {
    color: #c0392b;
}

/* ── Type badges (shared between cards and modal) ─────────────── */
.pokedex-type {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px 3px 5px;
    border-radius: 16px;
    color: #fff;
    font-weight: bold;
    font-size: 0.75em;
    text-transform: capitalize;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    letter-spacing: 0.3px;
}

.pokedex-modal-types .pokedex-type {
    padding: 4px 14px;
    font-size: 0.9em;
    border-radius: 20px;
}

.pokedex-type.type-normal   { background: #A8A878; }
.pokedex-type.type-fire     { background: #F08030; }
.pokedex-type.type-water    { background: #6890F0; }
.pokedex-type.type-electric { background: #F8D030; color: #3a2f00; }
.pokedex-type.type-grass    { background: #78C850; }
.pokedex-type.type-ice      { background: #98D8D8; color: #1f3a3a; }
.pokedex-type.type-fighting { background: #C03028; }
.pokedex-type.type-poison   { background: #A040A0; }
.pokedex-type.type-ground   { background: #E0C068; color: #3a2f00; }
.pokedex-type.type-flying   { background: #A890F0; }
.pokedex-type.type-psychic  { background: #F85888; }
.pokedex-type.type-bug      { background: #A8B820; }
.pokedex-type.type-rock     { background: #B8A038; }
.pokedex-type.type-ghost    { background: #705898; }
.pokedex-type.type-dragon   { background: #7038F8; }
.pokedex-type.type-dark     { background: #705848; }
.pokedex-type.type-steel    { background: #B8B8D0; color: #1f1f3a; }
.pokedex-type.type-fairy    { background: #EE99AC; }

/* ── Detail modal ──────────────────────────────────────────────── */
.pokedex-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pokedex-modal[hidden] {
    display: none !important;
}

.pokedex-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 32, 50, 0.55);
    backdrop-filter: blur(4px);
    cursor: pointer;
    animation: pokedexModalFadeIn 0.2s ease;
}

.pokedex-modal-card {
    position: relative;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border-radius: 22px;
    padding: 28px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 760px;
    max-height: min(90vh, 760px);
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    animation: pokedexModalPopIn 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pokedexModalFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes pokedexModalPopIn {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.pokedex-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    appearance: none;
    background: rgba(231, 76, 60, 0.12);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #c0392b;
    font-size: 1.5em;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pokedex-modal-close:hover {
    background: rgba(231, 76, 60, 0.25);
    transform: rotate(90deg);
}

.pokedex-modal-close:focus-visible {
    outline: 2px solid #c0392b;
    outline-offset: 2px;
}

body.pokedex-modal-open {
    overflow: hidden;
}

.pokedex-modal-body {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 28px;
    align-items: start;
}

.pokedex-modal-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 14px;
    background: radial-gradient(circle at center, rgba(255, 107, 107, 0.12), rgba(78, 205, 196, 0.08) 60%, transparent 80%);
    border-radius: 18px;
}

.pokedex-modal-sprite {
    width: 200px;
    height: 200px;
    object-fit: contain;
    filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.2));
    visibility: hidden;
}

.pokedex-modal-sprite.loaded {
    visibility: visible;
}

.pokedex-modal-dex {
    font-size: 0.9em;
    color: #95a5a6;
    font-weight: 700;
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
}

.pokedex-modal-name {
    margin: 0;
    font-size: 1.6em;
    font-weight: bold;
    color: #2c3e50;
    text-transform: capitalize;
    text-align: center;
}

.pokedex-modal-types {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.pokedex-modal-flags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.pokedex-modal-flags:empty {
    display: none;
}

.pokedex-modal-flag {
    padding: 4px 12px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.pokedex-modal-flag.baby {
    background: linear-gradient(145deg, #ffd1dc, #ff8fa3);
    color: #5a1530;
}

.pokedex-modal-flag.legendary {
    background: linear-gradient(145deg, #f7d046, #d18e06);
    color: #4a3000;
}

.pokedex-modal-flag.mythical {
    background: linear-gradient(145deg, #b69cff, #7038f8);
    color: #fff;
}

.pokedex-modal-info {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
}

.pokedex-modal-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.pokedex-modal-meta-item {
    background: linear-gradient(145deg, #ffffff, #f1f3f4);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pokedex-modal-meta-item-wide {
    grid-column: 1 / -1;
}

.pokedex-modal-meta-label {
    font-size: 0.75em;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pokedex-modal-meta-value {
    font-size: 1.05em;
    color: #2c3e50;
    font-weight: 700;
}

.pokedex-modal-stats-title {
    margin: 0 0 10px;
    font-size: 0.8em;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pokedex-modal-stats-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.pokedex-modal-stat {
    display: grid;
    grid-template-columns: 120px 40px 1fr;
    align-items: center;
    gap: 10px;
    font-size: 0.95em;
}

.pokedex-modal-stat-name {
    color: #34495e;
    font-weight: 600;
}

.pokedex-modal-stat-value {
    color: #2c3e50;
    font-weight: bold;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.pokedex-modal-stat-bar {
    display: block;
    background: #ecf0f1;
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
}

.pokedex-modal-stat-bar-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #4ecdc4, #45b7d1);
    border-radius: 10px;
    transition: width 0.6s ease;
}

.pokedex-modal-stat.total {
    grid-template-columns: 120px 40px;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(44, 62, 80, 0.1);
}

.pokedex-modal-stat.total .pokedex-modal-stat-name,
.pokedex-modal-stat.total .pokedex-modal-stat-value {
    color: #2c3e50;
    font-weight: 800;
}

.pokedex-modal-error {
    text-align: center;
    color: #c0392b;
    font-weight: 600;
    padding: 8px 0 0;
}

/* ── Section title (shared by matchups + evolution) ───────────── */
.pokedex-modal-section-title {
    margin: 0 0 6px;
    font-size: 0.8em;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pokedex-modal-section-hint {
    margin: 0 0 12px;
    font-size: 0.85em;
    color: #7f8c8d;
    line-height: 1.35;
}

/* ── Type matchups ─────────────────────────────────────────────── */
.pokedex-modal-matchup-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.pokedex-modal-matchup {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 12px;
    align-items: center;
    padding: 8px 14px;
    background: linear-gradient(145deg, #ffffff, #f1f3f4);
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    border-left: 4px solid transparent;
}

.pokedex-modal-matchup.matchup-4x       { border-left-color: #c0392b; }
.pokedex-modal-matchup.matchup-2x       { border-left-color: #e67e22; }
.pokedex-modal-matchup.matchup-half     { border-left-color: #82c91e; }
.pokedex-modal-matchup.matchup-quarter  { border-left-color: #27ae60; }
.pokedex-modal-matchup.matchup-immune   { border-left-color: #7f8c8d; }

.pokedex-modal-matchup-label {
    font-weight: 700;
    color: #2c3e50;
    font-variant-numeric: tabular-nums;
    font-size: 0.9em;
}

.pokedex-modal-matchup-types {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ── Offensive matchups (per STAB type) ────────────────────────── */
.pokedex-modal-offensive-groups {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.pokedex-modal-offensive-type {
    margin: 0 0 8px;
    font-size: 0.95em;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    text-transform: none;
}

.pokedex-modal-offensive-type .pokedex-type {
    padding: 3px 12px;
    border-radius: 14px;
    font-size: 0.85em;
}

/* ── Evolution chain ───────────────────────────────────────────── */
.pokedex-modal-evo-chain {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.pokedex-modal-evo-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.pokedex-modal-evo-arrow {
    font-size: 1.8em;
    color: #95a5a6;
    flex-shrink: 0;
    user-select: none;
}

.pokedex-modal-evo-stage {
    appearance: none;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border: 2px solid transparent;
    border-radius: 14px;
    padding: 10px 8px;
    width: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
    color: #2c3e50;
}

.pokedex-modal-evo-stage:hover,
.pokedex-modal-evo-stage:focus-visible {
    transform: translateY(-2px);
    border-color: #4ecdc4;
    box-shadow: 0 8px 16px rgba(78, 205, 196, 0.2);
    outline: none;
}

.pokedex-modal-evo-stage.current {
    border-color: #4ecdc4;
    background: linear-gradient(145deg, rgba(78, 205, 196, 0.18), rgba(255, 255, 255, 0.95));
    cursor: default;
}

.pokedex-modal-evo-stage.current:hover {
    transform: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.pokedex-modal-evo-sprite {
    width: 64px;
    height: 64px;
    object-fit: contain;
    image-rendering: pixelated;
    visibility: hidden;
}

.pokedex-modal-evo-sprite.loaded {
    visibility: visible;
}

.pokedex-modal-evo-name {
    font-size: 0.85em;
    font-weight: 700;
    text-transform: capitalize;
    text-align: center;
    line-height: 1.15;
}

.pokedex-modal-evo-dex {
    font-size: 0.7em;
    color: #95a5a6;
    font-variant-numeric: tabular-nums;
}

.pokedex-modal-evo-condition {
    font-size: 0.7em;
    color: #34495e;
    text-align: center;
    margin-top: 2px;
    line-height: 1.2;
}

.pokedex-modal-evo-loading,
.pokedex-modal-evo-empty {
    text-align: center;
    color: #95a5a6;
    font-style: italic;
    margin: 0;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .pokedex-filter-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 768px) {
    .pokedex-section {
        padding: 24px 18px;
    }

    .pokedex-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }

    .pokedex-card-sprite {
        width: 80px;
        height: 80px;
    }

    .pokedex-modal {
        padding: 12px;
    }

    .pokedex-modal-card {
        padding: 22px 18px;
        max-height: 94vh;
    }

    .pokedex-modal-body {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .pokedex-modal-sprite {
        width: 160px;
        height: 160px;
    }

    .pokedex-modal-stat {
        grid-template-columns: 100px 40px 1fr;
        font-size: 0.9em;
    }

    .pokedex-modal-matchup {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 10px 12px;
    }

    .pokedex-modal-evo-chain {
        /* Keep the chain as a single horizontal strip on small screens;
           if it overflows (3+ stages on a narrow phone), scroll horizontally
           rather than wrapping to a second row. `safe center` centers when
           content fits, falls back to start-align when it overflows so the
           first stage stays visible instead of being clipped. */
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: safe center;
        padding-bottom: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .pokedex-modal-evo-chain > * {
        flex-shrink: 0;
    }

    .pokedex-modal-evo-stage {
        width: 96px;
        padding: 8px 6px;
    }

    .pokedex-modal-evo-sprite {
        width: 56px;
        height: 56px;
    }

    .pokedex-modal-evo-arrow {
        font-size: 1.4em;
    }
}

@media (max-width: 480px) {
    .pokedex-filter-grid {
        grid-template-columns: 1fr 1fr;
    }

    .pokedex-field-wide {
        grid-column: 1 / -1;
    }
}
