/* Reset box sizing cross-browser */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: #f1f1f1;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Page background image, set via the --page-bg-image custom property in
   common.js (either a url(...) pointing at the root portfolio's icon image,
   or a neutral gradient fallback when no icon is set). Rendered as its own
   fixed full-viewport layer behind everything else, and kept heavily dimmed
   via a low opacity so it never competes with page content for readability.
   A separate layer (rather than applying background-image to body directly)
   keeps the dimming opacity from also fading body's own background-color/
   content. */
body.has-bg-image::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image: var(--page-bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.12;
}

.page-content {
    max-width: 1300px;
    margin: 0 auto;
    padding: 16px;
}

/* ---------------------------------------------------------------------
   Site header: sticky top bar with title + hamburger menu. Shared across
   index.html and about.html via common.js so the two pages can never end
   up with mismatched navigation.
   --------------------------------------------------------------------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 500;
    background-color: rgba(17, 17, 17, 0.96);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.site-header-bar {
    max-width: 1300px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
}

.site-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffffff;
    text-decoration: none;
    letter-spacing: 0.01em;
}

.site-title:hover,
.site-title:focus-visible {
    color: #cfe3ff;
}

.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
    background-color: rgba(255, 255, 255, 0.12);
}

.menu-toggle:focus-visible {
    outline: 2px solid #4da3ff;
    outline-offset: 2px;
}

.menu-toggle-bar {
    display: block;
    width: 22px;
    height: 2px;
    background-color: #ffffff;
    border-radius: 2px;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.menu-toggle[aria-expanded="true"] .menu-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.menu-toggle[aria-expanded="true"] .menu-toggle-bar:nth-child(2) {
    opacity: 0;
}
.menu-toggle[aria-expanded="true"] .menu-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.site-menu {
    display: flex;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background-color: rgba(17, 17, 17, 0.98);
}

.site-menu[data-open="true"] {
    max-height: 200px;
}

.site-menu-link {
    color: #ffffff;
    text-decoration: none;
    padding: 14px 24px;
    font-size: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.site-menu-link:hover,
.site-menu-link:focus-visible {
    background-color: rgba(255, 255, 255, 0.08);
}

.site-menu-link[aria-current="page"] {
    font-weight: 700;
    color: #7fb4ff;
}

@media (prefers-reduced-motion: reduce) {
    .site-menu,
    .menu-toggle-bar {
        transition: none !important;
    }
}

/* ---------------------------------------------------------------------
   About Me page
   --------------------------------------------------------------------- */
.about-page {
    display: flex;
    justify-content: center;
    padding-top: 48px;
}

.about-card {
    max-width: 640px;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.92);
    border-radius: 12px;
    padding: 40px 36px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

.about-photo {
    display: block;
    margin: 0 auto 24px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    object-fit: cover;
    background-color: #eee;
    border: 3px solid rgba(255, 255, 255, 0.85);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Responsive sizing across device classes. The 140px base above already
   covers tablet-ish widths; these two rules scale it down for phones and
   up for notebook/desktop screens, so the photo neither dominates a small
   screen nor looks undersized on a large one. */
@media screen and (max-width: 480px) {
    .about-photo {
        width: 96px;
        height: 96px;
    }
}

@media screen and (min-width: 1025px) {
    .about-photo {
        width: 180px;
        height: 180px;
    }
}

.about-card h1 {
    margin-top: 0;
    font-weight: 700;
}

.about-card p {
    line-height: 1.6;
    color: #333;
}

.about-contact {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

@media screen and (max-width: 600px) {
    .about-card {
        padding: 28px 20px;
    }
}

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 4px 20px;
    font-size: 0.95rem;
}

.breadcrumb button {
    background: none;
    border: none;
    color: #1a5fb4;
    cursor: pointer;
    padding: 4px 6px;
    font-size: inherit;
    text-decoration: underline;
    -webkit-tap-highlight-color: transparent;
}

.breadcrumb button:hover,
.breadcrumb button:focus-visible {
    color: #0d3a75;
}

.breadcrumb button[aria-current="true"] {
    color: #333;
    text-decoration: none;
    font-weight: 600;
    cursor: default;
}

.breadcrumb .breadcrumb-sep {
    color: #999;
}

/* Status text (loading / error / empty) */
.status-message {
    text-align: center;
    color: #666;
    padding: 16px;
    min-height: 1.4em;
}

.status-message.error {
    color: #b00020;
}

/* Shared grid used for both folders and images */
.cross-browser-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    gap: 16px;
}

.folder-grid {
    margin-bottom: 8px;
}

.folder-grid:empty {
    margin: 0;
}

/* Folder ("sub-portfolio") tile */
.folder-tile {
    width: 180px;
    height: 140px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px;
    background-color: #e4e6eb;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 8px;
    text-align: center;
    overflow: hidden;
}

.folder-tile:hover,
.folder-tile:focus-visible {
    background-color: #d7dae0;
}

.folder-tile:focus-visible {
    outline: 3px solid #4da3ff;
    outline-offset: 2px;
}

.folder-tile-icon {
    width: 100%;
    height: 70px;
    object-fit: cover;
    border-radius: 4px;
}

.folder-tile-icon-placeholder {
    width: 100%;
    height: 70px;
    border-radius: 4px;
    background-color: #c7cad1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.folder-tile-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #222;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Explicit container dimensions with fixed position context for Firefox & Safari */
.grid-img-container {
    width: 320px;
    height: 240px;
    position: relative;
    display: block;
    overflow: hidden;
    margin: 0;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.grid-img-container:focus-visible {
    outline: 3px solid #4da3ff;
    outline-offset: 2px;
}

.grid-img-container img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
}

/* Image zoom and caption-overlay visibility are driven by a JS-managed
   .is-active class (see script.js) rather than pure CSS :hover, because
   Safari (desktop and iOS/WebKit) has a well-documented bug where :hover
   can get "stuck" on an element after a click/tap -- WebKit only
   re-evaluates :hover on an actual pointer move, so if the mouse doesn't
   move between clicking a thumbnail and the lightbox closing again, the
   tile stays visually "hovered" indefinitely. Keyboard focus styling
   (:focus / :focus-within) is left as real CSS since that's unaffected by
   the bug and needs to keep working without JS for baseline accessibility. */
.grid-img-container:focus img,
.grid-img-container.is-active img {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}

.hover-text-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.grid-img-container:focus-within .hover-text-overlay,
.grid-img-container.is-active .hover-text-overlay {
    opacity: 1;
    visibility: visible;
}

/* Suppresses the overlay immediately after focus is restored
   programmatically (e.g. when the lightbox closes and sends focus back to
   the thumbnail that opened it). Without this, :focus-within keeps the
   overlay visibly "stuck" even though the user never tabbed to it
   themselves. See script.js closeLightbox(). */
.grid-img-container.suppress-focus-overlay .hover-text-overlay {
    opacity: 0 !important;
    visibility: hidden !important;
}

.grid-img-container.suppress-focus-overlay img {
    -webkit-transform: none !important;
    transform: none !important;
}

.hover-text-overlay p {
    margin: 0;
    padding: 16px;
    text-align: center;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.8);
    opacity: 0;
    -webkit-transform: translateY(10px);
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.grid-img-container:focus-within .hover-text-overlay p,
.grid-img-container.is-active .hover-text-overlay p {
    opacity: 1;
    -webkit-transform: translateY(0);
    transform: translateY(0);
}

.grid-img-container.suppress-focus-overlay .hover-text-overlay p {
    opacity: 0 !important;
}

/* Lightbox Modal Structure */
.lightbox-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(0, 0, 0, 0.92);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    touch-action: none;
    overscroll-behavior: contain;
}

.lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    z-index: 100000;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 2.2rem;
    line-height: 1;
    padding: 12px;
    cursor: pointer;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
    color: #cccccc;
}

@-webkit-keyframes scaleUp {
    from { -webkit-transform: scale(0.7); opacity: 0; }
    to { -webkit-transform: scale(1); opacity: 1; }
}

@keyframes scaleUp {
    from { transform: scale(0.7); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.lightbox-content {
    width: auto;
    height: auto;
    max-width: 88vw;
    max-height: 75vh;
    box-shadow: 0 4px 25px rgba(0,0,0,0.7);
    -webkit-animation: scaleUp 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    animation: scaleUp 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.lightbox-caption {
    color: #ffffff;
    font-size: 1.1rem;
    margin-top: 15px;
    text-align: center;
    padding: 0 20px;
    max-width: 90vw;
}

@media (prefers-reduced-motion: reduce) {
    .grid-img-container img,
    .hover-text-overlay,
    .hover-text-overlay p,
    .lightbox-content {
        transition: none !important;
        -webkit-animation: none !important;
        animation: none !important;
    }
}

.lightbox-btn {
    position: absolute;
    top: 50%;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 2.2rem;
    padding: 12px 18px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.3s ease;
    z-index: 100000;
    border-radius: 4px;
}

.lightbox-btn:hover,
.lightbox-btn:focus-visible {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev {
    left: 15px;
}

.lightbox-next {
    right: 15px;
}

@media screen and (max-width: 600px) {
    .lightbox-btn {
        padding: 8px 14px;
        font-size: 1.8rem;
    }
    .lightbox-prev { left: 8px; }
    .lightbox-next { right: 8px; }

    .folder-tile {
        width: 140px;
        height: 120px;
    }
}
