/* Mobile & touch optimizations */

html {
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
}

.author-img {
    width: 100%;
    max-width: 250px;
    height: auto;
    object-fit: cover;
}

/* Safe area for notched devices */
#header.fixed-top {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* --- Navbar --- */
@media (max-width: 767.98px) {
    .site-brand {
        max-width: calc(100% - 3.5rem);
    }

    .site-brand__name {
        font-size: 1.15rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .navbar-toggler {
        padding: 0.5rem 0.65rem;
    }

    .navbar-collapse {
        margin-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .navbar-nav .nav-link {
        font-size: 1.2rem;
    }

    body {
        padding-top: 58px;
    }
}

/* --- Layout spacing --- */
@media (max-width: 767.98px) {
    .container.my-5,
    .container.my-4 {
        margin-top: 1.25rem !important;
        margin-bottom: 1.5rem !important;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    h1:not(.page-header__title) {
        font-size: 1.5rem;
    }

    h2:not(.section-heading) {
        font-size: 1.35rem;
    }

    .breadcrumb {
        font-size: 0.85rem;
        flex-wrap: wrap;
        padding: 0.5rem 0.75rem;
        margin-bottom: 1rem;
    }
}

/* --- Home & contact author column --- */
@media (max-width: 991.98px) {
    .author-info {
        margin-bottom: 1.5rem !important;
    }

    .author-img {
        width: min(220px, 70vw) !important;
        height: min(220px, 70vw) !important;
    }
}

@media (max-width: 767.98px) {
    .author-img {
        width: min(180px, 60vw) !important;
        height: min(180px, 60vw) !important;
    }

    main p,
    main li {
        font-size: 1rem;
        line-height: 1.6;
    }
}

/* --- Contact --- */
@media (max-width: 767.98px) {
    .contact-link {
        padding: 0.75rem 1.25rem;
        font-size: 1.05rem;
        min-height: 44px;
    }

    .form-control {
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    .btn-lg {
        min-height: 48px;
        font-size: 1.05rem;
    }
}

/* --- Books grid --- */

#books-container.books-grid {
    width: 100%;
}

@media (max-width: 1199.98px) {
    #books-container.books-grid {
        justify-content: center !important;
        align-items: center;
        margin-left: auto;
        margin-right: auto;
        padding-left: 0;
        padding-right: 0;
    }

    #books-container .book-card {
        justify-content: center;
        align-items: stretch;
    }

    #books-container .card-link {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    #books-container .book-card .card {
        width: 100% !important;
        max-width: 100%;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

@media (max-width: 991.98px) {
    #books-container.books-grid {
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
    }

    #books-container .book-card,
    #books-container .book-card.ghost {
        flex: 0 0 auto !important;
        width: 100%;
        max-width: 22rem !important;
    }
}

@media (max-width: 767.98px) {
    #books-container.books-grid {
        padding: 0;
        gap: 1rem;
    }

    #books-container .book-card.ghost {
        display: none !important;
    }

    #books-container .book-card {
        margin-bottom: 0;
        max-width: min(22rem, 100%) !important;
    }

    #books-container .book-card .card {
        margin: 0 auto !important;
    }

    #books-container .card-img-top {
        height: auto !important;
        max-height: 280px;
    }

    #books-container .card-title {
        height: auto !important;
        min-height: 0;
        padding: 0.25rem 0;
    }

    #books-container .card-text {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
    }

    #books-container .card-text p {
        font-size: 0.875rem;
        line-height: 1.4;
    }

    #books-container .card::after {
        display: none !important;
    }
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    #books-container .book-card .card {
        width: 100% !important;
        max-width: 100%;
    }
}

/* --- Book detail, reviews, TOC --- */
@media (max-width: 767.98px) {
    .sidebar {
        position: static !important;
        top: auto !important;
        margin-top: 0 !important;
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid #e9ecef;
    }

    .sidebar__cover {
        max-width: min(200px, 55vw);
        margin-bottom: 1rem;
    }

    .sidebar .sidebar__title {
        font-size: 1.15rem !important;
        line-height: 1.45;
        text-align: center;
    }

    .sidebar .text-muted,
    .sidebar .sidebar__meta {
        text-align: center;
    }

    #sidebar-container .sidebar__title {
        display: none;
    }

    #sidebar-container .sidebar__info {
        display: none;
    }

    .book-nav {
        margin-top: 0;
        padding-top: 0.75rem;
    }

    .book-nav__link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    #reviews-preview .btn,
    #toc-preview .btn {
        display: block;
        width: 100%;
        min-height: 44px;
        margin-top: 0.75rem !important;
    }

    .book-flow {
        flex-direction: column;
        gap: 0.5rem;
    }

    .book-flow__link {
        display: block;
        min-height: 44px;
        line-height: 44px;
    }

    .blockquote {
        font-size: 0.95rem;
    }
}

/* --- Events --- */
@media (max-width: 767.98px) {
    .event-card__title {
        min-width: 0;
        font-size: 1.05rem;
    }

    .event-card__body {
        padding: 0.85rem 1rem;
    }

    .event-card__badge {
        font-size: 0.65rem;
    }
}

/* --- PDF modal --- */
@media (max-width: 767.98px) {
    #pdfModal .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    #pdfModal .modal-body {
        padding: 0.5rem;
    }

    #pdfIframe {
        height: 60vh !important;
        min-height: 300px;
    }

    #pdfModal .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    #pdfModal .modal-footer .btn {
        min-height: 44px;
    }
}

/* --- Footer --- */
@media (max-width: 767.98px) {
    footer {
        font-size: 0.85rem;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* --- Touch device interactions --- */
@media (hover: none) and (pointer: coarse) {
    .card-link:hover .card {
        transform: none !important;
        box-shadow: none !important;
    }

    .card-link:active .card {
        opacity: 0.92;
    }

    .btn-purchase-cta:hover,
    .btn-purchase-cta:focus {
        transform: none;
    }

    .event-card:hover {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }
}
