/* Mobile / tablet responsiveness */

html {
    overflow-x: clip;
}

body {
    overflow-x: clip;
    max-width: 100%;
}

.page-shell,
.main-column,
.content-stream,
.content-group,
.group-modules,
.module-slot,
.sidebar,
.profile-panel {
    min-width: 0;
}

.main-column,
.content-stream,
.content-group,
.group-modules,
.module-slot,
.sidebar,
.profile-panel {
    max-width: 100%;
}

/* Kill Bootstrap row overflow from nested HTM modules */
.module-slot .row {
    --bs-gutter-x: 0.75rem;
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100%;
    flex-wrap: wrap !important;
}

.module-slot [class*="col-"] {
    max-width: 100%;
    min-width: 0;
}

.module-slot .card,
.module-slot .card-header,
.module-slot .card-body {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.module-slot .card-header .row {
    row-gap: 0.5rem;
}

.module-slot .chip-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
}

.module-slot .click-chip,
.module-slot .click-chip-hover,
.module-slot .basic-chip {
    max-width: 100%;
    white-space: normal;
}

.module-slot .chip-p {
    white-space: normal;
}

.module-slot img,
.module-slot svg,
.module-slot .carousel-inner,
.module-slot .carousel-item,
.module-slot .carousel-item img {
    max-width: 100% !important;
    height: auto;
}

.module-slot .card-project-img {
    width: 100%;
    height: 180px;
    max-height: 220px;
    object-fit: cover;
}

.profile-contact a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (max-width: 960px) {
    :root {
        --page-pad: 0.85rem;
        --sidebar-width: 100%;
    }

    body {
        background-attachment: scroll;
    }

    .page-shell {
        grid-template-columns: 1fr;
        gap: 1.1rem;
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding: 0.85rem 0.85rem 5.5rem;
    }

    .sidebar {
        position: relative;
        top: auto;
        max-height: none;
        overflow: visible;
    }

    .profile-panel {
        gap: 0.7rem;
        padding: 1rem 0.95rem 1.1rem;
        border-radius: 16px;
        backdrop-filter: none;
    }

    .profile-brand {
        font-size: clamp(1.75rem, 8vw, 2.2rem);
    }

    .profile-photo-frame {
        --photo-size: 96px;
        margin: 0;
    }

    .profile-photo-ring {
        inset: -5px;
        border-radius: 20px;
    }

    .profile-photo-ring::before {
        inset: 2px;
        border-radius: 18px;
    }

    .profile-photo-orbit {
        inset: -10px;
    }

    .profile-photo-orbit--lag {
        inset: -14px;
    }

    .profile-photo {
        border-radius: 16px;
        width: calc(var(--photo-size) - 4px);
        height: calc(var(--photo-size) - 4px);
    }

    .profile-name {
        font-size: 1.15rem;
    }

    .profile-identity {
        display: grid;
        grid-template-columns: 96px 1fr;
        gap: 0.85rem;
        align-items: center;
    }

    .profile-identity-text {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        min-width: 0;
    }

    .profile-nav {
        position: fixed;
        left: 0.7rem;
        right: 0.7rem;
        bottom: max(0.65rem, env(safe-area-inset-bottom));
        z-index: 80;
        display: flex;
        gap: 0.4rem;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        padding: 0.45rem;
        margin: 0;
        border: 1px solid var(--line);
        border-radius: 999px;
        background: rgba(255, 253, 249, 0.94);
        box-shadow: 0 12px 30px rgba(29, 26, 23, 0.18);
        scrollbar-width: none;
    }

    .profile-nav::-webkit-scrollbar {
        display: none;
    }

    .profile-nav-link {
        flex: 1 0 auto;
        white-space: nowrap;
        text-align: center;
        padding: 0.6rem 0.85rem;
        border: 1px solid transparent;
        border-radius: 999px;
        background: transparent;
        box-shadow: none;
        font-size: 0.84rem;
    }

    .profile-nav-link.is-active {
        background: var(--brand);
        border-color: var(--brand);
        color: #fff;
        box-shadow: none;
    }

    .group-header {
        padding-left: 0;
        margin-bottom: 0.85rem;
    }

    .group-title {
        font-size: clamp(1.35rem, 6vw, 1.8rem);
    }

    .group-modules {
        gap: 0.95rem;
    }

    .group-modules::before,
    .module-slot::before {
        display: none;
    }

    .module-slot {
        padding-left: 0;
    }

    .module-slot .card-header {
        padding: 0.85rem 0.9rem;
    }

    .module-slot .card-body {
        padding: 0.85rem 0.9rem 1rem;
    }

    .module-slot .card-header h6 {
        font-size: 0.98rem;
    }

    /* Stack job header meta earlier than Bootstrap md */
    .module-slot .card-header .row > [class*="col-"] {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
    }

    .module-slot .periods {
        flex-wrap: wrap;
    }

    /* Projects: one column on phones/tablets */
    .module-slot .card-body .row > [class*="col-"] {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
    }

    .module-slot .some-project-card {
        min-height: 0 !important;
        margin-bottom: 0.75rem;
    }

    .module-slot .flip > .front,
    .module-slot .flip > .back {
        height: min(280px, 62vw);
        background-attachment: scroll !important;
    }

    /* Tap-friendly flip on touch: show back slightly via focus/active */
    .module-slot .flip:active > .front,
    .module-slot .flip:focus-within > .front {
        transform: rotateY(180deg);
    }

    .module-slot .flip:active > .back,
    .module-slot .flip:focus-within > .back {
        opacity: 1;
        transform: rotateY(0deg);
    }

    .closeImageModal {
        top: 10px;
        right: 16px;
        font-size: 2rem;
    }

    .site-footer {
        padding: 0.85rem 0.5rem;
        font-size: 0.82rem;
    }
}

@media (max-width: 560px) {
    .page-shell {
        padding-left: 0.7rem;
        padding-right: 0.7rem;
        gap: 0.9rem;
        padding-bottom: 5.5rem;
    }

    .profile-panel {
        padding: 0.9rem 0.8rem 1rem;
    }

    .profile-identity {
        grid-template-columns: 76px 1fr;
        gap: 0.7rem;
    }

    .profile-photo-frame {
        --photo-size: 76px;
    }

    .profile-photo {
        border-radius: 14px;
    }

    .profile-quote {
        font-size: 0.82rem;
        padding: 0.7rem 0.75rem;
    }

    .module-slot .accordion-button {
        font-size: 0.92rem;
        padding: 0.85rem 1rem;
    }

    .module-slot .click-chip,
    .module-slot .click-chip-hover,
    .module-slot .basic-chip {
        margin: 0.2rem;
        padding: 0.35rem 0.65rem;
    }

    .module-slot .chip-p {
        font-size: 0.72rem;
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .profile-brand {
        font-size: 1.55rem;
    }

    .profile-nav-link {
        padding: 0.5rem 0.7rem;
        font-size: 0.8rem;
    }
}
