/* Homepage tile sections (Phase 2, 2026-10-23): tile_block / brand_tiles / grouped_category_grid.
   Section colours come from two CSS variables the page sets inline (validated server-side):
   --km-sec-bg (background) and --km-sec-title (heading colour). Without them nothing changes. */

.km-tiles{ position:relative; }
.km-tiles--styled{
    background:var(--km-sec-bg, transparent);
    border-radius:18px;
    padding:14px 14px 16px;
    overflow:hidden;
}
.km-tiles .km-tiles-title{ color:var(--km-sec-title, inherit); position:relative; z-index:1; }
.km-tiles .km-section-head{ position:relative; z-index:1; }
.km-tiles-decor{
    position:absolute;
    top:0;
    right:0;
    width:auto;
    height:90px;
    max-width:34%;
    object-fit:contain;
    object-position:100% 0;
    pointer-events:none;
    z-index:0;
}

/* garland: the TOP 40% of a 2:1 picture (garland + bells) across the whole section, centred, at most 760px wide.
   A 2:1 picture's top 40% is 5:1, so the box is 5:1 and the picture is scaled to the box width. */
.km-tiles-garland{
    display:block;
    width:100%;
    max-width:760px;
    aspect-ratio:5 / 1;
    margin:-14px auto -2px;
    background-repeat:no-repeat;
    background-position:50% 0;
    background-size:100% auto;
    pointer-events:none;
    position:relative;
    z-index:0;
}

/* tile colours (soft, readable behind a picture) */
.km-tile--c0{ --km-tile-bg:#fdf1d9; }
.km-tile--c1{ --km-tile-bg:#e3f3ea; }
.km-tile--c2{ --km-tile-bg:#fde6e3; }
.km-tile--c3{ --km-tile-bg:#e6edfb; }
.km-tile--c4{ --km-tile-bg:#f1e7f8; }
.km-tile--c5{ --km-tile-bg:#e1f4f4; }

/* ---------- tile_block ---------- */
.km-tile-grid{ display:grid; gap:10px; position:relative; z-index:1; }
.km-tile{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:space-between;
    gap:6px;
    min-width:0;
    padding:10px 8px;
    background:var(--km-tile-bg, #f4f7fb);
    color:#172033;
    text-decoration:none;
    text-align:center;
    box-sizing:border-box;
}
a.km-tile:hover,
a.km-tile:focus-visible{ filter:brightness(.97); }
.km-tile-label{
    font-size:13px;
    line-height:1.2;
    font-weight:900;
    overflow-wrap:anywhere;
}
.km-tile-img{ display:block; width:100%; aspect-ratio:1 / 1; }
.km-tile-img img{ width:100%; height:100%; object-fit:contain; display:block; }

/* hexagon ("Diwali Ready") - 3 across on phones, up to 6 on wide screens */
.km-tiles--hex .km-tile-grid{ grid-template-columns:repeat(3, minmax(0, 1fr)); }
.km-tiles--hex .km-tile{
    aspect-ratio:1 / 1.12;
    clip-path:polygon(50% 0, 100% 14%, 100% 86%, 50% 100%, 0 86%, 0 14%);
    padding:16px 10px 14px;
    background:var(--km-tile-bg, #fdf1d9);
}
.km-tiles--hex .km-tile-img{ width:80%; }
/* on tablets / desktops the tiles stay a sensible size (they used to stretch to a third of the page each) and sit in the middle */
@media (min-width:768px){
    .km-tiles--hex .km-tile-grid{ grid-template-columns:repeat(auto-fit, minmax(140px, 180px)); justify-content:center; gap:12px; }
}

/* stores - 4 across, label top-left, picture bottom-right */
.km-tiles--stores4 .km-tile-grid{ grid-template-columns:repeat(4, minmax(0, 1fr)); gap:8px; }
.km-tiles--stores4 .km-tile{
    align-items:stretch;
    text-align:left;
    border-radius:14px;
    aspect-ratio:1 / 1.25;
    padding:8px;
}
.km-tiles--stores4 .km-tile-label{ font-size:12px; }
.km-tiles--stores4 .km-tile-img{ width:78%; align-self:flex-end; }
@media (min-width:768px){
    .km-tiles--stores4 .km-tile-grid{ grid-template-columns:repeat(auto-fit, minmax(150px, 220px)); justify-content:center; }
}

/* 2 x 2 */
.km-tiles--grid2x2 .km-tile-grid{ grid-template-columns:repeat(2, minmax(0, 1fr)); }
.km-tiles--grid2x2 .km-tile{ border-radius:16px; padding:12px; }
.km-tiles--grid2x2 .km-tile-label{ order:2; font-size:14px; }
.km-tiles--grid2x2 .km-tile-img{ order:1; width:72%; }
@media (min-width:768px){
    .km-tiles--grid2x2 .km-tile-grid{ grid-template-columns:repeat(auto-fit, minmax(200px, 300px)); justify-content:center; }
}

/* ---------- brand_tiles ---------- */
.km-brand-row{
    display:flex;
    gap:10px;
    overflow-x:auto;
    padding:2px 2px 8px;
    scroll-snap-type:x proximity;
    position:relative;
    z-index:1;
}
.km-brand-card{
    flex:0 0 auto;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:8px;
    width:112px;
    padding:10px 8px;
    border-radius:16px;
    background:var(--km-tile-bg, #fdf1d9);
    color:#172033;
    text-decoration:none;
    scroll-snap-align:start;
}
.km-brand-name{
    max-width:100%;
    font-size:13px;
    font-weight:900;
    text-align:center;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
}
.km-brand-thumbs{ display:flex; gap:6px; }
.km-brand-thumbs img{
    width:44px;
    height:44px;
    object-fit:contain;
    border-radius:10px;
    background:#fff;
}

/* ---------- grouped_category_grid ---------- */
.km-group-title{
    margin:14px 0 8px;
    font-size:18px;
    font-weight:900;
    color:var(--km-sec-title, #111827);
}
.km-group-title:first-of-type{ margin-top:4px; }
.km-group-grid{ display:grid; grid-template-columns:repeat(4, minmax(0, 1fr)); gap:10px; position:relative; z-index:1; }
.km-group-cat{ display:flex; flex-direction:column; align-items:center; gap:6px; min-width:0; color:#172033; text-decoration:none; }
.km-group-img{
    display:block;
    width:100%;
    aspect-ratio:1 / 1;
    border-radius:14px;
    background:#e9f5f3;
    overflow:hidden;
}
.km-group-img img{ width:100%; height:100%; object-fit:contain; display:block; padding:4px; box-sizing:border-box; }
.km-group-name{
    max-width:100%;
    font-size:12px;
    line-height:1.2;
    font-weight:800;
    text-align:center;
    overflow-wrap:anywhere;
}
@media (min-width:768px){
    .km-group-grid{ grid-template-columns:repeat(auto-fill, minmax(96px, 110px)); }
}

/* a rail heading the server has not filled (yet, or ever) takes no space */
.km-section-title[data-km-empty-title="1"]:empty{ display:none; }
