/* Responsive hardening; load after the existing component styles.
   Keeps the approved palette/fonts. Navigation and lullaby player own their layouts. */

/* 1. Intrinsic sizes, Persian wrapping, and flexible content rows. */
#main :is(h1,h2,h3,p,blockquote,.breadcrumbs,.reading-source>a){overflow-wrap:break-word;overflow-wrap:anywhere}
#main :is(.hero,.category-grid,.family-section,.family-features,.quiz-layout,.dashboard-layout,.watch-layout,.article-card,.guide-hero,.guide-featured,.guide-next,.reading-layout,.ext-account-layout,.ext-about-story,.ext-contact-layout,.ext-contact-faq,.ext-episode-layout)>*{min-width:0}
#main :is(.search-box,.catalog-search,.select-wrap,.sort-label,.shorts-main,.guide-search-field,.ext-series-toolbar){min-width:0;max-width:100%}
#main .button,dialog:not(.shorts-viewer) .button{max-width:100%;white-space:normal;overflow-wrap:anywhere}
.breadcrumbs{flex-wrap:wrap;gap:6px 10px}
.breadcrumbs>*{min-width:0}
.section-heading,.catalog-meta,.watch-title,.ext-end-note,.ext-series-detail-actions,.ext-series-toolbar{flex-wrap:wrap}
.section-heading>.text-link{white-space:normal}
.hero-actions,.hero-trust,.category-links,.dashboard-side{flex-wrap:wrap}
.card-body h3{white-space:normal;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}
.ext-account-panel,.ext-about-path>div,.ext-saved-shorts>div,.guide-library-heading>div,.guide-next-links a>span:nth-child(2){min-width:0}
.ext-series-filter,.filter-tabs,.shorts-filters,.guide-topic-filters{min-width:0;max-width:100%;overscroll-behavior-x:contain}
.ext-series-filter button,.filter-tabs button,.shorts-filters button{flex-shrink:0}
.shorts-filters{margin-left:0;padding-left:0}
.guide-library-heading{flex-wrap:wrap}
.guide-library-heading>p{white-space:normal}
.reading-checklist-items label{min-height:44px}

/* 2. Dialogs remain scrollable as the available browser viewport changes. */
dialog:not(.shorts-viewer){max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);overflow:auto;overscroll-behavior:contain}
dialog:not(.shorts-viewer) .search-box input{min-width:0;flex:1 1 120px;width:0}
dialog:not(.shorts-viewer) :is(input,textarea,select){max-width:100%;font-size:16px}
dialog:not(.shorts-viewer) .search-box{min-width:0}

/* 3. Immersive Shorts: vh fallback, then dynamic viewport; no page/nav padding. */
dialog.shorts-viewer{position:fixed;inset:0;width:100%;height:100vh;height:100dvh;max-height:none}
dialog.shorts-viewer[open]{display:flex;flex-direction:column}
.shorts-viewer-top{flex:0 0 auto;height:auto;min-height:73px;padding-top:calc(12px + env(safe-area-inset-top,0px));padding-left:max(15px,env(safe-area-inset-left,0px));padding-right:max(15px,env(safe-area-inset-right,0px))}
.shorts-viewer-stage{display:flex;flex:1 1 auto;height:auto;min-height:0;min-width:0}
.shorts-feed{min-width:0;min-height:0;max-height:min(100%,850px);flex-shrink:1}
.reel{min-width:0;max-width:100%}
.reel-caption{bottom:calc(76px + env(safe-area-inset-bottom,0px));min-width:0}
.reel-caption h2{overflow-wrap:anywhere;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;max-height:5.4em}
.reel-controls{bottom:calc(8px + env(safe-area-inset-bottom,0px));left:max(12px,env(safe-area-inset-left,0px));right:max(12px,env(safe-area-inset-right,0px));gap:8px}
.reel-controls button,.shorts-back{width:auto;min-width:44px;min-height:44px;height:44px}
.reel-controls button{width:44px}
.reel-controls input[type=range]{height:44px;min-width:0;padding:0;margin:0;flex:1 1 0;touch-action:manipulation}
.reel-controls>span{flex:0 0 auto;min-width:44px}
.reel-topline{min-width:0;flex-wrap:wrap;overflow-wrap:anywhere}
.reel-status{max-height:28%;overflow:auto;overflow-wrap:anywhere}
.reel-no-media{max-height:40%;overflow:auto}
.shorts-feedback{max-width:calc(100% - 24px);flex-wrap:wrap;overflow-wrap:anywhere}

/* 4. Tablets: keep text columns shrinkable without forcing phone layouts. */
@media(min-width:701px) and (max-width:1024px){
 .hero{grid-template-columns:minmax(0,1.1fr) minmax(0,1fr)}
 .hero-actions{gap:10px}
 .quiz-layout{grid-template-columns:minmax(0,.9fr) minmax(0,1.1fr)}
 .category-grid,.family-features{grid-template-columns:repeat(2,minmax(0,1fr))}
 .ext-account-layout{grid-template-columns:repeat(2,minmax(0,1fr))}
 .ext-episode-layout{grid-template-columns:minmax(0,310px) minmax(0,1fr)}
 .ext-about-v2 .ext-about-hero,.ext-contact-hero,.guide-hero{grid-template-columns:minmax(0,1.2fr) minmax(0,1fr)}
 .placement-banner,.catalog-series-banner,.ext-about-final{flex-wrap:wrap}
 .ext-about-v2 .ext-about-copy h1{font-size:clamp(2.35rem,4.2vw,3.45rem)}
 .ext-series-filter{flex-wrap:wrap}
}

/* 5. Phones and touch controls; the audio component has its own matching rules. */
@media(max-width:700px),(pointer:coarse){
 body:not([data-page=lullabies]) #main :is(input:not([type=range]):not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea){font-size:16px}
 body:not([data-page=lullabies]) #main button,dialog button{min-width:44px;min-height:44px}
 #main :is(.category-links>a,.ext-link-row>a,.ext-account-switch>a,.ext-about-jump>a,.reading-back,.reading-toc a,.reading-mobile-toc a){min-height:44px;display:inline-flex;align-items:center}
 #main :is(.save-button,.short-tile-save){width:44px;height:44px;flex-shrink:0}
 .short-tile-save{top:4px;left:4px}
 .shorts-saved-link{width:44px;height:44px}
 #main summary{min-height:44px}
 .shorts-viewer-top{min-height:62px;padding-bottom:6px;padding-top:calc(6px + env(safe-area-inset-top,0px))}
 .shorts-viewer-stage{padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px)}
 .reel-actions{bottom:calc(118px + env(safe-area-inset-bottom,0px))}
 .card-overline{gap:5px}
}
@media(max-width:700px){
 .shorts-feed{max-height:100%}
 .ext-account-art{grid-template-columns:minmax(0,145px) minmax(0,1fr)}
 .ext-series-detail-actions .button,.ext-saved-links .button,.ext-draft-actions .button{flex:0 1 auto}
 .ext-series-filter{overflow-x:auto}
 .watch-title>div{min-width:0;flex:1 1 180px}
 .shorts-grid-heading{flex-wrap:wrap}
 .shorts-grid-heading>span{white-space:normal}
 .ad-unit-label{flex-wrap:wrap}
 .reel-caption p{overflow-wrap:anywhere}
}

/* 6. Narrow phones: 280–480px, including compact Android and iPhone SE widths. */
@media(max-width:480px){
 .hero-actions .button{flex:1 1 150px}
 .category-grid,.family-features,.quiz-options{grid-template-columns:repeat(2,minmax(0,1fr))}
 .hero h1{font-size:clamp(2.35rem,10.5vw,3.6rem)}
 .hero .underline-word{white-space:normal}
 .catalog-search .select-wrap{flex:1 1 100%;justify-content:space-between}
 .catalog-search .select-wrap select{flex:1;max-width:80%}
 .catalog-meta .sort-label{min-width:0;max-width:100%}
 .watch-sidebar,.word-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .quiz-story>p{max-width:100%}
 .quiz-story>img{position:static;margin:12px auto 0;height:130px;width:130px}
 .quiz-box,.dashboard-card{padding:24px 18px}
 .ext-about-v2 .ext-about-actions .button{flex:1 1 160px}
 .ext-about-jump{grid-template-columns:repeat(2,minmax(0,1fr))}
 .ext-series-intro .ext-series-collage{width:100%;max-width:280px}
 .ext-account-art{grid-template-columns:minmax(0,110px) minmax(0,1fr);gap:12px}
 .ext-account-art>img{max-width:100%;height:155px}
 .ext-about-v2 .ext-about-copy h1,.ext-contact-hero h1{font-size:clamp(2.15rem,9.7vw,3.2rem)}
 .ext-contact-v2 .ext-contact-form-card{padding-inline:18px}
 .ext-contact-v2 .ext-draft-notice{padding:12px;gap:8px}
 .ext-topic-guide{grid-template-columns:minmax(0,1fr)}
 .ext-topic-guide-icon{display:none}
 .guide-library-heading>p{max-width:none;margin-top:0}
 .reading-section h2{overflow-wrap:anywhere}
 .ad-preview-art>img,.ad-unit--inline .ad-preview-art>img{max-width:100%;object-fit:contain}
 dialog:not(.shorts-viewer){width:calc(100% - 24px);padding:30px 18px 24px}
 dialog:not(.shorts-viewer) .search-box>.button{flex-basis:100%}
 .footer-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .footer-about{grid-column:1/-1}
}
@media(max-width:360px){
 #main>.container{width:calc(100% - 24px)}
 .shorts-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
 .video-grid,.dashboard-layout .video-grid,.article-card{grid-template-columns:minmax(0,1fr)}
 .article-card .article-image{aspect-ratio:16/9;min-height:0}
 .category-grid,.family-features,.quiz-options,.word-grid,.watch-sidebar{grid-template-columns:minmax(0,1fr)}
 .spotlight-reels{gap:8px}
 .short-tile-home{height:165px}
 .spotlight-copy h2{font-size:1.85rem}
 .ext-account-art{grid-template-columns:minmax(0,85px) minmax(0,1fr);padding:20px 16px}
 .ext-account-art h2{font-size:1.7rem}
 .ext-account-art>img{height:135px}
 .ext-help-topic-grid{grid-template-columns:minmax(0,1fr)}
 .ext-help-topic{min-height:0}
 .ext-about-path{grid-template-columns:minmax(0,1fr)}
 .ext-path-image,.ext-path-night-art,.ext-path-parent-art{display:none}
 .ext-saved-shorts{grid-template-columns:62px minmax(0,1fr);gap:13px;padding:20px 16px}
 .ext-saved-shorts-poster{width:62px;height:95px}
 .guide-search-field{flex-wrap:wrap}
 .guide-search-field>input[type=search]{flex:1 1 calc(100% - 32px)}
 .guide-search-field>button{flex-basis:100%}
 .ad-preview-creative,.ad-unit--inline .ad-preview-creative{grid-template-columns:minmax(0,1fr);padding:20px 17px}
 .ad-preview-art,.ad-unit--inline .ad-preview-art{display:none}
 .ad-preview-cta,.ad-unit--inline .ad-preview-cta{grid-column:1}
 .footer-grid{grid-template-columns:minmax(0,1fr)}
}

/* 7. Landscape/notches and short windows: every Reel action stays in the frame. */
@media(orientation:landscape) and (max-width:1024px){
 #main>.container{max-width:calc(100% - max(16px,env(safe-area-inset-left,0px)) - max(16px,env(safe-area-inset-right,0px)))}
}
@media(max-height:560px){
 .shorts-viewer-top{min-height:50px;padding-top:calc(3px + env(safe-area-inset-top,0px));padding-bottom:3px}
 .shorts-viewer-stage{padding-top:0;padding-bottom:0}
 .shorts-feed{max-width:520px;border-radius:0}
 .reels-desktop-copy,.reel-navigation,.reel-brand{display:none}
 .reel-actions{right:12px;left:12px;width:auto;bottom:calc(60px + env(safe-area-inset-bottom,0px));flex-direction:row;justify-content:flex-end;gap:4px}
 .reel-actions button{width:44px;height:44px;min-height:44px;flex:0 0 44px;gap:0}
 .reel-actions button>span,.reel-caption p,.reel-caption-tags,.reel-publisher{display:none}
 .reel-caption{right:16px;left:16px;bottom:calc(110px + env(safe-area-inset-bottom,0px))}
 .reel-caption h2{font-size:14px;line-height:1.5;-webkit-line-clamp:2;max-height:3em;margin:0}
 .reel-play{height:44px;width:44px;top:10px;left:calc(50% - 22px)}
 .reel-topline{top:9px;right:12px;left:12px;max-width:42%}
 .reel-status{top:56px;max-height:25%;font-size:14px}
 .reel-no-media{top:22%;max-height:32%}
}

/* 8. Avoid sticky hover motion on touch; preserve pinch zoom and reduced motion. */
@media(hover:none),(pointer:coarse){
 #main .button:hover,.guide-card:hover,.ext-series-card:hover,.ext-about-path:hover{transform:none}
 .short-tile:hover img,.guide-card:hover img,.guide-featured:hover img,.ext-series-card:hover img{transform:none}
 .reel.is-playing:hover .reel-play{opacity:0}
 .reel.is-playing .reel-play:focus-visible{opacity:1}
}
@media(prefers-reduced-motion:reduce){
 .shorts-feed,.shorts-filters,.guide-topic-filters{scroll-behavior:auto!important}
 .short-tile,.short-tile img,.reel-play,.guide-card,.ext-series-card,.ext-about-path{transition:none!important}
}
