/**
 * Course UX polish layer
 * ======================
 * Shared layout / mobile / readability improvements for shell + hybrid courses.
 * Load after course-dual-mode-fix.css.
 */

/* Prevent horizontal page scroll from wide content */
html,
body[data-course-shell] {
    max-width: 100%;
    overflow-x: clip;
}

body[data-course-shell] .course-shell-stage,
body[data-course-shell] .container,
body[data-course-shell] .content {
    max-width: 100%;
    min-width: 0;
}

/* Tables: always scroll inside viewport on small screens */
body[data-course-shell] .content table,
body[data-course-shell] .container table,
body[data-course-shell] .card table,
body[data-course-shell] .slide table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
}

body[data-course-shell] .content table thead,
body[data-course-shell] .content table tbody,
body[data-course-shell] .content table tr {
    width: 100%;
}

body[data-course-shell] .content th,
body[data-course-shell] .content td {
    white-space: nowrap;
}

body[data-course-shell] .content th {
    white-space: normal;
}

@media (min-width: 769px) {
    body[data-course-shell] .content th,
    body[data-course-shell] .content td {
        white-space: normal;
    }
}

/* Cards and content: tighter, more readable rhythm */
body[data-course-shell] .card,
body[data-course-shell] .icon-card,
body[data-course-shell] .highlight-box {
    border-radius: 1rem;
    box-sizing: border-box;
}

body[data-course-shell] .content p,
body[data-course-shell] .content li {
    line-height: 1.7;
    overflow-wrap: anywhere;
    word-break: break-word;
}

body[data-course-shell] .content img,
body[data-course-shell] .card img,
body[data-course-shell] .slide img {
    max-width: 100%;
    height: auto;
}

/* Pre / code blocks */
body[data-course-shell] pre,
body[data-course-shell] code {
    max-width: 100%;
    overflow-x: auto;
}

/* Grid safety: never force overflow */
body[data-course-shell] .grid-2,
body[data-course-shell] .grid-3,
body[data-course-shell] .grid-4 {
    width: 100%;
    min-width: 0;
}

/* Topbar: keep actions usable on narrow phones */
@media (max-width: 640px) {
    body[data-course-shell] {
        --course-shell-topbar-height: 118px;
    }

    body[data-course-shell] .course-shell-topbar__cluster--meta .course-shell-chip[data-shell-meta="time"] {
        display: none;
    }

    body[data-course-shell] .course-shell-back-link span {
        display: none;
    }

    body[data-course-shell] .course-shell-focus-btn span,
    body[data-course-shell] .course-shell-review-btn span,
    body[data-course-shell] .course-shell-notes-btn span,
    body[data-course-shell] .course-shell-bookmark-btn span {
        display: none;
    }

    body[data-course-shell] .course-shell-focus-btn,
    body[data-course-shell] .course-shell-review-btn,
    body[data-course-shell] .course-shell-notes-btn,
    body[data-course-shell] .course-shell-bookmark-btn {
        min-width: 44px;
        width: 44px;
        padding: 0;
    }

    body[data-course-shell] .course-shell-topbar__center .course-shell-topbar__title {
        max-width: min(42vw, 160px);
    }

    body[data-course-shell] .nav-buttons {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    body[data-course-shell] .nav-buttons .btn,
    body[data-course-shell] .nav-buttons button {
        width: 100%;
        justify-content: center;
    }

    body[data-course-shell] .header h1 {
        font-size: clamp(1.35rem, 5.5vw, 1.75rem);
        line-height: 1.25;
    }

    body[data-course-shell] .section-title {
        font-size: clamp(1.1rem, 4.5vw, 1.35rem);
    }
}

/* Medium phones / small tablets */
@media (max-width: 768px) {
    body[data-course-shell] .grid-2,
    body[data-course-shell] .grid-3,
    body[data-course-shell] .grid-4 {
        grid-template-columns: 1fr !important;
    }

    body[data-course-shell] .container {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    body[data-course-shell] .card,
    body[data-course-shell] .icon-card,
    body[data-course-shell] .highlight-box {
        padding: 0.95rem 1rem;
    }

    body[data-course-shell] .slide {
        padding-bottom: 2rem;
    }
}

/* Desktop breathing room */
@media (min-width: 1200px) {
    body[data-course-shell] .course-shell-stage .container {
        max-width: 1100px;
    }
}

/* Theme toggle always tappable and not clipped */
body[data-course-shell] .course-shell-theme-btn,
body[data-course-shell] #course-shell-theme-toggle {
    flex-shrink: 0;
    z-index: 2;
}

/* Quiz options: better touch targets */
body[data-course-shell] .quiz-option {
    min-height: 48px;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    text-align: left;
}

/* Floating legacy theme buttons: don't collide with shell topbar */
body[data-course-shell] .theme-toggle-btn:not(.course-shell-theme-btn) {
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    right: max(1rem, env(safe-area-inset-right));
}

/* Safe areas for notched phones */
@supports (padding: max(0px)) {
    body[data-course-shell] .course-shell-topbar {
        padding-left: max(0.8rem, env(safe-area-inset-left));
        padding-right: max(0.8rem, env(safe-area-inset-right));
    }
}

/* Light-mode polish: card elevation without harsh borders */
html[data-theme="light"] body[data-course-shell]:not(.dark-mode) .card,
html[data-theme="light"] body[data-course-shell]:not(.dark-mode) .icon-card {
    box-shadow: 0 10px 30px -22px rgba(15, 23, 42, 0.28);
}

/* Dark-mode polish: softer surfaces */
html[data-theme="dark"] body[data-course-shell] .card,
html[data-theme="dark"] body[data-course-shell] .icon-card,
html.dark-mode body[data-course-shell] .card,
body.dark-mode[data-course-shell] .card {
    box-shadow: 0 12px 32px -24px rgba(0, 0, 0, 0.55);
}

/* Hybrid content lists spacing */
body[data-course-shell] .content ul,
body[data-course-shell] .content ol {
    padding-left: 1.25rem;
    margin: 0.75rem 0 1rem;
}

body[data-course-shell] .content li + li {
    margin-top: 0.4rem;
}

/* Ensure header content doesn't crash into topbar */
body[data-course-shell] .course-shell-stage .slide > .container {
    padding-top: 0.25rem;
}
