html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100%;
    min-height: -webkit-fill-available;
    overscroll-behavior: none;
}

button,
.list-item,
.user-highlight,
.spoiler {
    -webkit-tap-highlight-color: transparent;
}

.content-titlebar {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.mobile-panel-actions,
.mobile-scrim {
    display: none;
}

.markdown-body pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.markdown-body img,
.markdown-body video {
    max-width: 100%;
    height: auto;
}

@media (max-width: 860px) {
    body {
        height: var(--app-viewport-height, 100dvh);
        width: 100%;
        position: fixed;
        inset: 0;
    }

    body.mobile-panel-open {
        touch-action: none;
    }

    .app-container {
        position: relative;
        height: var(--app-viewport-height, 100dvh);
        width: 100%;
        overflow: hidden;
    }

    .content-area {
        width: 100%;
        min-width: 100%;
        min-height: 0;
    }

    .content-header {
        height: auto;
        min-height: calc(56px + env(safe-area-inset-top));
        padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        align-items: stretch;
    }

    .content-titlebar {
        width: 100%;
        gap: 8px;
    }

    .mobile-panel-actions {
        display: flex;
        flex-shrink: 0;
        gap: 6px;
    }

    .mobile-panel-btn {
        width: auto;
        min-width: 46px;
        height: 34px;
        padding: 0 9px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
        background: var(--bg-sidebar-secondary);
    }

    .mobile-panel-btn[aria-expanded="true"] {
        color: var(--on-accent);
        border-color: var(--accent-color);
        background: var(--accent-color);
    }

    .content-header h1 {
        margin-right: 0;
        font-size: 15px;
        line-height: 1.35;
    }

    .actions {
        width: 100%;
        gap: 6px;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 1px;
    }

    .actions::-webkit-scrollbar {
        display: none;
    }

    .nav-btn {
        width: 34px;
        height: 34px;
        min-height: 34px;
        flex: 0 0 auto;
    }

    .mode-btn {
        min-width: 74px;
        padding: 0 9px;
        font-size: 12px;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 80;
        width: min(88vw, 360px);
        height: var(--app-viewport-height, 100dvh);
        max-width: none;
        border-right: 1px solid var(--border-color);
        box-shadow: 18px 0 42px rgba(0, 0, 0, 0.32);
        transform: translateX(-104%);
        transition: transform 0.22s ease, opacity 0.22s ease;
        opacity: 0.98;
        will-change: transform;
    }

    .episode-list {
        left: auto;
        right: 0;
        transform: translateX(104%);
        border-right: 0;
        border-left: 1px solid var(--border-color);
        box-shadow: -18px 0 42px rgba(0, 0, 0, 0.32);
    }

    .app-container[data-mobile-panel="series"] .series-list,
    .app-container[data-mobile-panel="episodes"] .episode-list {
        transform: translateX(0);
    }

    .app-container.immersive-mode .series-list,
    .app-container.immersive-mode .episode-list {
        width: min(88vw, 360px) !important;
        opacity: 0.98;
        pointer-events: auto;
        border-color: var(--border-color);
    }

    .mobile-scrim {
        position: fixed;
        inset: 0;
        z-index: 70;
        display: block;
        background: rgba(0, 0, 0, 0.38);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }

    .app-container[data-mobile-panel] .mobile-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-header {
        min-height: calc(62px + env(safe-area-inset-top));
        height: auto;
        padding: calc(16px + env(safe-area-inset-top)) 16px 14px;
    }

    .sidebar-content {
        padding: 8px 10px calc(18px + env(safe-area-inset-bottom));
    }

    .list-item {
        min-height: 44px;
        padding: 12px 12px;
        margin-bottom: 6px;
        font-size: 14px;
    }

    .list-item .text {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .markdown-body {
        max-width: none;
        width: 100%;
        padding: 22px max(17px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(17px, env(safe-area-inset-left));
        font-size: 17px;
        line-height: 1.82;
        overflow-x: hidden;
        touch-action: pan-y;
        scroll-padding-top: calc(86px + env(safe-area-inset-top));
    }

    .markdown-body h1 {
        font-size: 1.34em;
    }

    .markdown-body h2 {
        font-size: 1.18em;
    }

    .markdown-body p,
    .markdown-body li {
        overflow-wrap: anywhere;
    }

    .markdown-body table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .content-footer {
        padding: 10px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        gap: 8px;
        border-top: 1px solid var(--border-color);
        background: var(--header-bg);
        backdrop-filter: blur(10px);
    }

    .footer-nav-btn {
        min-width: 0;
        padding: 11px 10px;
        font-size: 12px;
        line-height: 1.35;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .fab-copy {
        right: max(16px, env(safe-area-inset-right));
        bottom: calc(76px + env(safe-area-inset-bottom));
        width: 52px;
        height: 52px;
    }

    .fab-copy::after,
    .user-highlight:hover::after {
        display: none;
    }

    .toast {
        width: calc(100% - 32px);
        max-width: 360px;
        bottom: calc(22px + env(safe-area-inset-bottom));
        text-align: center;
        border-radius: 999px;
    }
}

@media (max-width: 380px) {
    .content-header h1 {
        font-size: 14px;
    }

    .mode-btn {
        min-width: 68px;
        font-size: 11px;
    }

    .mobile-panel-btn {
        min-width: 42px;
        padding: 0 8px;
    }

    .markdown-body {
        font-size: 16px;
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
    }
}
