/* ============================================
   RESPONSIVE DESIGN - TABLET & DESKTOP (1024px)
   ============================================ */

@media (max-width: 851px) {
    .dropdown-content {
        top: 100%;
        right: 0;
        display: flex;
        flex-direction: column;
        gap: 4px;
        max-height: calc(100vh - 5rem);
        max-height: calc(100dvh - 5rem);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .dropdown-content > a,
    .dropdown-content > .nested-dropdown > a {
        display: flex;
        align-items: center;
        min-height: 44px;
        margin: 0;
    }

    .nested-dropdown-content a {
        display: flex;
        align-items: center;
        min-height: 44px;
    }

    .nested-dropdown-content {
        position: static;
        display: block;
        width: calc(100% - 15px);
        max-height: 0;
        margin: 0 0 0 15px;
        padding: 0 4px;
        overflow: hidden;
        background-color: rgba(0, 0, 0, 0.7);
        border-right: none;
        border-left: 0 solid transparent;
        box-shadow: none;
        transition: max-height 220ms ease, padding 220ms ease;
    }

    .nested-dropdown.open .nested-dropdown-content {
        max-height: 800px;
        padding-top: 6px;
        padding-bottom: 6px;
        border-left: 2px solid var(--accent-cyan);
    }

    .nested-dropdown-content a {
        margin: 1px 0;
    }

    .nested-dropdown > a::after {
        margin-top: 0.4rem;
        transform: rotate(45deg);
    }

    .nested-dropdown.open > a::after {
        transform: rotate(225deg);
    }
}

@media (max-width: 1024px) {
    .main {
        flex-direction: column;
        align-items: center;
        gap: 2rem;
        padding: 5%;
    }

    .welcome {
        width: 100%;
        font-size: 1.3rem;
        padding: 3%;
    }

    .d1, .d2 {
        width: 100%;
        padding: 3%;
    }

    .d2 {
        width: 100%;
        max-width: 400px;
        padding: 2%;
    }

    .home-portrait {
        width: 100%;
        max-width: 300px;
    }

    .d2 img {
        max-width: 100%;
        width: 100%;
    }

    .d3, .d4 {
        width: 95%;
    }

    .lightbox-image {
        max-width: 65%;
        max-height: 60vh;
    }

    .lightbox-prev,
    .lightbox-next {
        font-size: 30px;
        width: 50px;
        height: 50px;
        padding: 10px 15px;
    }

    .lightbox-title {
        font-size: 1.4rem;
        gap: 1.5rem;
    }

}

/* ============================================
   RESPONSIVE DESIGN - TABLET (768px)
   ============================================ */

@media (max-width: 768px) {
    .main {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        padding: 3%;
    }

    .welcome {
        width: 100%;
        font-size: 1.2rem;
        padding: 2%;
    }

    .d1, .d2 {
        width: 100%;
        padding: 2%;
        border-radius: 8px;
    }

    .d2 {
        width: 100%;
        max-width: 100%;
        padding: 2%;
    }

    .home-portrait {
        width: 90%;
        max-width: 300px;
    }

    .d2 img {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    .d3, .d4 {
        width: 97%;
        padding: 2%;
    }

    .d3 .img_left,
    .d3 .img_right {
        float: none;
        width: 100%;
        max-width: 100%;
        margin: 12px 0;
    }

    table {
        width: 100%;
        margin: 1rem auto;
        font-size: 0.9rem;
        table-layout: fixed;
    }

    th, td {
        padding: 8px 6px;
        overflow-wrap: anywhere;
    }

    .lightbox {
        padding: 1rem;
    }

    .lightbox-image {
        max-width: 90%;
        max-height: 55vh;
    }

    .lightbox-prev,
    .lightbox-next {
        font-size: 24px;
        width: 44px;
        height: 44px;
        padding: 8px 12px;
    }

    .lightbox-prev {
        position: absolute;
        left: 5%;
    }

    .lightbox-next {
        position: absolute;
        right: 5%;
    }

    .lightbox-title {
        font-size: 1.1rem;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .lightbox-close {
        top: 15px;
        right: 15px;
        font-size: 28px;
    }

}

/* ============================================
   RESPONSIVE DESIGN - MOBILE (480px)
   ============================================ */

@media (max-width: 480px) {
    /* Navigation fixes for mobile */
    nav {
        padding: 1% 2%;
    }

    .menu-container {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .dmolda_button {
        font-size: 1.45rem;
        padding: 8px 10px;
        width: auto;
        flex: 1;
        margin-bottom: 0;
        letter-spacing: 0.5px;
        min-width: 120px;
        white-space: nowrap;
    }

    /* Use JS-driven .open class to show dropdowns on small screens as well */
    .dropdown-content {
        position: absolute !important;
        top: 100%;
        right: 0;
        width: 200px;
        box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.5);
        background-color: rgba(0,0,0,0.9);
        border-top: 1px solid var(--accent-cyan);
        border-radius: 0;
        min-width: auto;
        transform-origin: top right;
        transform: translateY(-6px) scale(0.98);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 200ms ease, transform 200ms ease, visibility 200ms;
    }

    .dropdown.open .dropdown-content {
        transform: translateY(0) scale(1);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .dropdown-content a {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .nested-dropdown-content a {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    /* Main layout */
    .main {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        padding: 0;
        width: 100%;
    }

    .welcome {
        width: 100%;
        font-size: 1rem;
        padding: 1.5rem;
    }

    .home-continue {
        gap: 0.55rem;
        font-size: 1.3rem;
    }

    .d1, .d2 {
        width: 90%;
        padding: 1.5%;
        border-radius: 8px;
        margin: 0;
    }

    .d2 {
        width: 100%;
        max-width: 100%;
        padding: 1.5rem;
    }

    .home-portrait {
        width: 90%;
    }

    .d2 img {
        width: 90%;
        max-width: 100%;
        height: auto;
    }

    .d3, .d4 {
        width: 90%;
        padding: 1.5rem;
        margin: 0;
        box-shadow: none;
    }

    .d3 .img_left,
    .d3 .img_right {
        float: none;
        width: 100%;
        max-width: 100%;
        margin: 12px 0;
    }

    table {
        width: 95%;
        margin: 1rem auto;
        font-size: 0.9rem;
    }

    th, td {
        padding: 8px 10px;
    }

    .lightbox {
        padding: 0.5rem;
    }

    .lightbox-image {
        max-width: 100%;
        max-height: 50vh;
    }

    .lightbox-prev,
    .lightbox-next {
        font-size: 20px;
        width: 44px;
        height: 44px;
        padding: 6px 10px;
    }

    .lightbox-title {
        font-size: 0.9rem;
        gap: 0.8rem;
    }

    .lightbox-close {
        top: 10px;
        right: 10px;
        font-size: 24px;
    }

}