:root {
    --bg: #0b0f17; --card: #121826; --text: #e8ecf1; --muted:#93a1b0; --accent:#4cc3ff; --border:#1f2a3a;
    --page-pad: 1rem;
    --section-gap: 2rem;     /* vertical spacing between sections */
    --content-width: 1200px; /* match grid’s max width if you set one */
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif; }
header, footer { padding: 12px 16px; border-bottom: 1px solid var(--border); }
footer { border-top: 1px solid var(--border); border-bottom: none; color: var(--muted); font-size: 12px; text-align:center; }
h1 { font-size: 24px; margin: 0; letter-spacing: 0.5px;}
h2 { font-size: 20px; margin: 0; letter-spacing: 0.5px; text-align: center; }
.container { padding: 16px; max-width: 1200px; margin: 0 auto; }
.grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(6, 1fr); } }
/* Phones/tablets: stack vertically */
@media (max-width: 768px) {
    .modal-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;   /* image then story */
        min-height: auto;               /* allow natural height on small screens */
    }
    .modal-media {
        min-height: auto;
    }
    #modalImg {
        max-height: 40vh;               /* sensible cap when stacked */
    }
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.thumb-wrap {
    aspect-ratio: 1 / 1; /* square thumb area */
    width: 100%;
    overflow: hidden;
    background: #0e1421;
    display:flex; align-items:center; justify-content:center;
}
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { padding: 10px; }
.name { font-size: 13px; font-weight: 600; line-height: 1.2; margin-bottom: 6px; color: var(--text); }
.world { font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center; padding: 16px; z-index: 1000;
}
/* the dialog containers inside backdrops */
.modal {
    margin: auto;
    max-width: 1000px;   /* main modal */
    width: 90%;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}
.market-dialog {
    margin: auto;
    width: 420px;        /* small modal */
    max-width: calc(100% - 2rem);
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}
.modal header { display:flex; align-items:center; justify-content:space-between; border-bottom: 1px solid var(--border); }
.modal h2 { font-size: 16px; margin: 0; }
.modal-hero { width: 100%; background: #0e1421; }
.modal-hero img { width: 100%; height: auto; display: block; }
.modal-content { padding: 14px; }
.modal-world { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.story { white-space: pre-wrap; line-height: 1.45; font-size: 14px; color: var(--text); }

.img-col { display: flex; align-items: center; justify-content: center; }
.img-col img { max-width: 100%; height: auto; max-height: 70vh; display: block; }
.story-col { overflow: auto; }
.close-btn {
    border: 1px solid var(--border); background: transparent; color: var(--text);
    padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.close-btn:hover { border-color: var(--accent); }

/* Make the modal body occupy available height, and split 50/50 on desktop */
#modal {
    max-width: 1000px;
    width: min(1000px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

/* Give the content area real height and split it 50/50 */
.modal-body {
/* occupies all space between header (title) and footer (actions) */
    flex: 1 1 auto;
    min-height: 60vh;                 /* << key: guarantees vertical space */
    display: grid;
    grid-template-columns: 1fr 1fr;   /* 50/50 split on wide screens */
    gap: 16px;
    padding: 16px;
    overflow: hidden;                  /* internal sections manage scroll */
    align-items: stretch;
}

/* Default: wide screens = 50/50 split */
/* Left side (image) centers and fills its half */
.modal-media {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 45vh;                  /* << ensures a decent initial size */
    overflow: hidden;
}

/* Story area scrolls internally if long */
/* Image can expand big but won’t overflow */
#modalImg {
    max-width: 100%;
    max-height: 100%;
    height: auto;
    object-fit: contain; /* no cropping, uses full half if room exists */
    display: block;
}
/* Right side (story) fills and scrolls internally if long */
.modal-text {
    overflow: auto;
}

#modalStory {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Footer buttons row */
/* Footer stays at bottom */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px 16px;
    border-top: 1px solid #eee;
}

/* Overlay */
.backdrop {
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.5); z-index: 1000;
}

/* Dialog shell */
.modal-dialog {
    background: #111; color: #eee;
    width: min(1100px, 95vw);
    max-height: 90vh;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0,0,0,.6);
    display: flex; flex-direction: column;
    overflow: hidden; /* contain inner scrolls */
}

/* Header */
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.modal-header h2 {
    margin: 0; font-size: 1.1rem; font-weight: 600;
    line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modal-header,
.modal-header * { color: #000 !important; }
.btn-close {
    border: 0; background: transparent; color: #aaa; font-size: 1.4rem; cursor: pointer;
}
#modalTitle { color: #000 !important; }
.modal-header { opacity: 1 !important; }
.btn-close:hover { color: #fff; }

/* Two-column content (switches to single column on small screens) */
.modal-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0; /* seamless split */
    min-height: 300px;
    max-height: calc(90vh - 56px); /* header height allowance */
}
/* Left: image panel */
.modal-left {
    background: #0b0b0b;
    display: grid; /* center nicely */
    place-items: center;
    padding: 12px;
    overflow: hidden;
}
.img-wrap {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: 1fr auto; /* image, then meta */
    align-items: center;
    }
.meta {
    padding: 8px 0 0;
    text-align: center;
    font-size: .95rem;
    color: #ccc;
}
/* Right: story panel (scrolls if needed) */
.modal-right {
    background: #121212;
    padding: 14px 16px;
    overflow: auto;      /* story can scroll; image side does not */
}
.story {
    margin: 0;
    white-space: pre-wrap; /* wrap text from file */
    word-break: break-word;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    line-height: 1.45;
    color: #e9e9e9;
}
.market-backdrop .panel {
    background: #111; color: #eee; padding: 16px 20px; border-radius: 12px; min-width: 320px;
    max-width: 90vw; position: relative;
}

.modal-mini {
    position: fixed;
    inset: 0;
    display: none;            /* toggled to flex when open */
    align-items: center;
    justify-content: center;
    z-index: 2000;            /* above your main modal content */
}
.modal-mini::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.25);  /* subtle scrim behind the panel */
}
.modal-mini .panel {
    position: relative;
    background: #fff;
    width: min(380px, 92vw);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.close-x {
    position: absolute;
    top: .5rem;
    right: .5rem;
    font-size: 1.25rem;
    line-height: 1;
    border: none;
    background: transparent;
    cursor: pointer;
}
.muted { opacity: 0.8; font-size: 0.9em; margin-bottom: 8px; }

/* Modal sizing shell: do NOT change display of backdrop/modal container */
.modal-content {
    max-height: 90vh;           /* keep everything on-screen */
    display: flex;
    flex-direction: column;
    overflow: hidden;            /* prevent body from scrolling behind */
}

/* Inner layout: default = stacked (mobile-first) */
.modal-body {
    display: grid;
    grid-template-columns: 1fr;  /* stack image + story */
    gap: 1rem;
    overflow: hidden;            /* we’ll scroll the story only */
}

/* Image area */
.modal-left {
    min-width: 0;                /* avoid grid overflow */
}

#modalImg, .modal-img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 45vh;            /* comfortable on phones */
    object-fit: contain;
}

/* Story area: scrolls independently with smooth iOS behavior */
#modalStory, .story-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;  /* iOS momentum */
    max-height: 40vh;                   /* phone: keeps footer/buttons visible */
    padding-right: .5rem;               /* avoid text flush against edge */
}

/* Desktop / large screens: go side-by-side 50/50 with bigger image */
@media (min-width: 900px) {
.modal-body {
    grid-template-columns: 1fr 1fr;   /* two columns */
    align-items: start;
}
#modalImg, .modal-img {
    max-height: 70vh;                  /* larger image on desktop */
}
#modalStory, .story-scroll {
    max-height: 70vh;                  /* story shares space with image */
}
}

/* Desktop: make the story column fill the modal height with a solid bg */
@media (min-width: 900px) {
    .modal-body {
        align-items: stretch;         /* both columns equal height */
    }

    .modal-right {
        background: #000;             /* full-height black panel */
        color: #fff;
        display: flex;                 /* let inner story area stretch */
        flex-direction: column;
        min-height: 0;                 /* fix flex overflow in Firefox */
        padding: 1rem;                 /* match your spacing */
        border-bottom-right-radius: 12px; /* optional: match your modal rounding */
    }

    /* story area fills the right column vertically */
    #modalStory.story-scroll {
        flex: 1;                       /* take remaining height */
        height: 100%;
        max-height: unset;             /* let the column control height */
        overflow: auto;                /* keeps scroll only in the story pane */
        -webkit-overflow-scrolling: touch;

        .about, .featured, .filters { margin: 1rem auto; max-width: 1200px; padding: 0 1rem; }

        .featured-header {
            display: flex;
            justify-content: center;   /* center the title */
            align-items: center;
            gap: 0.5rem;
            margin: 1rem;            /* keep some breathing room */
        }
        .featured .featured-header h2 { margin: 0 0 1rem 0; }
        .filters-row { display:flex; flex-wrap:wrap; gap:.5rem; align-items:center; }
        .filters-row input, .filters-row select { padding:.4rem .6rem; }

    }

    .container,
    .about,
    .featured,
    .filters {
        max-width: var(--content-width);
        margin: 0 auto;
        padding: 0 var(--page-pad);
    }

    /* section spacing */
    .about { margin-top: var(--section-gap); margin-bottom: var(--section-gap); }
    .featured { margin-top: var(--section-gap); margin-bottom: var(--section-gap); }
    .filters { margin-top: var(--section-gap); margin-bottom: var(--section-gap); }

    /* center the featured grid */
    #featuredGrid.grid {
        justify-content: center;
        margin-top: 1rem !important;
    }

    /* center the filters row */
    .filters .filters-row {
        display: flex;
        flex-wrap: wrap;
        gap: .75rem;
        justify-content: center;
        align-items: center;
    }

    /* optional: nicer horizontal rules */
    .rule {
        max-width: var(--content-width);
        margin: var(--section-gap) auto;
        border: 0;
        height: 1px;
        background: linear-gradient(to right, transparent, #ccc, transparent);
    }

    /* make the message span the whole grid and center on screen */
    .empty-center {
      grid-column: 1 / -1;          /* span all grid columns */
      display: flex;
    /*  align-items: center; */
      justify-content: center;
      min-height: 50vh;              /* pushes it toward screen center */
      text-align: center;
    }

    .empty-center h2 {
      margin: 0;
      font-weight: 600;
    }

}
