html {
    overflow-x: visible;
}

p span {
    font-size: 24px;
}

.per-container {
    width: calc(100% - 16px);
    max-width: var(--pageWidth);
    height: 100% !important;
    margin: 48px auto;
}

.per-container,
.box {
    display: flex;
    align-items: start;
    flex: 1;
    justify-content: center;
}

.box {
    position: relative;
    width: 100%;
    background-color: transparent;
}

.box a,
.box a:hover {
    background-image: none;
}

.age {
    display: flex;
    position: relative;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    min-width: 145px; /* Prevent collapse below 2-col width */
    height: 100%;
    min-height: 850px;
    margin: 6px;
    transition: all 500ms ease-in-out;
    text-align: center;
    text-decoration: none;
    z-index: 3;
}

.age p {
    position: absolute;
    font-family: Cinzel, serif;
    font-size: 22px;
    line-height: 22px;
    left: 50%;
    margin: 0;
    transform: translateX(-50%);
    text-wrap: nowrap;
    color: var(--secondary);
    z-index: 3;
}

.age p:first-of-type {
    display: flex;
    top: 0;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    height: 72px;
    gap: 2px;
}

.age p:last-of-type {
    display: flex;
    bottom: 0;
    align-items: center;
    flex-direction: column;
    justify-content: flex-start; /* Align to top for tighter spacing */
    height: 72px;
    margin-bottom: -12px;
    gap: 4px; /* 8px spacing between chronology and title */
}

.age .chronology {
    font-family: "Poppins", serif !important;
    font-size: 15px;
    padding-top: 0;
    color: var(--text-color);
}

.overlay {
    background-color: rgb(from var(--text-color) r g b / 0.15);
    z-index: 2;
}

.overlay,
.image {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin-top: 72px;
    margin-bottom: 72px;
    border-radius: 12px;
}

.image {
    transform: translate3d(0, 0, 0);
    opacity: 0.85;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    width: 100%;
    min-width: 100%;
    height: 100%;
}

.age,
.overlay,
.image {
    transition: all 500ms ease-in-out;
}

.age:hover {
    flex-grow: 1.4;
    cursor: pointer;
    color: #fff;
}

.age:hover .overlay {
    background-color: transparent;
    box-shadow: 0 0 5px 1px rgb(from var(--text-color) r g b / 0.5);
}

.age:hover .image {
    opacity: 0.25;
}

/* NOTED PERSONALITIES */

.noted-container {
    display: flex;
    position: absolute;
    top: 100px;
    bottom: 100px;
    left: 50%;
    align-items: center;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    width: calc(100% - 16px);
    max-width: 180px;
    padding: 0;
    transform: translateX(-50%);
    background-color: transparent;
    gap: 0;
}

/* Dynamic Grids */
.age-section {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 180px;
    transition: all 400ms ease-in-out;
    z-index: 2;
    gap: 15px;
}

.age-section.transit {
    gap: 20px;
}

.age:hover .age-section {
    gap: 30px;
}

.age:hover .age-section.transit {
    gap: 30px;
}

.hex-item {
    display: flex;
    position: relative;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    transition: all 400ms ease-in-out;
    border-radius: 50%;
    z-index: 2;
    backdrop-filter: blur(8px);
}

.hex-item img {
    width: 100%;
    height: 100%;
    margin: 0 !important;
    transition: all 500ms ease-in-out;
    object-fit: cover;
}

.age:hover .hex-item {
    transform: scale(1.05);
    border: 4px solid transparent;
    background-color: rgb(from var(--white) r g b / 0.4);
    box-shadow: 0 8px 80px 8px rgb(from var(--gold) r g b / 0.8);
    backdrop-filter: brightness(3) blur(0);
}

.age:hover .hex-item img {
    transition: all 700ms ease-in-out;
    transform: scale(1.1) translateY(-12px); /* Pop out effect */
}

[class^="hex"] {
    position: relative;
    overflow: visible; /* Ensure visible */
    transition: all 400ms ease-in-out;
    transform: scale(1);
    border: 4px solid rgb(from var(--bold-bright) r g b / 0.5);
    border-radius: 50%;
    z-index: 2;
    backdrop-filter: blur(2px);
}

[class^="hex"] img {
    position: relative;
    margin: 0 !important;
    transition: all 500ms ease-in-out;
    transform: scale(0.85);
    border-radius: 50px;
}

@media (max-width: 1025px) {
    .age p {
        font-size: 19px;
    }

    .main-noted-grid {
        grid-template-columns: repeat(1, 24px);
        grid-auto-rows: 24px;
        grid-template-areas:
      "g1"
      "."
      "g2"
      "."
      "g3";
    }

    .age:hover .main-noted-grid {
        gap: 30px;
    }
}

@media (max-width: 768px) {
    .per-container {
        display: flex;
        overflow: hidden;
        height: 100%;
    }

    .box {
        flex-direction: column;
        margin-right: 12px;
        border: none;
    }

    .age {
        flex-direction: column;
        min-height: unset;
        margin-bottom: 24px;
        border-radius: 16px;
        background-color: var(--bg-container-small);
        box-shadow: 0 0 5px 1px rgb(from var(--text-color) r g b / 0.5);
    }

    .overlay,
    .image {
        margin-top: 72px !important;
        margin-bottom: 72px !important;
    }

    .age p {
        display: flex;
        position: relative;
        font-size: 24px;
        line-height: normal;
        top: auto;
        right: auto;
        bottom: auto;
        left: auto;
        align-items: center;
        flex-direction: column; /* Ensure vertical stacking */
        justify-content: center;
        width: 100%;
        height: 72px; /* Fixed height to match gap */
        transform: none;
    }

    .age p:first-of-type,
    .age p:last-of-type {
        top: auto;
        bottom: auto;
    }

    /* Adjust dynamic grid to start after header */
    .age .image,
    .age .overlay {
        border-radius: 0;
    }

    .noted-container {
        display: flex;
        position: relative;
        top: auto;
        bottom: auto;
        left: auto;
        align-items: center;
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        max-width: none;
        padding: 0;
        transform: none;
    }

    .age-section {
        display: flex;
        align-items: center;
        flex-direction: column;
        max-width: 100%;
        margin: 20px 0;
        gap: 15px;
    }

    .age-section .hex-item {
        flex: 0 0 60px;
    }

    /* Top section: align left */
    .age-section.top {
        align-items: flex-start;
        margin-left: 24px;
    }

    /* Transit section: align center */
    .age-section.transit {
        align-items: center;
        gap: 20px;
    }

    /* Bottom section: align right */
    .age-section.bottom {
        align-items: flex-end;
        margin-right: 24px;
    }

    /* Disable gap increase on hover for mobile */
    .age:hover .age-section {
        gap: 15px;
    }

    .age:hover .age-section.transit {
        gap: 20px;
    }

    .age:hover .hex-item img,
    .hex-item[class^="hex"] img {
        transform: scale(0.8) translateY(-4px);
    }

    .main-noted-grid {
        padding-top: 160px;
        padding-bottom: 80px;
        grid-template-columns: repeat(2, 24px);
        grid-auto-rows: 24px;
        grid-template-areas: ". g1 . g2 . g3 . g4";
        gap: 30px;
    }

    .age:hover .main-noted-grid {
        gap: 48px;
    }

    .age p {
        margin-bottom: 16px;
    }

    .age:hover .overlay {
        box-shadow: none;
    }

    .main-noted-grid::before {
        position: absolute;
        top: 60%;
        left: 50%;
        width: 40%;
        height: 50%;
        content: "";
        transform: translate(-50%, -50%);
        border-radius: 16px;
        z-index: 0;
        backdrop-filter: blur(1px);
    }

    .main-noted-grid::after {
        backdrop-filter: blur(0);
    }
}

@media (max-width: 375px) {
    .main-noted-grid {
        gap: 20px;
    }

    .age:hover .main-noted-grid {
        gap: 20px;
    }

    [class^="hex"] {
        transform: scale(2);
    }

    .age:hover [class^="hex"] {
        transform: scale(2.1);
    }

    [class^="hex"]:hover img {
        transition: all 700ms ease-in-out;
        transform: translate(1px, -3px) scale(1.2);
    }
}
