/*
 * Mobile-aware layer for the Publications, Projects and Blog pages.
 * Loaded AFTER css/style.css and the page stylesheet, so it only overrides what is needed.
 *
 * Part 1 - base rules (all screen sizes)
 * Part 2 - phones and small tablets (<= 700px)
 * Part 3 - touch devices and reduced motion
 */

/* ======================================================================
   1. PERFORMANCE
   ====================================================================== */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Desktop auto-load: the photo is just a quiet placeholder, no button or "Loading" text. */
.model-auto .model-activate {
    pointer-events: none;
    cursor: default;
}
.model-auto .model-activate span {
    display: none;
}

/* Images never overflow their column. */
img,
model-viewer {
    max-width: 100%;
}

/* "Activate 3D" poster button (markup + loading logic live in js/page-performance.js). */
.model-activate img {
    box-shadow:
        0 0 0 3px rgba(141, 235, 220, 0.35),
        0 12px 28px rgba(0, 0, 0, 0.45);
}
.model-activate span {
    font-weight: 600;
    letter-spacing: 0.2px;
}

/* ======================================================================
   2. PHONES (<= 700px)
   ====================================================================== */
@media (max-width: 700px) {
    body {
        overflow-x: hidden;
    }

    /* ---- navigation: single tidy row, big touch targets ---- */
    .navbar,
    .publications-page .navbar,
    .projects-page .navbar,
    .personal-blog .navbar {
        position: sticky;
        top: 0;
        display: grid;
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 6px;
        padding: 8px 10px calc(8px + env(safe-area-inset-top, 0px) * 0);
    }
    .nav-signature {
        font-size: 1.35rem;
        line-height: 1.1;
        text-align: center;
    }
    .nav-digital-life {
        display: none;
    }
    .nav-menu {
        display: flex;
        justify-content: center;
        flex-wrap: nowrap;
        gap: 4px;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .nav-menu::-webkit-scrollbar {
        display: none;
    }
    .navbar .nav-btn,
    .publications-page .nav-btn,
    .projects-page .nav-btn,
    .personal-blog .nav-btn {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 44px;
        padding: 8px 12px;
        font-size: 12.5px;
        white-space: nowrap;
    }
    .navbar .nav-btn i {
        margin: 0;
    }

    /* ---- hero: avatar becomes the headline visual instead of hiding behind the text ---- */
    .publications-page .project-hero,
    .projects-page .project-hero,
    .personal-blog .project-hero {
        margin: 12px 12px 0;
        padding: 22px 18px 26px;
        border-radius: 20px;
    }
    .publications-page .hero-layout,
    .projects-page .hero-layout,
    .personal-blog .hero-layout {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        padding: 0;
    }
    .publications-page model-viewer.hero-avatar,
    .personal-blog model-viewer.hero-avatar,
    .projects-page .hero-model-wrap {
        position: relative;
        order: -1;
        inset: auto;
        flex: none;
        align-self: center;
        width: min(70vw, 280px);
        height: min(70vw, 280px);
        margin: 0 auto 4px;
        /* No overflow:hidden / border-radius here: clipping a WebGL canvas can hide the model. */
        overflow: visible;
        box-shadow: none;
    }
    .projects-page .hero-model-wrap model-viewer {
        width: 100%;
        height: 100%;
    }
    .model-activate {
        gap: 12px;
    }
    .model-activate img {
        width: min(58vw, 220px);
    }
    .model-activate span {
        min-height: 40px;
        padding: 11px 18px;
        border-radius: 999px;
        font-size: 13px;
    }
    .publications-page .eyebrow,
    .projects-page .eyebrow,
    .personal-blog .eyebrow {
        padding-right: 0;
        justify-content: center;
    }
    .publications-page .project-hero h1,
    .projects-page .project-hero h1,
    .personal-blog .project-hero h1 {
        margin: 10px 0 6px;
        font-size: clamp(32px, 9.5vw, 44px);
        text-align: center;
    }
    .publications-page .hero-description,
    .projects-page .hero-description,
    .personal-blog .hero-description {
        font-size: 14.5px;
        line-height: 1.7;
        text-align: center;
        margin-inline: auto;
    }
    .publications-page .topic-list,
    .projects-page .topic-list,
    .personal-blog .topic-list {
        justify-content: center;
        margin-top: 16px;
    }
    .projects-page .hero-actions {
        justify-content: center;
    }
    /* Fewer decorative twinkling stars: each one carries a drop-shadow filter. */
    .hero-stars .hero-star:nth-child(n + 8) {
        display: none;
    }

    /* ---- publications: search, filters and cards ---- */
    .publications-page .results-background {
        margin: 16px 12px 0;
        padding: 14px 12px;
        border-radius: 18px;
    }
    .publications-page .search-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 0 0 10px;
        padding: 0;
    }
    .publications-page .search-container #searchInput {
        grid-column: 1 / -1;
        width: 100%;
        min-height: 46px;
        font-size: 16px; /* 16px stops iOS Safari zooming the page on focus */
    }
    .publications-page .search-container #searchButton {
        grid-column: 1 / -1;
    }
    .publications-page .search-container button,
    .publications-page .search-container .download-japanese-btn {
        min-height: 46px;
        width: 100%;
        justify-content: center;
    }
    .publications-page .filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 0;
        margin: 0 0 10px;
    }
    .publications-page .filters select {
        width: 100%;
        min-width: 0;
        min-height: 46px;
        font-size: 16px;
    }
    .publications-page .filters .keyword-row {
        grid-column: 1 / -1;
    }
    .publications-page #publicationsContainer {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
        padding: 6px 0 16px;
    }
    .publications-page #publicationsContainer .publication-card {
        max-width: none;
        width: 100%;
    }
    .publications-page #publicationsContainer .publication-thumbnail {
        height: 170px;
    }
    .publications-page #publicationsContainer .publication-content h3 {
        font-size: 16.5px;
    }
    .publications-page #publicationsContainer .publication-content p,
    .publications-page #publicationsContainer .publication-abstract {
        font-size: 13.5px;
    }
    .publications-page #publicationsContainer .tag {
        font-size: 11.5px;
        padding: 4px 9px;
    }
    .publications-page #publicationsContainer .paper-button {
        min-height: 40px;
        padding: 8px 14px;
        font-size: 13px;
    }

    /* ---- projects & blog: keep controls thumb-friendly ---- */
    .projects-page button,
    .personal-blog button {
        min-height: 40px;
    }
    .projects-page input,
    .projects-page select,
    .personal-blog input,
    .personal-blog select {
        font-size: 16px;
    }

    /* ---- footer ---- */
    footer {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    footer .footer-links a {
        font-size: 1.6rem;
        padding: 6px;
    }
}

/* Extra-small phones */
@media (max-width: 380px) {
    .nav-signature {
        font-size: 1.15rem;
    }
    .navbar .nav-btn,
    .publications-page .nav-btn,
    .projects-page .nav-btn,
    .personal-blog .nav-btn {
        padding: 8px 9px;
        font-size: 11.5px;
    }
    .publications-page .filters {
        grid-template-columns: 1fr;
    }
}

/* Phones turned sideways: avatar sits beside the copy instead of pushing it off-screen. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .publications-page .hero-layout,
    .projects-page .hero-layout,
    .personal-blog .hero-layout {
        flex-direction: row;
        align-items: center;
    }
    .publications-page model-viewer.hero-avatar,
    .personal-blog model-viewer.hero-avatar,
    .projects-page .hero-model-wrap {
        order: 2;
        width: 38vh;
        height: 38vh;
        margin: 0;
    }
}

/* ======================================================================
   3. TOUCH + REDUCED MOTION
   ====================================================================== */

/* No sticky hover lift on touch screens. */
@media (hover: none) {
    .publications-page #publicationsContainer .publication-card:hover,
    .paper-button:hover {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hero-star,
    .publications-page #publicationsContainer .publication-card::after {
        animation: none !important;
    }
    html {
        scroll-behavior: auto;
    }
}
