:root {
    --grid-padding: 12px;
    --grid-column-gap: 8px;
    --grid-row-gap: 0px;
    --grid-tile-font-size: clamp(18px, 1.5vw, 28px);
    --grid-tile-padding: 12px;
}

html {
    /*height: 100%; /* overwites same stype in style.css */
    /*margin: 0;*/
    /*padding: 0;*/
    scrollbar-gutter:stable;
    overflow-y:scroll;
}


/* page-stack fills whatever vertical space remains after the header/search.
   The flex chain (body → form → .row → .column.middle → .page-stack) handles
   this correctly without any hardcoded pixel offset. */
.page-stack {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.myHomePage .page-stack {
    overflow: hidden;
}

/* Home page desktop/tablet: keep the full grid inside viewport (no clipping, no scroll).
   Every flex ancestor is allowed to shrink via min-height:0. */
.myHomePage {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    min-height: 0;
    font-size: clamp(18px, 1.5vw, 26px);
}

.myHomePage > form {
    height: 100%;
    min-height: 0;
    flex: 1 1 auto;
}

.myHomePage .row,
.myHomePage .middle {
    min-height: 0;
    flex: 1 1 auto;
}

/* Grid fills remaining space; items flow down, then across */
.grid {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
    display: grid;
    padding: var(--grid-padding);
    padding-bottom: calc(var(--grid-padding) + 4px);
    column-gap: var(--grid-column-gap);
    row-gap: var(--grid-row-gap);
    grid-template-columns: repeat(var(--grid-columns, 4), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-rows, 101), minmax(0, 1fr));
    align-content: stretch;
}

.myHomePage .grid {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    align-content: stretch;
}

/* Tiles use explicit DB-driven placement: column, start row, and span height. */
.block {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    box-sizing: border-box;
    color: #fff;
    text-decoration: none;
    font-family: 'Playfair Display', serif;
    font-size: var(--grid-tile-font-size);
    font-weight: bold;
    border-radius: 10px;
    border: 2px solid var(--myBackground);
    text-align: center;
    padding: var(--grid-tile-padding);

    box-shadow: 0 4px 10px rgba(0,0,0,.12);
    transition: transform .15s ease, box-shadow .15s ease;

    grid-column: var(--col, auto);
    grid-row: var(--row, auto) / span var(--h, 33);
}

.block:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 18px rgba(0,0,0,.18);
}
.block  button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    text-align: center;
    white-space: normal;
    word-wrap:break-word;
}

.block button:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.block button img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

/* Make form blocks behave like anchors */
form.block {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    box-sizing: border-box;
    color: #fff;
    text-decoration: none;
    font-family: 'Playfair Display', serif;
    font-size: var(--grid-tile-font-size);
    font-weight: 600;
    border-radius: 10px;
    text-align: center;
    padding: 0;              /* no padding on form; button fills it */
    margin: 0;

    box-shadow: 0 4px 10px rgba(0,0,0,.12);
    transition: transform .15s ease, box-shadow .15s ease;

    grid-column: var(--col, auto);
    grid-row: var(--row, auto) / span var(--h, 33);
}

form.block:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 18px rgba(0,0,0,.18);
}

/* Button fills entire block */
form.block button {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    padding: var(--grid-tile-padding);           /* padding inside button for text breathing room */
    box-sizing: border-box;
    text-align: center;
    border-radius: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 1440px) {
    :root {
        --grid-padding: 10px;
        --grid-column-gap: 6px;
        --grid-row-gap: 0px;
        --grid-tile-font-size: clamp(16px, 1.35vw, 22px);
        --grid-tile-padding: 10px;
    }
}

@media (max-height: 1080px) and (min-width: 601px) {
    :root {
        --grid-padding: 10px;
        --grid-column-gap: 6px;
        --grid-row-gap: 0px;
        --grid-tile-padding: 9px;
    }
}

@media (max-height: 900px) and (min-width: 601px) {
    :root {
        --grid-padding: 10px;
        --grid-column-gap: 6px;
        --grid-row-gap: 0px;
        --grid-tile-font-size: clamp(15px, 1.25vw, 20px);
        --grid-tile-padding: 8px;
    }
}

@media (max-height: 820px) and (min-width: 601px) {
    :root {
        --grid-padding: 8px;
        --grid-column-gap: 5px;
        --grid-row-gap: 0px;
        --grid-tile-font-size: clamp(14px, 1.15vw, 18px);
        --grid-tile-padding: 7px;
    }
}

form.block button:hover {
    background: rgba(255, 255, 255, 0.1); /* subtle hover on button */
}

/* Mobile: single column, vertical scroll */
@media (max-width: 600px) {
    .myHomePage {
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .myHomePage > form,
    .myHomePage .row,
    .myHomePage .middle {
        height: auto;
        min-height: 0;
        max-height: none;
        flex: 0 0 auto;
    }

    .myHomePage .page-stack {
        height: auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .myHomePage .grid {
        height: auto;
        min-height: 0;
        overflow: visible;
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-rows: auto;
        row-gap: 6px;
        column-gap: 0;
    }

    .myHomePage .block,
    .myHomePage form.block {
        grid-column: auto;
        grid-row: auto;
        min-height: calc(var(--h, 33) * 0.5vh);
        height: auto;
        font-size: 4vw;
    }
}

/* iPhone landscape: preserve desktop/tablet rules elsewhere, but allow vertical scroll on index */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
    .myHomePage {
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .myHomePage > form,
    .myHomePage .row,
    .myHomePage .middle {
        height: auto;
        min-height: 0;
        max-height: none;
        flex: 0 0 auto;
    }

    .myHomePage .page-stack {
        height: auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .myHomePage .grid {
        height: auto;
        min-height: 0;
        overflow: visible;
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-rows: auto;
        row-gap: 6px;
        column-gap: 0;
    }

    .myHomePage .block,
    .myHomePage form.block {
        grid-column: auto;
        grid-row: auto;
        min-height: calc(var(--h, 33) * 1vh);
        height: auto;
        font-size: 3.8vw;
    }
}
