/**
 * Card-Grid Infographic Base Styles
 *
 * Shared styles for card-grid pattern infographics.
 * Used by: instruments, containers, sports, naadam, western-music, art-terms, world-literature.
 *
 * Pattern: legend strip → grouped sections → numbered accent cards
 *
 * Individual infographic CSS files should ONLY include:
 * - body.{slug}-infographic-page background override
 * - Any truly unique customizations
 */

/* =========================================================
   BASE LAYOUT (Apply via CSS class inheritance)

   Usage: Each infographic uses its own class like:
   .instruments-infographic, .containers-infographic, etc.

   These rules use attribute selector to match any class
   ending with "-infographic" for shared base layout.
   ========================================================= */

[class$="-infographic"] {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    background: var(--card-bg, #fff);
}

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

[class$="-infographic__header"] {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--line-gray, #dcd1c3);
    padding-bottom: 1.5rem;
}

[class$="-infographic__meta"] {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

/* =========================================================
   LEGEND (category overview strip)
   ========================================================= */

[class$="-legend"] {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--entry-bg, #fffaf0);
    border: 1px solid var(--line-gray, #dcd1c3);
    border-radius: var(--radius-main, 12px);
}

[class$="-legend__item"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid;
    transition: opacity 0.2s;
}

[class$="-legend__item"]:hover {
    opacity: 0.8;
}

[class$="-legend__color"] {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

[class$="-legend__item"] small {
    color: #666;
    font-weight: 400;
}

[class$="-legend__count"] {
    background: rgba(0, 0, 0, 0.08);
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* =========================================================
   CATEGORY SECTIONS
   ========================================================= */

[class$="-section"] {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--line-gray, #e0e0e0);
}

[class$="-section"]:last-of-type {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

/* Section title */
[class$="-section__title"] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 1rem;
    padding: 0 0 0.5rem;
    border-bottom: 3px solid;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-dark, #3b2411);
}

[class$="-section__title-jp"] {
    font-size: 1.15rem;
}

[class$="-section__title-mn"] {
    font-size: 0.9rem;
    color: var(--ink-soft, #5a4943);
    font-weight: 400;
}

[class$="-section__count"] {
    margin-left: auto;
    background: var(--entry-bg, #fffaf0);
    border: 1px solid var(--line-gray, #dcd1c3);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-soft, #5a4943);
}

/* =========================================================
   CARD GRID
   ========================================================= */

[class$="-grid"] {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

/* =========================================================
   NUMBERED CARDS (universal for all card-grid infographics)
   ========================================================= */

[class$="-card"] {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    background: var(--card-bg, var(--entry-bg, #fffaf0));
    border: 2px solid var(--line-gray, #dcd1c3);
    border-radius: var(--radius-main, 12px);
    border-left: 4px solid var(--card-accent, var(--wood-orange, #e07a00));
    transition: all 0.22s cubic-bezier(0.25, 1, 0.5, 1);
    text-decoration: none;
    color: inherit;
}

[class$="-card"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 36, 17, 0.1);
    border-color: var(--card-accent, var(--wood-orange, #e07a00));
}

/* Linked card variant */
a[class$="-card--linked"],
a[class$="-card--linked"]:hover,
a[class$="-card--linked"]:visited,
a[class$="-card--linked"]:active {
    text-decoration: none;
    color: inherit;
}

/* Number badge */
[class$="-card__number"] {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    background: var(--card-accent, var(--wood-orange, #e07a00));
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    margin-top: 1px;
}

/* Card body */
[class$="-card__body"] {
    flex: 1;
    min-width: 0;
}

/* Text content within cards */
[class$="-card__mn"] {
    margin: 0 0 3px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-dark, #3b2411);
    line-height: 1.3;
}

[class$="-card__jp"] {
    margin: 0 0 2px;
    font-size: 0.85rem;
    color: var(--ink-soft, #5a4943);
    line-height: 1.4;
}

[class$="-card__en"] {
    margin: 0 0 4px;
    font-size: 0.75rem;
    color: var(--ink-soft, #6f6961);
    line-height: 1.3;
    font-style: italic;
}

[class$="-card__desc"] {
    margin: 5px 0 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--ink-soft, #5a4943);
    padding-top: 5px;
    border-top: 1px solid var(--line-soft, #e8e2d8);
}

/* =========================================================
   IMAGE SLOT
   For cards that include a __image child element.
   Add <div class="xxx-card__image"></div> (or with <img>)
   to any card to activate this layout.
   ========================================================= */

[class$="-card__image"] {
    width: 100%;
    aspect-ratio: 3/2;
    overflow: hidden;
    background: var(--entry-bg, #f5f0e8);
    flex-shrink: 0;
}

[class$="-card__image"] img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Placeholder shown when image slot is empty (no <img> child) */
[class$="-card__image"]:empty {
    background: var(--entry-bg, #f5f0e8);
    border: 2px dashed var(--line-gray, #c8bfb4);
    border-bottom: 1px solid var(--line-gray, #dcd1c3);
}

/*
   IMAGE CARD VARIANT (to be added when PHP outputs image divs)
   Cards that include a __image element need vertical layout:
     image top → number badge → text body
   Use a modifier class on the card element:
     <article class="xxx-card--image xxx-card">
   and add [class*="-card--image"] rules here per page type.
*/

/* =========================================================
   FOOTER
   ========================================================= */

[class$="-footer"] {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--line-gray, #dcd1c3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

[class$="-footer__total"] {
    margin: 0;
    font-size: 0.9rem;
    color: var(--ink-soft, #5a4943);
    font-weight: 600;
}

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

@media (max-width: 1100px) {
    [class$="-grid"] {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 900px) {
    [class$="-grid"] {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }

    [class$="-legend"] {
        flex-direction: column;
        align-items: stretch;
    }

    [class$="-legend__item"] {
        justify-content: flex-start;
    }
}

@media (max-width: 640px) {
    [class$="-grid"] {
        grid-template-columns: repeat(2, 1fr);
    }

    [class$="-section__title"] {
        flex-wrap: wrap;
        font-size: 1rem;
    }

    [class$="-section__title-jp"] {
        font-size: 1rem;
    }

    [class$="-section__title-mn"] {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    [class$="-infographic"] {
        padding: 0 0.5rem;
    }

    [class$="-grid"] {
        grid-template-columns: 1fr;
    }

    [class$="-card"] {
        padding: 12px;
    }

    [class$="-legend"] {
        padding: 0.75rem;
    }
}

/* =========================================================
   PRINT STYLES
   ========================================================= */

@media print {
    [class$="-infographic"] {
        max-width: 100%;
    }

    [class$="-card"] {
        page-break-inside: avoid;
        break-inside: avoid;
        border-left-width: 3px;
    }

    [class$="-section"] {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    [class$="-legend"] {
        page-break-after: avoid;
        break-after: avoid;
    }
}