/* ================================================================
   ANIDEX — Animal Warfare Database Web UI
   Premium Dark Theme designed to mirror the Flutter Anidex app
   ================================================================ */

/* --- Google Fonts loaded in HTML --- */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---- Variables ---- */
:root {
    --bg-root: #080c10;
    --bg-sidebar: #0a0f14;
    --bg-card: #0f1923;
    --bg-card-hover: #141f2e;
    --bg-modal: #0d1520;
    --accent: #4cffb3;
    --accent-dim: rgba(76, 255, 179, 0.08);
    --accent-glow: rgba(76, 255, 179, 0.15);
    --text-main: #e8edf2;
    --text-dim: rgba(232, 237, 242, 0.45);
    --text-faint: rgba(232, 237, 242, 0.2);
    --border: rgba(255,255,255,0.08);
    --border-bright: rgba(255,255,255,0.14);
    --sidebar-w: 290px;
    --radius-card: 14px;
    --radius-sm: 8px;
    --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg-root);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ================================================================
   SIDEBAR
   ================================================================ */

#sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 300;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-inner {
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 100%;
}

/* Brand */
.sidebar-brand {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 30px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.brand-pixel {
    font-family: 'Press Start 2P', monospace;
    font-size: 13px;
    color: var(--accent);
    letter-spacing: 2px;
    text-shadow: 0 0 16px var(--accent-glow);
}

.sidebar-subtitle {
    font-size: 8px;
    color: var(--text-faint);
    letter-spacing: 1px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Filter Sections */
.filter-section {
    margin-bottom: 20px;
}

.filter-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* Search */
.search-wrap {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--accent);
    pointer-events: none;
}

#q {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px 10px 36px;
    color: var(--text-main);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

#q:focus {
    border-color: var(--accent);
    background: rgba(76, 255, 179, 0.05);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

#q::placeholder { color: var(--text-faint); }

/* Tab Switch */
.tab-switch {
    display: flex;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 8px 6px;
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    border-radius: 5px;
    transition: var(--transition);
    letter-spacing: 0.5px;
}

.tab-btn.active {
    background: var(--accent);
    color: #000;
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* Selects */
select {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text-main);
    font-size: 11px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234cffb3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

select option { background: #0a0f14; color: var(--text-main); }

/* Sort Chips */
.sort-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.sort-chip {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 5px 10px;
    border-radius: 20px;
    font-family: 'Press Start 2P', monospace;
    font-size: 6.5px;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.5px;
}

.sort-chip.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.order-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--accent);
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    transition: var(--transition);
    width: 100%;
    justify-content: space-between;
}

.order-btn:hover { border-color: var(--accent); background: var(--accent-dim); }

.reset-btn {
    margin-top: auto;
    padding-top: 20px;
    background: transparent;
    border: 1px solid rgba(255,80,80,0.2);
    border-radius: var(--radius-sm);
    color: rgba(255,100,100,0.7);
    padding: 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    cursor: pointer;
    width: 100%;
    transition: var(--transition);
    margin-top: 16px;
    letter-spacing: 0.5px;
}

.reset-btn:hover { background: rgba(255,80,80,0.1); border-color: rgba(255,80,80,0.5); color: #ff6464; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 250;
    backdrop-filter: blur(2px);
}

/* ================================================================
   MOBILE HEADER
   ================================================================ */

.mobile-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    justify-content: space-between;
    align-items: center;
}

.mobile-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    color: var(--accent);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover { background: var(--accent-dim); }

/* ================================================================
   MAIN CONTENT
   ================================================================ */

main {
    margin-left: var(--sidebar-w);
    padding: 24px;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 80% 0%, rgba(76,255,179,0.04) 0%, transparent 60%),
        var(--bg-root);
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.result-count {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
}

/* ================================================================
   GRID & CARDS
   ================================================================ */

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

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px var(--accent-glow);
    background: var(--bg-card-hover);
}

.card-sprite-wrap {
    position: relative;
    background: linear-gradient(180deg, rgba(255,255,255,0.02) 0%, transparent 100%);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 160px;
    overflow: hidden;
}

.item-sprite-wrap { height: 130px; }

.card-sprite-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

.sprite-fallback {
    font-size: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-rarity-tag {
    position: absolute;
    top: 8px;
    right: 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 5px;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 900;
    letter-spacing: 0.5px;
}

.card-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.card-type-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.type-badge {
    font-size: 7px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    text-transform: uppercase;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Type colors mirroring the Flutter app */
.type-basic    { background: #3a3a33; color: #ccc; }
.type-blaze    { background: #7a1a0a; color: #ff9977; }
.type-aquatic  { background: #0a2a5a; color: #66aaff; }
.type-grass    { background: #1a4a1a; color: #77dd55; }
.type-electric { background: #4a3a00; color: #ffcc33; }
.type-cryo     { background: #0a3a4a; color: #aaddff; }
.type-martial  { background: #4a0a1a; color: #ff6688; }
.type-toxic    { background: #3a0a4a; color: #cc77ee; }
.type-earth    { background: #3a2010; color: #cc9966; }
.type-flying   { background: #0a2a4a; color: #99ccff; }
.type-mystic   { background: #4a0a2a; color: #ff88cc; }
.type-arthropod{ background: #2a3a0a; color: #aabb55; }
.type-rock     { background: #3a3010; color: #ccbb77; }
.type-darkness { background: #1a1a3a; color: #8899ff; }
.type-spectral { background: #2a0a4a; color: #bb88ff; }
.type-metal    { background: #1a2a3a; color: #99bbcc; }
.type-aura     { background: #0a3a3a; color: #55cccc; }
.type-sound    { background: #4a2a00; color: #ff9944; }
.type-holy     { background: #3a3000; color: #ffcc55; }
.type-drake    { background: #2a0a3a; color: #9966cc; }

.card-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #fff;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-sub {
    font-size: 9px;
    color: var(--text-faint);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-stats-mini {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.card-stats-mini span {
    font-size: 9px;
    color: var(--text-dim);
    font-weight: 600;
}

/* Item card */
.item-card .card-name { font-size: 7.5px; }

/* ================================================================
   INFINITE SCROLL / LOADING
   ================================================================ */

.loading-more {
    display: flex;
    justify-content: center;
    padding: 32px;
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(76, 255, 179, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-faint);
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    line-height: 2;
}

/* ================================================================
   MODAL
   ================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    backdrop-filter: blur(12px);
    z-index: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--bg-modal);
    width: 100%;
    max-width: 740px;
    max-height: 90vh;
    border-radius: 24px;
    border: 1px solid var(--border-bright);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 40px 80px rgba(0,0,0,0.6);
    position: relative;
    transform: translateY(20px);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open .modal-box {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    z-index: 10;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover { background: rgba(255,80,80,0.2); color: #ff6464; border-color: #ff6464; }

#modal-content {
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* Detail Header */
.detail-header {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 36px 32px 28px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.detail-sprite-wrap {
    flex-shrink: 0;
    width: 140px;
    height: 140px;
    background: rgba(255,255,255,0.03);
    border-radius: 20px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.detail-sprite-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 6px 16px rgba(0,0,0,0.6));
}

.detail-intro {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.detail-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    color: #fff;
    line-height: 1.4;
    margin: 0;
}

.detail-sciname {
    font-style: italic;
    color: var(--text-dim);
    font-size: 11px;
}

.rarity-pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    border: 1px solid;
    letter-spacing: 0.5px;
}

/* Detail Body */
.detail-body {
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.detail-section { display: flex; flex-direction: column; gap: 14px; }

.detail-section-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: var(--accent);
    letter-spacing: 1px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.detail-desc {
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.8;
}

/* Stats */
.detail-stat-row { display: flex; flex-direction: column; gap: 6px; }

.detail-stat-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-stat-label {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
}

.detail-stat-val {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    font-weight: 700;
}

.stat-track {
    height: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    overflow: hidden;
}

.stat-bar {
    height: 100%;
    border-radius: 10px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 6px currentColor;
}

.total-stat {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: var(--accent);
    text-align: right;
    margin-top: 4px;
}

/* Biomes */
.biome-row { display: flex; gap: 10px; flex-wrap: wrap; }

.biome-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: var(--accent);
    overflow: hidden;
}

.biome-chip img { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; }

/* Abilities */
.detail-ability-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ability-name {
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

.ability-desc {
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.6;
}

/* Moves table */
.move-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.move-table thead tr {
    border-bottom: 1px solid var(--border);
}

.move-table th {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    color: var(--text-faint);
    padding: 8px 10px;
    text-align: left;
    letter-spacing: 0.5px;
}

.move-table tbody tr {
    border-bottom: 1px solid rgba(255,255,255,0.04);
    cursor: pointer;
    transition: var(--transition);
}

.move-table tbody tr:hover { background: rgba(76, 255, 179, 0.04); }

.move-table td {
    padding: 12px 10px;
    vertical-align: middle;
}

.move-name {
    color: #4cffb3;
    font-weight: 600;
}

.move-val {
    text-align: center;
    color: var(--text-dim);
}

/* Drops */
.drops-row { display: flex; gap: 8px; flex-wrap: wrap; }

.drop-tag {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 10px;
    color: var(--text-dim);
}

/* Dim text */
.dim { color: var(--text-faint); font-size: 11px; }

/* ================================================================
   MOVE DETAIL OVERLAY (on top of modal)
   ================================================================ */

.move-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 24px;
}

.move-detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border-bright);
    border-radius: 20px;
    padding: 28px;
    width: 100%;
    max-width: 380px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.close-move-overlay {
    position: absolute;
    top: 14px; right: 14px;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
}

.move-detail-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: #fff;
    line-height: 1.4;
}

.move-detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-sm);
    padding: 14px;
}

.mds-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mds-row span {
    font-size: 8px;
    color: var(--text-faint);
    font-weight: 600;
    text-transform: uppercase;
}

.mds-row b {
    font-size: 14px;
    color: var(--accent);
    font-weight: 700;
}

.move-detail-desc {
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.7;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 900px) {
    #sidebar {
        transform: translateX(-100%);
    }

    #sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 60px rgba(0,0,0,0.5);
    }

    .sidebar-overlay.active { display: block; }

    main { margin-left: 0; padding: 16px; padding-top: 68px; }

    .mobile-header { display: flex; }

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

    .card-sprite-wrap { height: 130px; }

    .card-name { font-size: 7px; }

    .detail-header { flex-direction: column; text-align: center; padding: 24px; }

    .detail-sprite-wrap { width: 120px; height: 120px; }

    .detail-name { font-size: 12px; }

    .type-row { justify-content: center; }

    .detail-body { padding: 20px; gap: 24px; }

    .modal-box { border-radius: 20px; }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .card-sprite-wrap { height: 110px; }

    .detail-header { padding: 20px 16px; }
    .detail-body { padding: 16px; }

    .move-table th { font-size: 6px; padding: 6px; }
    .move-table td { padding: 8px 6px; font-size: 10px; }
}

@media (min-width: 1400px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}